Logo Hardware.com.br
Piu_ssj2
Piu_ssj2 Tô em todas Registrado
1.5K Mensagens 84 Curtidas

Modificar script de letras - Amarok 1.4

#1 Por Piu_ssj2 07/03/2011 - 00:57
baixei um script de letras, porém, queria modificá-lo, para buscar as letras num determinado site.
segue o script:

#!/usr/bin/env ruby
#
# Amarok Script for fetching song lyrics from http://lyrics.games.onego.ru.
# Ported from Amarok's contextbrowser.cpp.
#
# (c) 2006 Mark Kretschmann
# (c) 2004 Christian Muehlhaeuser
# (c) 2005 Reigo Reinmets
# (c) 2005 Alexandre Pereira de Oliveira
# ( ) 2010 Dirk Lucky
#
# License: GNU General Public License V2

require "net/http"
require "rexml/document"
# require File.dirname( File.expand_path( __FILE__ ) ) + "/../ruby_debug/debug.rb"
require "uri"

@app_name = "Gyrics"

class String
def shellquote
return "'" + self.gsub("'", "'\\\\''") + "'"
end
end

def showLyrics( lyrics )
system("dcop", "amarok", "contextbrowser", "showLyrics", lyrics)
end


def parseLyrics( lyrics )
if !(/^\{\"/.match(lyrics))
showLyrics( "" )
return
end
if lyrics.include? "{\"similar\": ["
parseSuggestions(lyrics)
return
else
# {"artist": "%s", "song": "%s", "text": "%s"}
# Get artist
lyrics = lyrics.gsub(/^\{\"artist\": \"/, '')
artist = lyrics.gsub(/\n/,'').gsub(/\",.*/, '')
lyrics = lyrics.gsub(/^#{artist}\", /, '')
# Get title
lyrics = lyrics.gsub(/\"song\": \"/, '')
title = lyrics.gsub(/\n/,'').gsub(/\", .*/, '')
lyrics = lyrics.gsub(/^#{title}\", /, '')
# Get text
lyrics = lyrics.gsub(/\"text\": \"/, '')
text = lyrics.gsub(/\"\}$/, '')
end

doc = REXML:big_green.pngocument.new( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" )
root = doc.add_element( "lyrics" )

#root.add_attribute( "page_url", @page_url )
root.add_attribute( "title", title.unpack("C*").pack("U*") )
root.add_attribute( "artist", artist.to_s().unpack("C*").pack("U*") )
root.text = text.unpack("C*").pack("U*")

xml = ""
doc.write( xml )
showLyrics( xml )
end


def showError(error)
doc = REXML:big_green.pngocument.new( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" )
root = doc.add_element( "suggestions" )
xml = ""
doc.write( xml )
showLyrics( xml )
end

def parseSuggestions( lyrics )
doc = REXML:big_green.pngocument.new( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" )
root = doc.add_element( "suggestions" )

lyrics = lyrics.gsub(/\n/,'').gsub(/^\{\"similar\": \[/, '').gsub(/\]\}$/, '').gsub(/^\{/, '').gsub(/\}$/, '')

lyrics.split('},{').each do |str|
str = str.gsub(/^\"id\": \"/, '').gsub(/\"$/, '')
id = str.gsub(/\", \".*/, '')
str = str.gsub(/#{id}\", \"artist\": \"/, '')
artist = str.gsub(/\", \".*/, '')
str = str.gsub(/#{artist}\", \"song\": \"/, '')
title = str
# ---
artist = artist.unpack("C*").pack("U*") if artist
title = title.unpack("C*").pack("U*") if title
suggestion = root.add_element( "suggestion" )
suggestion.add_attribute( "id", id )
suggestion.add_attribute( "artist", artist )
suggestion.add_attribute( "title", title )
end

xml = ""
doc.write( xml )
showLyrics( xml )
end


def fetchLyrics( artist, title, id )
host = "lyrics.games.onego.ru"
port = "80"
path = "/lyrics.php"
@page_url = "http://" + host + ":" + port + path

if id.empty?
vars = "action=get2&artist=#{artist}&song=#{title}"
else
vars = "action=get&id=#{id}"
end

proxy_host = nil
proxy_port = nil
proxy_user = nil
proxy_pass = nil
if ( @proxy == nil )
@proxy = `dcop amarok script proxyForUrl #{@page_url.shellquote}`
end
proxy_uri = URI.parse( @proxy )
if ( proxy_uri.class != URI::Generic )
proxy_host = proxy_uri.host
proxy_port = proxy_uri.port
proxy_user, proxy_pass = proxy_uri.userinfo.split(':') unless proxy_uri.userinfo.nil?
end

h = Net::HTTP.new( host, port, proxy_host, proxy_port, proxy_user, proxy_pass )
response = h.post( path, vars )

unless response.code == "200"
# error "HTTP Error: #{response.message}"
`dcop amarok contextbrowser showLyrics ""`
return
end

lyrics = response.body()
parseLyrics(lyrics)

rescue SocketError
showLyrics( "" )
end


##################################################################
# MAIN
##################################################################

# TESTS BEFORE MAIN LOOP:
## fetchLyrics( "Пурген", "Негативные люди", "" )
## fetchLyrics( "Mohinde", "", "" )
## fetchLyrics( "station_rose_", "_dave_(original_1992)", "" )
## exit()
#####

loop do
message = gets().chomp()
command = /[A-Za-z]*/.match( message ).to_s()

case command
when "configure"
`dcop amarok playlist popupMessage "This script does not require any configuration."`

when "fetchLyrics"
args = message.split()

artist = args[1]
title = args[2]

fetchLyrics( artist, title, "" )

when "fetchLyricsByUrl"
url = message.split()[1]

fetchLyrics( "", "", url )
end
end


não entendi muito bem, como ele busca as letras.
se alguém puder me explicar, como faço pra trocar o site, eu agradeceria.
^^
© 1999-2024 Hardware.com.br. Todos os direitos reservados.
Imagem do Modal