* Added '--add-description' option This new option will add the track description to a txt file (using the same filename as the music file). Some music players will display this text whilst the track is playing - great for tracklists on DJ mixes and podcasts. * Added subfolder switch * Revert: Added subfolder switch Accidently pushed to my branch by mistake - changes reverted * Fix lint errors * Add test for description file * Fix tests for pull requests --------- Co-authored-by: 7x11x13 <x7x11x13@gmail.com>
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
import music_tag # type: ignore[import]
|
|
from soundcloud import SoundCloud
|
|
|
|
client_id = SoundCloud().client_id
|
|
|
|
|
|
def call_scdl_with_auth(
|
|
*args: str,
|
|
encoding: Optional[str] = "utf-8",
|
|
) -> subprocess.CompletedProcess:
|
|
auth_token = os.getenv("AUTH_TOKEN", "")
|
|
args = ("scdl", *args, f"--auth-token={auth_token}", f"--client-id={client_id}")
|
|
return subprocess.run(
|
|
args,
|
|
capture_output=True,
|
|
encoding=encoding,
|
|
errors="ignore" if encoding is not None else None,
|
|
check=False,
|
|
)
|
|
|
|
|
|
def assert_track(
|
|
tmp_path: Path,
|
|
expected_name: str,
|
|
expected_title: str = "testing - test track",
|
|
expected_artist: str = "7x11x13-testing",
|
|
expected_genre: Optional[str] = "Testing",
|
|
expected_artwork_len: Optional[int] = 16136,
|
|
expected_album: Optional[str] = None,
|
|
expected_albumartist: Optional[str] = None,
|
|
expected_tracknumber: Optional[int] = None,
|
|
check_metadata: bool = True,
|
|
) -> None:
|
|
file = tmp_path / expected_name
|
|
assert file.exists()
|
|
|
|
if check_metadata:
|
|
f = music_tag.load_file(file)
|
|
assert f["#length"].value
|
|
assert f["title"].value == expected_title
|
|
assert f["artist"].value == expected_artist
|
|
if expected_genre:
|
|
assert f["genre"].value == expected_genre
|
|
if expected_artwork_len is not None:
|
|
if expected_artwork_len > 0:
|
|
assert len(f["artwork"].value.data) == expected_artwork_len
|
|
else:
|
|
assert not f["artwork"]
|
|
if expected_album:
|
|
assert f["album"].value == expected_album
|
|
if expected_albumartist:
|
|
assert f["albumartist"].value == expected_albumartist
|
|
if expected_tracknumber is not None:
|
|
assert f["tracknumber"].value == expected_tracknumber
|
|
|
|
|
|
def assert_not_track(tmp_path: Path, expected_name: str) -> None:
|
|
file = tmp_path / expected_name
|
|
assert not file.exists()
|