Class: YoutubePlaylist

Inherits:
Youtube show all
Defined in:
lib/youtube.rb

Instance Method Summary collapse

Methods inherited from WebRadio

instance

Constructor Details

#initialize(params, options) ⇒ YoutubePlaylist

Returns a new instance of YoutubePlaylist.



53
54
55
56
# File 'lib/youtube.rb', line 53

def initialize(params, options)
  super
  @target_content = ["contents", "twoColumnBrowseResultsRenderer", "tabs", 0, "tabRenderer", "content", "sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "playlistVideoListRenderer", "contents"].freeze
end

Instance Method Details

#downloadObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/youtube.rb', line 58

def download
    first_video(URI.open(@url).read) do |content|
        item = content['playlistVideoRenderer']
        @cover = item['thumbnail']['thumbnails'].last['url']
        title = item['title']['runs'][0]['text']
        serial = title.scan(/\d+/).first.to_i
        url = "https://www.youtube.com/watch?v=#{item["videoId"]}"

        mp4_file = serial_file title, @label, serial, 'mp4'
        mp3_file = serial_file title, @label, serial, 'mp3'

        youtube_download url, mp4_file, mp3_file
    end
end

#dumpObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/youtube.rb', line 73

def dump
 uri = URI(@url)
 tag = Hash[URI.decode_www_form(File.basename(uri.query))]['list']
 html = Nokogiri(uri.open.read)
 label, = html.css('title').text.split(/ - .*\Z/)
 return {
   tag => {
     'desc' => label,
     'url' => @url,
     'label' => label
   }
 }
end