diff options
author | Wolfgang Rohdewald <wolfgang@rohdewald.de> | 2009-01-11 23:14:12 +0100 |
---|---|---|
committer | Wolfgang Rohdewald <wolfgang@rohdewald.de> | 2009-01-11 23:14:12 +0100 |
commit | c405cdff24427c485e493424f8dbd3a2c3061be8 (patch) | |
tree | 780634b8cf992010e92bc6b5edf96d0cacd45849 | |
parent | 2975f47469b4f881d01324d4905c6371ac358b4b (diff) | |
download | vdr-plugin-muggle-c405cdff24427c485e493424f8dbd3a2c3061be8.tar.gz vdr-plugin-muggle-c405cdff24427c485e493424f8dbd3a2c3061be8.tar.bz2 |
split lines now works with unicode. Fixes bug #52
-rw-r--r-- | HISTORY | 4 | ||||
-rw-r--r-- | README | 11 | ||||
-rw-r--r-- | mg_menu.c | 40 | ||||
-rwxr-xr-x | scripts/muggle_getlyrics | 30 |
4 files changed, 48 insertions, 37 deletions
@@ -388,3 +388,7 @@ Balke. - Lyrics: rewrite the shell script muggle_getlyrics in python and talk directly to the Googlyrics2 python code - load images: fix buggy error handling (reported in vdr-portal.de by stevie101) +- Lyrics: Fix bug #52: line split could split within 2byte unicode char. Now + removed this code from C++ and put it into the python script muggle_getlyrics. +- Lyrics: when calling "mv" to rename a file make sure mv never gets interactive +- muggle-image-convert produces less output if needed programs are not installed @@ -340,10 +340,15 @@ Instead it waits until the script has finished. Meanwhile it will not 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 -mgLyrics.py which in turn uses the Googlyrics2 python modules. +Muggle calls the python program muggle_getlyrics which +uses the Googlyrics2 python modules. Googlyrics2 is a plugin to the amarok music player, it can currently ask -26 different sources. +27 different sources. + +If the lyrics lines are too long, they are split by muggle_getlyrics. If +those lines are too short or too long, adapt MAXLINELENGTH in muggle_getlyrics. +Currently lines are split at normal space and at nbsp (unicode non breaking +space). Lines that have no such spaces are not split. @@ -255,35 +255,23 @@ mgOsd::AddText(const char* text,bool selectable) { } void -mgOsd::AddLongText(const char* text) { - char *s=strdup(text); - char *p=s; - unsigned int brk=57; - bool selectable = strlen(s); - while (strlen(p)>=brk) { - char save=p[brk]; - p[brk]=0; - AddText(p,selectable); - p[brk]=save; - p+=brk; - } - if (strlen(p)) - AddText(p,selectable); - free(s); -} - -void mgOsd::AddFile(const string filename) { - ifstream infile(filename.c_str()); - string line; - if(infile) { - while(getline(infile, line , '\n')) - AddLongText(line.c_str()); - } - else { + FILE *fp = fopen(filename.c_str(),"r"); + if (fp) { + char* line = NULL; + size_t len = 0; + while (getline(&line, &len , fp) != -1) { + char *lf = strrchr(line,'\n'); + if (lf) *lf = 0; + AddText(line,strlen(line)); + } + if (line) + free(line); + fclose(fp); + } else { char *s; msprintf(&s,tr("File %s not found"),filename.c_str()); - AddLongText(s); + AddText(s); free(s); } } diff --git a/scripts/muggle_getlyrics b/scripts/muggle_getlyrics index f0d5701..b187487 100755 --- a/scripts/muggle_getlyrics +++ b/scripts/muggle_getlyrics @@ -6,6 +6,28 @@ import os, sys, locale, re, codecs import filecmp from htmlentitydefs import name2codepoint as n2cp +MAXLINELENGTH = 50 + +def writeFile(name,s): + if not os.path.isdir(outdir): + os.mkdir(outdir) + outname = outdir + '/' + name + outfile = open(outname,"w") + lines = s.splitlines() + for line in lines: +# xa0 is unicode non breaking space + words = re.split(r' |\xa0',line) + widx1 = 0 + while widx1 < len(words): + widx2 = len(words) + while widx2 > widx1 + 1 and len(' '.join(words[widx1:widx2])) > MAXLINELENGTH: + widx2 -= 1 + newline = ' '.join(words[widx1:widx2])+'\n' + newline = newline.encode(locale.getdefaultlocale()[1]) + outfile.write(newline) + widx1 = widx2 + outfile.close + charset = locale.getdefaultlocale()[1] title = sys.argv[1].decode(charset).encode('UTF8') artist = sys.argv[2].decode(charset).encode('UTF8') @@ -52,13 +74,6 @@ def countFiles(): return 0 return len(os.listdir(outdir)) -def writeFile(name,s): - if not os.path.isdir(outdir): - os.mkdir(outdir) - outfile = open(outdir + '/' + name,"w") - outfile.write(s) - outfile.close - def load(debug=False): if debug: outlyric=["Version 1","Version 2","Version 3"] @@ -98,7 +113,6 @@ def load(debug=False): # private use, but still some sites use them.. s = s.replace(r'\xc2\x91',r'\x27') s = s.replace(r'\xc2\x92',r'\x27') - s = s.encode(locale.getdefaultlocale()[1]) writeFile(str(idx)+'-'+l.sitename,s) # ----------------------------------------------- |