[RUBY] MP3Crank Leecher v0.2

Iniciado por Eleкtro, 18 Noviembre 2012, 08:27 AM

0 Miembros y 1 Visitante están viendo este tema.

Eleкtro

MP3Crank es una página web que actualizan constantemente con albums de muchos estilos... pop, rock, dance, electro, heavy metal, indie, folk, hiphop, r&b etc...
Yo personalmente descargo musica casi todos los días en esta página porque los enlaces están en "potload" y se descargan enseguida usando JDownloader.

La cuestión es que para acceder a un link de descarga primer hay que pasar por 3 páginas, así que para evitar ese tiempo de espera tán incómodo he decidido hacer este pequeño script que parsea las "X" primeras páginas de la página web y guarda los links en un archivo de texto...

Los enlaces que se listen se registran en un archivo log para que no se vuelvan a listar en el próximo uso del script.













- Se puede configurar el máximo de páginas a parsear.
- Se pueden excluir los albumes por "tags", en la configuración del script. por ejemplo si excluimos el tag "pop" no se listará ningún album de estilo pop.
NOTA: Tener en cuenta que muchos albumes de la página tienen varios tags, por ejemplo "pop, rock, indie", si el tag "pop" lo hemos excluido, ese album se omitirá tenga los otros tags que tenga.

- El archivo de salida que obtendremos es algo parecido a este:

Title   : Layo & Bushwacka! - Rising & Falling
Genre   : House, Techno
Year    : 2012
Page    : http://www.mp3crank.com/layo-bushwacka/rising-falling.htm
Download: http://potload.com/w34j2fem2bra


Title   : Press Gang Metropol - Checkpoint
Genre   : New Wave, Post-punk
Year    : 2012
Page    : http://www.mp3crank.com/press-gang-metropol/checkpoint.htm
Download: http://potload.com/dizvwuf3m3sy


Title   : Porcupine Tree - Octane Twisted (Live) (2CD)
Genre   : Progressive, Rock
Year    : 2012
Page    : http://www.mp3crank.com/porcupine-tree/octane-twisted-live-2cd.htm
Download: http://potload.com/7h1rld0rfz03


Title   : Nightwish - Imaginaerum (The Score)
Genre   : Symphonic Metal
Year    : 2012
Page    : http://www.mp3crank.com/nightwish/imaginaerum-the-score.htm
Download: http://potload.com/eqznab8d44uk



EXECUTABLE: http://exoshare.com/download.php?uid=1Z1TPBQO

MP3Crank.rb:
Código (ruby) [Seleccionar]
# -*- coding: UTF-8 -*-


# MP3Crank Leecher v0.2
#
# By Elektro H@cker


# Description:
# -----------
#
# MP3Crank Leecher it's a tool that helps you to keep updated your music collection.
#
# This tool is intended for (almost) daily use.
#
# The script retreives all the downloadable links of the first "X" pages from the MP3Crank website,
# And then list the links into a text file for use it with a download managaer like "JDownloader".
#
# All the links are stored permanently into a log file to be excluded at the next use,
# (that's the reason why this tool is intended for daily use).
#
#
# The pass for the links is: mp3crank.com


require 'net/http'
require 'win32/registry'
require "highline/system_extensions"
include HighLine::SystemExtensions


exit if Object.const_defined?(:Ocra)


def logo()
puts "
MP3CRANK Leecher v0.2
By Elektro H@cker"
end


def main()
puts "\n\n(Remember, the password for the links is: \"mp3crank.com\")\n\n[+] Press \"C\" to config or press any other key to start leeching..."
key = get_character
config("") if key.to_s =~ /^67$|^99$/
get_downloads_list()
puts "\n\n\n[+] All links are stored in: #{$mp3crank_leecherfile}\n\n(Remember, the password for the links is: \"mp3crank.com\")"
exit
end


def get_settings()
begin
$mp3crank_logfile = regread("LOGFILEPATH")
rescue
$mp3crank_logfile = "#{ENV['WINDIR']}\\MP3Crank Leecher LOG.txt"
end

begin
$mp3crank_leecherfile = regread("LEECHERFILEPATH") +  "MP3Crank Leecher #{Time.new.strftime("%Y-%m-%d")}.txt"
rescue
$mp3crank_leecherfile = "#{ENV['USERPROFILE']}\\Desktop\\MP3Crank Leecher #{Time.new.strftime("%Y-%m-%d")}.txt"
end

begin
$max_pages = regread("MAXPAGES")
$max_pages = $max_pages.to_i
rescue
$max_pages = 10
end

begin
$excluded_tags = regread("EXCLUDED TAGNAMES")
rescue
$excluded_tags = ""
end

end


def config(errorcode)

puts "
º---------------------------------º---------------------------------º
| [1] Set the log file path       | [S] Show the current settings   |
| [2] Set the leecher file path   | [R] Reset the settings          |
| [3] Delete the log file         | [Z] Backup all the settings     |
|---------------------------------|---------------------------------|
| [M] Max. Pages to parse         |                                 |
| [T] Tagnames to exclude         | [E] Exit                        |
º---------------------------------º---------------------------------º
"
get_settings()
puts errorcode

keystr = "NOTHING"
until keystr =~ /^49$|^50$|^51$|^69$|^80$|^82|^83$|^84$|^90$|^101$|^112$|^114$|^115$|^116$|^122$/
print "\nChoose an option >> "
key = get_character
keystr = key.to_s
end

# Log file path
if key == 49
logfilepath = "NOTHING"
until File.directory?(logfilepath)
print "\n\nEnter the path to an existing directory for the logfile: "
logfilepath = STDIN.gets.chomp
end
if logfilepath[-1] == '\\' then logfilepath = logfilepath[0..-2] end
regwrite("LOGFILEPATH", logfilepath + "\\MP3Crank Leecher LOG.txt")
config("[+] Operation completed.")
end

# Leecher file path
if key == 50
leecherfile = "NOTHING"
until File.directory?(leecherfile)
print "\n\Enter the path to an existing directory for the leecher file: "
leecherfile = STDIN.gets.chomp
end
if not leecherfile[-1] == '\\' then leecherfile = leecherfile+"\\" end
regwrite("LEECHERFILEPATH", leecherfile)
config("[+] Operation completed.")
end

# delete log file
if key == 51
filedel = "NOTHING"
while not filedel =~ /^78$|^89$|^110$|^121$/
print "\n\nWant to delete the log file, Are you sure? [Y/N]: "
filedel = get_character.to_s
end
begin
if filedel =~ /^89$|^121$/ then File.delete($mp3crank_logfile) end
config("[+] Operation completed.")
rescue
config("\n\nERROR\n\nCan't find the logfile.")
end
end

# Max pages
if key == 80 or key == 112
maxpages = "NOTHING"
puts "\n\nThis option lets you configure the maximum pages to leech..."
until not maxpages[/[a-z]/i]
print "\nEnter a number for the max pages value: "
maxpages = STDIN.gets.chomp
end
regwrite("MAXPAGES", maxpages)
config("[+] Operation completed.")
end

# exclude tagnames
if key == 84 or key == 116
addtag = "NOTHING"
puts "\n\nThis option lets you exclude albums by their genre tagnames..."
until not addtag == "NOTHING"
print "\n\nEnter a tagname (Example: \"Hip Hop\") \nor enter the word \"none\" to reset the exclusions: "
addtag = STDIN.gets.chomp
end
begin
tags=regread("EXCLUDED TAGNAMES")
rescue
tags=""
end
if addtag =~ /^none$/i then regwrite("EXCLUDED TAGNAMES", "") else regwrite("EXCLUDED TAGNAMES", "#{tags};#{addtag}") end
config("[+] Operation completed.")
end

# show the current settings
if key == 83 or key == 115
config("

Log file path       : #{$mp3crank_logfile}

Leecher file path   : #{$mp3crank_leecherfile}

Max. pages to parse : #{$max_pages} pages

Excluded tagnames   : #{$excluded_tags.gsub(";","|")}

")
end

# reset the settings
if key == 114 or key == 82
resetkey = "NOTHING"
while not resetkey =~ /^78$|^89$|^110$|^121$/
print "\n\nWant to reset all the settings, Are you sure? [Y/N]: "
resetkey = get_character.to_s
end
if resetkey =~ /^89$|^121$/
Win32::Registry::HKEY_CURRENT_USER.open("SOFTWARE\\MP3Crank Leecher\\", Win32::Registry::KEY_ALL_ACCESS) do |reg|
reg['LOGFILEPATH'] = 'DELETE'
reg.delete_value("LOGFILEPATH")
reg['LEECHERFILEPATH'] = 'DELETE'
reg.delete_value("LEECHERFILEPATH")
reg['MAXPAGES'] = 'DELETE'
reg.delete_value("MAXPAGES")
reg['EXCLUDED TAGNAMES'] = 'DELETE'
reg.delete_value("EXCLUDED TAGNAMES")
end
config("[+] Operation completed.")
end
end

# backup the settings
if key == 90 or key == 122
system %[ regedit /e \"%USERPROFILE%\\Desktop\\MP3Crank Leecher settings %DATE:/=-%.reg\" \"HKEY_CURRENT_USER\\Software\\MP3Crank Leecher\" ]
config("\n\n[+] Settings stored in #{ENV['USERPROFILE']}\\Desktop\\MP3Crank Leecher settings.reg")
end

# exit
if key == 69 or key == 101 then main() end

end


def show_info()
  @info = "

Title   : #{@album_title}
Genre   : #{@album_tags.to_s.gsub('\\t','').gsub(']','').gsub('[','').gsub('"','').gsub('nil','').gsub(', , ','')}
Year    : #{@year}
Page    : #{@album_page}
Download: #{@potload_url}

"
  puts @info
end


def get_downloads_list()
@page = 0
print "\n\n[+] Leeching pages "
for i in 1..$max_pages do
@page = @page+1
@url  = "http://www.mp3crank.com/page/#{@page}"
print "#{@page}/#{$max_pages}..."
Net::HTTP.get_response(URI.parse(@url)).body.split('<!--/centercol -->').first.split('<div id="centercol">').last.each_line do |line|

if (line['class="release"']) then @downloadable = "yes" end

if line['class="year"'] then @year = line.split('</').first.split('>').last end

if line['class="genres"']
for tag in line.split('rel="tag">').each do
@album_tags = @album_tags, tag.split('<').first.gsub('&amp;','&')
for excluded_tag in $excluded_tags.split(";").each do
if not excluded_tag == "" and tag.split('<').first.to_s.chomp[/^#{Regexp.escape(excluded_tag)}$/i] then @downloadable = "no" end
end
end
end

if line['class="album"']
@album_title   = line.split('title="').last.split('">').first.gsub('Free MP3 download ','').gsub('&amp;','&')
@album_page    = line.split('" rel=').first.split('"').last
@download_page = Net::HTTP.get_response(URI.parse(@album_page)).body[/http:\/\/www.mp3crank.com\/download\/album\/[0-9]+/i]
@potload_url   = Net::HTTP.get_response(URI.parse(@download_page)).body[/http:\/\/potload.com\/[a-z0-9]+/i]
if @downloadable == "yes"
filewrite()
end
@album_tags  = nil
end

end
end
end


def regread(keyname)
Win32::Registry::HKEY_CURRENT_USER.open("SOFTWARE\\MP3Crank Leecher\\") do |reg| reg[keyname] end
end


def regwrite(keyname, value)
Win32::Registry::HKEY_CURRENT_USER.create("SOFTWARE\\MP3Crank Leecher\\") do |reg| reg[keyname, Win32::Registry::REG_SZ] = value end
end


def filewrite()
if not File.exist?($mp3crank_logfile) then File.open($mp3crank_logfile, "w") do |write| write.puts "MP3Crack leeched URLs\n\n(Remember, the password for the links is: \"mp3crank.com\")\n\n" end end
if not File.open($mp3crank_logfile, "r").read[@album_page]
show_info()
File.open($mp3crank_logfile,     "a+") do |write| write.puts @album_page end
File.open($mp3crank_leecherfile, "a+") do |write| write.puts @info end
end
end


logo()
get_settings()
main()