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

Add album_level_tags plugin #219

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from

Conversation

Harakku
Copy link

@Harakku Harakku commented May 6, 2019

New plugin to transform multiple file specific tags into single
strings which are usable in the file naming script via script
functions.

@Harakku Harakku force-pushed the album_level_tags branch 4 times, most recently from 54070de to 43e1e52 Compare May 15, 2019 01:11
@zas zas requested review from zas and samj1912 June 6, 2019 16:14
Copy link
Collaborator

@zas zas left a 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 ?

@Harakku
Copy link
Author

Harakku commented Jun 18, 2019

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.

@zas
Copy link
Collaborator

zas commented Jul 22, 2019

Gonna make those changes soonish.

Should we merge as is or do you have changes to make before?

@Harakku Harakku force-pushed the album_level_tags branch 2 times, most recently from 44a4d6d to af8cf0c Compare July 23, 2019 00:17
New plugin to transform multiple file specific tags into single
strings which are usable in the file naming script via script
functions.
@Harakku
Copy link
Author

Harakku commented Jul 23, 2019

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
Copy link
Collaborator

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
Copy link
Collaborator

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()
Copy link
Collaborator

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):
Copy link
Collaborator

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:
Copy link
Collaborator

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 })
Copy link
Collaborator

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
Copy link
Collaborator

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())
Copy link
Collaborator

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
Copy link
Collaborator

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).

@Sophist-UK
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants