Created
September 25, 2010 16:15
-
-
Save tobynet/597000 to your computer and use it in GitHub Desktop.
Digitally Imported radio playlist getter
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
| #!ruby -Ku | |
| # Digitally Imported radio playlist getter | |
| require 'rubygems' | |
| #require 'faster_require' | |
| require 'mechanize' | |
| require 'json' | |
| require 'open-uri' | |
| require 'pp' | |
| agent = Mechanize.new | |
| json = JSON.parse(open("http://listen.di.fm/").read) | |
| $stdout.sync = true | |
| # default filename is like a "../[DI]Trance(96k).pls" | |
| def make_file_name(name) | |
| pre_name = ENV["PLS_GETTER_PRE_NAME"] || "[DI]" | |
| post_name = ENV["PLS_GETTER_POST_NAME"] || "(96k)" | |
| ext_name = ENV["PLS_GETTER_EXT_NAME"] || ".pls" | |
| out_dir = ENV["PLS_GETTER_OUT_DIR"] || ".." | |
| return File.join(out_dir, "#{pre_name}#{name}#{post_name}#{ext_name}") | |
| end | |
| #json = json[0..3] # test | |
| json.each_with_index do |item, index| | |
| uri = "http://listen.di.fm/public3/#{item["key"]}.pls" | |
| puts "downloading %.2d/%.2d(%2d%%)" % [index + 1, json.count,((index+1).to_f/json.count * 100)] | |
| puts " fetching from #{uri}" | |
| page = agent.get(uri) | |
| file_name = make_file_name(item["name"].scan(/\w+/).first) | |
| puts " saving to #{file_name}" | |
| page.save_as file_name | |
| sleep 0.5 | |
| end | |
| puts "DONE!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment