Skip to content

Commit 5749b19

Browse files
author
Michal Warda
committed
Offload source search to the media worker
1 parent 9271329 commit 5749b19

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

deploy/pipeline/sam-cinematic-continuous.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SAM_CONTINUOUS_SOURCE_STAGING_DIR=/mnt/sam-source-staging
4242
# private NFS mount). Tasks left out of this list always execute locally.
4343
# SAM_MEDIA_WORKER_SSH_TARGET=ubuntu@172.31.0.10
4444
# SAM_MEDIA_WORKER_SSH_IDENTITY=/home/ubuntu/.ssh/sam-media-worker
45-
# SAM_MEDIA_WORKER_REMOTE_TASKS=download,ffmpeg
45+
# SAM_MEDIA_WORKER_REMOTE_TASKS=download,ffmpeg,search
4646
SAM_CONTINUOUS_DOWNLOADED_HIGH_WATER=512
4747
SAM_CONTINUOUS_DOWNLOADED_HIGH_WATER_BYTES=34359738368
4848
SAM_CONTINUOUS_PROVIDER_CIRCUIT_FAILURE_THRESHOLD=12

deploy/pipeline/sam-source-discovery.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Group=ubuntu
1010
WorkingDirectory=/home/ubuntu/sam-audio-deploy/pipeline
1111
EnvironmentFile=/etc/sam-cinematic-continuous.env
1212
ExecStart=/home/ubuntu/sam-audio-deploy/deploy/pipeline/run-source-discovery.sh
13+
ExecStopPost=/home/ubuntu/sam-audio-deploy/pipeline/.venv/bin/python -m sam_audio_pipeline.remote_media cleanup search
1314
Restart=always
1415
RestartSec=5
1516
TimeoutStopSec=15

pipeline/src/sam_audio_pipeline/youtube_random.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ def _run(command: list[str], *, timeout: float) -> subprocess.CompletedProcess[s
507507
return completed
508508

509509

510+
def _run_search_command(
511+
command: list[str], *, timeout: float
512+
) -> subprocess.CompletedProcess[str]:
513+
"""Run yt-dlp discovery work on the media host when one is configured."""
514+
wrapped, wrapped_timeout = command_for_media_worker(
515+
command,
516+
task="search",
517+
timeout=timeout,
518+
)
519+
return _run(wrapped, timeout=wrapped_timeout)
520+
521+
510522
def _terminate_process_group(process: subprocess.Popen[str]) -> tuple[str, str]:
511523
"""Stop and reap a downloader plus every ffmpeg/ffprobe descendant."""
512524
try:
@@ -709,7 +721,7 @@ def _cinematic_candidate_priority(item: dict[str, Any]) -> int:
709721

710722

711723
def _search_youtube(query: str, results: int, profile: str) -> list[dict[str, Any]]:
712-
response = _run(
724+
response = _run_search_command(
713725
[
714726
YTDLP_PYTHON,
715727
"-m",
@@ -749,7 +761,7 @@ def _hydrate_search_result(
749761
affinity_key: str,
750762
timeout: float = 90,
751763
) -> dict[str, Any]:
752-
response = _run(
764+
response = _run_search_command(
753765
[
754766
YTDLP_PYTHON,
755767
"-m",
@@ -786,7 +798,7 @@ def _search_ytdlp_provider(
786798
if provider.get("site"):
787799
provider_query = f"site:{provider['site']} {provider_query}"
788800
target = f"{provider['search_key']}{limited_results}:{provider_query}"
789-
response = _run(
801+
response = _run_search_command(
790802
[
791803
YTDLP_PYTHON,
792804
"-m",

0 commit comments

Comments
 (0)