libretime/analyzer/tests/pipeline/analyze_metadata_test.py
dakriy 02a779b413
feat(analyzer): parse comment fields from mp3 files (#3082)
### Description

Upload comments from mp3 files into libretime `comments` and
`description` fields.

**This is a new feature**:

Yes

**I have updated the documentation to reflect these changes**:

No none required

### Testing Notes

**What I did:**

I uploaded tracks that contained comments into LibreTime and checked the
database to ensure that the `comments` and `description` fields were
correctly populated. I then went to the UI and confirmed that the
description field had the MP3 comment in it inside of the metadata
editor. I then uploaded some files that did not have comments to make
sure I did not break any existing functionality.

**How you can replicate my testing:**

Follow the steps in what I did

### **Links**

Fixes #526

---------

Co-authored-by: Kyle Robbertze <paddatrapper@users.noreply.github.com>
2024-11-22 18:28:06 +00:00

51 lines
1.3 KiB
Python

from pathlib import Path
import pytest
from libretime_analyzer.pipeline.analyze_metadata import analyze_metadata
from ..fixtures import FILE_INVALID_DRM, FILE_INVALID_TXT, FILES_TAGGED
@pytest.mark.parametrize(
"filepath,metadata",
map(lambda i: (i.path, i.metadata), FILES_TAGGED),
)
def test_analyze_metadata(filepath: Path, metadata: dict):
found = analyze_metadata(str(filepath), {})
assert len(found["md5"]) == 32
del found["md5"]
# Handle filesize
assert found["filesize"] < 3e6 # ~3Mb
assert found["filesize"] > 1e5 # 100Kb
del found["filesize"]
# Handle track formatted length
assert metadata["length"] in found["length"]
del metadata["length"]
del found["length"]
# ogg,flac files does not support comments yet
if not filepath.suffix == ".m4a" and not filepath.suffix == ".mp3":
if "comment" in metadata:
del metadata["comment"]
assert found == metadata
def test_analyze_metadata_invalid_wma():
metadata = analyze_metadata(str(FILE_INVALID_DRM), {})
assert metadata["mime"] == "audio/x-ms-wma"
def test_analyze_metadata_unparsable_file():
metadata = analyze_metadata(str(FILE_INVALID_TXT), {})
assert metadata == {
"filesize": 10,
"ftype": "audioclip",
"hidden": False,
"md5": "4d5e4b1c8e8febbd31fa9ce7f088beae",
}