Commit Graph
51 Commits
Author SHA1 Message Date
Šarūnas Nejus 5933fcad85 Refactor template evaluation to handle format strings ONLY
- Handle formats as strings ONLY and evaluate them through a shared
  cached template helper.
- This removes the need for conditional logic that acts on Template
  objects or strings.
2026-08-05 01:56:59 +01:00
Šarūnas Nejus 951e32a852 Use pathlib.Path wherever possible in tests 2026-07-30 12:18:49 +01:00
Šarūnas Nejus d24c0d341e Rename PathsMixin.temp_dir_path to PathsMixin.temp_path for consistency 2026-07-21 11:15:25 +01:00
Šarūnas Nejus 230bf19c7f Remove redundant test logic exposed by full coverage
- Removing the coverage omit configuration exposed unused branches, helpers, and
  fixtures across the test suite.
- Delete that redundant logic and simplify affected tests while preserving their
  behavior.
2026-07-07 15:57:35 +01:00
Sebastian Mohr 54a2bd20e1 Removed This file is part of beets... headers. 2026-06-29 11:20:15 +02:00
Šarūnas Nejus 648f24cbc2 Enable and fix flake8-builtins 2026-06-09 00:14:06 +01:00
Sebastian Mohr adfb73b66d Run ruff format 2026-05-20 16:53:06 +02:00
Šarūnas Nejus d4fd36a033 sort: Update imports 2026-05-17 07:39:13 +01:00
Šarūnas Nejus 8809de2f7b Define set_item_uri 2026-04-25 20:29:16 +01:00
Šarūnas Nejus 50afcea6e9 Simplify get_playlist_items 2026-04-25 20:29:16 +01:00
J0J0 Todos 04904902f5 smartplaylist: Fix existing tests after CLI overhaul 2026-04-19 22:55:35 +02:00
J0J0 Todos f5adad7e43 smartplaylist: Tests for CLI overhaul 2026-04-19 22:55:29 +02:00
J0J0 Todos b32f220523 smartplaylist: Test new shell quoting behavior 2026-04-04 13:35:22 +01:00
Pierre Ayoub 49cb2f5544 chore(test_smartplaylist): Add future TODO about Mocks usage 2026-03-13 19:17:56 +00:00
Pierre Ayoub 1393cd0ae7 fix(test_smartplaylist.py): mypy type error as commit 002a051d0 2026-03-13 19:17:56 +00:00
Pierre Ayoub 523e504f5e fix(test_smartplaylist): Adapt to changes from commit d01727019
The aforementioned commits introduced a nmuber of changes since I
implemented this test:
- The syntax `self.assertExists(m3u_filepath)` was an old and now invalid
  way of checking existence of a path using assertion, change to `assert
  m3u_filepath.exists()` which now use string instead of bytes
- Use of `Path()` and strings instead of `path.join` and bytes for
  handling directory path
2026-03-13 19:17:56 +00:00
Pierre Ayoub f5a08712b1 chore(test): Lint test_smartplaylist.py 2026-03-13 19:17:56 +00:00
Pierre Ayoub e80fa746af chore(test): Format test_smartplaylist.py 2026-03-13 19:17:56 +00:00
Pierre Ayoub 2dcd8f4066 fix(test): Linting issues in smartplaylist 2026-03-13 19:17:56 +00:00
Pierre Ayoub 760271c456 chore(test): format with poe 2026-03-13 19:17:56 +00:00
Pierre Ayoub ad2529adb0 test(plugins): write dest_regen test for smartplaylist
Test functions inspired from `test_playlist_update_output_extm3u()` in
`test_smartplaylist.py`.
Test successfully passed using:
`poetry run pytest test/plugins/test_smartplaylist.py`
2026-03-13 19:17:56 +00:00
Šarūnas Nejus a8d53f78de Fix the rest of the tests 2026-02-27 18:34:26 +00:00
Šarūnas Nejus d613981efe Replace capture_output with io.getoutput 2026-02-10 00:53:20 +00:00
Alok Saboo 002a051d06 fix(smartplaylist): Resolve mypy type errors and update tests 2025-11-26 13:44:29 -05:00
Alok Saboo 71f4cc1814 Remove duplicate tracks 2025-11-23 09:59:34 -05:00
Alok Saboo f00bf83f05 lint 2025-11-23 09:52:26 -05:00
Alok Saboo 0511c4f202 cleanup 2025-11-23 09:50:53 -05:00
Alok Saboo ec95c8df25 preserve the order in which queries were specified in the configuration 2025-11-23 09:45:12 -05:00
Šarūnas Nejus 1c16b2b308 Replace string concatenation (' + ')
- Join hardcoded strings
- Replace concatenated variables with f-strings
2025-08-30 23:10:15 +01:00
Šarūnas Nejus d017270196 Use pathlib.Path in test_smartplaylist.py 2025-07-09 09:17:14 +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 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 5d4911e905 Replace assertIsNone 2024-08-12 08:43:41 +01:00
Šarūnas Nejus cb82917fe0 Replace assertFalse 2024-08-12 08:43:41 +01:00
Šarūnas Nejus 0ecc345143 Replace assertTrue 2024-08-05 17:11:16 +01:00
Šarūnas Nejus fcff5d72af Remove def suite TestLoader definitions 2024-07-28 18:58:51 +01:00
Šarūnas Nejus 432da560e4 Create PluginTestCase to dedupe plugin setup 2024-07-28 18:58:35 +01:00
Šarūnas Nejus 2d5fd907c3 Remove redundant setup_beets and teardown_beets instructions 2024-07-28 18:58:34 +01:00
Šarūnas Nejus 3e278159ed Dedupe TestHelper and _common.TestCase setup 2024-07-28 18:58:33 +01:00
Šarūnas Nejus f388ff6ec1 Replace py3_path with builtin os.fsdecode
`os.fsdecode` has only been available since Python 3.2.
2024-06-16 00:52:37 +01:00
Serene 7543a351ed Merge pull request #5184 from freddiewanah/master
Enhancement: Refactor Test Code for Efficiency and Quality
2024-04-21 09:06:38 +10:00
Max Goltzsche 883bbb3e4b smartplaylist: rename output format m3u8 to extm3u 2024-04-13 04:55:43 +02:00
Max Goltzsche c0afd3eb3c smartplaylist: allow exporting item fields
Allow generating extm3u playlists so that they contain additional item fields such as the `id`.

