mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Use new MediaFile api to embed art
This commit is contained in:
parent
43f94ab7e6
commit
071a5c363d
1 changed files with 4 additions and 17 deletions
|
|
@ -33,17 +33,7 @@ def _embed(path, items, maxwidth=0):
|
||||||
path = ArtResizer.shared.resize(maxwidth, syspath(path))
|
path = ArtResizer.shared.resize(maxwidth, syspath(path))
|
||||||
|
|
||||||
data = open(syspath(path), 'rb').read()
|
data = open(syspath(path), 'rb').read()
|
||||||
kindstr = imghdr.what(None, data)
|
image = mediafile.Image(data, type=Image.TYPES.front)
|
||||||
if kindstr is None:
|
|
||||||
log.error(u'Could not embed art of unkown type: {0}'.format(
|
|
||||||
displayable_path(path)
|
|
||||||
))
|
|
||||||
return
|
|
||||||
elif kindstr not in ('jpeg', 'png'):
|
|
||||||
log.error(u'Image type {0} is not allowed as cover art: {1}'.format(
|
|
||||||
kindstr, displayable_path(path)
|
|
||||||
))
|
|
||||||
return
|
|
||||||
|
|
||||||
# Add art to each file.
|
# Add art to each file.
|
||||||
log.debug('Embedding album art.')
|
log.debug('Embedding album art.')
|
||||||
|
|
@ -56,7 +46,7 @@ def _embed(path, items, maxwidth=0):
|
||||||
displayable_path(item.path), exc
|
displayable_path(item.path), exc
|
||||||
))
|
))
|
||||||
continue
|
continue
|
||||||
f.art = data
|
f.images = [image]
|
||||||
f.save(config['id3v23'].get(bool))
|
f.save(config['id3v23'].get(bool))
|
||||||
|
|
||||||
class EmbedCoverArtPlugin(BeetsPlugin):
|
class EmbedCoverArtPlugin(BeetsPlugin):
|
||||||
|
|
@ -139,11 +129,8 @@ def embed_current(lib, query):
|
||||||
|
|
||||||
# "extractart" command.
|
# "extractart" command.
|
||||||
def extract(lib, outpath, query):
|
def extract(lib, outpath, query):
|
||||||
items = lib.items(query)
|
item = lib.items(query).get()
|
||||||
for i_item in items:
|
if not item:
|
||||||
item = i_item
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
log.error('No item matches query.')
|
log.error('No item matches query.')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue