Last active
April 22, 2022 20:03
-
-
Save arashm/58c9c9098a00d71d26d2 to your computer and use it in GitHub Desktop.
Fetch download links of RadioJavan Playlists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# gem install mechanize | |
require 'mechanize' | |
abort "Usage:\n\tradiojavan.rb \"https://www.radiojavan.com/playlists/playlist/mp3/02596ef9986a\" output_txt" if ARGV.size < 2 | |
playlist_url = ARGV[0] | |
output_file = ARGV[1] | |
HOST = 'https://www.radiojavan.com' | |
agent = Mechanize.new | |
playlist_url = "#{playlist_url}" | |
puts '-> Getting playlist page' | |
playlist_page = agent.get(playlist_url) | |
songs_page_links = playlist_page.search('//table/tbody/tr/td[2]/a/@href').map(&:to_s) | |
puts "-> Found \"#{songs_page_links.size}\" songs there!" | |
download_links = [] | |
pages_with_no_download_link = [] | |
songs_page_links.each do |link| | |
begin | |
page = agent.get(HOST + link) | |
puts "-> Got page \"#{page.title}\"" | |
download_links << page.links_with(:class => 'mp3_download_link').first.attributes['link'] | |
rescue NoMethodError | |
puts "-> No chance for \"#{page.title}\" :(" | |
pages_with_no_download_link << page.title | |
next | |
end | |
end | |
File.open(output_file, 'w') { |f| f.puts download_links } | |
puts | |
puts "## Extracted \"#{download_links.size}\" links and saved them into file \"#{output_file}\"" | |
puts "## Download them with this command: aria2c -i ./#{output_file}" | |
puts | |
puts "## There wasn't any download link provided for following songs:" | |
pages_with_no_download_link.each do |title| | |
puts "\t- #{title}" | |
end |
@erfanoabdi Nope, doesn't work anymore since the website has changed drastically. Doesn't have any plans to update it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any updates in this?