feat: Enhance metadata extraction and formatting, improve extractor architecture, and update documentation

This commit is contained in:
sha
2025-12-26 13:38:17 +00:00
parent 8f68624529
commit 91df347727
13 changed files with 170 additions and 76 deletions
+7 -1
View File
@@ -90,7 +90,6 @@ The Invention of Lying (2009) [720p,ukr,eng].mkv
The Island of Dr. Moreau.(1977).[720p,ukr].mp4
The Killing.(1956).[SD,ukr,eng].mkv
The Love Guru.(2008).[SD,ukr].avi
The Love Guru.(2008).[SD,ukr].avi
The Manchurian Candidate.(2004).[720p,ukr,eng].mkv
The Mortal Instruments. City of Bones.(2013).[720p,ukr,eng].mkv
The Mutant Chronicles.(2008).[SD,ukr,eng].mkv
@@ -203,3 +202,10 @@ Upgrade.(2018).[SD,eng].mkv
Человек с бульвара Капуцинов (1987) [1080p,rus] [tmdbid-45227].mkv
Человек-амфибия (1961) [SD,rus] [tmdbid-43685].avi
Чук и Гек (1953) [SD,rus] [tmdbid-148412].avi
The long title.(2008).[SD 720p,ukr].avi
The_long_title.(2008).2K.1440p.ukr.avi
The long title (2008) SD 720p UKR.avi
The long title (2008) UHD 1440p ENG.mp4
The long title (2008) UHD 1440 ENG.mp4
The long title (2008) 8K 4320p ENG.mp4
+13 -10
View File
@@ -4,32 +4,35 @@ from renamer.extractors.fileinfo_extractor import FileInfoExtractor
class TestFileInfoExtractor:
@pytest.fixture
def extractor(self, test_file):
return FileInfoExtractor(test_file)
@pytest.fixture
def test_file(self):
"""Use the filenames.txt file for testing"""
return Path(__file__).parent / "filenames.txt"
def test_extract_size(self, test_file):
def test_extract_size(self, extractor):
"""Test extracting file size"""
size = FileInfoExtractor.extract_size(test_file)
size = extractor.extract_size()
assert isinstance(size, int)
assert size > 0
def test_extract_modification_time(self, test_file):
def test_extract_modification_time(self, extractor):
"""Test extracting modification time"""
mtime = FileInfoExtractor.extract_modification_time(test_file)
mtime = extractor.extract_modification_time()
assert isinstance(mtime, float)
assert mtime > 0
def test_extract_file_name(self, test_file):
def test_extract_file_name(self, extractor):
"""Test extracting file name"""
name = FileInfoExtractor.extract_file_name(test_file)
name = extractor.extract_file_name()
assert isinstance(name, str)
assert name == "filenames.txt"
def test_extract_file_path(self, test_file):
def test_extract_file_path(self, extractor):
"""Test extracting file path"""
path = FileInfoExtractor.extract_file_path(test_file)
path = extractor.extract_file_path()
assert isinstance(path, str)
assert "filenames.txt" in path
assert str(test_file) == path
assert "filenames.txt" in path
+8 -4
View File
@@ -17,7 +17,8 @@ def load_test_filenames():
def test_extract_title(filename):
"""Test title extraction from filename"""
file_path = Path(filename)
title = FilenameExtractor.extract_title(file_path)
extractor = FilenameExtractor(file_path)
title = extractor.extract_title()
# Print filename and extracted title clearly
print(f"\nFilename: \033[1;36m{filename}\033[0m")
print(f"Extracted title: \033[1;32m{title}\033[0m")
@@ -29,7 +30,8 @@ def test_extract_title(filename):
def test_extract_year(filename):
"""Test year extraction from filename"""
file_path = Path(filename)
year = FilenameExtractor.extract_year(file_path)
extractor = FilenameExtractor(file_path)
year = extractor.extract_year()
# Print filename and extracted year clearly
print(f"\nFilename: \033[1;36m{filename}\033[0m")
print(f"Extracted year: \033[1;32m{year}\033[0m")
@@ -42,7 +44,8 @@ def test_extract_year(filename):
def test_extract_source(filename):
"""Test source extraction from filename"""
file_path = Path(filename)
source = FilenameExtractor.extract_source(file_path)
extractor = FilenameExtractor(file_path)
source = extractor.extract_source()
# Print filename and extracted source clearly
print(f"\nFilename: \033[1;36m{filename}\033[0m")
print(f"Extracted source: \033[1;32m{source}\033[0m")
@@ -54,7 +57,8 @@ def test_extract_source(filename):
def test_extract_frame_class(filename):
"""Test frame class extraction from filename"""
file_path = Path(filename)
frame_class = FilenameExtractor.extract_frame_class(file_path)
extractor = FilenameExtractor(file_path)
frame_class = extractor.extract_frame_class()
# Print filename and extracted frame class clearly
print(f"\nFilename: \033[1;36m{filename}\033[0m")
print(f"Extracted frame_class: \033[1;32m{frame_class}\033[0m")
+5 -5
View File
@@ -5,8 +5,8 @@ from renamer.extractors.mediainfo_extractor import MediaInfoExtractor
class TestMediaInfoExtractor:
@pytest.fixture
def extractor(self):
return MediaInfoExtractor()
def extractor(self, test_file):
return MediaInfoExtractor(test_file)
@pytest.fixture
def test_file(self):
@@ -15,18 +15,18 @@ class TestMediaInfoExtractor:
def test_extract_resolution(self, extractor, test_file):
"""Test extracting resolution from media info"""
resolution = extractor.extract_resolution(test_file)
resolution = extractor.extract_resolution()
# Text files don't have video resolution
assert resolution is None
def test_extract_hdr(self, extractor, test_file):
"""Test extracting HDR info"""
hdr = extractor.extract_hdr(test_file)
hdr = extractor.extract_hdr()
# Text files don't have HDR
assert hdr is None
def test_extract_audio_langs(self, extractor, test_file):
"""Test extracting audio languages"""
langs = extractor.extract_audio_langs(test_file)
langs = extractor.extract_audio_langs()
# Text files don't have audio tracks
assert langs == ''
+11 -17
View File
@@ -4,35 +4,29 @@ from renamer.extractors.metadata_extractor import MetadataExtractor
class TestMetadataExtractor:
@pytest.fixture
def extractor(self, test_file):
return MetadataExtractor(test_file)
@pytest.fixture
def test_file(self):
"""Use the filenames.txt file for testing"""
return Path(__file__).parent / "filenames.txt"
def test_extract_title(self, test_file):
def test_extract_title(self, extractor):
"""Test extracting title from metadata"""
title = MetadataExtractor.extract_title(test_file)
title = extractor.extract_title()
# Text files don't have metadata, so should be None
assert title is None
def test_extract_duration(self, test_file):
def test_extract_duration(self, extractor):
"""Test extracting duration from metadata"""
duration = MetadataExtractor.extract_duration(test_file)
duration = extractor.extract_duration()
# Text files don't have duration
assert duration is None
def test_extract_artist(self, test_file):
def test_extract_artist(self, extractor):
"""Test extracting artist from metadata"""
artist = MetadataExtractor.extract_artist(test_file)
artist = extractor.extract_artist()
# Text files don't have artist
assert artist is None
def test_extract_all_metadata(self, test_file):
"""Test extracting all metadata"""
metadata = MetadataExtractor.extract_all_metadata(test_file)
expected = {
'title': None,
'duration': None,
'artist': None
}
assert metadata == expected
assert artist is None