[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ajuda com script do Amarok
From: |
podestafox |
Subject: |
Ajuda com script do Amarok |
Date: |
Wed, 07 May 2008 19:06:39 -0000 |
User-agent: |
eGroups-EW/0.82 |
Gente estou tentando a mais de tempos alterar este script às minhas
necessidades.
O que preciso é que ele pega as letras que vai baixar pelo amarok, e
salva-las.
Só que isso já acontece naturalmente.
O que preciso é que ele salve as letras na pasta: Letras, organizado
da seguinte ordem:
Letras/ (Nome do Artista) / (Nome do Álbum) / (Nome da Música) .lyric
E tudo isso com espaços ( ) ao invés de traços (-) e underlines (_).
#!/bin/bash
#
# amaroK's plugin to fetch lyrics from www.letras.mus.br, a
# amazing website with a really big lyrics database.
#
# Copyright Caio Begotti 2006 <http://caio.ueberalles.net>
# Licensed under GPL2 on Sat, 27 May 2006 23:19:25 -0300
#
# current TODO list:
# - URL data conversion
# - handle suggestions
# - "translate into" option
# - "display cached only"
# - "contribua enviando a letra"
lang=en_US
cache=${HOME}/lyrics
cfg="-cfg=$(dirname $0)/lynx.cfg"
command=$1
dcop=$(which dcop)
template=/tmp/amarok.tpl
amarok --version | grep 1.4 || ${dcop} amarok playlist popupMessage
"This script requires amaroK 1.4 or later!"
get="$(which lynx)" || ${dcop} amarok playlist popupMessage "The
'lynx' package is required to fetch lyrics!"
alert="$(which kdialog)" || ${dcop} amarok playlist popupMessage "The
'kdialog' binary is required to configure me!"
saveCache()
{
varArtista="$(echo ${1} | sed 's/\ /_/g')"
varMusica="$(echo ${2} | sed 's/\ /_/g')"
cachedFile=${cache}/${varArtista}-${varMusica}.txt
test -d ${cache} || mkdir -p ${cache}
cp -f ${template} ${cachedFile}
}
fetchContent()
{
# can we call it template?
cat << EOF > ${template}
<?xml version="1.0" encoding="UTF-8" ?>
<lyric artist="ARTIST" title="TITLE" page_url="http://letras.mus.br">
LYRICS_GOES_HERE
</lyric>
EOF
varArtista="$(echo ${1} | sed 's/_/+/g'| sed
'y/ÁÀÃÂÉÊÍÓÕÚÜÇáàãâéêíóõúüç/AAAAEEIOOUUCaaaaeeioouuc/')"
varMusica="$(echo ${2} | sed 's/_/+/g' | sed 's/_/+/g'| sed
'y/ÁÀÃÂÉÊÍÓÕÚÜÇáàãâéêíóõúüç/AAAAEEIOOUUCaaaaeeioouuc/')"
# PID number allow multi-user
data=$(mktemp /tmp/amarok.$$.XXXX)
case ${lang} in
pt_BR)
# they provide nice URLs for parsing, yay!
${get} -source
"http://letras.terra.com.br/winamp.php?musica=${varMusica}&artista=${varArtista}"
> ${data}
tradCode=$(sed -e '/tradu/!d' -e
"s/^.*href='//" -e "s/'alt.*$//"
${data})
# almost there for the parser...
[ ! -s "${tradCode}" ] && ${get} -dump ${cfg}
"${tradCode}" >
${data}.iso
;;
*)
# that's the regular lyrics in english
${get} -dump ${cfg}
"http://letras.terra.com.br/winamp.php?musica=${varMusica}&artista=${varArtista}"
> ${data}.iso
;;
esac
# just to make sure...
cat ${data}.iso | iconv -f "ISO-8859-1" -t "UTF-8" -o ${data}
# formatting the whole thing to display in the contextBrowser
cat ${data} | sed '1,7d' | tac > ${data}.invert
cat ${data}.invert | sed '1,14d;s/^\ \+//g' | tac > ${data}
# if empty or not found, alert the user about it
test -s ${data} || echo -e "Lyrics not found...\nCheck your ID3
tag!" > ${data}
# corrigindo a condificação dos nomes do artista e da
música
varArtista="$(echo ${1})"
varMusica="$(echo ${2})"
# fucking amazing hack from m4n from #address@hidden to
capitalize all line's first word
# sed 's/^[a-z]/\u&/' could be used as well, but it's not that
portable
sed -i
'h;s/.\(.*\)/\1/;x;s/\(.\).*/\1/;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;G;s/\n//;'
${data}
sed -i "/LYRICS_GOES_HERE/r ${data}" ${template}
sed -i -e "s/ARTIST/${varArtista}/" \
-e "s/TITLE/${varMusica}/" \
-e "/LYRICS_GOES_HERE/d" \
-e /"[1]"/d \
-e /"[2]"/d \
-e /"[3]"/d \
-e /"[4]"/d \
-e /"[5]"/d \
-e /"[6]"/d \
-e /"[7]"/d \
-e /"[8]"/d \
-e /"[9]"/d \
-e "s/+/ /g" ${template}
sed -i -e '/Esta letra/d' -e '/Referências/d' -e
'/Ligações visÃveis/d' -e '/. LYNX/d' ${template}
# show it in the big screen then save locally
${dcop} amarok contextbrowser showLyrics "$(cat ${template})"
saveCache "${varArtista}" "${varMusica}"
}
checkCached()
{
host letras.terra.com.br
return=$?
case ${return} in
0) fetchContent "${artistName}" "${songTitle}" ;;
69)
varArtista="$(echo ${1})"
varMusica="$(echo ${2})"
cachedFile=${cache}/${varArtista}-${varMusica}.txt
[ -f "${cachedFile}" ] && ${dcop} amarok contextbrowser
showLyrics
"$(cat ${cachedFile})"
;;
esac
}
callFetcher()
{
artistName="$(${dcop} amarok player artist)"
songTitle="$(${dcop} amarok player title)"
checkCached "${artistName}" "${songTitle}"
}
while read command
do
case ${command} in
configure)
option=$(${alert} --title Lyrics1982 --radiolist
\
"Do you wanna fetch lyrics in which language?"
\
en_US "English (default value, en_US)" on
\
pt_BR "Portugues (brasileiro, pt_BR)" off)
case ${option} in
en_US)
sed -i 's/^lang=.._../lang=en_US/' $0
export lang="en_US"
;;
pt_BR)
sed -i 's/^lang=.._../lang=pt_BR/' $0
export lang="pt_BR"
;;
*)
;;
esac
;;
trackChange)
callFetcher
;;
fetchLyrics*)
callFetcher
;;
fetchLyricsByUrl) # expect a valid lyric URL
;;
engineStateChange) # is it empty|idle|paused|playing?
;;
customMenuClicked*) # submenu itemTitle paths
;;
*)
;;
esac
done
exit 0
# how in hell could i make this suggestions thing work?
<suggestions page_url="http://provided.by">
<suggestion artist="artist name" title="song title"
url="http://url.to/the/specific/lyrics" />
</suggestions>
# null suggestions template that i dont know how to use yet
<suggestions page_url="http://provided.by"></suggestions>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Ajuda com script do Amarok,
podestafox <=