-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Add album_level_tags plugin #219
base: 2.0
Are you sure you want to change the base?
Conversation
54070de
to
43e1e52
Compare
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.
LGTM
@phw: ok for you ?
I just realized how this plugin could be made much cleaner. Instead of scribing down tags as they come by, an album object can be saved as a global variable. Then the album object can be accessed when the script functions are being called. Duhhh. Gonna make those changes soonish. |
Should we merge as is or do you have changes to make before? |
44a4d6d
to
af8cf0c
Compare
New plugin to transform multiple file specific tags into single strings which are usable in the file naming script via script functions.
af8cf0c
to
79e8a0e
Compare
Almost forgot to update this. The plugin has some option pages now and quite big changes in the way it works. Didn't end up needing the new hooks after all. (Awkward.) The option editing is a bit rough but I hope it's somewhat easy to understand. All in all, I'm happy with the plugin now. |
|
||
# Check if cached data is recent enough to be used (i.e. we can assume that the user hasn't modified the tags | ||
# in the meantime) or remove other releases from the cache to keep it small | ||
global tag_cache |
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.
global
keyword isn't strictly needed here I think.
t = time.time() | ||
|
||
cached_results = album_cache.get((metadata_key, option_profile)) | ||
if cached_results and t - last_run_time < 4: # seconds |
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.
I'd replace 4
with a explicit variable/constant (something like DELAY_IN_SECONDS
) and remove the comment.
global last_run_time | ||
album_cache = tag_cache.get(album.id, {}) | ||
if album_cache: | ||
t = time.time() |
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.
Instead of t
, I'd use now
or current_time
since it stores current time.
|
||
if option_profile is not None and option_profile not in all_user_options: | ||
raise KeyError("{0}: Unknown option profile \"{1}\" used in a script.".format(PLUGIN_NAME, option_profile)) | ||
if profile_options.get(FORMATTER_WHEN_ONE_OPTION): |
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.
Perhaps:
formatter2_is_default = False if profile_options.get(FORMATTER_WHEN_ONE_OPTION) else True
Since you're using few of those below.
group_by_medium = True if metadata_key == "media" else False | ||
discnumber = 0 | ||
temp = defaultdict(list) | ||
for t in album.tracks: |
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.
Use track
instead of t
.
|
||
if average_mode: | ||
tag_counter = Counter({ sum(map(float, tag_list)) / len(tag_list): 1 | ||
for tag_list in temp.values() if len(tag_list) > 0 }) |
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.
This expression deserves at least a comment, you may also cache len(tag_list)
.
|
||
# Effectively removes the None key from the counter | ||
tag_counter[None] = 0 | ||
tag_counter = +tag_counter |
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.
Typo? Or?
text_area = self.ui.plainTextEdit_raw_2 | ||
label = self.ui.label_valid_raw_2 | ||
try: | ||
_ = json.loads(text_area.toPlainText()) |
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.
Please avoid the use of _
, it is reserved for gettextization (see https://github.com/metabrainz/picard/blob/master/picard/i18n.py)
) | ||
from PyQt5 import QtGui | ||
from PyQt5.QtWidgets import QButtonGroup | ||
import time |
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.
You might want to re-order imports to fit usual Picard import order (see https://github.com/metabrainz/picard/blob/master/CONTRIBUTING.md and search for isort
).
I can't help but wonder whether it might be better for this plugin simply to calculate the lists and averages of various file metadata and place them in the album metadata as new variables. |
New plugin to transform multiple file specific tags into single
strings which are usable in the file naming script via script
functions.