-
-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PICARD-1877: Support language for lyrics tags #1650
Draft
phw
wants to merge
1
commit into
metabrainz:master
Choose a base branch
from
phw:PICARD-1877-lyrics-tags-with-lang
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,7 @@ def display_tag_name(name): | |
def parse_comment_tag(name): # noqa: E302 | ||
""" | ||
Parses a tag name like "comment:XXX:desc", where XXX is the language. | ||
If language is not set ("comment:desc") "eng" is assumed as default. | ||
If language is not set ("comment:desc") default_language is used. | ||
Returns a (lang, desc) tuple. | ||
""" | ||
try: | ||
|
@@ -159,3 +159,36 @@ def parse_comment_tag(name): # noqa: E302 | |
lang = match.group(1) | ||
desc = desc[4:] | ||
return (lang, desc) | ||
|
||
|
||
RE_LYRICS_TAG = re.compile('^(?P<name>[^:]+)(?::(?P<lang>[a-zA-Z]{3})?)?(?::(?P<desc>.*))?$') | ||
def parse_lang_desc_tag(name, default_language='xxx'): # noqa: E302 | ||
""" | ||
Parses a tag name like with a language and description such as "lyrics:XXX:desc". | ||
|
||
Language must be a 3 letter language code as defined in ISO639-2, with the special | ||
value 'xxx' being used if the language is not specified. If language is not set ("lyrics" | ||
or "lyrics::desc") default_language is used. | ||
Language and description are optional. | ||
|
||
Returns a (lang, desc) tuple. | ||
""" | ||
match = RE_LYRICS_TAG.match(name) | ||
lang = default_language | ||
desc = '' | ||
if match: | ||
lang = match.group('lang') or default_language | ||
desc = match.group('desc') or '' | ||
return (lang, desc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps return |
||
|
||
|
||
def create_lang_desc_tag(name, language='xxx', description='', default_language='xxx'): | ||
name_parts = [name, ] | ||
if language and language.lower() != default_language: | ||
name_parts.append(language) | ||
elif description: | ||
# Add empty language part if description is also set | ||
name_parts.append('') | ||
if description: | ||
name_parts.append(description) | ||
return ':'.join(name_parts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of 'lyrics:eng' it will return empty desc and lang='eng', but in case of 'lyrics:123' it will return empty lang and '123' as desc. Is this the expected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It kind of was intentional, using the second element as language only if it is a valid 3 letter language code (as this is what is also supported in ID3). It also serves as a fallback if one should indeed use a
lyrics:something
tag with something being the description. But my thinking was also that lyrics with description are probably not that common, but setting the language for lyrics is more important. That's probably a bit different to how it is with comments!?Anyway, this is really messy and I'm unsure how to proceed. Ideally I would like both comment and lyrics the same, ideally without breaking someones existing use case. But maybe we need to break things a bit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against breaking changes if required to improve overall user experience on the long term. It just have to be well documented.