Last active
May 26, 2021 12:06
-
-
Save safaeean/437eab554f0b861fa71c39a5d1a0794c to your computer and use it in GitHub Desktop.
Fetch download links of RadioJavan Playlists #radiojavan-downloader
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(".//ul[@class='listView']/li/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}\"" | |
| script = page.search(".//script").map(&:to_s)[9] | |
| if script.match(/mp3-256/) | |
| file_name = script.split("\n")[2].scan(/\'.+\'/)[0].delete_suffix("'") | |
| file_name[0] = '' | |
| download_links.push "https://host2.rj-mw1.com/media/" + file_name + ".mp3" | |
| end | |
| 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 |
Author
Author
#radiojavan-downloader
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
install requirements
usage
ruby radiojavan.rb "https://www.radiojavan.com/playlists/playlist/mp3/09385e59d4df" file.txt