Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

feature: download all videos from a user

  • Loading branch information...
commit 5e2d7ef66d0b2fffd1ae3fac58496dd940a0f73a 1 parent bef7ce2
Kalle Lindström authored

Showing 1 changed file with 26 additions and 8 deletions. Show diff stats Hide diff stats

  1. +26 8 plugins/youtube.rb
34 plugins/youtube.rb
@@ -5,6 +5,11 @@ def self.matches_provider?(url)
5 5 url.include?("youtube.com") || url.include?("youtu.be")
6 6 end
7 7
  8 + def self.get_video_urls(feed)
  9 + #get all videos and return their urls in an array
  10 + feed.search("//entry/link[@rel='alternate']").map { |link| link["href"] }
  11 + end
  12 +
8 13 def self.parse_playlist(url)
9 14 #http://www.youtube.com/view_play_list?p=F96B063007B44E1E&search_query=welt+auf+schwäbisch
10 15 #http://www.youtube.com/watch?v=9WEP5nCxkEY&videos=jKY836_WMhE&playnext_from=TL&playnext=1
@@ -14,17 +19,22 @@ def self.parse_playlist(url)
14 19 puts "[YOUTUBE] Playlist ID: #{playlist_ID}"
15 20 url_array = Array.new
16 21 video_info = Nokogiri::HTML(open("http://gdata.youtube.com/feeds/api/playlists/#{playlist_ID}?v=2"))
17   - video_info.search("//content").each do |video|
18   - url_array << video["url"] if video["url"].include?("http://www.youtube.com/v/") #filters out rtsp links
19   - end
  22 + url_array = self.get_video_urls(video_info)
  23 + puts "[YOUTUBE] #{url_array.size} links found!"
  24 + url_array
  25 + end
20 26
  27 + def self.parse_user(username)
  28 + puts "[YOUTUBE] User: #{username}"
  29 + user_video_feed = Nokogiri::HTML(open("http://gdata.youtube.com/feeds/api/users/#{username}/uploads?v=2"))
  30 + url_array = get_video_urls(user_video_feed)
21 31 puts "[YOUTUBE] #{url_array.size} links found!"
22 32 url_array
23 33 end
24   -
  34 +
25 35 def self.get_urls_and_filenames(url)
26 36 return_values = []
27   - if url.include?("view_play_list") || url.include?("playlist?list=")
  37 + if url.include?("view_play_list") || url.include?("playlist?list=") #if playlist
28 38 puts "[YOUTUBE] playlist found! analyzing..."
29 39 files = self.parse_playlist(url)
30 40 puts "[YOUTUBE] Starting playlist download"
@@ -32,12 +42,20 @@ def self.get_urls_and_filenames(url)
32 42 puts "[YOUTUBE] Downloading next movie on the playlist (#{file})"
33 43 return_values << self.grab_single_url_filename(file)
34 44 end
35   - else
  45 + elsif match = url.match(/\/user\/([\w\d]+)$/) #if user url, e.g. youtube.com/user/woot
  46 + username = match[1]
  47 + video_urls = self.parse_user(username)
  48 + puts "[YOUTUBE] Starting user videos download"
  49 + video_urls.each do |url|
  50 + puts "[YOUTUBE] Downloading next user video (#{url})"
  51 + return_values << self.grab_single_url_filename(url)
  52 + end
  53 + else #if single video
36 54 return_values << self.grab_single_url_filename(url)
37 55 end
38   - return_values
  56 + return_values
39 57 end
40   -
  58 +
41 59 def self.grab_single_url_filename(url)
42 60 #the youtube video ID looks like this: [...]v=abc5a5_afe5agae6g&[...], we only want the ID (the \w in the brackets)
43 61 #addition: might also look like this /v/abc5-a5afe5agae6g

0 comments on commit 5e2d7ef

Please sign in to comment.
Something went wrong with that request. Please try again.