Created
February 16, 2011 15:26
-
-
Save michitux/829555 to your computer and use it in GitHub Desktop.
Simple script for downloading Arte videos. Use at your own risk (and respect the copyright of Arte), it requires rtmpdump.
This file contains hidden or 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
#!/usr/bin/ruby | |
require 'net/http' | |
require 'cgi' | |
require 'rexml/document' | |
require 'optparse' | |
require 'time' | |
options = { | |
:lang => 'de', | |
:quality => 'hd' | |
} | |
OptionParser.new do |opts| | |
opts.on('-l', '--lang LANGUAGE', ['de', 'fr'], "Language (de, fr)") { |v| options[:lang] = v } | |
opts.on('-u', '--url URL', "URL to download from", :REQUIRED) { |v| options[:url] = v } | |
opts.on('-q', '--quality QUALITY', ['hd', 'EQ', 'sd'], 'Quality of the video (hd, EQ, sd)') { |v| options[:quality] = v } | |
opts.on('-o', '--output-file FILE', 'Location of the output file') { |v| options[:output_file] = v } | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts opts | |
exit | |
end | |
end.parse! | |
htmlContent = Net::HTTP.get_response(URI.parse(options[:url])).body | |
swfURL = htmlContent.scan(/var url_player = "(.*?\.swf)"/).first.first | |
xmlURL = CGI::unescape(htmlContent.scan(/videorefFileUrl=(.*?)"/).first.first) | |
languageXML = REXML::Document.new(Net::HTTP.get_response(URI.parse(xmlURL)).body) | |
qualityXMLURL = languageXML.elements["videoref/videos/video[@lang='" + options[:lang] + "']"].attributes['ref'] | |
qualityXML = REXML::Document.new(Net::HTTP.get_response(URI.parse(qualityXMLURL)).body) | |
streamURL = qualityXML.elements["video/urls/url[@quality='" + options[:quality] + "']"].text | |
if options[:output_file].nil? | |
options[:output_file] = Time.rfc2822(qualityXML.elements['video/dateVideo'].text).strftime("%Y-%m-%d-") + qualityXML.elements['video/name'].text.gsub('/','-') + '.mp4' | |
end | |
exec('rtmpdump', '--resume', '-r', streamURL, '-o', options[:output_file], '--swfVfy', swfURL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment