viddl-rb 0.77 → 0.78

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/plugins/youtube.rb +32 -15
  2. metadata +6 -5
data/plugins/youtube.rb CHANGED
@@ -4,7 +4,7 @@ class Youtube < PluginBase
4
4
  # see http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
5
5
  # TODO: we don't have all the formats from the wiki article here
6
6
  VIDEO_FORMATS = {
7
- "38" => {:extension => "mp4", :name => "MP4 Highest Quality 4096x3027 (H.264, AAC)"},
7
+ "38" => {:extension => "mp4", :name => "MP4 Highest Quality 4096x3027 (H.264, AAC)"},
8
8
  "37" => {:extension => "mp4", :name => "MP4 Highest Quality 1920x1080 (H.264, AAC)"},
9
9
  "22" => {:extension => "mp4", :name => "MP4 1280x720 (H.264, AAC)"},
10
10
  "46" => {:extension => "webm", :name => "WebM 1920x1080 (VP8, Vorbis)"},
@@ -15,10 +15,10 @@ class Youtube < PluginBase
15
15
  "35" => {:extension => "flv", :name => "FLV 854x480 (H.264, AAC)"},
16
16
  "34" => {:extension => "flv", :name => "FLV 640x360 (H.264, AAC)"},
17
17
  "5" => {:extension => "flv", :name => "FLV 400x240 (Soerenson H.263)"},
18
- "17" => {:extension => "3gp", :name => "3gp"}
18
+ "17" => {:extension => "3gp", :name => "3gp"}
19
19
  }
20
20
 
21
- DEFAULT_FORMAT_ORDER = %w[38 37 22 45 44 18 35 34 5 7]
21
+ DEFAULT_FORMAT_ORDER = %w[38 37 22 46 45 44 43 18 35 34 5 17]
22
22
  VIDEO_INFO_URL = "http://www.youtube.com/get_video_info?video_id="
23
23
  VIDEO_INFO_PARMS = "&ps=default&eurl=&gl=US&hl=en"
24
24
 
@@ -53,20 +53,37 @@ class Youtube < PluginBase
53
53
  end
54
54
 
55
55
  def self.grab_single_url_filename(url)
56
+ grab_url_embeddable(url) || grab_url_non_embeddable(url)
57
+ end
58
+
59
+ def self.grab_url_embeddable(url)
56
60
  video_info = get_video_info(url)
57
61
  video_params = extract_video_parameters(video_info)
62
+ unless video_params[:embeddable]
63
+ notify("VIDEO IS NOT EMBEDDABLE")
64
+ return false
65
+ end
58
66
 
59
- if video_params[:embeddable]
60
- urls_formats = extract_urls_formats(video_info)
61
- selected_format = choose_format(urls_formats)
62
- title = video_params[:title]
63
- file_name = PluginBase.make_filename_safe(title) + "." + VIDEO_FORMATS[selected_format][:extension]
67
+ urls_formats = extract_urls_formats(video_info)
68
+ selected_format = choose_format(urls_formats)
69
+ title = video_params[:title]
70
+ file_name = PluginBase.make_filename_safe(title) + "." + VIDEO_FORMATS[selected_format][:extension]
64
71
 
65
- {:url => urls_formats[selected_format], :name => file_name}
66
- else
67
- notify "Video is not embeddable and can't be downloaded."
68
- :no_embed
69
- end
72
+ {:url => urls_formats[selected_format], :name => file_name}
73
+ end
74
+
75
+ def self.grab_url_non_embeddable(url)
76
+ video_info = open(url).read
77
+ stream_map = video_info[/url_encoded_fmt_stream_map\" *: *\"([^\"]+)\"/,1]
78
+ urls_formats = parse_stream_map(url_decode(stream_map))
79
+ selected_format = choose_format(urls_formats)
80
+ title = video_info[/<meta name="title" content="([^"]*)">/, 1]
81
+ file_name = PluginBase.make_filename_safe(title) + "." + VIDEO_FORMATS[selected_format][:extension]
82
+
83
+ # cleaning
84
+ clean_url = urls_formats[selected_format].gsub(/\\u0026[^&]*/, "")
85
+
86
+ {:url => clean_url, :name => file_name}
70
87
  end
71
88
 
72
89
  def self.get_video_info(url)
@@ -218,7 +235,7 @@ class Youtube < PluginBase
218
235
  urls_titles.merge!(grab_urls_and_titles(result_feed))
219
236
 
220
237
  #as long as the feed has a next link we follow it and add the resulting video urls
221
- loop do
238
+ loop do
222
239
  next_link = result_feed.search("//feed/link[@rel='next']").first
223
240
  break if next_link.nil?
224
241
  result_feed = Nokogiri::HTML(open(next_link["href"]))
@@ -232,7 +249,7 @@ class Youtube < PluginBase
232
249
  def grab_urls_and_titles(feed)
233
250
  feed.remove_namespaces! #so that we can get to the titles easily
234
251
  urls = feed.search("//entry/link[@rel='alternate']").map { |link| link["href"] }
235
- titles = feed.search("//entry/group/title").map { |title| title.text }
252
+ titles = feed.search("//entry/group/title").map { |title| title.text }
236
253
  Hash[urls.zip(titles)] #hash like this: url => title
237
254
  end
238
255
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viddl-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 145
4
+ hash: 151
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 77
9
- version: "0.77"
8
+ - 78
9
+ version: "0.78"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marc Seeger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-02-24 00:00:00 Z
17
+ date: 2013-03-21 00:00:00 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
@@ -160,9 +160,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements: []
161
161
 
162
162
  rubyforge_project: viddl-rb
163
- rubygems_version: 1.8.15
163
+ rubygems_version: 1.8.25
164
164
  signing_key:
165
165
  specification_version: 3
166
166
  summary: An extendable commandline video downloader for flash video sites.
167
167
  test_files: []
168
168
 
169
+ has_rdoc: false