summaryrefslogtreecommitdiff
path: root/scripts/mgLyric.py
diff options
context:
space:
mode:
authorWolfgang Rohdewald <wolfgang@rohdewald.de>2009-01-05 14:43:43 +0100
committerWolfgang Rohdewald <wolfgang@rohdewald.de>2009-01-05 14:43:43 +0100
commit81f501620a3d8c5193121a0ad069ddc1b4c04376 (patch)
tree76ec08f4dfaee4eeb1db4d1c9ec1d9b31e5e2a87 /scripts/mgLyric.py
parentac8b392c635fea872b7cb97cdc858512d10aa90e (diff)
downloadvdr-plugin-muggle-81f501620a3d8c5193121a0ad069ddc1b4c04376.tar.gz
vdr-plugin-muggle-81f501620a3d8c5193121a0ad069ddc1b4c04376.tar.bz2
Lyrics now work with Googlyrics2
if several versions of lyrics for a song are found, it is now possible to choose among them.
Diffstat (limited to 'scripts/mgLyric.py')
-rwxr-xr-xscripts/mgLyric.py52
1 files changed, 52 insertions, 0 deletions
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
+