diff options
-rw-r--r-- | HISTORY | 4 | ||||
-rw-r--r-- | README | 23 | ||||
-rw-r--r-- | lyrics.c | 49 | ||||
-rw-r--r-- | lyrics.h | 4 | ||||
-rw-r--r-- | mg_db.c | 8 | ||||
-rw-r--r-- | po/de.po | 5 | ||||
-rw-r--r-- | po/fi.po | 5 | ||||
-rw-r--r-- | po/fr.po | 5 | ||||
-rwxr-xr-x | po/it.po | 12 | ||||
-rw-r--r-- | po/muggle.pot | 5 | ||||
-rwxr-xr-x | scripts/mgLyric.py | 52 | ||||
-rwxr-xr-x | scripts/muggle_getlyrics | 118 |
12 files changed, 203 insertions, 87 deletions
@@ -381,3 +381,7 @@ Balke. - updated translations by Ville Skyttä and Diego Pierotto 2009-XX-XX Version 0.2.3 +- last version broke importing from setup menu +- Lyrics now work with Googlyrics2 +- if several versions of lyrics for a song are found, it is now possible + to choose among them. @@ -57,7 +57,7 @@ required: http://www.xiph.org/ogg/vorbis/) - optionally libFLAC++ to replay FLAC files (Debian package libflac++-dev or sources from flac.sourceforge.net) - - recode if you want to download lyrics + - recode, python and Googlyrics2 if you want to download lyrics The developer versions are needed because their headers are required for compilation. The server need not be on the same machine as the @@ -313,17 +313,25 @@ not saved. Both files can coexist, however if .lyrics.tmp exists, this one will be displayed with the option to save it. Saving of course removes .lyrics.tmp +The directory lyrics.tmp.new contains all versions downloaded from +the internet. If the user wants to download or rejects a version, +the first version from this directory is returned and removed +from the lyrics.tmp.new. Only if no version is available from +lyrics.tmp.new, muggle actually invokes googlyrics2 for a new +download. + If a track starts playing and lyrics are wanted, muggle first tries the local file. If it does not exist, muggle will automatically get it from the -internet. If you do not like the text, you can edit the lyrics file +internet and save the first version. If you do not like the text, +you can edit the lyrics file (outside of muggle) or request another load from the internet - maybe somebody fixed it meanwhile. If characters in the lyrics are not shown correcly, you can try to adjust the muggle_getlyrics script. Muggle starts the retrieval script in the background and displays the lyrics as soon as it is available. If you change track before -the retrieval finished, two retrieval scripts might be running at -the same time - no problem. +the retrieval finished, two ore more retrieval scripts might be +running at the same time - no problem. with vdr versions before 1.5.4, muggle cannot start this in the background. Instead it waits until the script has finished. Meanwhile it will not @@ -331,10 +339,9 @@ respond to commands, and the message "loading lyrics" will only appear after they have been loaded. Muggle calls the script muggle_getlyrics which in turn calls -googlyrics - this is slightly adapted to muggle. The original is -here: http://www.kde-apps.org/content/show.php/GoogLyrics?content=73850 -googlyrics is a plugin to the amarok music player, it can currently ask -27 different sources. +mgLyrics.py which in turn uses the Googlyrics2 python modules. +Googlyrics2 is a plugin to the amarok music player, it can currently ask +26 different sources. @@ -35,10 +35,19 @@ int mgLyrics::RunCommand(const string cmd) { return res; } +bool +mgLyrics::HasMoreVersions() { + struct stat stbuf; + if (!displayItem) + return 0; + return (!stat(displayItem->getCachedFilename("lyrics.tmp.new").c_str(),&stbuf)); +} + void mgLyrics::LoadExternal() { mgLog("LoadExternal"); - osd()->Message1(tr("Loading lyrics from internet...")); + if (!HasMoreVersions()) + osd()->Message1(tr("Loading lyrics from internet...")); string script=the_setup.ConfigDirectory + "/scripts/muggle_getlyrics"; if (RunCommand(script)==0) { state=lyricsLoading; @@ -63,17 +72,21 @@ mgLyrics::SaveExternal() { free(cmd); } +void +mgLyrics::ThrowTmpAway(const mgItemGd& item) { + char *cmd; + msprintf(&cmd,"rm -f \"%s\"",item.getCachedFilename("lyrics.tmp").c_str()); + SystemExec(cmd); + free(cmd); + state=lyricsSaved; +} + eOSState mgLyrics::Process(eKeys key) { playItem=mutPlayingItem(); LyricsState prevstate=state; - if (displayItem!=playItem && prevstate==lyricsLoaded) { - char *cmd; - msprintf(&cmd,"rm -f \"%s\"",displayItem->getCachedFilename("lyrics.tmp").c_str()); - SystemExec(cmd); - free(cmd); - state=lyricsSaved; - } + if (displayItem!=playItem && prevstate==lyricsAsking) + ThrowTmpAway(displayItem); long cl=playItem->getCheckedForTmpLyrics(); if (displayItem!=playItem || (cl>0 && cl<time(0))) { if (!access(playItem->getCachedFilename("lyrics.tmp.loading").c_str(),R_OK)) { @@ -83,10 +96,24 @@ mgLyrics::Process(eKeys key) { bool normfound=!access(playItem->getCachedFilename("lyrics").c_str(),R_OK); if (!access(playItem->getCachedFilename("lyrics.tmp").c_str(),R_OK)) { playItem->setCheckedForTmpLyrics(0); - state=lyricsLoaded; if (!normfound) { SaveExternal(); state=lyricsSaved; + } else { + state=lyricsAsking; + BuildOsd(); + osd()->Display(); + if (Interface->Confirm(tr("Save this version?"))) { + SaveExternal(); + state=lyricsSaved; + } else { + if (HasMoreVersions()) + LoadExternal(); + else { + ThrowTmpAway(playItem); + state=lyricsSaved; + } + } } } else if (displayItem!=playItem) { if (normfound) { @@ -150,8 +177,8 @@ mgLyrics::BuildOsd () { case lyricsLoading: BlueAction=actNone; break; - case lyricsLoaded: - BlueAction=actSaveExternalLyrics; + case lyricsAsking: + BlueAction=actLoadExternalLyrics; loadfile=playItem->getCachedFilename("lyrics.tmp"); break; default: @@ -6,7 +6,7 @@ enum LyricsState { lyricsNone, lyricsLoading, - lyricsLoaded, + lyricsAsking, lyricsSaved }; @@ -16,6 +16,8 @@ class mgLyrics : public mgMenu int RunCommand(string cmd); void LoadExternal(); void SaveExternal(); + void ThrowTmpAway(const mgItemGd& item); + bool HasMoreVersions(); const mgItemGd *displayItem; mgItemGd *playItem; LyricsState state; @@ -1210,11 +1210,15 @@ mgDb::SyncFile(const char *filename) { mgSQLString c_lang(m_TLAN); mgSQLString c_cddbid(getAlbum(filename,c_album,c_artist)); - const char *cwd = mugglepath(); + const char *cwd; + if (the_setup.IsMugglei()) + cwd = mugglepath(); + else + cwd = strdup(""); int tldlen = strlen(the_setup.ToplevelDir); int cwdlen = strlen(cwd); const char *relpath=cwd; - if (cwdlen>tldlen); relpath += tldlen; + if (cwdlen>tldlen) relpath += tldlen; char *b; msprintf(&b,"%s%s",relpath,cfilename); free((void*)cwd); @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: de\n" "Report-Msgid-Bugs-To: <vdr-muggle-develop@sourceforge.net>\n" -"POT-Creation-Date: 2008-12-25 15:40+0200\n" +"POT-Creation-Date: 2009-01-05 11:43+0100\n" "PO-Revision-Date: 2008-12-23 22:40+0100\n" "Last-Translator: Wolfgang Rohdewald <wolfgang@rohdewald.de>\n" "Language-Team: German <wolfgang@rohdewald.de>\n" @@ -23,6 +23,9 @@ msgstr "" msgid "Loading lyrics from internet..." msgstr "Lade Text aus dem Internet..." +msgid "Save this version?" +msgstr "Diese Version speichern?" + msgid "empty database created" msgstr "leere Datenbank angelegt" @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: fi\n" "Report-Msgid-Bugs-To: <vdr-muggle-develop@sourceforge.net>\n" -"POT-Creation-Date: 2008-12-25 15:40+0200\n" +"POT-Creation-Date: 2009-01-05 11:43+0100\n" "PO-Revision-Date: 2008-12-25 15:37+0200\n" "Last-Translator: Ville Skyttä <ville.skytta@iki.fi>\n" "Language-Team: Finnish <ville.skytta@iki.fi>\n" @@ -22,6 +22,9 @@ msgstr "" msgid "Loading lyrics from internet..." msgstr "Ladataan sanoituksia verkosta..." +msgid "Save this version?" +msgstr "" + msgid "empty database created" msgstr "tyhjä tietokanta luotu" @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: fr\n" "Report-Msgid-Bugs-To: <vdr-muggle-develop@sourceforge.net>\n" -"POT-Creation-Date: 2008-12-25 15:40+0200\n" +"POT-Creation-Date: 2009-01-05 11:43+0100\n" "PO-Revision-Date: 2008-12-23 22:45+0100\n" "Last-Translator: Wolfgang Rohdewald <wolfgang@rohdewald.de>\n" "Language-Team: French <wolfgang@rohdewald.de>\n" @@ -22,6 +22,9 @@ msgstr "" msgid "Loading lyrics from internet..." msgstr "Cherchant le texte dans le web" +msgid "Save this version?" +msgstr "Sauvegarder cette version?" + msgid "empty database created" msgstr "créé base des données vide" @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: <wolfgang@rohdewald.de>\n" -"POT-Creation-Date: 2008-12-24 12:05+0100\n" +"Report-Msgid-Bugs-To: <vdr-muggle-develop@sourceforge.net>\n" +"POT-Creation-Date: 2009-01-05 11:43+0100\n" "PO-Revision-Date: 2008-12-24 18:33+0100\n" "Last-Translator: Diego Pierotto <vdr-italian@tiscali.it>\n" "Language-Team: Italian <vdr-italian@tiscali.it>\n" @@ -20,6 +20,9 @@ msgstr "" msgid "Loading lyrics from internet..." msgstr "Caricamento testi canzoni da Internet..." +msgid "Save this version?" +msgstr "Salvare questa versione?" + msgid "empty database created" msgstr "Creato database vuoto" @@ -167,8 +170,8 @@ msgstr "Predefinito" msgid "Set default to collection '%s'" msgstr "Imposta predefiniti nella raccolta '%s'" -#, c-format -msgid "Default collection now is '%s'" +#, fuzzy, c-format +msgid "Default collection is now '%s'" msgstr "Ora la raccolta predefinita è '%s'" msgid "Set" @@ -383,4 +386,3 @@ msgstr "Trasparenza copertina" msgid "Delete stale references" msgstr "Elimina riferimenti blocco" - diff --git a/po/muggle.pot b/po/muggle.pot index bd84a7a..428191c 100644 --- a/po/muggle.pot +++ b/po/muggle.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: <vdr-muggle-develop@sourceforge.net>\n" -"POT-Creation-Date: 2008-12-25 15:40+0200\n" +"POT-Creation-Date: 2009-01-05 14:23+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -19,6 +19,9 @@ msgstr "" msgid "Loading lyrics from internet..." msgstr "" +msgid "Save this version?" +msgstr "" + msgid "empty database created" msgstr "" diff --git a/scripts/mgLyric.py b/scripts/mgLyric.py new file mode 100755 index 0000000..97042f5 --- /dev/null +++ b/scripts/mgLyric.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +import os, sys, locale + +title = sys.argv[1] +artist = sys.argv[2] +outdir = sys.argv[3] + +# add other possible paths here: +googlFound = False +for scriptdir in ('/usr/share/apps/amarok/scripts/Googlyrics2', \ + 'NULL'): + if os.path.isdir(scriptdir+'/sites/'): + sys.path.append(scriptdir + "/lib/") + sys.path.append(scriptdir + "/sites/") + os.chdir(scriptdir) + googlFound = True + break + +if not googlFound: + outfile = open(outdir + '/1.raw',"w") + outfile.write("Googlyrics2 is not installed\nSee http://quicode.com/googlyircs2") + outfile.close + sys.exit(0) + +Debugging = False + +if Debugging: + outlyric=["Version 1","Version 2","Version 3"] + for idx,item in enumerate(outlyric): + outfile = open(outdir + '/' + str(idx) + '.raw',"w") + outfile.write(item) + outfile.close + sys.exit(0) + +from Googlyrics import * +g = Googlyrics() + +outlyric = g.find_lyrics(title, artist) +if len(outlyric) > 0: + for idx,item in enumerate(outlyric): + l = item.getLyric() + if l is not None: + if l.lyrics is not None: + if len(l.lyrics)>2: +# if we pipe or write output to a file, python by default recodes into ascii, +# and sys.stdout.encoding is also set to ascii. But if the system +# default locale is for example utf-8, we also want the file to be +# encoded like that + outfile = open(outdir + '/' + str(idx) + '.raw',"w") + outfile.write(l.lyrics.encode(locale.getdefaultlocale()[1])) + outfile.close + diff --git a/scripts/muggle_getlyrics b/scripts/muggle_getlyrics index 190e413..db7fbdf 100755 --- a/scripts/muggle_getlyrics +++ b/scripts/muggle_getlyrics @@ -1,66 +1,72 @@ #!/bin/sh -export GOOGLYRICS=/usr/share/apps/amarok/scripts/googlyrics/googlyrics +# usage: +# artist title outfile +# +# we might find several different lyrics for a song. This is handled +# by this script: We use a subdirectory outfile.new. If it exists +# and contains a file, we just return that file and remove it from +# outfile.new. If outfile.new is empty, we read all versions again +# with googlyrics. -rm -f "$3" -txtfound=0 -artist=`echo $1 | sed 's/ /%20/'g` -title=`echo $2 | sed 's/ /%20/'g` +# ultimately I want to integrate this shell script into mgLyrics.py -if test ! -x $GOOGLYRICS -then - echo $GOOGLYRICS nicht gefunden > $3 - exit 2 -fi +artist="$1" +title="$2" +outfile="$3" +orgoutfile=`echo "$3" | sed 's/.tmp$//'` +outdir="$3.new" -export success=0 -echo fetchLyrics $artist $title | $GOOGLYRICS 2>&1 | - sed 's/\x0d//g' | - sed 's/\xc2\xb4/\x27/g' | - sed 's/\xc3\x82\x27/\x27/g' | - sed 's/\xc3\x82/\x27/g' | - sed 's/\xc3\xb9/\x27/g' | - sed 's/\xe2\x80\x99/\x27/g' | - grep -ive 'NEW.*ringtones' | - grep -v '--------------' | - recode HTML..utf8 | - sed 's/\xc2\x91/\x27/g' | # in unicode, those two are reserved for - sed 's/\xc2\x92/\x27/g' | # private use, but still some sites use them... -while read line -do -# did we find a text yet? - if expr "$line" : '<br>Regex success' >/dev/null 2>&1 - then - success=1 - continue - fi -# googlyrics tries to send the finished text to amarok: - if expr "$line" : 'object not accessible' >/dev/null 2>&1 - then - killall googlyrics >/dev/null 2>&1 - break - fi -# googlyrics starts main loop again: - if expr "$line" : '.*scalar chomp.*STDIN' >/dev/null 2>&1 +echo > "$outfile".loading + +if test ! -d "$outdir" +then + mkdir "$outdir" + MGLYRICS="`dirname $0`/mgLyric.py" + if test ! -x "$MGLYRICS" then - killall googlyrics >/dev/null 2>&1 - break + echo $MGLYRICS not found > "$outdir"/1.raw + else + "$MGLYRICS" "$title" "$artist" "$outdir" fi - test $success = 0 && continue -# suppress other googlyrics error messages - expr "$line" : '.*'$GOOGLYRICS >/dev/null 2>&1 && continue - notempty=0 - test x"$line" = x || notempty=1; - test $notempty -eq 1 && txtfound=1; - test $txtfound -eq 1 && echo $line -done > "$3".loading 2>/dev/null -# use .loading because the file is already there when googlyrics starts -# but muggle thinks we are done as soon as $3 exists -if test -s "$3".loading + for i in "$outdir"/*.raw + do + test -r "$i" || break + cat "$i" | + sed 's/\x0d//g' | + sed 's/\xc2\xb4/\x27/g' | + sed 's/\xc3\x82\x27/\x27/g' | + sed 's/\xc3\x82/\x27/g' | + sed 's/\xc3\xb9/\x27/g' | + sed 's/\xe2\x80\x99/\x27/g' | + grep -ive 'NEW.*ringtones' | + grep -v -e '--------------' | + recode HTML..utf8 | + sed 's/\xc2\x91/\x27/g' | # in unicode, those two are reserved for + sed 's/\xc2\x92/\x27/g' | # private use, but still some sites use them... + cat > "$i.converted" 2>/dev/null + rm -f "$i" + echo cmp -s "$i.converted" "$orgoutfile">>/tmp/log.wr + cmp -s "$i.converted" "$orgoutfile" + if test $? -eq 0 + then + echo rm -f "$i.converted" >>/tmp/log.wr + rm -f "$i.converted" + continue + fi + done +fi + +rmdir "$outdir" 2>/dev/null +if test -d "$outdir" then - mv "$3".loading "$3" -else - rm -f "$3".loading + ls -l "$outdir" + ls "$outdir"/*.converted | head -1 | while read fn + do + test -r "$fn" || break + mv "$fn" "$outfile" + done + rmdir "$outdir" 2>/dev/null fi -test -s "$3" # we want the exit code +rm -f "$outfile".loading |