refactor(analyzer): split analyze_cuepoint steps
This commit is contained in:
parent
45b5c5caf1
commit
3a9ca109c3
|
@ -8,11 +8,10 @@ from loguru import logger
|
|||
from ._ffmpeg import compute_silences, probe_duration
|
||||
|
||||
|
||||
def analyze_cuepoint(filepath: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def analyze_duration(filepath: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Extracts the cuein and cueout times along and sets the file duration using ffmpeg.
|
||||
Extracts the file duration using ffmpeg.
|
||||
"""
|
||||
|
||||
try:
|
||||
duration = probe_duration(filepath)
|
||||
|
||||
|
@ -30,7 +29,23 @@ def analyze_cuepoint(filepath: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
|||
metadata["length"] = str(timedelta(seconds=duration))
|
||||
metadata["cuein"] = 0.0
|
||||
metadata["cueout"] = duration
|
||||
except (CalledProcessError, OSError):
|
||||
pass
|
||||
|
||||
return metadata
|
||||
|
||||
|
||||
def analyze_cuepoint(filepath: str, metadata: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Extracts the cuein and cueout times using ffmpeg.
|
||||
|
||||
This step must run after the 'analyze_duration' step.
|
||||
"""
|
||||
|
||||
# Duration has been computed in the 'analyze_duration' step
|
||||
duration = metadata["length_seconds"]
|
||||
|
||||
try:
|
||||
silences = compute_silences(filepath)
|
||||
|
||||
if len(silences) > 2:
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Protocol
|
|||
|
||||
from loguru import logger
|
||||
|
||||
from .analyze_cuepoint import analyze_cuepoint
|
||||
from .analyze_cuepoint import analyze_cuepoint, analyze_duration
|
||||
from .analyze_metadata import analyze_metadata
|
||||
from .analyze_playability import UnplayableFileError, analyze_playability
|
||||
from .analyze_replaygain import analyze_replaygain
|
||||
|
@ -77,6 +77,7 @@ class Pipeline:
|
|||
# First, we extract the ID3 tags and other metadata:
|
||||
metadata = {}
|
||||
metadata = analyze_metadata(audio_file_path, metadata)
|
||||
metadata = analyze_duration(audio_file_path, metadata)
|
||||
metadata = analyze_cuepoint(audio_file_path, metadata)
|
||||
metadata = analyze_replaygain(audio_file_path, metadata)
|
||||
metadata = analyze_playability(audio_file_path, metadata)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import pytest
|
||||
|
||||
from libretime_analyzer.pipeline.analyze_cuepoint import analyze_cuepoint
|
||||
from libretime_analyzer.pipeline.analyze_cuepoint import (
|
||||
analyze_cuepoint,
|
||||
analyze_duration,
|
||||
)
|
||||
|
||||
from ..fixtures import FILES
|
||||
|
||||
|
@ -15,7 +18,8 @@ from ..fixtures import FILES
|
|||
),
|
||||
)
|
||||
def test_analyze_cuepoint(filepath, length, cuein, cueout):
|
||||
metadata = analyze_cuepoint(filepath, {})
|
||||
metadata = analyze_duration(filepath, {})
|
||||
metadata = analyze_cuepoint(filepath, metadata)
|
||||
|
||||
assert metadata["length_seconds"] == pytest.approx(length, abs=0.1)
|
||||
assert float(metadata["cuein"]) == pytest.approx(float(cuein), abs=1)
|
||||
|
|
Loading…
Reference in New Issue