diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b32de4..1e4fb38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - An input file with no usable songs now says `No songs to download` instead of ending silently with an empty summary. - The `Already completed` count now says that it comes from `done.txt`. +## [2.2.7] - 2026-11-15 + +### Added +- `--no-logs` option and the `no_logs` config key: trackfetch stops reading `done.txt` and stops writing `done.txt` and `failed.txt`. Progress from earlier runs is not restored while this mode is on. + ## [2.2.6] - 2026-11-10 ### Added @@ -101,7 +106,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - PyInstaller spec, plus prebuilt binaries for Linux, macOS and Windows on x86_64 and ARM64. - Automated releases: pushing a new version to `master` builds and publishes all binaries. -[Unreleased]: https://github.com/ByteMe6/trackfetch/compare/v2.1.0...HEAD +[Unreleased]: https://github.com/ByteMe6/trackfetch/compare/v2.2.7...HEAD +[2.2.7]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.2.7 +[2.2.6]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.2.6 +[2.2.5]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.2.5 +[2.2.0]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.2.0 [2.1.0]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.1.0 [2.0.0]: https://github.com/ByteMe6/trackfetch/releases/tag/v2.0.0 [1.0.0]: https://github.com/ByteMe6/trackfetch/releases/tag/v1.0.0 diff --git a/README.md b/README.md index 5ea0f9b..be21683 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ trackfetch "My Playlist.txt" -o ~/Music/"My Playlist" ## Usage ```text -trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [INPUT ...] +trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [--no-logs] [INPUT ...] ``` | Option | Default | What it does | @@ -202,6 +202,7 @@ trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f { | `--list-sources` | — | Show available metadata providers and artwork fallbacks, then exit. Makes no network requests. | | `--spotify-client-id` | `$SPOTIFY_CLIENT_ID` | Spotify API client ID. See [Spotify credentials](#spotify-credentials). | | `--spotify-client-secret` | `$SPOTIFY_CLIENT_SECRET` | Spotify API client secret. | +| `--no-logs` | off | Do not read `done.txt` and do not write `done.txt` or `failed.txt`. Progress from earlier runs is ignored, so finished songs are not skipped. | ```bash trackfetch songs.txt -o ~/Music/RoadTrip # save to a specific folder @@ -303,6 +304,7 @@ disable_sources = spotify spotify_enabled = false spotify_client_id = your-client-id spotify_client_secret = your-client-secret +no_logs = false itunes_enabled = true itunes_country = us @@ -416,6 +418,12 @@ trackfetch retry.txt **Re-download a song** by deleting its MP3 and its line in `done.txt`. +With `--no-logs`, trackfetch does not read `done.txt` and does not write +`done.txt` or `failed.txt`. Progress is therefore not restored between runs: +songs finished in an earlier run are downloaded again, and the failure log is +neither created nor updated. `failed.txt` is a write-only log in every mode, so +the flag only makes trackfetch stop producing it. + ### Cheat sheet A [tldr](https://tldr.sh/) page is in [`docs/tldr/trackfetch.md`](https://github.com/ByteMe6/trackfetch/blob/master/docs/tldr/trackfetch.md). To use it with [tealdeer](https://github.com/tealdeer-rs/tealdeer), copy it into your custom pages folder as `trackfetch.page.md`. diff --git a/README.ru.md b/README.ru.md index ef39616..1b7a305 100644 --- a/README.ru.md +++ b/README.ru.md @@ -182,7 +182,7 @@ trackfetch "My Playlist.txt" -o ~/Music/"My Playlist" ## Использование ```text -trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [INPUT ...] +trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [--no-logs] [INPUT ...] ``` | Параметр | По умолчанию | Что делает | @@ -202,6 +202,7 @@ trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f { | `--list-sources` | — | Показать доступные источники и запасные варианты обложек и выйти. Сеть не используется. | | `--spotify-client-id` | `$SPOTIFY_CLIENT_ID` | Client ID для Spotify API. См. [Данные Spotify](#данные-spotify). | | `--spotify-client-secret` | `$SPOTIFY_CLIENT_SECRET` | Client secret для Spotify API. | +| `--no-logs` | выключен | Не читать `done.txt` и не писать `done.txt` и `failed.txt`. Прогресс прошлых запусков не учитывается, поэтому готовые песни не пропускаются. | ```bash trackfetch songs.txt -o ~/Music/RoadTrip # сохранить в конкретную папку @@ -305,6 +306,7 @@ disable_sources = spotify spotify_enabled = false spotify_client_id = твой-client-id spotify_client_secret = твой-client-secret +no_logs = false itunes_enabled = true itunes_country = us @@ -416,6 +418,11 @@ trackfetch retry.txt **Скачать песню заново:** удали её MP3 и её строку в `done.txt`. +При `--no-logs` trackfetch не читает `done.txt` и не пишет `done.txt` или +`failed.txt`. Поэтому прогресс между запусками не восстанавливается: песни, +готовые в прошлом запуске, скачиваются снова, а файл с ошибками не создаётся +и не обновляется. `failed.txt` — журнал только для записи в любом режиме. + ### Шпаргалка Страница для [tldr](https://tldr.sh/) лежит в [`docs/tldr/trackfetch.md`](docs/tldr/trackfetch.md). Чтобы пользоваться ей в [tealdeer](https://github.com/tealdeer-rs/tealdeer), скопируй её в папку пользовательских страниц под именем `trackfetch.page.md`. diff --git a/README.uk.md b/README.uk.md index fdfab92..5164a28 100644 --- a/README.uk.md +++ b/README.uk.md @@ -182,7 +182,7 @@ trackfetch "My Playlist.txt" -o ~/Music/"My Playlist" ## Використання ```text -trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [INPUT ...] +trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f {mp3,m4a,opus}] [--title-only] [--delay DELAY] [-s SOURCES] [--disable-sources SOURCES] [--provider-opt NAME.KEY=VALUE] [--match-threshold SCORE] [--title-threshold SCORE] [--list-sources] [--spotify-client-id ID] [--spotify-client-secret SECRET] [--no-logs] [INPUT ...] ``` | Параметр | За замовчуванням | Що робить | @@ -202,6 +202,7 @@ trackfetch [-h] [--track ARTIST - TITLE ...] [-o OUTPUT] [--config CONFIG] [-f { | `--list-sources` | — | Показати доступні джерела й запасні варіанти обкладинок і вийти. Мережа не використовується. | | `--spotify-client-id` | `$SPOTIFY_CLIENT_ID` | Client ID для Spotify API. Див. [Дані Spotify](#дані-spotify). | | `--spotify-client-secret` | `$SPOTIFY_CLIENT_SECRET` | Client secret для Spotify API. | +| `--no-logs` | вимкнено | Не читати `done.txt` і не писати `done.txt` та `failed.txt`. Прогрес минулих запусків не враховується, тому готові пісні не пропускаються. | ```bash trackfetch songs.txt -o ~/Music/RoadTrip # зберегти в конкретну теку @@ -305,6 +306,7 @@ disable_sources = spotify spotify_enabled = false spotify_client_id = твій-client-id spotify_client_secret = твій-client-secret +no_logs = false itunes_enabled = true itunes_country = us @@ -416,6 +418,11 @@ trackfetch retry.txt **Завантажити пісню заново:** видали її MP3 і її рядок у `done.txt`. +За `--no-logs` trackfetch не читає `done.txt` і не пише `done.txt` чи +`failed.txt`. Тому прогрес між запусками не відновлюється: пісні, готові в +минулому запуску, завантажуються знову, а файл із помилками не створюється й не +оновлюється. `failed.txt` — журнал лише для запису в будь-якому режимі. + ### Шпаргалка Сторінка для [tldr](https://tldr.sh/) лежить у [`docs/tldr/trackfetch.md`](docs/tldr/trackfetch.md). Щоб користуватися нею в [tealdeer](https://github.com/tealdeer-rs/tealdeer), скопіюй її в теку користувацьких сторінок під іменем `trackfetch.page.md`. diff --git a/pyproject.toml b/pyproject.toml index 1121f27..1bdcd50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "trackfetch" -version = "2.2.6" +version = "2.2.7" description = "Turn a text file of songs into tagged MP3s: Spotify metadata and cover art, best-match YouTube audio via yt-dlp." readme = "README.md" license = "GPL-3.0-or-later" diff --git a/tests/test_config.py b/tests/test_config.py index ab7d7d1..0d76419 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -337,6 +337,38 @@ def test_delay_from_config(self, pipeline, monkeypatch, tmp_path): assert sleeps == [2.5] + def test_no_logs_true_from_config(self, pipeline, monkeypatch, tmp_path, capsys): + songs = tmp_path / "songs.txt" + songs.write_text("Daft Punk - One More Time\n", encoding="utf-8") + out = tmp_path / "o" + out.mkdir() + done = out / "done.txt" + done.write_text("Daft Punk - One More Time\n", encoding="utf-8") + config = write_config( + tmp_path / "cfg.ini", f"[trackfetch]\noutput = {out}\nno_logs = true\n" + ) + + run_cli(monkeypatch, songs, "--config", config) + log = capsys.readouterr().out + + assert (out / "Daft Punk - One More Time.m4a").exists() + assert done.read_text(encoding="utf-8") == "Daft Punk - One More Time\n" + assert "DONE FILE" not in log + + def test_no_logs_false_from_config(self, pipeline, monkeypatch, tmp_path, capsys): + songs = tmp_path / "songs.txt" + songs.write_text("Daft Punk - One More Time\n", encoding="utf-8") + out = tmp_path / "o" + config = write_config( + tmp_path / "cfg.ini", f"[trackfetch]\noutput = {out}\nno_logs = false\n" + ) + + run_cli(monkeypatch, songs, "--config", config) + log = capsys.readouterr().out + + assert m.read_done(out / "done.txt") == {"Daft Punk - One More Time"} + assert "DONE FILE" in log + def test_config_path_is_reported(self, pipeline, monkeypatch, tmp_path, capsys): songs = tmp_path / "songs.txt" songs.write_text("Daft Punk - One More Time\n", encoding="utf-8") diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 60e66c7..88a02eb 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -198,6 +198,86 @@ def spotify_for(sp, artist, title): assert "SKIP: already completed" in log assert pipeline["searched"] == [("Bad", "Song")] + def test_logs_are_written_without_no_logs(self, pipeline, monkeypatch, tmp_path): + songs = tmp_path / "songs.txt" + songs.write_text("Daft Punk - One More Time\nBad - Song\n", encoding="utf-8") + out = tmp_path / "o" + + def video_for(artist, title): + return None if artist == "Bad" else pipeline["video"] + + def spotify_for(sp, artist, title): + return None if artist == "Bad" else pipeline["track"] + + monkeypatch.setattr(m, "find_youtube_video", video_for) + monkeypatch.setattr(m, "find_spotify_track", spotify_for) + + run_cli(monkeypatch, songs, "-o", out, "--delay", "0") + + assert m.read_done(out / "done.txt") == {"Daft Punk - One More Time"} + assert (out / "failed.txt").read_text( + encoding="utf-8" + ) == "Bad - Song | no YouTube result\n" + + def test_no_logs_does_not_read_logs(self, pipeline, monkeypatch, tmp_path): + songs = tmp_path / "songs.txt" + songs.write_text("Daft Punk - One More Time\n", encoding="utf-8") + out = tmp_path / "o" + out.mkdir() + done = out / "done.txt" + done.write_text("Daft Punk - One More Time\n", encoding="utf-8") + + run_cli(monkeypatch, songs, "-o", out, "--no-logs", "--delay", "0") + + assert (out / "Daft Punk - One More Time.m4a").exists() + assert pipeline["downloaded_urls"] == ["https://www.youtube.com/watch?v=abc"] + assert done.read_text(encoding="utf-8") == "Daft Punk - One More Time\n" + + def test_no_logs_does_not_write_logs(self, pipeline, monkeypatch, tmp_path, capsys): + songs = tmp_path / "songs.txt" + songs.write_text("Daft Punk - One More Time\nBad - Song\n", encoding="utf-8") + out = tmp_path / "o" + out.mkdir() + done = out / "done.txt" + failed = out / "failed.txt" + done.write_text("Old - Song\n", encoding="utf-8") + failed.write_text("Bad - Song | old reason\n", encoding="utf-8") + + def video_for(artist, title): + return None if artist == "Bad" else pipeline["video"] + + def spotify_for(sp, artist, title): + return None if artist == "Bad" else pipeline["track"] + + monkeypatch.setattr(m, "find_youtube_video", video_for) + monkeypatch.setattr(m, "find_spotify_track", spotify_for) + + run_cli(monkeypatch, songs, "-o", out, "--no-logs", "--delay", "0") + log = capsys.readouterr().out + + assert (out / "Daft Punk - One More Time.m4a").exists() + assert done.read_text(encoding="utf-8") == "Old - Song\n" + assert failed.read_text(encoding="utf-8") == "Bad - Song | old reason\n" + assert "DONE FILE" not in log + assert "FAILED FILE" not in log + + def test_no_logs_still_removes_duplicates(self, pipeline, monkeypatch, tmp_path, capsys): + songs = tmp_path / "songs.txt" + songs.write_text( + "Daft Punk - One More Time\nDaft Punk - One More Time\n", + encoding="utf-8", + ) + out = tmp_path / "o" + + run_cli(monkeypatch, songs, "-o", out, "--no-logs", "--delay", "0") + log = capsys.readouterr().out + + assert "Removed 1 duplicate(s)" in log + assert "SUCCESS: 1" in log + assert pipeline["downloaded_urls"] == ["https://www.youtube.com/watch?v=abc"] + assert not (out / "done.txt").exists() + assert not (out / "failed.txt").exists() + def test_delay_between_songs_only(self, pipeline, monkeypatch, tmp_path): songs = tmp_path / "songs.txt" songs.write_text("A - 1\nA - 2\nA - 3\n", encoding="utf-8") diff --git a/trackfetch.py b/trackfetch.py index 34a7add..1d3cee7 100755 --- a/trackfetch.py +++ b/trackfetch.py @@ -2739,6 +2739,16 @@ def main(): help="Spotify client secret (overrides the config file and the env)", ) + parser.add_argument( + "--no-logs", + action="store_true", + default=None, + help=( + "Do not read done.txt and do not write done.txt or failed.txt; " + "progress from earlier runs is ignored (default: off)" + ), + ) + args = parser.parse_args() try: @@ -2782,6 +2792,9 @@ def main(): if args.delay is None: args.delay = DEFAULT_DELAY + if args.no_logs is None: + args.no_logs = False + if not math.isfinite(args.delay): print(f"ERROR: Delay must be a finite number: {args.delay}") sys.exit(1) @@ -2853,17 +2866,23 @@ def main(): exist_ok=True, ) - done_file = args.output / "done.txt" - failed_file = args.output / "failed.txt" + if not args.no_logs: + done_file = args.output / "done.txt" + failed_file = args.output / "failed.txt" - done = read_done(done_file) + done = read_done(done_file) + else: + done_file = None + failed_file = None + done = set() print(f"Found {len(songs)} songs") if duplicates: print(f"Removed {duplicates} duplicate(s)") - print(f"Already completed: {len(done)} (from done.txt)") + if not args.no_logs: + print(f"Already completed: {len(done)} (from done.txt)") if skipped_lines: print( @@ -2936,10 +2955,11 @@ def main(): ) if ok: - append_line( - done_file, - song_key, - ) + if not args.no_logs: + append_line( + done_file, + song_key, + ) done.add(song_key) @@ -2950,10 +2970,11 @@ def main(): success += 1 else: - append_line( - failed_file, - f"{song_key} | {reason}", - ) + if not args.no_logs: + append_line( + failed_file, + f"{song_key} | {reason}", + ) failed += 1 @@ -2966,8 +2987,10 @@ def main(): print(f"SUCCESS: {success}") print(f"SKIPPED: {skipped}") print(f"FAILED: {failed}") - print(f"DONE FILE: {done_file}") - print(f"FAILED FILE: {failed_file}") + + if not args.no_logs: + print(f"DONE FILE: {done_file}") + print(f"FAILED FILE: {failed_file}") if __name__ == "__main__":