viddl-rb 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/viddl-rb +1 -1
  2. data/plugins/youtube.rb +30 -9
  3. metadata +4 -4
@@ -29,7 +29,7 @@ PluginBase.registered_plugins.each do |plugin|
29
29
  begin
30
30
  download_queue = plugin.get_urls_and_filenames(url)
31
31
  rescue StandardError => e
32
- puts "Error while running the #{plugin.name.inspect} plugin. Maybe it has to be updated?"
32
+ puts "Error while running the #{plugin.name.inspect} plugin. Maybe it has to be updated? Error: #{e.message}."
33
33
  exit
34
34
  end
35
35
  download_queue.each do |url_name|
@@ -50,17 +50,37 @@ class Youtube < PluginBase
50
50
  puts "[YOUTUBE] ID FOUND: #{video_id}"
51
51
  end
52
52
  #let's get some infos about the video. data is urlencoded
53
- video_info = open("http://www.youtube.com/get_video_info?video_id=#{video_id}").read
54
-
53
+ yt_url = "http://www.youtube.com/get_video_info?video_id=#{video_id}"
54
+ video_info = open(yt_url).read
55
55
  #converting the huge infostring into a hash. simply by splitting it at the & and then splitting it into key and value arround the =
56
56
  #[...]blabla=blubb&narf=poit&marc=awesome[...]
57
57
  video_info_hash = Hash[*video_info.split("&").collect { |v|
58
- key, value = v.split "="
59
- value = CGI::unescape(value) if value
58
+ key, encoded_value = v.split("=")
59
+ if encoded_value.to_s.empty?
60
+ value = ""
61
+ else
62
+ #decode until everything is "normal"
63
+ while (encoded_value != CGI::unescape(encoded_value)) do
64
+ #"decoding"
65
+ encoded_value = CGI::unescape(encoded_value)
66
+ end
67
+ value = encoded_value
68
+ end
69
+
60
70
  if key =~ /_map/
71
+ orig_value = value
61
72
  value = value.split(",")
62
- value = if key == "fmt_map"
63
- Hash[*value.collect{ |v|
73
+ if key == "url_encoded_fmt_stream_map"
74
+ url_array = orig_value.split("url=").map{|url_string| url_string.chomp(",")}
75
+ result_hash = {}
76
+ url_array.each do |url|
77
+ next if url.to_s.empty?
78
+ format_id = url.match(/\&itag=(\d+)/)[1]
79
+ result_hash[format_id] = url
80
+ end
81
+ value = result_hash
82
+ elsif key == "fmt_map"
83
+ value = Hash[*value.collect{ |v|
64
84
  k2, *v2 = v.split("/")
65
85
  [k2, v2]
66
86
  }.flatten(1)]
@@ -82,7 +102,8 @@ class Youtube < PluginBase
82
102
 
83
103
 
84
104
  #for the formats, see: http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
85
- available_formats = video_info_hash["fmt_map"].keys
105
+ fmt_list = video_info_hash["fmt_list"]
106
+ available_formats = fmt_list.map{|format| format.split("/").first}
86
107
 
87
108
  format_ext = {}
88
109
  format_ext["38"] = {:extension => "mp4", :name => "MP4 Highest Quality 4096x3027 (H.264, AAC)"}
@@ -107,8 +128,8 @@ class Youtube < PluginBase
107
128
  #best quality seems always to be firsts
108
129
  puts "[YOUTUBE] formats available: #{available_formats.inspect} (downloading format #{selected_format} -> #{format_ext[selected_format][:name]})"
109
130
 
110
-
111
- download_url = video_info_hash["fmt_url_map"][selected_format]
131
+ #video_info_hash.keys.sort.each{|key| puts "#{key} : #{video_info_hash[key]}" }
132
+ download_url = video_info_hash["url_encoded_fmt_stream_map"][selected_format]
112
133
  file_name = title.delete("\"'").gsub(/[^0-9A-Za-z]/, '_') + "." + format_ext[selected_format][:extension]
113
134
  puts "downloading to " + file_name
114
135
  {:url => download_url, :name => file_name}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viddl-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marc Seeger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-28 00:00:00 +02:00
18
+ date: 2011-10-12 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency