2024-05-14 19:02:45 -04:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2023-10-31 15:51:44 -04:00
|
|
|
import pytest
|
|
|
|
from mutagen.flac import FLAC
|
|
|
|
from util import arun
|
|
|
|
|
2024-05-14 19:27:41 -04:00
|
|
|
from streamrip.metadata import (
|
|
|
|
AlbumInfo,
|
|
|
|
AlbumMetadata,
|
|
|
|
Covers,
|
|
|
|
TrackInfo,
|
|
|
|
TrackMetadata,
|
|
|
|
tag_file,
|
|
|
|
)
|
2023-10-31 15:51:44 -04:00
|
|
|
|
2024-05-14 19:02:45 -04:00
|
|
|
TEST_FLAC_ORIGINAL = "tests/silence.flac"
|
|
|
|
TEST_FLAC_COPY = "tests/silence_copy.flac"
|
2023-10-31 15:51:44 -04:00
|
|
|
test_cover = "tests/1x1_pixel.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
def wipe_test_flac():
|
2024-05-14 19:02:45 -04:00
|
|
|
audio = FLAC(TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
# Remove all tags
|
|
|
|
audio.delete()
|
|
|
|
audio.save()
|
|
|
|
|
|
|
|
|
2023-12-21 01:21:58 -05:00
|
|
|
@pytest.fixture()
|
2023-10-31 15:51:44 -04:00
|
|
|
def sample_metadata() -> TrackMetadata:
|
|
|
|
return TrackMetadata(
|
|
|
|
TrackInfo(
|
|
|
|
id="12345",
|
|
|
|
quality=3,
|
|
|
|
bit_depth=24,
|
|
|
|
explicit=True,
|
|
|
|
sampling_rate=96,
|
|
|
|
work=None,
|
|
|
|
),
|
|
|
|
"testtitle",
|
|
|
|
AlbumMetadata(
|
|
|
|
AlbumInfo("5678", 4, "flac"),
|
|
|
|
"testalbum",
|
|
|
|
"testalbumartist",
|
|
|
|
"1999",
|
|
|
|
["rock", "pop"],
|
|
|
|
Covers(),
|
|
|
|
14,
|
|
|
|
3,
|
|
|
|
"testalbumcomposer",
|
|
|
|
"testcomment",
|
|
|
|
compilation="testcompilation",
|
|
|
|
copyright="(c) stuff (p) other stuff",
|
|
|
|
date="1998-02-13",
|
|
|
|
description="testdesc",
|
|
|
|
encoder="ffmpeg",
|
|
|
|
grouping="testgroup",
|
|
|
|
lyrics="ye ye ye",
|
|
|
|
purchase_date=None,
|
|
|
|
),
|
|
|
|
"testartist",
|
|
|
|
3,
|
|
|
|
1,
|
|
|
|
"testcomposer",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_tag_flac_no_cover(sample_metadata):
|
2024-05-14 19:02:45 -04:00
|
|
|
shutil.copy(TEST_FLAC_ORIGINAL, TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
wipe_test_flac()
|
2024-05-14 19:02:45 -04:00
|
|
|
arun(tag_file(TEST_FLAC_COPY, sample_metadata, None))
|
|
|
|
file = FLAC(TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
assert file["title"][0] == "testtitle"
|
|
|
|
assert file["album"][0] == "testalbum"
|
|
|
|
assert file["composer"][0] == "testcomposer"
|
|
|
|
assert file["comment"][0] == "testcomment"
|
|
|
|
assert file["artist"][0] == "testartist"
|
|
|
|
assert file["albumartist"][0] == "testalbumartist"
|
|
|
|
assert file["year"][0] == "1999"
|
|
|
|
assert file["genre"][0] == "rock, pop"
|
|
|
|
assert file["tracknumber"][0] == "03"
|
|
|
|
assert file["discnumber"][0] == "01"
|
|
|
|
assert file["copyright"][0] == "© stuff ℗ other stuff"
|
|
|
|
assert file["tracktotal"][0] == "14"
|
|
|
|
assert file["date"][0] == "1998-02-13"
|
|
|
|
assert "purchase_date" not in file, file["purchase_date"]
|
2024-05-14 19:02:45 -04:00
|
|
|
os.remove(TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_tag_flac_cover(sample_metadata):
|
2024-05-14 19:02:45 -04:00
|
|
|
shutil.copy(TEST_FLAC_ORIGINAL, TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
wipe_test_flac()
|
2024-05-14 19:02:45 -04:00
|
|
|
arun(tag_file(TEST_FLAC_COPY, sample_metadata, test_cover))
|
|
|
|
file = FLAC(TEST_FLAC_COPY)
|
2023-10-31 15:51:44 -04:00
|
|
|
assert file["title"][0] == "testtitle"
|
|
|
|
assert file["album"][0] == "testalbum"
|
|
|
|
assert file["composer"][0] == "testcomposer"
|
|
|
|
assert file["comment"][0] == "testcomment"
|
|
|
|
assert file["artist"][0] == "testartist"
|
|
|
|
assert file["albumartist"][0] == "testalbumartist"
|
|
|
|
assert file["year"][0] == "1999"
|
|
|
|
assert file["genre"][0] == "rock, pop"
|
|
|
|
assert file["tracknumber"][0] == "03"
|
|
|
|
assert file["discnumber"][0] == "01"
|
|
|
|
assert file["copyright"][0] == "© stuff ℗ other stuff"
|
|
|
|
assert file["tracktotal"][0] == "14"
|
|
|
|
assert file["date"][0] == "1998-02-13"
|
|
|
|
with open(test_cover, "rb") as img:
|
|
|
|
assert file.pictures[0].data == img.read()
|
|
|
|
assert "purchase_date" not in file, file["purchase_date"]
|
2024-05-14 19:02:45 -04:00
|
|
|
os.remove(TEST_FLAC_COPY)
|