class PlaylistDownloader

Playlist downloader, calls SongDownloader for each song in playlist

Constants

Public Class Methods

download(url, counter, settings) click to toggle source
# File lib/playlist_downloader.rb, line 31
def self.download(url, counter, settings)
  playlist = new(url, counter, settings)
  playlist.urls.each do |song_url|
    SongDownloader.download(song_url, playlist.counter, playlist.settings)
    playlist.counter.playlist_current += 1
  end
end
new(url, counter, settings) click to toggle source
# File lib/playlist_downloader.rb, line 9
def initialize(url, counter, settings)
  @url = url
  @urls = urls
  @name = parse_name(@url.scrapify[:title]) + '/'
  @counter = counter.dup
  @counter.playlist_current = 1
  @counter.playlist_total = @urls.size
  @settings = settings.dup
  @settings.subfolder = @name
end
playlist?(url) click to toggle source
# File lib/playlist_downloader.rb, line 5
def self.playlist?(url)
  url.include? YOUTUBE_BASE_URL + '/playlist?list='
end

Public Instance Methods

urls() click to toggle source
# File lib/playlist_downloader.rb, line 20
def urls
  html = Nokogiri::HTML(open(url).read)
  html.css(LINKS_CSS_PATH)
      .select { |link| link.attr('href').include?('watch') }
      .map { |link| YOUTUBE_HTTPS_URL + link.attr('href') }
      .uniq
rescue
  SimpleLogger.couldnt_fetch_playlist_url
  []
end