Created
October 10, 2010 21:46
-
-
Save oriolgual/619605 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'cgi' | |
class Goear | |
def self.find(song) | |
puts "Searching for #{song}" | |
url = "http://www.goear.com/search.php?q=#{CGI.escape(song)}" | |
doc = Nokogiri::HTML(open(url)) | |
link = doc.css(".textobuscar a").select{|link| link[:href] =~ /listen\/[a-z0-9]+\/.*/}.compact | |
(link and link.first and link.first[:href] ? link.first[:href] : nil) | |
end | |
def self.find_from_file(file) | |
links = File.foreach(file).collect do |line| | |
artist, song, foo = line.strip.gsub(/–/, ' - ').split('-') | |
find("#{artist.strip} - #{song.strip}") | |
end.compact | |
end | |
def self.export_to_file(from, to) | |
links = find_from_file(from) | |
puts "Writing #{links.length} links to #{to}..." | |
File.open(to, 'w') do |file| | |
links.each do |link| | |
file.puts "http://www.goear.com/#{link}" | |
end | |
end | |
puts "Done!" | |
end | |
end | |
Goear.export_to_file("/home/oriol/mp3/spotify.txt", "/home/oriol/mp3/goear.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment