Skip to content
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

albumart #106

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions greg/aux_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor

@sabberworm sabberworm May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than guessing the MIME type from the extension, couldn’t we leverage mime-info on systems that have it? It’s more accurate in most cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit wary of multiplying dependencies; also, users can pretty much choose their own extension with file_to_tag, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed that EyeD3 bundled magic anyway for use with https://eyed3.readthedocs.io/en/latest/eyed3.plugins.html#module-eyed3.plugins.mimetype but looking at the source, it seems I was mistaken.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but perhaps I'm being silly about dependencies. You seem to be a serious dev, much unlike me :) So I'm willing to listen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think you’re being perfectly reasonable. Also I might be a serious dev (whatever that means) but not all that familiar with the Python ecosystem…

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
Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cool if the coverart_filename could be a http(s) URL. And if the images linked from the feed (e.g. <image><url> in the feed and <itunes:image> in the article) would be made available as placeholders. This way we could do:

coverart = {articleimage}

or

coverart = {feedimage}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, let me look into that.

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):
Expand Down
11 changes: 10 additions & 1 deletion greg/data/greg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down Expand Up @@ -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.
#