File: test_tagger.py

package info (click to toggle)
streamrip 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,560 kB
  • sloc: python: 6,308; makefile: 5
file content (111 lines) | stat: -rw-r--r-- 3,283 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import shutil

import pytest
from mutagen.flac import FLAC
from util import arun

from streamrip.metadata import (
    AlbumInfo,
    AlbumMetadata,
    Covers,
    TrackInfo,
    TrackMetadata,
    tag_file,
)

TEST_FLAC_ORIGINAL = "tests/silence.flac"
TEST_FLAC_COPY = "tests/silence_copy.flac"
test_cover = "tests/1x1_pixel.jpg"


def wipe_test_flac():
    audio = FLAC(TEST_FLAC_COPY)
    # Remove all tags
    audio.delete()
    audio.save()


@pytest.fixture()
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):
    shutil.copy(TEST_FLAC_ORIGINAL, TEST_FLAC_COPY)
    wipe_test_flac()
    arun(tag_file(TEST_FLAC_COPY, sample_metadata, None))
    file = FLAC(TEST_FLAC_COPY)
    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"]
    os.remove(TEST_FLAC_COPY)


def test_tag_flac_cover(sample_metadata):
    shutil.copy(TEST_FLAC_ORIGINAL, TEST_FLAC_COPY)
    wipe_test_flac()
    arun(tag_file(TEST_FLAC_COPY, sample_metadata, test_cover))
    file = FLAC(TEST_FLAC_COPY)
    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"]
    os.remove(TEST_FLAC_COPY)