Last active
December 16, 2015 06:38
-
-
Save xldenis/5392522 to your computer and use it in GitHub Desktop.
Auto Spotify playlist torrenting system
This file contains 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
require 'net/http' | |
require 'json' | |
require 'nokogiri' | |
def http_req(url,limit=3) | |
response = Net::HTTP.get_response(URI(url)) | |
case response | |
when Net::HTTPSuccess then | |
response.body | |
else | |
if limit > 0 | |
http_req(url,limit-1) | |
else | |
raise HTTPError, response.code | |
end | |
end | |
end | |
# Note: This was purely added as an experimental feature to show what can be done using the data extracted from spotify. | |
# I do not condone pirating, nor do I encourage anyone to use this script for this, besides it is very buggy and was | |
# only written for education purposes. | |
results = [] | |
p "Downloading song info" | |
f = File.open("#{File.basename(ARGF.filename,".*")}.csv","w") | |
ARGF.read.split("\n").each do |l| | |
unless l.include? "local" | |
url = "http://ws.spotify.com/lookup/1/.json?uri=#{l}" | |
response = http_req(url) | |
parsed = JSON.parse(response) | |
name = parsed["track"]["name"] | |
artist = parsed["track"]["artists"].first["name"] | |
album = parsed["track"]["album"]["name"] | |
results << {:name => name, :artist => artist, :album => album} | |
f.puts "#{name},#{artist},#{album}" | |
end | |
end | |
p "Finding Torrents for Albums" | |
results.uniq! {|t| t[:album]} | |
f_mag = File.open("#{File.basename(ARGF.filename,".*")}.mag","w") | |
results.each do |track| | |
url = URI.escape("http://thepiratebay.se/search/#{track[:artist]+" "+track[:album]}/0/7/0") | |
response = Nokogiri::HTML(http_req(url)) | |
begin | |
link = response.css("#searchResult > tr").css("td")[1].css("a")[1]['href'] | |
if !link.include? "magnet" | |
p "Malformed HTML" | |
else | |
f_mag.puts link | |
end | |
rescue | |
p "No links for "+track[:artist]+" "+track[:album] | |
end | |
end | |
f_mag.close | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently works using ruby 1.9. Accepts a file containing spotify uri and outputs two files, one a list of albums, artists and songs and two a list of magnet urls for all albums which exist on tpb.