Commit graph

4193 commits

Author SHA1 Message Date
Šarūnas Nejus
9e4559b8e9
Merge branch 'master' into discogs-404 2025-08-08 21:57:46 +01:00
Rebecca Turner
0430bd383a discogs: don't crash if a release is deleted 2025-08-07 20:25:09 -07:00
Sebastian Mohr
dc6f07d705 Added typing_extensions to all python version. Removed sys.version checks 2025-08-04 11:19:14 +02:00
Martin Atukunda
4a7e474efc
Merge branch 'master' into feature/add-artist-to-item-entry-template 2025-07-18 00:25:42 +03:00
Šarūnas Nejus
3be4a89aee
refactor: convert _types from class attributes to cached properties
Convert static _types dictionaries to dynamic cached class properties to
enable proper plugin type inheritance and avoid mutating shared state.

Key changes:
- Replace static _types dicts with @cached_classproperty decorators
- Update cached_classproperty to support proper caching with class names
- Remove manual _types mutation in plugin loading/unloading
- Add pluginload event and cache clearing for proper plugin integration
- Fix test to trigger type checking during item creation

This ensures plugin types are properly inherited through the class
hierarchy and eliminates issues with shared mutable state between
test runs.
2025-07-16 14:45:25 +01:00
Šarūnas Nejus
7509843517
Fix a generic type error and warnings in spotify 2025-07-16 14:15:27 +01:00
Šarūnas Nejus
a5bbe57490
Fix types in test_player 2025-07-16 14:06:34 +01:00
Šarūnas Nejus
816d06f160
Fix plugin types 2025-07-16 14:06:34 +01:00
Sebastian Mohr
f70e5ec758 split imports 2025-07-16 12:07:49 +02:00
Sebastian Mohr
47f8fbe629 Plugin should call super init. 2025-07-16 11:48:34 +02:00
Sebastian Mohr
0c6b383b06 Track info should not be imported from metadata_plugin. 2025-07-16 11:43:17 +02:00
Sebastian Mohr
1d33580b68 Renamed class method to _extract_id. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
3ce33631a6 Renamed import in mbsync and missing plugins. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
3eadf17e8f Opt in beatport plugin. Also enhanced type hints and minor cleanup for
the beatport plugin.
2025-07-15 15:03:14 +02:00
Sebastian Mohr
a97633dbf6 Opt in dicogs plugin. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
6f623ee7b0 Opt in deezer plugin. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
a770cfb669 Opt in chroma plugin. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
b62fb10da8 Opt in musicbrainz plugin. 2025-07-15 15:03:14 +02:00
Sebastian Mohr
fd800dce7c Opt in spotify plugin and enhanced typing for the search responses. 2025-07-15 15:03:14 +02:00
Martin Atukunda
8126eaa0fa
Merge branch 'master' into feature/add-artist-to-item-entry-template 2025-07-15 13:58:25 +03:00
54562474
48d45b4df7 feat: mpdstats: add config option for played ratio threshold to determine if a
track was played or skipped.
2025-07-09 14:16:23 -06:00
Šarūnas Nejus
afe97cf31e
Do not assign args to query 2025-07-08 11:37:34 +01:00
Šarūnas Nejus
4260162d44
Remove all Python 2 references 2025-07-08 11:37:34 +01:00
Šarūnas Nejus
7cada1c9f8
Remove no-op decargs 2025-07-08 11:37:33 +01:00
Nicolas Mémeint
eb497eee1a Only consider release collections in mbcollection plugin 2025-07-07 13:25:25 +02:00
Sebastian Mohr
50604b0510 Fixed linting issue after rebase. 2025-07-07 11:40:51 +02:00
Sebastian Mohr
04a3dd2169 Adjusted typehint for search api. Removed optional none from filter. 2025-07-07 11:37:02 +02:00
Sebastian Mohr
1f15598294 Moved constants back to top. 2025-07-07 11:37:02 +02:00
Sebastian Mohr
6ab0f8d3a7 Removed old docstring. 2025-07-07 11:37:02 +02:00
Sebastian Mohr
085b89b70b Minor improvements to deezer plugin typing. 2025-07-07 11:37:02 +02:00
Sebastian Mohr
59ecfd9a49 Moved fetch_data and _get_track function. 2025-07-07 11:36:38 +02:00
Martin Atukunda
a64acf8aa2
Merge branch 'master' into feature/add-artist-to-item-entry-template 2025-07-07 09:35:15 +03:00
J0J0 Todos
cf557fb41b playlist: Use pathlib.Path and add types for is_m3u_file()
Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-07-07 08:05:47 +02:00
J0J0 Todos
dcd3a9f7f4 playlist: Support m3u8 ending in playlist plugin 2025-07-07 07:58:59 +02:00
Šarūnas Nejus
0de27cbfb3
Merge branch 'master' into feature/add-artist-to-item-entry-template 2025-07-06 16:43:37 +01:00
Šarūnas Nejus
1a045c9166
Copy paste query, types from library to dbcore 2025-07-06 16:03:46 +01:00
Martin Atukunda
54e76368d0
Avoid rendering extraneous separators
handling cases where the artist or album data might be missing to avoid
rendering extraneous separators. Suggested by Copilot.
2025-07-06 12:22:02 +03:00
Martin Atukunda
8ea7346575
Merge branch 'master' into feature/add-artist-to-item-entry-template 2025-07-06 12:14:48 +03:00
J0J0 Todos
47eee070ba duplicates: remove or delete options mutually exclusive
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-05 07:22:33 +02:00
J0J0 Todos
537a71ff82 duplicates: Add --remove option to duplicates plugin
Removes from library but keeps files.
2025-07-05 07:17:59 +02:00
dhruvravii
dd6cb538ac
Fix: Spotify plugin unable to recognize Chinese and Japanese albums. (#5705)
Fixes an issue where each spotify query was converted to ascii before sending. Adds a 
new config option to enable legacy behaviour.

A file called japanese_track_request.json was made to mimic the Spotify
API response since I don't have the credentials. Entries in that will
need to be modified with the actual entries.

Co-authored-by: Sebastian Mohr <sebastian@mohrenclan.de>
Co-authored-by: Sebastian Mohr <39738318+semohr@users.noreply.github.com>
Co-authored-by: J0J0 Todos <2733783+JOJ0@users.noreply.github.com>
2025-07-01 11:08:54 +02:00
Nicolas Mémeint
4893cee5e5 Fix the MusicBrainz search not taking into account the album/recording aliases 2025-06-15 21:33:20 +01:00
Sebastian Mohr
66864fcc27
Minor improvements to spotify plugin typing. (#5815)
## Description

Added some more typehints to the spotify plugin. Also added a method to
get the tokenfile and changed to logic for the handle_response to use
`requests.request`.

This is done mainly to prepare for
https://github.com/beetbox/beets/pull/5787, see also
https://github.com/beetbox/beets/pull/5814
2025-06-11 15:19:46 +02:00
Šarūnas Nejus
adbd50b237
Move distance to a separate module 2025-05-31 19:17:43 +01:00
Šarūnas Nejus
509cbdcbe4
Move sanitize_pairs/choices from plugins to util module 2025-05-31 17:55:41 +01:00
Uncorrupt3318
dd2f203090
Feat: Add replace plugin (#5644)
Adds replace plugin. The plugin allows the user to replace the audio
file of a song, while keeping the tags and file name.

Some music servers keep track of favourite songs via paths and tags. Now
there won't be a need to 'refavourite'. Plus, this skips the
import/merge steps.
2025-05-27 00:17:52 +02:00
wisp3rwind
728076e97d fetchart: assert some invariants to satisfy mypy
Eventually, it would be nice to avoid this by more expressive typings.
For now, avoid such larger refactoring.
2025-05-20 10:06:11 +02:00
wisp3rwind
10d1c51a1d fetchart: consistently use lazy string formatting for debug logging 2025-05-20 09:23:34 +02:00
wisp3rwind
a6f2389aed typing: fetchart + tests 2025-05-20 08:57:30 +02:00
wisp3rwind
395aec96a3 fetchart: fixup #5244
by restoring config validation and making things more Pythonic
2025-05-20 08:57:30 +02:00
Šarūnas Nejus
e151b4b49b
Implement track_for_id to allow fetching singletons by discogs id 2025-05-19 09:43:56 +01:00
Šarūnas Nejus
d9b67acff5
discogs: simplify getting track from album 2025-05-19 09:43:03 +01:00
Šarūnas Nejus
9cc7ecaceb
discogs: cache TRACK_INDEX_RE 2025-05-19 09:43:03 +01:00
Šarūnas Nejus
8e5858254b
discogs: cache master release lookups 2025-05-19 09:43:03 +01:00
Šarūnas Nejus
12149b3e6d
discogs: remove duplicate error handling 2025-05-19 09:43:03 +01:00
Šarūnas Nejus
09862aeaea
discogs: Add types to public methods 2025-05-19 09:43:01 +01:00
Šarūnas Nejus
9242db04a5
discogs: add configurable search_limit 2025-05-19 09:42:06 +01:00
Šarūnas Nejus
e8e9369bc7
Remove unused extra_tags parameter 2025-05-19 09:18:06 +01:00
Šarūnas Nejus
2ec65ed8ca
Deduplicate candidate methods using _search_api method 2025-05-18 20:09:52 +01:00
Šarūnas Nejus
0102f3ce7d
Take into account va_likely param and remove redundant checks
- Instead of checking for empty `artist` query, use `va_likely`
  parameter to determine whether we should query for Various Artists or
  not.
- `album` / `title` is always a truthy string - no need to handle empty
  criteria case
- `tracks` list always has at least one track - no need to check for
  `len(items)`
2025-05-18 20:09:52 +01:00
Šarūnas Nejus
6487893315
Synchronise docs with the actual supported extra_tags 2025-05-18 20:09:51 +01:00
Šarūnas Nejus
be74936134
Handle extra_tags the way they used to be handled 2025-05-18 20:09:50 +01:00
Martin Atukunda
7c799beda8
style(plugin/web): run djlint over html to clean it up a bit 2025-05-18 20:59:29 +03:00
Martin Atukunda
992d376d1b
feat(plugin/web): add artist and album to the item entry template 2025-05-18 20:59:29 +03:00
Martin Atukunda
a75d2b4aa6 Update beetsplug/web/static/beets.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-18 17:16:29 +01:00
Martin Atukunda
d1d58569e1 Update beetsplug/web/static/beets.js
don't pollute global scope with album_id

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-18 17:16:29 +01:00
Martin Atukunda
b0238d934e feat: plugins/web: use media session api for notifications.
The Media Session API provides a way to customize media notifications.
This commit updates the metadata for the media session whenever a new
track (item) starts playing.

https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API
2025-05-18 17:16:29 +01:00
Šarūnas Nejus
b520981c9c
plugins: restructure id extraction 2025-05-17 14:57:34 +01:00
Sebastian Mohr
a2e316d444 Merge remote-tracking branch 'upstream/master' into importer-restructure 2025-05-17 10:32:50 +02:00
Šarūnas Nejus
f1dc75f743
Fix types in all edited files 2025-05-17 03:32:01 +01:00
Šarūnas Nejus
7ff73d9747
musicbrainz: set default config in the code 2025-05-17 03:31:59 +01:00
Šarūnas Nejus
a538a3a150
musicbrainz: move handling of extra tags to musicbrainz plugin 2025-05-17 03:31:58 +01:00
Šarūnas Nejus
de0958ca65
Use candidate function from plugins instead of hooks 2025-05-17 03:31:57 +01:00
Šarūnas Nejus
2fcb48d7a4
Remove ...for_mbid methods and simplify the rest 2025-05-17 03:31:57 +01:00
Šarūnas Nejus
d8067b219b
musicbrainz: use self.config and self._log 2025-05-17 03:31:57 +01:00
Šarūnas Nejus
fd62d6a0b8
Integrate functionality with BeetsPlugin shenanigans 2025-05-17 03:31:57 +01:00
Šarūnas Nejus
529aaac7dc
Move functionality under MusicBrainzPlugin 2025-05-16 23:08:38 +01:00
Šarūnas Nejus
06dde6e37e
Define MusicBrainzPlugin 2025-05-16 20:17:59 +01:00
Šarūnas Nejus
5dc6f45110
musicbrainz: reorder methods
This will make it easier to track changes in later commits.
2025-05-16 19:56:50 +01:00
Šarūnas Nejus
e6e610a3ef
Move musicbrainz to beetsplug directory 2025-05-16 19:56:50 +01:00
Sebastian Mohr
68acaa6470 Renamed all action occurrences with Action. 2025-05-13 13:01:46 +02:00
Šarūnas Nejus
fdc1aba603
Replace typing.cast with explicit type definitions and ignore TC006 2025-05-07 20:39:33 +01:00
Šarūnas Nejus
99dc0861c2
Redact sensitive fields
Redacted fields reported by GitHub secrets scanner[1] and a couple of others.

1: https://github.com/beetbox/beets/security/secret-scanning?query=is%3Aclosed
2025-05-07 20:39:32 +01:00
Šarūnas Nejus
c490ac5810
Fix formatting 2025-05-07 10:41:01 +01:00
Šarūnas Nejus
52951bf719
Fix legalize_path types
Background
  The `_legalize_stage` function was causing issues with Mypy due to
  inconsistent type usage between the `path` and `extension` parameters.
  This inconsistency stemmed from the `fragment` parameter influencing the
  types of these variables.

Key issues
  1. `path` was defined as `str`, while `extension` was `bytes`.
  2. Depending on `fragment`, `extension` could be either `str` or `bytes`.
  3. `path` was sometimes converted to `bytes` within `_legalize_stage`.

Item.destination` method
  - The `fragment` parameter determined the output format:
    - `False`: Returned absolute path as bytes (default)
    - `True`: Returned path relative to library directory as str

Thus
  - Rename `fragment` parameter to `relative_to_libdir` for clarity
  - Ensure `Item.destination` returns `bytes` in all cases
  - Code expecting strings now converts the output to `str`
  - Use only `str` type in `_legalize_stage` and `_legalize_path`
    functions
  - These functions are no longer dependent on `relative_to_libdir`
2025-05-04 12:23:22 +01:00
Aidan Epstein
ecdff785f7
Only output verbose details for parentwork plugin when running explicitly (#5135)
Fixes #4120.
2025-05-04 09:34:37 +02:00
Šarūnas Nejus
9acfa3c175
Remove arg_encoding 2025-04-21 12:41:57 +01:00
Šarūnas Nejus
179ed13e09
Say bye to util._fsencoding 2025-04-21 12:41:57 +01:00
wisp3rwind
b495286127 ftintitle: flatten code
linear code with early exits instead of more complicated nested
conditionals
2025-04-14 20:50:01 +02:00
wisp3rwind
8413de1a85 ftintitle: add typings 2025-04-14 20:42:59 +02:00
Peter Dolan
447cc82e04
Do not write unchanged items to the library in FtInTitle (#5718)
FtInTitle performs a library store operation for every item it
processes, whether or not the item has changed. By limiting the
`item.store()` call to only those cases when the item has changed, the
plugin’s performance when processing an entire library improves by two
to three orders of magnitude.
2025-04-14 18:22:41 +00:00
Šarūnas Nejus
8f209d85b9
Tidy up mbsync logs
No need to call `format` since this is done automatically at the point
the object is logged (if required).
2025-04-14 02:58:58 +01:00
Šarūnas Nejus
d1d681c1ff
mbsync: support other data sources 2025-04-14 02:28:43 +01:00
Šarūnas Nejus
441cd36e8a
missing: clarify that only musicbrainz backend supports missing albums for artist
And give this functionality a small refactor.
2025-04-14 02:28:43 +01:00
Šarūnas Nejus
4c1f217ce0
missing: support non-musicbrainz data sources 2025-04-14 02:28:42 +01:00
Skia
225c21b90f plugins/thumbnails: fix FFI with GIO on s390x
Using the correct function signature for g_file_new_for_path fixes the
tests on s390x.
I do not have the full story on why this failed consistently only on
s390x, but I guess the big endian might have something to play with
this.

Here is how the tests were failing:
```
169s ___________________________ ThumbnailsTest.test_uri ____________________________
169s
169s self = <test.plugins.test_thumbnails.ThumbnailsTest testMethod=test_uri>
169s
169s     def test_uri(self):
169s         gio = GioURI()
169s         if not gio.available:
169s             self.skipTest("GIO library not found")
169s
169s >       assert gio.uri("/foo") == "file:///"  # silent fail
169s E       AssertionError: assert '' == 'file:///'
169s E
169s E         - file:///
169s
169s test/plugins/test_thumbnails.py:268: AssertionError
```
You can see a full log here [1] and a history of consistent failure
here [2]. Both links are bound to expire at some point, sorry future
archeologist 🤷.

[1]: https://autopkgtest.ubuntu.com/results/autopkgtest-plucky/plucky/s390x/b/beets/20250403_162414_5d1da@/log.gz#S5
[2]: https://autopkgtest.ubuntu.com/packages/beets/plucky/s390x
2025-04-14 02:19:10 +01:00
J0J0 Todos
eb83491788 lastgenre: Fix "original fallback" conditions
This was not thought through clearly before. It now behaves as follows
which I suppose is least surprising to a user:

- force is on, keep_existing is on, but the whitelist is DISABLED
- no stage found anything on last.fm
- fall back to the original genre

If in this example the whitelist would be ENABLED, the behaviour
changes: Only if the existing genre passes the whitelist test the
original is kept.
2025-04-09 22:52:07 +02:00
J0J0 Todos
f4d22a83b5 lastgenre: Catch NoneType errors in _fitler_valid_genres 2025-04-09 22:52:07 +02:00
J0J0 Todos
702ddf493e lastgenre: Early validate genres, new debug option
- Revert/fix last.fm fetcher methods to validate genres.

  - In past versions (<=2.2) _resolve_genres which included whitelist
    checks ran instantly after fetching last.fm tags which made sure the
    next stage is hit when nothing worthwhile was found (e.g fallback
    album -> artist).

  - Bring back this behavior but don't run a full _resolve_genres but a
    quick valid (whitelist) check only!

- Introduce an extended config/CLI option that allows to really log what
  each stage fetches (prior to validation/whitelist filtering).

  - Since this potentially is verbose especially with VA albums (a lot
    of artist tag fetches) for performance and debug log clutter reasons
    this is disabled by default.

- Clarify final last.fm tags debug log message to "valid last.fm genres"
2025-04-09 22:52:07 +02:00
J0J0 Todos
c57e5a1fb8 lastgenre: Tiny fix in early no-force return 2025-04-09 22:52:07 +02:00
J0J0 Todos
edd366e766 lastgenre: Fix album not falling back to artist stage
which was the usual behaviour in lastgenre ever since and it should be
kept that way. Also refactor "if track" to use a similar notation for
overall code readability.
2025-04-09 22:52:07 +02:00
J0J0 Todos
2b276e07f1 lastgenre: Log unconfigured fallback 2025-04-09 22:52:07 +02:00
J0J0 Todos
e20cf7f20b lastgenre: Rework combine, stringify, count reduction
- Rename method from _combine_genres() to _combine_resolve_and_log() to
  make clear that it not only combines new and old genres but also
  resolves them (which in this plugin's wording means "do the magic" of
  canonicalizationm, whitelist checking and reducing to a configured
  genre count).

- Clarify in _resolve docstring that a possible outcome might be all
  genres being removed.

- Add an additional log message telling which existing genres are taken
  into account BEFORE "the magic happens".

- Rename _to_delimited_genre_string() to _format_and_stringify()

- Move count reduction logic to _resolve_genres()

- Fix and rename a test
2025-04-09 22:52:07 +02:00
J0J0 Todos
3291aa03e7 lastgenre: Describe in docstring what _resolve_genres does 2025-04-09 22:52:07 +02:00
J0J0 Todos
15f4b2ac29 lastgenre: Place to_delim. func near _get_genre
and the other helpers.
2025-04-09 22:52:07 +02:00
J0J0 Todos
eba3dc15fd lastgenre: Final label only if required in _get_genre() 2025-04-09 22:52:07 +02:00
J0J0 Todos
94f78ae70f lastgenre: Prevent returning empty genre list
As reported in #5649 when new last.fm genres were found, they still might
get kicked out by the whitelist check in _resolve_genres(). This might
lead to _combine_genres() returning an empty list.

The desired outcome though is that since still nothing worthwhile was
found, the next stage should be entered - which in this case is,
returning with the configured fallback genre (or the default fallback
None).

The any() check makes sure this is the case and moving out the
string conversion from _combine_genres() makes this code slightly more
readable.
2025-04-09 22:52:07 +02:00
Allen
b7521f9a0b
fix: plugins/listenbrainz: Fix UnboundLocalError in cases where 'mbid' is not defined (#5651)
Fix ocurrence of `UnboundLocalError` in plugins/listenbrainz >
`get_tracks_from_listens()` when `mbid` is not available.
Removed a print statment.
Fix link to config.yaml.
Fix link to Listenbrainz "get the token" documentation.

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2025-03-12 07:08:53 +00:00
Pierre Ayoub
5c8f1c1ee5
Fix convert plugin attempting to process a non-media file (#5261)
## Description

My library is managed using Beets for organization and
[git-annex](https://git-annex.branchable.com/) as storage backend.
Therefore when using this system, while my library files always exists
on my filesystem, some files may be empty (without content). In this
case, when I'm running the `convert` plugin, I don't wants it to process
files which are empty (same apply for any Beets plugin). Hence, I added
a check that the file is readable as a `MediaFile` before doing any
process.

Before this fix, trying to encode an empty file would have lead to an
error while leaving `convert` doing its side-effects **and** `convert`
would also copy empty files to destination for files that doesn't need
to be re-encoded.

In my case, this is empty files, but the problem can be anything else
(depending on the storage backend) and/or corrupted files. Conclusion, I
think **checking that the file is readable is always recommended before
proceeding to heavy operation** like this.
2025-02-20 16:23:14 +00:00
Šarūnas Nejus
b713d72612
translations: use a more distinctive separator
I found that the translator would sometimes replace the pipe character
with another symbol (maybe it got confused thinking the character is
part of the text?).

Added spaces around the pipe to make it more clear that it's definitely
the separator.
2025-02-20 03:47:04 +00:00
Šarūnas Nejus
43032f7bc7
translations: make sure we do not re-translate 2025-02-20 03:47:04 +00:00
Šarūnas Nejus
7893766e4c
Improve flags structure and add tests 2025-02-20 03:47:04 +00:00
Šarūnas Nejus
c95156adcd
Refactor writing rest files 2025-02-20 03:47:04 +00:00
Šarūnas Nejus
d7201062a8
Resurrect translation functionality 2025-02-20 03:47:04 +00:00
J0J0 Todos
2286511ebe
Merge branch 'master' into smartplaylist-attr-url-encoding 2025-02-17 21:16:09 +01:00
Max Goltzsche
5d96509cfe
smartplaylist: change encoding of additional field
URL-encode additional item `fields` within generated EXTM3U playlists instead of JSON-encoding them.
This is because JSON-encoding additional fields/attributes made it difficult to parse the `EXTINF` line but using URL-encoding for these values makes parsing easy (because URL-encoded values cannot contain commas, quotation marks and spaces).

I introduced the generation of additional EXTM3U item fields earlier this year and I want to correct that now.

**Design/definition background:**
Unfortunately, I didn't find a clear definition of how additional playlist item attributes should be encoded - apparently there is none.
Given that item URIs within an M3U playlist can be URL-encoded already, defining the values of additional attributes to be URL-encoded is consistent design.
I didn't find examples of additional EXTM3U item attributes in the web where the attribute value contains a comma, space or quotation mark but examples that specified numeric IDs and URLs as attribute values.
Because the URL attribute examples I found didn't contain URL-encoded characters and because it is more readable and unproblematic for parsing, I've let the attribute URL encoding treat `:` and `/` as safe characters.

**Breaking change:**
While this is a breaking change in theory, in practice it is not since afaik all integrations of the smartplaylist plugin's additional EXTM3U item attribute generation feature (beets-webm3u) work with simple attribute values such as the item ID (numeric) whose formatting/encoding is not affected when changing from JSON to URL-encoding.
In other words the change is backward-compatible with the beets-webm3u plugin (which I'll adjust correspondingly after this beets PR was merged).
2025-02-01 01:14:27 +01:00
Šarūnas Nejus
916d40f86f
Remove outdated namespace package definition and update docs
See https://realpython.com/python-namespace-package.

This setup is backwards-compatible, so plugins using the old
pkgutil-based setup will continue working fine.

This setup has an advantage where external plugins will now be able to
import modules from 'beetsplug' package for typing purposes. Previously,
mypy could not resolve these modules due to presence of `__init__.py`.
2025-01-30 12:20:11 +00:00
Šarūnas Nejus
dab9a0d7c4
Bring back Tekstowo search
It was my mistake to remove search earlier - I found that in many cases
it works fine.
2025-01-27 10:56:54 +00:00
Šarūnas Nejus
7389f241f4
Do not search for Various Artists, split titles by ' / ' 2025-01-27 10:56:53 +00:00
Šarūnas Nejus
39c479fcab
Google: add support for dainuzodziai.lt 2025-01-27 10:56:53 +00:00
Šarūnas Nejus
734bcc28a8
Append source to the lyrics 2025-01-27 10:56:53 +00:00
Šarūnas Nejus
bdc564a573
Tidy up handling of backends 2025-01-27 10:56:53 +00:00
Šarūnas Nejus
04054cac5c
Remove dependency existence checks
I think we can make our life easier by removing these checks assuming
that users follow the instructions in the docs.
2025-01-27 10:56:53 +00:00
Šarūnas Nejus
b2402b1634
Google: make sure we do not return the captcha text
If we get caught by Cloudfare, it forwards our request somewhere else
and returns some validation text response. To make sure that this text
does not get assumed for lyrics, we can disable redirects for the Google
backend, check the response code and raise if there's a redirect
attempt. This source will then be skipped and the backend continues with
the next one.
2025-01-27 10:56:53 +00:00
Šarūnas Nejus
07d372c13d
Google: prioritise Songlyrics and AZlyrics sources 2025-01-27 10:56:53 +00:00
Šarūnas Nejus
70554640e5
Create Html class for cleaning up the html text
Additionally, improve HTML pre-processing:

* Ensure a new line between blocks of lyrics text from letras.mus.br.
* Parse a missing last block of lyrics text from lacocinelle.net.
* Parse a missing last block of lyrics text from paroles.net.
* Fix encoding issues with AZLyrics by setting response encoding to
  None, allowing `requests` to handle it.
2025-01-27 10:56:52 +00:00
Šarūnas Nejus
c5c4138d66
Google: Refactor and improve
* Type the response data that Google Custom Search API return.
* Exclude some 'letras.mus.br' pages that do not contain lyric.
* Exclude results from Musixmatch as we cannot access their pages.
* Improve parsing of the URL title:
  - Handle long URL titles that get truncated (end with ellipsis) for
    long searches
  - Remove domains starting with 'www'
  - Parse the title AND the artist. Previously this would only parse the
    title, and fetch lyrics even when the artist did not match.
* Remove now redundant credits cleanup and checks for valid lyrics.
2025-01-27 10:56:52 +00:00
Šarūnas Nejus
12c5eaae5e
Unite Genius, Tekstowo and Google backends under the same interface 2025-01-27 10:56:52 +00:00
Šarūnas Nejus
745c5eb9f0
Genius: refactor and simplify 2025-01-27 10:56:52 +00:00
Šarūnas Nejus
54fc67b30a
Remove extract_text_between 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
55b7824948
Replace custom unescape implementation by html.unescape 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
8a1ce27421
lyrics: Do not write item unless lyrics have changed 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
8bdc2c6cf0
lyrics: Add symbols for better visual feedback in the logs 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
f94d2767f9
Use a single slug implementation
Tidy up 'Google.is_page_candidate' method and remove 'Google.sluggify'
method which was a duplicate of 'slug'.

Since 'GeniusFetchTest' only tested whether the artist name is cleaned
up (the rest of the functionality is patched), remove it and move its
test cases to the 'test_slug' test.
2025-01-27 08:50:50 +00:00
Šarūnas Nejus
dd9f178fff
Do not try to strip cruft from the parsed lyrics text.
Having removed it I fuond that only the Genius lyrics changed: it had en
extra new line. Thus I defined a function 'collapse_newlines' which now
gets called for the Genius lyrics.
2025-01-27 08:50:50 +00:00
Šarūnas Nejus
7c2fb31136
Leave a single chef in the kitchen 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
cb29605bfd
Include class name in the log messages 2025-01-27 08:50:50 +00:00
Šarūnas Nejus
283c513c72
Centralise request error handling 2025-01-27 08:50:49 +00:00
Šarūnas Nejus
06eac79c0d
Centralize requests setup with requests.Session
Improve requests performance with requests.Session which uses connection
pooling for repeated requests to the same host.

Additionally, this centralizes request configuration, making sure that
we use the same timeout and provide beets user agent for all requests.
2025-01-27 08:50:49 +00:00
Šarūnas Nejus
c40db1034a
Make lyrics plugin documentation slightly more clear 2025-01-27 08:50:49 +00:00
Šarūnas Nejus
2ff57505d8
Apply dist_thresh to Genius and Google backends
This commit introduces a distance threshold mechanism for the Genius and
Google backends.

- Create a new `SearchBackend` base class with a method `check_match`
  that performs checking.
- Start using undocumented `dist_thresh` configuration option for good,
  and mention it in the docs. This controls the maximum allowable
  distance for matching artist and title names.

These changes aim to improve the accuracy of lyrics matching, especially
when there are slight variations in artist or title names, see #4791.
2025-01-27 08:50:48 +00:00
J0J0 Todos
9d4653f92f Final lastgenre docstring nitpicks
and a tiny docs fix.
2025-01-23 09:04:06 +01:00
J0J0 Todos
2708be257d Final nitpicks on lastgenre --help wording 2025-01-23 08:32:10 +01:00
J0J0 Todos
2f40b315f4 Add lastgenre --no-force, reword help 2025-01-22 18:39:36 +01:00
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