#!/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