FEATURE: propogate improvements from CLI version to web-backend
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Dict, List, Any
|
||||
from typing import List, Dict, Any
|
||||
import time
|
||||
|
||||
from backend.config import settings
|
||||
from backend.services.task_manager import task_manager
|
||||
@@ -13,31 +13,12 @@ from backend.services.file_manager import FileManager
|
||||
from backend.models.request import TracklistEntry
|
||||
from backend.models.response import TaskStatus
|
||||
|
||||
# Import central defaults
|
||||
from audio_splitter.defaults import (
|
||||
DEFAULT_FORMAT,
|
||||
DEFAULT_OUTPUT_TEMPLATE,
|
||||
DEFAULT_REPLACEMENT_CHAR,
|
||||
DEFAULT_BAD_CHARS,
|
||||
DEFAULT_ALBUM,
|
||||
DEFAULT_COMMENT,
|
||||
DEFAULT_NO_COMMENT,
|
||||
DEFAULT_COMMENT_STREAM,
|
||||
DEFAULT_MERGE_COMMENTS,
|
||||
DEFAULT_COMMENT_SEPARATOR,
|
||||
DEFAULT_DROP_VIDEO,
|
||||
DEFAULT_DROP_SUBS,
|
||||
DEFAULT_NUMBER_TRACKS,
|
||||
DEFAULT_REPLACE_BAD_CHARS,
|
||||
DEFAULT_SKIP_EXISTING,
|
||||
DEFAULT_DELETE_ORIGINAL,
|
||||
DEFAULT_TRANSCODE_TO,
|
||||
)
|
||||
|
||||
|
||||
def run_split_task(task_id: str, tracklist: List[TracklistEntry], options: Dict[str, Any]) -> None:
|
||||
try:
|
||||
task_manager.update_task_with_progress(task_id, progress=5, message="Initializing...")
|
||||
task_manager.update_task_with_progress(
|
||||
task_id, progress=5, message="Initializing..."
|
||||
)
|
||||
|
||||
input_path = FileManager.get_input_path(task_id)
|
||||
if not input_path or not input_path.exists():
|
||||
@@ -45,7 +26,6 @@ def run_split_task(task_id: str, tracklist: List[TracklistEntry], options: Dict[
|
||||
|
||||
output_dir = FileManager.ensure_output_dir(task_id)
|
||||
|
||||
# Convert tracklist to dicts (CLI format)
|
||||
tracks = []
|
||||
for entry in tracklist:
|
||||
track_dict = {
|
||||
@@ -58,25 +38,30 @@ def run_split_task(task_id: str, tracklist: List[TracklistEntry], options: Dict[
|
||||
}
|
||||
tracks.append(track_dict)
|
||||
|
||||
# Build args namespace using defaults where options not provided
|
||||
from types import SimpleNamespace
|
||||
|
||||
# Build args namespace using the new fields
|
||||
args = SimpleNamespace(
|
||||
format=options.get("format", DEFAULT_FORMAT),
|
||||
transcode_to=options.get("transcode_to", DEFAULT_TRANSCODE_TO),
|
||||
drop_video=options.get("drop_video", DEFAULT_DROP_VIDEO),
|
||||
drop_subs=options.get("drop_subs", DEFAULT_DROP_SUBS),
|
||||
number_tracks=options.get("number_tracks", DEFAULT_NUMBER_TRACKS),
|
||||
replace_bad_chars=options.get("replace_bad_chars", DEFAULT_REPLACE_BAD_CHARS),
|
||||
replacement_char=options.get("replacement_char", DEFAULT_REPLACEMENT_CHAR),
|
||||
bad_chars=options.get("bad_chars", DEFAULT_BAD_CHARS),
|
||||
skip_existing=options.get("skip_existing", DEFAULT_SKIP_EXISTING),
|
||||
output_template=options.get("output_template", DEFAULT_OUTPUT_TEMPLATE),
|
||||
album=options.get("album", DEFAULT_ALBUM),
|
||||
comment=options.get("comment", DEFAULT_COMMENT),
|
||||
no_comment=options.get("no_comment", DEFAULT_NO_COMMENT),
|
||||
comment_stream=options.get("comment_stream", DEFAULT_COMMENT_STREAM),
|
||||
merge_comments=options.get("merge_comments", DEFAULT_MERGE_COMMENTS),
|
||||
comment_separator=options.get("comment_separator", DEFAULT_COMMENT_SEPARATOR),
|
||||
delete_original=DEFAULT_DELETE_ORIGINAL, # never delete in web
|
||||
container=options.get("container"), # None -> auto-detect
|
||||
audio_codec=options.get("audio_codec", "copy"),
|
||||
video_codec=options.get("video_codec", "copy"),
|
||||
subtitle_codec=options.get("subtitle_codec", "copy"),
|
||||
video_quality=options.get("video_quality"),
|
||||
drop_video=options.get("drop_video", False),
|
||||
drop_subs=options.get("drop_subs", False),
|
||||
number_tracks=options.get("number_tracks", False),
|
||||
replace_bad_chars=options.get("replace_bad_chars", False),
|
||||
replacement_char=options.get("replacement_char", "_"),
|
||||
bad_chars=options.get("bad_chars", r'!@#№$;:%^&?*(){}[]\/<>+=~`\' '),
|
||||
skip_existing=options.get("skip_existing", False),
|
||||
output_template=options.get("output_template", "%an-%tn.%ext"),
|
||||
album=options.get("album", None),
|
||||
comment=options.get("comment", None),
|
||||
no_comment=options.get("no_comment", False),
|
||||
comment_stream=options.get("comment_stream", None),
|
||||
merge_comments=options.get("merge_comments", False),
|
||||
comment_separator=options.get("comment_separator", "; "),
|
||||
delete_original=False,
|
||||
)
|
||||
|
||||
project_root = Path(__file__).parent.parent.parent.parent
|
||||
@@ -85,7 +70,25 @@ def run_split_task(task_id: str, tracklist: List[TracklistEntry], options: Dict[
|
||||
|
||||
from audio_splitter.core import split_audio
|
||||
|
||||
task_manager.update_task_with_progress(task_id, progress=10, message="Starting split...")
|
||||
# Detect attached picture and extract if applicable
|
||||
cover_image_path = None
|
||||
if not args.drop_video:
|
||||
from audio_splitter.ffmpeg import is_attached_picture, extract_cover_image, get_stream_info
|
||||
input_path_str = str(input_path)
|
||||
stream_info = get_stream_info(input_path_str)
|
||||
if stream_info.get('has_video') and is_attached_picture(input_path_str):
|
||||
cover_image_path = output_dir / 'cover.png'
|
||||
if extract_cover_image(input_path_str, str(cover_image_path)):
|
||||
print(f"Extracted cover image for task {task_id}")
|
||||
else:
|
||||
cover_image_path = None
|
||||
|
||||
# Attach cover image to args
|
||||
args.cover_image = str(cover_image_path) if cover_image_path else None
|
||||
|
||||
task_manager.update_task_with_progress(
|
||||
task_id, progress=10, message="Starting split..."
|
||||
)
|
||||
|
||||
split_audio(str(input_path), str(output_dir), tracks, args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user