mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
Add initial version of the embed coverart plugin.
This plugin allows users to embed the cover into the audio file. Probaly still has a few bugs but it should work in most cases right now.
This commit is contained in:
parent
322038550a
commit
0628d8df0e
1 changed files with 45 additions and 0 deletions
45
beetsplug/embedcoverart.py
Normal file
45
beetsplug/embedcoverart.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from beets.plugins import BeetsPlugin
|
||||
from beets import mediafile
|
||||
|
||||
import os, logging
|
||||
|
||||
from email.mime.image import MIMEImage
|
||||
|
||||
log = logging.getLogger('beets')
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
|
||||
class EmbedAlbumartPlugin(BeetsPlugin):
|
||||
'''Allows albumart to be embedded into the actual files'''
|
||||
|
||||
def __init__(self):
|
||||
self.register_listener('loaded', self.loaded)
|
||||
self.register_listener('album_imported', self.album_imported)
|
||||
|
||||
def configure(self, config):
|
||||
pass
|
||||
|
||||
def loaded(self):
|
||||
pass
|
||||
|
||||
def album_imported(self, album):
|
||||
albumart = album.artpath
|
||||
ALLOWED_MIMES = ('jpeg','png')
|
||||
|
||||
if albumart:
|
||||
albumart_raw = open(albumart, 'rb').read()
|
||||
img = MIMEImage(albumart_raw)
|
||||
mime_img = img.get_content_subtype()
|
||||
|
||||
if mime_img in ALLOWED_MIMES:
|
||||
mime_type = 'image/%s' % mime_img
|
||||
|
||||
for item in album.items():
|
||||
f = mediafile.MediaFile(item)
|
||||
|
||||
if "mp3" in item.type:
|
||||
f.albumart_mime = mime_type
|
||||
|
||||
f.albumart_data = albumart_raw
|
||||
f.save()
|
||||
|
||||
Loading…
Reference in a new issue