Created
February 24, 2010 01:58
-
-
Save rafapolo/312982 to your computer and use it in GitHub Desktop.
PegaCoda
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
#!ruby19 | |
# encoding: utf8 | |
# author: rafael polo | |
# created_at 23.fev.2010 | |
require 'open-uri' | |
require 'timeout' | |
require 'cgi' | |
class PegaCoda | |
REGEX_ARTISTA = /<a href='\/artists\/([\d]+)'>\n<img/ | |
REGEX_ALBUM = /<a href='\/albums\/([\d]+)'>\n<img/ | |
def self.vai | |
23.times do |x| # a..z | |
x = 1 | |
page = load_url("http://coda.fm/artists?page=#{x}") | |
artistas = page.scan(REGEX_ARTISTA) | |
artistas.each do |artista_id| | |
pegaAlbuns(artista_id) | |
puts | |
end | |
end | |
end | |
def self.pegaAlbuns(artista_id) | |
page = load_url("http://coda.fm/artists/#{artista_id}") | |
artist = page.scan(/<h2>(.*)<\/h2>/) | |
puts "Artista: #{artist}" | |
albuns = page.scan(REGEX_ALBUM) | |
albuns.each do |album_id| | |
pegaAlbum(album_id) | |
end | |
end | |
def self.pegaAlbum(album_id) | |
page = load_url("http://coda.fm/albums/#{album_id}") | |
album = page.scan(/<h2 class='bottom'>(.*)<\/h2>/) | |
href = page.scan(/class='link' href='(.*)' onClick/) | |
puts "Album: #{album}" | |
puts "Torrent: #{href}" | |
end | |
def self.load_url(url) | |
#puts "Pegando #{url}" | |
response="" | |
begin | |
timeout(8) do | |
uri = URI.parse(url) | |
response = uri.read if uri | |
end | |
rescue Exception=>error | |
response = false | |
puts "Erro: #{error}\n\n" | |
end | |
response | |
end | |
end | |
PegaCoda.vai | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment