Skip to content

Instantly share code, notes, and snippets.

@ggtmtmgg
Created January 18, 2017 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggtmtmgg/ef005419b123a84ebc540947dadedf43 to your computer and use it in GitHub Desktop.
Save ggtmtmgg/ef005419b123a84ebc540947dadedf43 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
URL = 'https://www.youtube.com'
PLAYLIST_URL = URL + '<Playlist Path>'
puts = 'Scraping..'
doc = Nokogiri::HTML(open(PLAYLIST_URL))
videos_xpath = '//*[@id="pl-load-more-destination"]/tr'
videos = doc.xpath(videos_xpath)
a_tag_xpath = 'td[4]/a'
videos.each do |video, i|
a_tag_xpath = 'td[4]/a'
a_tag = video.xpath(a_tag_xpath)
path = a_tag.attr('href').value.gsub(/\&.*/, '')
puts full_url = URL + path
`youtube-dl --extract-audio --audio-format mp3 '#{full_url}'`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment