Commit graph

264 commits

Author SHA1 Message Date
J0J0 Todos
24a3394b97 Fix keep-none option, reword help
and a tiny hint along the way: clarify that -a is implicit.
2025-01-22 18:39:31 +01:00
J0J0 Todos
f695d463e2 Main variables init in _get_genre() 2025-01-22 18:14:42 +01:00
J0J0 Todos
1b05a1295d Revert "Further clarify lastgenre log-labels"
This reverts commit 8da98e52ee.

since we applied a PR suggestions where this is done in one place.
2025-01-22 18:11:18 +01:00
J0J0 Todos
86e1bd47a4 Single place for whitelist/any log-label suffix
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-22 18:07:43 +01:00
J0J0 Todos
87d9f57e24 In _get_existing_genres ensure empty string ignore 2025-01-22 18:07:43 +01:00
J0J0 Todos
92e84a2b45 Make sure existing genres are ALWAYS looked at
first thing. Only if genres are existing and force is disabled we return
early!
2025-01-21 18:06:11 +01:00
J0J0 Todos
6530d76319 Revert "Simplify _get_existing_genres()"
This reverts commit 7ff06df17c.

This was here for a reason: Ab empty string genre should als become an
empty list!
2025-01-21 17:44:17 +01:00
J0J0 Todos
4f0837c724 Revert "Include lower-casing in _get_existing already"
This reverts commit d5cf376a51.
2025-01-21 17:21:03 +01:00
J0J0 Todos
44901873f7 Clarify log-label: keep any, no-force 2025-01-21 17:04:03 +01:00
J0J0 Todos
d5cf376a51 Include lower-casing in _get_existing already
since we don't use it for early-returning no-force-existing genres
anymore.
2025-01-21 17:04:03 +01:00
J0J0 Todos
8da98e52ee Further clarify lastgenre log-labels
state if whitelist was applied or any genre is accepted.
2025-01-21 17:04:03 +01:00
J0J0 Todos
6e6a0ad9a9 Return empty tuple instead of disabling type issue 2025-01-21 17:04:03 +01:00
J0J0 Todos
c9187b40bd Don't uselessly split/join early returned genres 2025-01-21 17:04:03 +01:00
J0J0 Todos
169ec20a2f Remove unused _polish_existing_genres 2025-01-21 17:04:03 +01:00
J0J0 Todos
3cc2a5e2c6 Fix Tuple with tuple in sources property 2025-01-21 17:04:03 +01:00
J0J0 Todos
5d94eb3e13 Fix _get_genre docstring 2025-01-21 17:04:03 +01:00
J0J0 Todos
7ff06df17c Simplify _get_existing_genres()
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-21 17:04:03 +01:00
J0J0 Todos
c3f0abd61c Fix docstring _resolve_genres
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-21 17:04:03 +01:00
J0J0 Todos
bb3f9c53c2 lastgenre new defaults, remove config sanity check 2025-01-21 17:04:03 +01:00
J0J0 Todos
ca5e471f05 Refactor again _last_lookup 2025-01-21 17:04:03 +01:00
J0J0 Todos
ec10507fab Return as-is if no-force 2025-01-21 17:04:03 +01:00
J0J0 Todos
6e3f5b3127 Fix type hints, Refactor existing genres method
- Rename method _dedup_genre, since it's only used for
  finalizing/polishing existing genres.
- Return separator-delimited string already.
- Decide on not passing "separator" to methods, it's a config
  setting available throughout the plugin. Assign to variable where
  useful for readability though.
- In the force branch, remove re-assigning keep_genres to empty list.
- Fix a test. Existing genres are "polished" now, which means:
  configured title_case is applied.
- Fix/add type hints on all touched and new methods
2025-01-21 17:04:03 +01:00
J0J0 Todos
ed68bc019b Refactor _get_genre, simplify _combine_genre 2025-01-21 17:04:03 +01:00
J0J0 Todos
4580757c8e Simplify _last_lookup()
f-string, list comprehension, remove redundant vars.
2025-01-21 17:04:03 +01:00
J0J0 Todos
f16e671ff6 Simplify _get_genre keep_existing conditional
- If the keep_existing option is set, just remember everything for now.
- Dedup happening later on via _combine... _resolve_genres...
- Even knowing if whitelist or not is not important at this point.
2025-01-21 17:04:03 +01:00
J0J0 Todos
f698f21a28 Ensure _resolve returns list, add type hint
Prevents potential type erros when handing over to
_to_delimited_genre_string.
2025-01-21 17:04:03 +01:00
J0J0 Todos
d358a24ed9 Remove redundant unique_list call in _combine
and clarify in _resolve_genre docstring.
2025-01-21 17:04:02 +01:00
J0J0 Todos
2a80a10aa8 Use util.unique_list in fav of deduplicate 2025-01-21 17:04:02 +01:00
J0J0 Todos
79b5379dce Refactor and rename _is_valid() helper 2025-01-21 17:04:02 +01:00
J0J0 Todos
e1fe6fd3d0 Prevent album genre inherit only when source:track
is configured.
2025-01-21 17:04:02 +01:00
J0J0 Todos
bd0c02437a Apply temp logging leftover review suggestions
Useless variables that only were introduced for temporary debug logging
while refactoring earlier. Get rid of them.

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-21 17:04:02 +01:00
J0J0 Todos
b476560d76 Integrate _format_tag in _to_delimited_...
optimize by checking for config once and simplify tags list slicing.
Remove _format_tags method.

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-21 17:04:02 +01:00
J0J0 Todos
593f5460b6 Apply type hint suggestions from review
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-01-21 17:04:02 +01:00
J0J0 Todos
6b41743b91 Polish 'fetched last.fm tags' debug message
The best place to log what we actually fetched from last.fm seems to be
here in _combine_and_label_genres. Leave out the existing genres we also
receive in this function - less is more.
2025-01-21 17:04:02 +01:00
J0J0 Todos
8d43517a71 Remove all lastgenre temporary debug logging 2025-01-21 17:04:02 +01:00
J0J0 Todos
847b7260b4 Fix most popular track genre fetching (VA albums) 2025-01-21 17:04:02 +01:00
J0J0 Todos
1aca3989d7 Fix previous temp log messages 2025-01-21 17:04:02 +01:00
J0J0 Todos
da98d37632 Temporary debug messages in _sort_by_depth 2025-01-21 17:04:02 +01:00
J0J0 Todos
a717998587 Add a temporary log around whitelist setup 2025-01-21 17:04:02 +01:00
J0J0 Todos
37fc1b6b7f Final lastgenre plugin linting 2025-01-21 17:04:02 +01:00
J0J0 Todos
13ae699230 Fix _dedup_genre, ensure lower case
otherwise deduplicate() can't handle it.
2025-01-21 17:04:02 +01:00
J0J0 Todos
569ba73016 Refactor again _combine_and_label_genres 2025-01-21 17:04:02 +01:00
J0J0 Todos
3d036473e7 lastgenre _is_allowed detailed logging
- Add detailed debug logging to learn when and why things go wrong here.
- Shorten docstring
2025-01-21 17:04:02 +01:00
J0J0 Todos
9f5b4badb2 Handle genres as list, count/format/str helper
- Return fetched genres as a list from _resolve_genres().
- Format, limit to count and join to delimited string in helper
  function.
- Fix docstring.
- Leave a couple of temporary debug messages.
- Fix original genre fallback - just keep as-is.
2025-01-21 17:04:02 +01:00
J0J0 Todos
5e6d9170d7 Fix lastgenre "count" issue
When original genres were kept (keep_existing option), the final genre
count was "off". The reason was that reducing genres to that count is
handled in _resolve_genre which wasn't run.

- This fixes it by ensuring a run of _resolve_genre in
  _combine_and_label_genres.
- There is a small caveat though: New genres have been run through
  _resolve_genres already. When they are combined with the old ones,
  they run through it again. Let's take this into account for now and
  hope performance doesn't suffer too much.
2025-01-21 17:04:02 +01:00
J0J0 Todos
d0abc0d830 Rename lastgenre option, refactor, new default
- Refactor and simplify logic of _get_genre()
- Add a config validation function.
- New default force: yes, keep_existing: yes (closest to original
  behaviour)
2025-01-21 17:04:02 +01:00
J0J0 Todos
4c7d0c98cf Clarify lastgenre _is_allowed docstring 2025-01-21 17:04:02 +01:00
J0J0 Todos
90c48ea8cf Temporary lastgenre debug messages for @arsaboo 2025-01-21 17:04:02 +01:00
J0J0 Todos
b0e0f1b048 Fallback to next stage when fetch_ returns None
This was the original behaviour and broke when _combine_and_label helper
was introduced.
2025-01-21 17:04:02 +01:00
J0J0 Todos
462a7a524a _combine_and_label return None not empty str 2025-01-21 17:04:02 +01:00
J0J0 Todos
6866fce364 Fix default for _dedup_genre whitelist arg
when not stated otherwise whitelist_only must be disabled, we assume it
that way in _get_genre calls.
2025-01-21 17:04:02 +01:00
J0J0 Todos
cbc33e78fc lastgenre: Add comments over groups of methods
trying to get a little order in the chaos. Maybe reordering and/or
moving out of the main plugin logic would be a better idea for some
methods but don't put much more refactoring into this PR to keep it
readable.
2025-01-21 17:04:02 +01:00
J0J0 Todos
11f7a98917 Refactor keep/new genres combination
- Handle genre combination logic in a well documented helper function
  that also include type hints.
- Throughout the _get_genre function rename the result variable to
  new_genres to make it clearly descriptive.
- Rewrite thze _get_genre function's docstring.
2025-01-21 17:04:02 +01:00
J0J0 Todos
d935ec869c Implement --force and --keep-allowed behaviours
- Retrieving, filtering and deduplicating present genres of Items/Albums
  via separate methods.
- Implement all four cases of behaviour as described in PR#4982
- Issues:
  - There is quite some unnecessary spliting of genres from strings into
    lists and the other way round happening throughout the plugin.
  - In the case where existing genres get "augmented" with last.fm
    genres, we might end up with _more_ genres than the configured
    limit.
2025-01-21 17:04:02 +01:00
J0J0 Todos
318c02099a Add lastgenre keep_allowed options (-k/-K)
- Default to False.
- During PR#4982 discussions we came to the conclusion that the
  following behaviour would be a good new default choice:
  - Keep whitelisted existing genres
  - Only Fetch last.fm genres for empty tags.
  - To get this we also have to change the default of the force
    option!!!
  - Resulting in "force: no" and "keep_allowed: yes"; see Case 4 in
    PR#4982 description
- Options are not put to use yet, just defined and defaults set!
2025-01-21 17:04:02 +01:00
J0J0 Todos
4ea8650799 Use provided deduplicate function for keep_allowed
generation, instead of a simple set(). This way we keep the original
order of genres.
2025-01-21 17:04:02 +01:00
J0J0 Todos
fe466f4bb3 Use separator as configured instead of hardcoding
in lastgenre plugin.
2025-01-21 17:04:02 +01:00
J0J0 Todos
517c037c25 Refactor lastgenre keep_allowed to list comprehension 2025-01-21 17:04:02 +01:00
J0J0 Todos
7d6a4046ce Handle dups of existing genres in lastgenre plugin
When handling existing comma-separated genres in the _get_genre method
of the plugin, make sure duplicate genres are removed.
2025-01-21 17:04:02 +01:00
J0J0 Todos
6ab6ae2051 Fix track-level genre handling in lastgenre plugin
When `lastgenre.source: track` is configured,

