|
@ -11,6 +11,27 @@ def _indent(string): |
|
|
"""Return and indented version of argument.""" |
|
|
"""Return and indented version of argument.""" |
|
|
return "\n".join([" {}".format(line) for line in string.split('\n')]) |
|
|
return "\n".join([" {}".format(line) for line in string.split('\n')]) |
|
|
|
|
|
|
|
|
|
|
|
#: Available directives, that is, directives that we know how to deal with |
|
|
|
|
|
AVAILABLE_DIRECTIVES = [ |
|
|
|
|
|
"album", |
|
|
|
|
|
"artist", |
|
|
|
|
|
"capo", |
|
|
|
|
|
"comment", |
|
|
|
|
|
"copyright", |
|
|
|
|
|
"columns", |
|
|
|
|
|
"cov", |
|
|
|
|
|
"define", |
|
|
|
|
|
"guitar_comment", |
|
|
|
|
|
"image", |
|
|
|
|
|
"key", |
|
|
|
|
|
"language", |
|
|
|
|
|
"newline", |
|
|
|
|
|
"partition", |
|
|
|
|
|
"subtitle", |
|
|
|
|
|
"tag", |
|
|
|
|
|
"title", |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
#: List of properties that are to be displayed in the flow of the song (not as |
|
|
#: List of properties that are to be displayed in the flow of the song (not as |
|
|
#: metadata at the beginning or end of song. |
|
|
#: metadata at the beginning or end of song. |
|
|
INLINE_DIRECTIVES = { |
|
|
INLINE_DIRECTIVES = { |
|
@ -30,8 +51,8 @@ DIRECTIVE_SHORTCUTS = { |
|
|
"by": "artist", |
|
|
"by": "artist", |
|
|
"c": "comment", |
|
|
"c": "comment", |
|
|
"gc": "guitar_comment", |
|
|
"gc": "guitar_comment", |
|
|
"cover": "cov", |
|
|
"cov": "cover", |
|
|
"language": "lang", |
|
|
"lang": "language", |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def directive_name(text): |
|
|
def directive_name(text): |
|
@ -208,6 +229,7 @@ class Song(AST): |
|
|
|
|
|
|
|
|
def add(self, data): |
|
|
def add(self, data): |
|
|
"""Add an element to the song""" |
|
|
"""Add an element to the song""" |
|
|
|
|
|
# pylint: disable=too-many-branches |
|
|
if isinstance(data, Error): |
|
|
if isinstance(data, Error): |
|
|
pass |
|
|
pass |
|
|
elif data is None: |
|
|
elif data is None: |
|
@ -222,6 +244,8 @@ class Song(AST): |
|
|
self.content[0].prepend(data.strip()) |
|
|
self.content[0].prepend(data.strip()) |
|
|
elif isinstance(data, Directive) and data.inline: |
|
|
elif isinstance(data, Directive) and data.inline: |
|
|
# Add a directive in the content of the song. |
|
|
# Add a directive in the content of the song. |
|
|
|
|
|
# It is useless to check if directive is in AVAILABLE_DIRECTIVES, |
|
|
|
|
|
# since it is in INLINE_DIRECTIVES. |
|
|
self.content.append(data) |
|
|
self.content.append(data) |
|
|
elif data.inline: |
|
|
elif data.inline: |
|
|
# Add an object in the content of the song. |
|
|
# Add an object in the content of the song. |
|
@ -229,6 +253,8 @@ class Song(AST): |
|
|
elif isinstance(data, Directive): |
|
|
elif isinstance(data, Directive): |
|
|
# Add a metadata directive. Some of them are added using special |
|
|
# Add a metadata directive. Some of them are added using special |
|
|
# methods listed in ``METADATA_ADD``. |
|
|
# methods listed in ``METADATA_ADD``. |
|
|
|
|
|
if data.keyword not in AVAILABLE_DIRECTIVES: |
|
|
|
|
|
LOGGER.warning("Ignoring unknown directive '{}'.".format(data.keyword)) |
|
|
if data.keyword in self.METADATA_ADD: |
|
|
if data.keyword in self.METADATA_ADD: |
|
|
getattr(self, self.METADATA_ADD[data.keyword])(data) |
|
|
getattr(self, self.METADATA_ADD[data.keyword])(data) |
|
|
else: |
|
|
else: |
|
|