diff --git a/greg/aux_functions.py b/greg/aux_functions.py index 6eacced..b66e577 100755 --- a/greg/aux_functions.py +++ b/greg/aux_functions.py @@ -176,7 +176,21 @@ def tag(placeholders): filename = substitute_placeholders(template, placeholders) podpath = os.path.join(placeholders.directory, filename) # ... and this is it - + # We also retrieve the path of a cover image, if there is one + coverart = placeholders.feed.retrieve_config("coverart", False) + if coverart: + import mimetypes + coverart_filename = substitute_placeholders(coverart, placeholders) + if not os.path.exists(coverart_filename): + print("""The file that I was supposed to use as cover art does not + exist.""", file=sys.stderr, flush=True) + coverart = False + else: + coverart_mime = mimetypes.guess_type(coverart_filename)[0] + if not coverart_mime: + print("""I couldn't guess the mimetype of this file, please use a + more perspicuous extension""", file=sys.stderr, flush=True) + coverart = False # now we create a dictionary of tags and values tagdict = placeholders.feed.defaulttagdict # these are the defaults try: # We do as if there was a section with potential tag info @@ -205,8 +219,12 @@ def tag(placeholders): setattr(file_to_tag.tag, mytag, tagdict[mytag]) except AttributeError: setattr(file_to_tag.tag, mytag, tagdict[mytag]) + if coverart: + with open(coverart_filename, 'rb') as imagefile: + image = imagefile.read() + file_to_tag.tag.images.set( + type_=3, img_data=image, mime_type=coverart_mime) file_to_tag.tag.save() - def filtercond(placeholders): diff --git a/greg/data/greg.conf b/greg/data/greg.conf index e81baf1..57cca02 100644 --- a/greg/data/greg.conf +++ b/greg/data/greg.conf @@ -139,6 +139,16 @@ tag_artist = {podcasttitle} tag_title = {title} tag_genre = Podcast +# You can also add a front-cover image to your podcast, if you wish, like so: +# +# coverart = path/to/image/file +# +# Note that greg will rely on the image file extension to guess its mimetype, +# so be sure to name it something reasonable (e.g. "something_or_other.png", or +# "thus_and_so.jpeg" are perfectly good names, but "cover.art" is not.) +# Note also that adding a cover image counts as tagging, so greg will only do +# it if you have 'Tag = yes' in the options to the relevant podcast. + # If you want to *remove* any of the tags that the podcast ships with, simply # leave it blank, like so: # @@ -247,4 +257,3 @@ notype = no # In the global version of this file (that is, /etc/greg.conf) sections for # individual feeds will not be read. # -