|
@ -7,30 +7,12 @@ import logging |
|
|
import os |
|
|
import os |
|
|
import pickle |
|
|
import pickle |
|
|
import re |
|
|
import re |
|
|
from collections import OrderedDict |
|
|
|
|
|
|
|
|
|
|
|
from patacrep.authors import process_listauthors |
|
|
from patacrep.authors import process_listauthors |
|
|
from patacrep import files, encoding |
|
|
from patacrep import files, encoding |
|
|
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__) |
|
|
LOGGER = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
BABEL_LANGUAGES = OrderedDict(( |
|
|
|
|
|
('fr', 'french'), |
|
|
|
|
|
('en', 'english'), |
|
|
|
|
|
('de', 'german'), |
|
|
|
|
|
('es', 'spanish'), |
|
|
|
|
|
('it', 'italian'), |
|
|
|
|
|
('pt', 'portuguese'), |
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
def lang2language(lang): |
|
|
|
|
|
try: |
|
|
|
|
|
return BABEL_LANGUAGES[lang] |
|
|
|
|
|
except KeyError: |
|
|
|
|
|
available = ", ".join(BABEL_LANGUAGES.keys()) |
|
|
|
|
|
LOGGER.error('Unknown lang code: ' + lang + '. Supported: ' + available) |
|
|
|
|
|
return 'english' |
|
|
|
|
|
|
|
|
|
|
|
def cached_name(datadir, filename): |
|
|
def cached_name(datadir, filename): |
|
|
"""Return the filename of the cache version of the file.""" |
|
|
"""Return the filename of the cache version of the file.""" |
|
|
fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename)) |
|
|
fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename)) |
|
@ -107,7 +89,7 @@ class Song: |
|
|
"cached", |
|
|
"cached", |
|
|
"data", |
|
|
"data", |
|
|
"subpath", |
|
|
"subpath", |
|
|
"language", |
|
|
"lang", |
|
|
"authors", |
|
|
"authors", |
|
|
"_filehash", |
|
|
"_filehash", |
|
|
"_version", |
|
|
"_version", |
|
@ -204,8 +186,7 @@ class Song: |
|
|
|
|
|
|
|
|
- titles: the list of (raw) titles. This list will be processed to |
|
|
- titles: the list of (raw) titles. This list will be processed to |
|
|
remove prefixes. |
|
|
remove prefixes. |
|
|
- language: the main language of the song, as language recognized by |
|
|
- lang: the main language of the song, as language code.. |
|
|
the LaTeX babel package. |
|
|
|
|
|
- authors: the list of (raw) authors. This list will be processed to |
|
|
- authors: the list of (raw) authors. This list will be processed to |
|
|
'clean' it (see function :func:`patacrep.authors.processauthors`). |
|
|
'clean' it (see function :func:`patacrep.authors.processauthors`). |
|
|
- data: song metadata. Used (among others) to sort the songs. |
|
|
- data: song metadata. Used (among others) to sort the songs. |
|
@ -264,21 +245,6 @@ class Song: |
|
|
filepath = self.search_file(filename, ['', '.ly']) |
|
|
filepath = self.search_file(filename, ['', '.ly']) |
|
|
return filepath if none_if_not_found or filepath else filename |
|
|
return filepath if none_if_not_found or filepath else filename |
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
def language(self): |
|
|
|
|
|
"""Return the string corresponding to the babel (LaTeX) language""" |
|
|
|
|
|
return lang2language(self.lang) |
|
|
|
|
|
|
|
|
|
|
|
@language.setter |
|
|
|
|
|
def language(self, language): |
|
|
|
|
|
"""Set the language code""" |
|
|
|
|
|
for lang, babel_language in BABEL_LANGUAGES.items(): |
|
|
|
|
|
if language == babel_language: |
|
|
|
|
|
self.lang = lang |
|
|
|
|
|
return |
|
|
|
|
|
# TODO: raise a nice error |
|
|
|
|
|
print('Unsupported language:' + language) |
|
|
|
|
|
|
|
|
|
|
|
def unprefixed_title(title, prefixes): |
|
|
def unprefixed_title(title, prefixes): |
|
|
"""Remove the first prefix of the list in the beginning of title (if any). |
|
|
"""Remove the first prefix of the list in the beginning of title (if any). |
|
|
""" |
|
|
""" |
|
|