Last active
April 24, 2020 02:25
-
-
Save augustt198/240b5971a8b6cccafc8208e4e2b741d3 to your computer and use it in GitHub Desktop.
download lecture video from MIT ODL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ARGV.length != 1 | |
puts "Give one URL as argument" | |
exit | |
end | |
url = ARGV[0] | |
match = url.match(/\/videos\/([0-9a-f]+)/) | |
video_id = match[1] if match | |
if not video_id | |
puts "Could not find video ID" | |
exit | |
end | |
puts "Video id: #{video_id}" | |
MEDIA_URL = "https://d3tsb3m56iwvoq.cloudfront.net/transcoded/#{video_id}/video_1504127981921-c2jlwt%05d.ts" | |
i = 0 | |
while true | |
system("mkdir -p #{video_id}") | |
url_formatted = MEDIA_URL % i | |
cmd = ("wget -O #{video_id}/%05d.ts " % i) + url_formatted | |
res = system(cmd) | |
break if not res | |
i = i + 1 | |
puts "downloaded #{i}" | |
end | |
ffmpeg_file_list = (0..i).map do |n| | |
"file '%05d.ts'" % n | |
end.join("\n") | |
File.write("#{video_id}/list.txt", ffmpeg_file_list) | |
system("mkdir -p videos/") | |
system("ffmpeg -f concat -i #{video_id}/list.txt -vcodec copy -acodec copy videos/#{video_id}.mp4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment