-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support for APEv2 cover tags #1042
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -868,7 +868,7 @@ class VorbisImageStorageStyle(ListStorageStyle): | |
base64-encoded. Values are `Image` objects. | ||
""" | ||
formats = ['OggOpus', 'OggTheora', 'OggSpeex', 'OggVorbis', | ||
'OggFlac', 'APEv2File', 'WavPack', 'Musepack', 'MonkeysAudio'] | ||
'OggFlac'] | ||
|
||
def __init__(self): | ||
super(VorbisImageStorageStyle, self).__init__( | ||
|
@@ -950,6 +950,70 @@ def delete(self, mutagen_file): | |
mutagen_file.clear_pictures() | ||
|
||
|
||
class APEv2ImageStorageStyle(ListStorageStyle): | ||
"""Store images in APEv2 tags. Values are `Image` objects. | ||
""" | ||
formats = ['APEv2File', 'WavPack', 'Musepack', 'MonkeysAudio', 'OptimFROG'] | ||
|
||
_APE_COVER_TAG_NAMES = {ImageType.other: 'Cover Art (other)', | ||
ImageType.icon: 'Cover Art (icon)', | ||
ImageType.other_icon: 'Cover Art (other icon)', | ||
ImageType.front: 'Cover Art (front)', | ||
ImageType.back: 'Cover Art (back)', | ||
ImageType.leaflet: 'Cover Art (leaflet)', | ||
ImageType.media: 'Cover Art (media)', | ||
ImageType.lead_artist: 'Cover Art (lead)', | ||
ImageType.artist: 'Cover Art (artist)', | ||
ImageType.conductor: 'Cover Art (conductor)', | ||
ImageType.group: 'Cover Art (band)', | ||
ImageType.composer: 'Cover Art (composer)', | ||
ImageType.lyricist: 'Cover Art (lyricist)', | ||
ImageType.recording_location: 'Cover Art (studio)', | ||
ImageType.recording_session: 'Cover Art (recording)', | ||
ImageType.performance: 'Cover Art (performance)', | ||
ImageType.screen_capture: 'Cover Art (movie scene)', | ||
ImageType.fish: 'Cover Art (colored fish)', | ||
ImageType.illustration: 'Cover Art (illustration)', | ||
ImageType.artist_logo: 'Cover Art (band logo)', | ||
ImageType.publisher_logo: 'Cover Art (publisher logo)' | ||
} | ||
|
||
def __init__(self): | ||
super(APEv2ImageStorageStyle, self).__init__(key='') | ||
|
||
def fetch(self, mutagen_file): | ||
images = [] | ||
for cover_type, cover_tag in APEv2ImageStorageStyle._APE_COVER_TAG_NAMES.iteritems(): | ||
try: | ||
frame = mutagen_file[cover_tag] | ||
text_delimiter_index = frame.value.find('\x00') | ||
comment = frame.value[0:text_delimiter_index] if text_delimiter_index > 0 else None | ||
image_data = frame.value[text_delimiter_index+1:] | ||
images.append(Image(data=image_data, type=cover_type, desc=comment)) | ||
except KeyError: | ||
pass | ||
|
||
return images | ||
|
||
def set_list(self, mutagen_file, values): | ||
self.delete(mutagen_file) | ||
|
||
for image in values: | ||
image_type = image.type if image.type is not None else ImageType.other | ||
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.
|
||
comment = image.desc if image.desc else '' | ||
image_data = comment + "\x00" + image.data | ||
cover_tag = APEv2ImageStorageStyle._APE_COVER_TAG_NAMES[image_type] | ||
mutagen_file[cover_tag] = image_data | ||
|
||
def delete(self, mutagen_file): | ||
"""Remove all images from the file. | ||
""" | ||
for cover_tag in APEv2ImageStorageStyle._APE_COVER_TAG_NAMES.itervalues(): | ||
try: | ||
del mutagen_file[cover_tag] | ||
except KeyError: | ||
pass | ||
|
||
# MediaField is a descriptor that represents a single logical field. It | ||
# aggregates several StorageStyles describing how to access the data for | ||
# each file type. | ||
|
@@ -1206,6 +1270,7 @@ def __init__(self): | |
ASFImageStorageStyle(), | ||
VorbisImageStorageStyle(), | ||
FlacImageStorageStyle(), | ||
APEv2ImageStorageStyle(), | ||
) | ||
|
||
def __get__(self, mediafile, _): | ||
|
Binary file not shown.
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.
Cool—I think the answer is "yes", but just to confirm: all three formats almost always use APE tags, right (WavPack, Musepack, and Monkey's Audio)? I've never run across any with Vorbis comments, but it would be great to have a second opinion.
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.
Yes, all these formats use ape tags as primary metadata format. The mutagen classes also inherit from APEv2File.