class YoutubePlaylist

Public Class Methods

new(params, options) click to toggle source
Calls superclass method Youtube::new
# 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

Public Instance Methods

download() click to toggle source
# 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
dump() click to toggle source
# 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