The feature is required by the mgoltzsche/beets-webm3u plugin (M3U server) to transform playlists using a request based item URI template which may require additional fields such as the `id`, e.g. `beets:library:track;$id`.
2024-04-13 04:55:37 +02:00
freddiewanah e0de6e1b89 refactor the test methods to avoid suboptimal asserts. 2024-04-08 21:39:25 +08:00
Lars Kruse 508d28f66b tests: move reusable test-related modules into the beets package
External Python packages interfacing beets may want to use an in-memory
beets library instance for testing beets-related code.
The `TestHelper` class is very helpful for this purpose.
Previously `TestHelper` was located in the `test/` directory.
Now it is part of `beets` itself (`beets.test.helper.TestHelper`) and
can be easily imported.
2024-01-15 19:40:57 +01:00
Max Goltzsche 58e5b02929 smartplaylist: add --uri-format option
Beets web API already allows remote players to access audio files but it doesn't provide a way to expose the playlists defined using the smartplaylist plugin.
Now the smartplaylist plugin provides an option to generate ID-based item URIs/URLs instead of paths.
Once playlists are generated this way, they can be served using a regular HTTP server such as nginx.

To provide sufficient flexibility for various ways of integrating beets remotely (e.g. beets API, beets API with context path, AURA API, mopidy resource URI, etc), the new option has been defined as a template with an `$id` placeholder (assuming each remote integration requires a different path schema but they all rely on using the beets item `id` as identifier/path segment).

To prevent local path-related plugin configuration from leaking into a HTTP URL-based playlist generation (invoked with CLI option in addition to the local playlists generated into another directory), setting the new option makes the plugin ignore the other path-related options `prefix`, `relative_to`, `forward_slash` and `urlencode`.

Usage examples:
* `beet splupdate --uri-format 'http://beets:8337/item/$id/file'` (for beets web API)
* `beet splupdate --uri-format 'http://beets:8337/aura/tracks/$id/audio'` (for AURA API)

(While it was already possible to generate playlists containing HTTP URLs previously using the `prefix` option, it did not allow to generate ID-based URLs pointing to the beets web API but required to expose the audio files using a web server directly and refer to them using their file system `$path`.)

Relates to #5037
2023-12-16 05:37:27 +01:00
Max Goltzsche 385c05f98e smartplaylist: change option --extm3u to --output
The boolean flags `--extm3u` and `--no-extm3u` are replaced with a string option `--output=m3u|m3u8`.
This reduces the amount of options and allows to evolve the CLI to support more playlist output formats in the future (e.g. JSON) without polluting the CLI at that point.
2023-12-16 00:23:03 +01:00
Max Goltzsche b07a2e42f4 smartplaylist: add extm3u/extinf/m3u8 support
This is to be able to display meaningful metadata and search a playlist within a player without having to load the linked audio files of a playlist.
2023-12-14 01:46:14 +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