- `lastgenre -a` _should not_ fall back to the album level genre (by
  making use of the with_album=False kwarg of the Libary's get method).
- `lastgenre -a`, when finally storing the genres of _an album_, should
  _not_ also write the tracks genres (by making use of the inherit=False
  kwarg of the Album's store method.
2025-01-21 17:04:02 +01:00
J0J0 Todos
4ff8c34ed1 Quickfix lastgenre always overwriting multi-genre 2025-01-21 17:04:02 +01:00
J0J0 Todos
0c10635ff7 Another round of lastgenre logging nitpicks
- Printing out album/item in default format could lead to unreadable
  clutter depending on the user's configured formats.
- The album's name and the individual tracks' title should be just
  sufficient to provide context as well readability.
- Log like this while importing as well as in standalone runs.
2025-01-07 01:54:17 +01:00
J0J0 Todos
9d09d6f317 Fix lastgenre source:track handling during imports 2025-01-07 01:54:17 +01:00
J0J0 Todos
18e76f08c7 Prevent album genre inherit only when source:track
is configured.
2025-01-07 01:54:17 +01:00
J0J0 Todos
9ec2a8146f Streamline lastgenre singleton log with album log
It was rather confusing that the lastgenre plugin, when handling
singletons, sometimes showed that it applied genres from last.fm and
sometimes didn't (it did only in debug log). This streamlines the
behaviour:

- Change debug to info log.
- Streamline wording.
- Display details about the track.
2025-01-07 01:54:17 +01:00
J0J0 Todos
d4ada3ce43 Fix track-level genre handling in lastgenre plugin
When `lastgenre.source: track` is configured,

- `lastgenre -a` _should not_ fall back to the album level genre (by
  making use of the with_album=False kwarg of the Libary's get method).
- `lastgenre -a`, when finally storing the genres of _an album_, should
  _not_ also write the tracks genres (by making use of the inherit=False
  kwarg of the Album's store method.
2025-01-07 01:53:58 +01:00
Šarūnas Nejus
85a17ee503
Reformat the codebase 2024-09-21 11:57:48 +01:00
Serene-Arc
a6e5201ff3 Apply formatting tools to all files
This is 'the big one', which touches every file so that it all conforms
to the given standard.
2023-10-22 09:53:18 +10:00
Kian-Meng Ang
873a91c541 Fix typos
Found via `codespell -S ./test/rsrc,genres.txt -L
caf,fo,ue,searchin,crashers,crasher,te,skool,egal,nothin`
2023-09-25 12:52:26 +08:00
Andrew Rogl
ee4268dabb Remove unused imports
Fix imports
Fix formatting
2021-08-26 20:59:48 +10:00
Andrew Rogl
1ec87a3bdd pyupgrade beetsplug and tests
All tests working
More tidy up to be done
2021-08-26 19:12:51 +10:00
sentriz
95677c8626
lastgenre: Make TitleCasing optional 2020-12-15 23:37:16 +00:00
Rainer Hihn
b7d3ef6274 - Improved doc and changelog
- Cleaner implementation of mutual excursion of the command line
arguments.
2019-04-21 18:32:41 +02:00
Rainer Hihn
ddd7b4b3b4 Removed empty line 2019-04-19 21:17:15 +02:00
Rainer Hihn
5c643a8f16 Removed ipdb import 2019-04-19 21:08:26 +02:00
Rainer Hihn
e4b2e7b476 Made -a and -A mutually exclusive. 2019-04-19 20:58:13 +02:00
Rainer Hihn
0b2334f8e8 Added command line options to query explicit for albums and / or tracks. 2019-04-18 22:31:49 +02:00
rain0r
fc95fb86a1
Update __init__.py
Also fetch genres for single tracks via query.
2019-04-17 20:57:58 +02:00
Adrian Sampson
63b7ede4f7 Merge pull request #3054 from discopatrick/2704-lastgenre-force
WIP: Remove `default` arg for `lastgenre --force` flag
2019-04-06 13:49:07 -04:00
Alexei Datskevich
be12a89372 Fix PyYAML yaml.load(input) Deprecation 2019-03-30 08:34:13 +01:00
Patrick Heneghan
9c7a313b0d
Remove default arg for lastgenre --force flag 2018-10-16 18:51:39 +01:00
Zsin Skri
ceabc72feb lastgenre: remove unnecessary check
In _resolv_genres wo do not have to explicitly check if self.c14n_branches is
not empty. The tree will have been loaded when self.canonicalize is truthy. Also
if self.c14n_branches would be empty the canonicalization is a no-op anyway...
2018-07-01 09:15:05 +02:00
Zsin Skri
cef9a3311c LastGenre: allow prefer_specific without canonical
This improves lastgenre's behaviour when the configuration option
`prefer_specific` is set but `canonical` is not.
Previously it would not set any tags. Now it does apply tags, sorted using the
canonicalization tree, but not canonicalized.

For this the default tree is loaded even when `canonical` is not set.
An extra check is added to only use it for canonicalization when `canonical` is
set.
2018-06-30 22:27:29 +02:00
Jakub Turski
ee46a5150f Don't crash if non-canonical genre and prefer_specific: yes.
Also, add a test for this.
2017-06-02 15:48:05 +01:00
Adrian Sampson
4ae02e0d27 Merge pull request #2211 from heylookltsme/better-genre
Proposal: Add specificity option to lastgenre plugin
2016-09-27 09:07:39 -04:00
Corinne Hoener
a7e3bf2d0b third time's a charm 2016-09-27 06:21:51 -04:00
Corinne Hoener
1c9202cc86 moar indents! 2016-09-26 21:21:15 -04:00
Corinne Hoener
c10fe1e126 change option name to prefer_specific 2016-09-26 19:06:34 -04:00
Corinne Hoener
be5ce3194f better syntax; better comments 2016-09-26 19:02:10 -04:00
Corinne Hoener
288ff6ba19 Add specificity option to lastgenre in order to prefer the most specific genres 2016-09-26 16:13:04 -04:00
Johnny Robeson
7a2bdf502f s/utf8/utf-8/ in all encoding/decoding contexts
This matches up with the python documentation.
2016-09-06 23:10:24 -04:00
Johnny Robeson
d41949d326 close files we open, but forgot to close
This fixes all the obvious `ResourceWarning`s seen in the tests
2016-08-09 01:15:28 -04:00
Johnny Robeson
01483f9600 change most googlecode refs to their new locations 2016-07-27 02:57:04 -04:00
Johnny Robeson
1da919bc40 open lastgenre genres file with codecs.open()
This should fix an error when decoding the file on Windows. It defaults
to using the code page there and not utf-8 as intended for yaml.
2016-07-17 06:57:38 -04:00
Adrian Sampson
5efd5b21c5 Use new as_str method
Instead of `get(six.text_type)`, which was a surprisingly large portion of our
uses of six.
2016-06-25 19:16:14 -07:00
Johnny Robeson
e8afcbe7ec replace unicode with six.text_type 2016-06-24 05:53:49 -04:00
Johnny Robeson
02165fc3a9 open lastgenre whitelist in binary mode 2016-06-09 23:53:40 -04:00
Johnny Robeson
81484529c9 remove b' from a few more stdlib calls 2016-05-31 00:13:09 -04:00
Adrian Sampson
e54c7eec3d Standardize __future__ imports without parentheses
Since the list is short enough now, we don't need parentheses for the line
wrap. This is a little less ugly.
2016-02-28 15:03:51 -08:00
Adrian Sampson
d53019f9db Further whitespace fiddling
Most commonly, this sticks with:

    log.debug(
        'some long message here'
    )

instead of placing the closing ) at the end of the string literal.
2016-02-28 14:48:10 -08:00