from unittest import TestCase import os import subprocess from mutagen import mp3 import config import http_pool import id3pp TEST_MP3 = 'music/test.mp3' INFO_BEFORE = { "filepath": TEST_MP3, "title": "A Line in the Sand", "uploader": "Linkin Park - Topic", "playlist": "Album \u2013 The Hunting Party", "playlist_index": 12, "release_year": 2015, "genre": "numetal", } INFO_AFTER = { **INFO_BEFORE, "track": "A Line in the Sand", "artist": "Linkin Park", "artists": ["Linkin Park"], "album": "The Hunting Party", "track_number": 12, } class TestPostProcessorsOnFakeData(TestCase): def setUp(self) -> None: cfg = config.get() cfg.save_lyrics = False cfg.save_cover = False http_pool.get() def test_infoytpp(self) -> None: _, info = id3pp.InfoGenPP().run(INFO_BEFORE) self.assertDictEqual(info, INFO_AFTER) def test_id3(self) -> None: try: if os.path.exists(TEST_MP3): os.unlink(TEST_MP3) ret = subprocess.call( [ 'ffmpeg', '-nostdin', '-f', 'lavfi', '-i', 'anullsrc=r=44100:cl=mono', '-t', '1', '-b:a', '32k', '-acodec', 'libmp3lame', TEST_MP3, ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) if ret != 0: raise RuntimeError(f'FFmpeg returned {ret} exit code') except Exception as err: self.skipTest(f'Error while writing empty MP3: {err!r}') id3pp.ID3TagsPP().run(INFO_AFTER) file = mp3.MP3(TEST_MP3) self.assertEqual(file['TIT2'].text[0], 'A Line in the Sand') self.assertEqual(file['TPE1'].text[0], 'Linkin Park') self.assertEqual(file['TALB'].text[0], 'The Hunting Party') self.assertEqual(file['TDRC'].text[0].get_text(), '2015') self.assertEqual(file['TRCK'].text[0], '12') self.assertEqual(file['TCON'].text[0], 'numetal') def tearDown(self) -> None: http_pool.get().clear()