Open an Io Stream from a Local File or Url

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



Leave a reply



Submit