Open an IO stream from a local file or url
open-uri is part of the standard Ruby library, and it will redefine the behavior of open
so that you can open a url, as well as a local file. It returns a File
object, so you should be able to call methods like read
and readlines
.
require 'open-uri'
file_contents = open('local-file.txt') { |f| f.read }
web_contents = open('http://www.stackoverflow.com') {|f| f.read }
Returning a stream from File.OpenRead()
You forgot to seek:
str.CopyTo(data);
data.Seek(0, SeekOrigin.Begin); // <-- missing line
byte[] buf = new byte[data.Length];
data.Read(buf, 0, buf.Length);
InputStream from a URL
Use java.net.URL#openStream()
with a proper URL (including the protocol!). E.g.
InputStream input = new URL("http://www.somewebsite.com/a.txt").openStream();
// ...
See also:
- Using java.net.URLConnection to fire and handle HTTP requests
Python adding files from URL to file on local file
You're doing it wrong. The gist of this answer has already been given by @Tempo810, you need to download the files separately and concatenate them into a single file later.
I am assuming you have both video1.mp4
and video2.mp4
downloaded from your urls separately. Now to combine them, you simply cannot use append to concat the files, since video files contains format header and metadata, and combining two media files into one means you need to rewrite new metadata and format header, and remove the old ones.
Instead you can use the the library moviepy
to save yourself. Here is a small sample of code how to utilise moviepy
's concatenate_videoclips()
to concat the files:
from moviepy.editor import VideoFileClip, concatenate_videoclips
# opening the clips
clip1 = VideoFileClip("video1.mp4")
clip3 = VideoFileClip("video2.mp4")
# lets concat them up
final_clip = concatenate_videoclips([clip1,clip2])
final_clip.write_videofile("output.mp4")
Your resulting combined file is output.mp4
. Thats it!
Related Topics
What Does the "===" Operator Do in Ruby
Difference Between Include and Require in Ruby
How Does Instance_Eval Work and Why Does Dhh Hate It
Ruby: Kind_Of? Vs. Instance_Of? Vs. Is_A
How to Install Sqlite3 For Ruby on Windows
Difference Between Collection Route and Member Route in Ruby on Rails
How to Get Source Code of a Method Dynamically and Also Which File Is This Method Locate In
Ruby Operator Precedence Table
Confusion With the Assignment Operation Inside a Falsy 'If' Block
Rails :Dependent =≫ :Destroy VS :Dependent =≫ :Delete_All
How to Avoid Tripping Over Utf-8 Bom When Reading Files
Difference Between Include and Extend in Ruby
Rails: Access to Current_User from Within a Model in Ruby on Rails