Commit Graph
130 Commits
Author SHA1 Message Date
Šarūnas Nejus 10ce22e289 Enable querying related flexible attributes
Unify query creation logic from
- queryparse.py:construct_query_part,
- Model.field_query,
- DefaultTemplateFunctions._tmpl_unique

to a single implementation under `LibModel.field_query` class method.
This method should be used for query resolution for model (flex)fields.

Allow filtering item attributes in album queries and vice versa by
merging `flex_attrs` from Album and Item together as `all_flex_attrs`.
This field is only used for filtering and is discarded after.
2024-12-29 12:19:56 +00:00
Šarūnas Nejus fb4834e0ab Add ability to filter flexible attributes through the Query
For a flexible attribute query, replace the `col_name` property with
a function call that extracts that attribute from the `field_attrs`
field introduced in the earlier commit.

Additionally, for boolean, numeric and date queries CAST the value to
NUMERIC SQLite affinity to ensure that our queries like 'flex:1..5' and
'flex:true' continue working fine.

This removes the concept of 'slow query', since every query for any
field now has an SQL clause.
2024-12-29 11:35:12 +00:00
Šarūnas Nejus 5c81f94cf7 Move imports required for typing under the TYPE_CHECKING block 2024-12-10 06:10:04 +00:00
Šarūnas Nejus 161b0522bb Update deprecated imports 2024-12-10 06:10:04 +00:00
Šarūnas Nejus 51f9dd229e Use PEP585 lowercase collections typing annotations 2024-12-10 06:10:03 +00:00
Šarūnas Nejus 7be8f9c97a Update CI config, minimum ruff version, docs and add changelog note 2024-12-10 06:10:03 +00:00
Edgars Supe 09360259cc lyrics: Fallback to plain lyrics if synced not available 2024-12-07 19:08:37 +02:00
Stefano Rivera 336b5b369e Skip autobpm tests if librosa isn't available
Except under GitHub CI, where we expect all tests to run.
2024-11-30 09:32:08 -04:00
Šarūnas Nejus 65e935bee5 Perform a regex substitution in the substitute plugin (#5357)
This utilises regex substitution in the substitute plugin. The previous
approach only used regex to match the pattern, then replaced it with a
static string. This change allows more complex substitutions, where the
output depends on the input.

### Example use case
Say we want to keep only the first artist of a multi-artist credit, as
in the following list:
```
Neil Young & Crazy Horse -> Neil Young
Michael Hurley, The Holy Modal Rounders, Jeffrey Frederick & The Clamtones -> Michael Hurley
James Yorkston and the Athletes -> James Yorkston
````
This would previously have required three separate rules, one for each
resulting artist. By using a regex substitution, we can get the desired
behaviour in a single rule:
```yaml
substitute:
  ^(.*?)(,| &| and).*: \1
```
(Capture the text until the first `,` ` &` or ` and`, then use that
capture group as the output)

### Notes
I've kept the previous behaviour of only applying the first matching
rule, but I'm not 100% sure it's the ideal approach.
I can imagine both cases where you want to apply several rules in
sequence and cases where you want to stop after the first match.
2024-11-22 05:02:50 +00:00
Šarūnas Nejus de171f03fc Test helpers: Remove unneeded data generation abstractions (#5463)
This PR refactors the test codebase by removing redundant functions and
simplifying item and album creation. Key changes include:

- Removed redundant `_item_ident` index tracker from `_common.py`.
- Removed `album` function from `_common.py` replacing it with direct
`library.Album` invocations.
- Removed `generate_album_info` and `generate_track_info` functions,
replacing them directly with `TrackInfo` and `AlbumInfo`.
- Updated `setup.cfg` to exclude test helper files from coverage
reports.
- Adjusted the tests regarding the changes, and simplified
`test_mbsync.py`.
2024-11-13 14:16:15 +00:00
Šarūnas Nejus 69dbfd9868 Fix lints
These seem to have managed to escape the CI checks since the previously
merged PR was based on master commit which did not include the checks.
2024-10-30 12:13:30 +00:00
Joseph Bushell 4b78abd939 create seperate in_no_convert function, update tests 2024-10-26 19:09:56 +01:00
Joseph Bushell bba11be9f7 update test assertions 2024-10-26 18:17:39 +01:00
Joseph Bushell a73919b4ba add test for no_convert when using OR query 2024-10-26 18:17:27 +01:00
Joseph Bushell d1c88bbd25 consider value of no_convert as one query rather than splitting 2024-10-26 18:17:00 +01:00
Nicholas Boyd Isacsson 8e0558b804 Apply substitute rules in sequence 2024-10-16 16:36:36 +02:00
Nicholas Boyd Isacsson 19eb729db3 Refactor tests to make 2024-10-16 16:35:39 +02:00
Šarūnas Nejus d161111342 test helpers: remove redundant _get_item_count
It always returns 1.
2024-10-16 12:33:17 +01:00
Šarūnas Nejus 2681c83c5b Remove redundant generate_album_info and generate_track_info functions
These functions were used to generate mock data for tests but have been
replaced with direct instantiation of AlbumInfo and TrackInfo objects.
This change simplifies the test code and removes unnecessary helper
functions.
2024-10-16 06:39:30 +01:00
Nicholas Boyd Isacsson ffdc3f73ab Revert configuration format changes 2024-10-14 22:54:38 +02:00
Nicholas Boyd Isacsson 195644fc46 Refactor according to review comments 2024-10-12 15:34:05 +02:00
Šarūnas Nejus d3955bac65 Update Tekstowo backend to fetch lyrics directly
- Refactored Tekstowo backend to fetch lyrics directly from song pages.
- Added `encode` method to convert artist and title to their URL format,
  where non-alphanumeric characters are replaced with underscores.
- Removed the now redundant search functionality and associated tests.
- Simplified `extract_lyrics` method to directly parse lyrics without
  any checks.
2024-10-12 02:14:18 +01:00
Nicholas Boyd Isacsson 913d51af5c Preserve rule order in substitute configuration 2024-10-05 15:51:41 +02:00
Nicholas Boyd Isacsson 876dcb9bee Fix substitute test formatting 2024-10-05 15:51:41 +02:00
Nicholas Boyd Isacsson 16ac231f7f Refactor substitute tests 2024-10-05 15:51:41 +02:00
Nicholas Boyd Isacsson 81b79a08c1 Add test cases for substitute plugin 2024-10-05 15:51:41 +02:00
Karl Besser 37879d0b18 Remove redundant unit tests for ftintitle plugin
Remove redundant unit tests for the `ftintitle.cotains_feat` function
2024-10-01 15:55:38 -05:00
Karl Besser 669307c91c Update ftintitle.contains_feat unit tests
Since the `for_artist` keyword has been removed from
`ftintitle.contains_feat`, the unit tests need to be updated.
This includes the deletion of the test cases that test the
`for_artist=True` delimiters.
2024-09-30 10:28:23 -05:00
Karl Besser 6cb2e5926b Add unit tests for separate "feat. X" detection
The unit tests for the `ftintitle.contains_feat` function are now split
up for artist and title matching.
2024-09-26 17:22:25 -04:00
Karl Besser 6c8bd424e8 Add unit tests to test new feat. X detection regex
The previous version of the `plugins.feat_tokens` regular expression
only matched "feat. X" parts if preceded by a space. This caused missed
detections in the `ftintitle.contains_feat` function.
This commit adds unit tests for the updated regex that also matches
"feat. X" parts within parentheses and brackets
2024-09-22 18:30:28 -04:00
Šarūnas Nejus 11fa6c7b3f Introduce integration_test marker and update testing docs 2024-09-21 13:26:05 +01:00
Šarūnas Nejus 5f78d1b82b Remove some lint exclusions and fix the issues
* Replace `noqa` comments in `assert...` method definitions with
  a configuration option to ignore these names.
* Use the `__all__` variable to specify importable items from the
  module, replacing `*` imports and `noqa` comments for unused imports.
* Address issues with poorly named variables and methods by renaming
  them appropriately.
2024-09-21 11:59:19 +01:00
Šarūnas Nejus f36bc497c8 Fix lint issues
- Fix imports
- Fix pytest issues
- Do not assign lambda as variable
- Use isinstance instead of type to check type
- Rename ambiguously named variables
- Name custom errors with Error suffix
2024-09-21 11:59:18 +01:00
Šarūnas Nejus 85a17ee503 Reformat the codebase 2024-09-21 11:57:48 +01:00
KonstantinandŠarūnas Nejus 796c9addfb Fixes TypeError in the Discogs plugin (#5415)
Handles the case when discogs return `None` for format descriptions.

---------

Co-authored-by: Šarūnas Nejus <snejus@protonmail.com>
2024-09-19 21:27:16 +01:00
Šarūnas Nejus 5785522170 fetchart: defer file removal config option evaluation (#5244)
Defer the evaluation of the source file removal options (`import.delete`
and `import.move`) to the point where the fetchart plugin is actually
called instead of only evaluating those configuration options on plugin
initialization.
This is to allow other plugins (such as the
[ytimport](https://github.com/mgoltzsche/beets-ytimport/blob/v1.8.1/beetsplug/ytimport/__init__.py#L194)
plugin) to invoke the import directly (within the same python process;
implicitly invoking the fetchart plugin) with temporarily overwritten
configuration options.

Addresses
https://github.com/beetbox/beets/issues/5167#issuecomment-2106465172
2024-09-16 11:44:46 +01:00
Karl-Ludwig Besser 39acba5200 Merge branch 'master' into ftintitle_keep_artist 2024-09-05 12:32:20 +02:00
Šarūnas Nejus 111686e563 autobpm: add tests 2024-08-19 22:44:17 +01:00
Šarūnas Nejus 4b69b493d2 Use f-string syntax 2024-08-16 17:47:23 +01:00
Šarūnas Nejus d3bdd93bf6 Replace assertAlmostEqual 2024-08-12 08:49:30 +01:00
Šarūnas Nejus fcc4d8481d Replace assertListEqual 2024-08-12 08:43:43 +01:00
Šarūnas Nejus fdb8c28271 Replace assertCountEqual 2024-08-12 08:43:43 +01:00
Šarūnas Nejus 46bdb84b46 Replace assertGreater and assertGreaterEqual 2024-08-12 08:43:43 +01:00
Šarūnas Nejus eda0ef11d6 Replace assertIsInstance 2024-08-12 08:43:42 +01:00
Šarūnas Nejus f9359df0d1 Replace assertNotEqual 2024-08-12 08:43:42 +01:00
Šarūnas Nejus 847e3858a6 Replace assertRaises 2024-08-12 08:43:42 +01:00
Šarūnas Nejus 9a05d27acf Replace assertEqual 2024-08-12 08:43:42 +01:00
Šarūnas Nejus 6631b6aef6 Replace assertNotIn 2024-08-12 08:43:42 +01:00
Šarūnas Nejus 11e948121c Replace assertIn 2024-08-12 08:43:42 +01:00
Šarūnas Nejus 2616bcc950 Replace assertIsNotNone 2024-08-12 08:43:41 +01:00