refactor: media uses snapshot instead of link
This commit is contained in:
parent
48aa9d5c08
commit
29ec48a35f
|
@ -3,6 +3,8 @@ __package__ = 'archivebox.extractors'
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from django.db.models import Model
|
||||||
|
|
||||||
from ..index.schema import Link, ArchiveResult, ArchiveOutput, ArchiveError
|
from ..index.schema import Link, ArchiveResult, ArchiveOutput, ArchiveError
|
||||||
from ..system import run, chmod_file
|
from ..system import run, chmod_file
|
||||||
from ..util import (
|
from ..util import (
|
||||||
|
@ -21,10 +23,10 @@ from ..logging_util import TimedProgress
|
||||||
|
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def should_save_media(link: Link, out_dir: Optional[Path]=None) -> bool:
|
def should_save_media(snapshot: Model, out_dir: Optional[Path]=None) -> bool:
|
||||||
out_dir = out_dir or link.link_dir
|
out_dir = out_dir or snapshot.snapshot_dir
|
||||||
|
|
||||||
if is_static_file(link.url):
|
if is_static_file(snapshot.url):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (out_dir / "media").exists():
|
if (out_dir / "media").exists():
|
||||||
|
@ -33,10 +35,10 @@ def should_save_media(link: Link, out_dir: Optional[Path]=None) -> bool:
|
||||||
return SAVE_MEDIA
|
return SAVE_MEDIA
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def save_media(link: Link, out_dir: Optional[Path]=None, timeout: int=MEDIA_TIMEOUT) -> ArchiveResult:
|
def save_media(snapshot: Model, out_dir: Optional[Path]=None, timeout: int=MEDIA_TIMEOUT) -> ArchiveResult:
|
||||||
"""Download playlists or individual video, audio, and subtitles using youtube-dl"""
|
"""Download playlists or individual video, audio, and subtitles using youtube-dl"""
|
||||||
|
|
||||||
out_dir = out_dir or Path(link.link_dir)
|
out_dir = out_dir or Path(snapshot.snapshot_dir)
|
||||||
output: ArchiveOutput = 'media'
|
output: ArchiveOutput = 'media'
|
||||||
output_path = out_dir / output
|
output_path = out_dir / output
|
||||||
output_path.mkdir(exist_ok=True)
|
output_path.mkdir(exist_ok=True)
|
||||||
|
@ -44,7 +46,7 @@ def save_media(link: Link, out_dir: Optional[Path]=None, timeout: int=MEDIA_TIME
|
||||||
YOUTUBEDL_BINARY,
|
YOUTUBEDL_BINARY,
|
||||||
*YOUTUBEDL_ARGS,
|
*YOUTUBEDL_ARGS,
|
||||||
*([] if CHECK_SSL_VALIDITY else ['--no-check-certificate']),
|
*([] if CHECK_SSL_VALIDITY else ['--no-check-certificate']),
|
||||||
link.url,
|
snapshot.url,
|
||||||
]
|
]
|
||||||
status = 'succeeded'
|
status = 'succeeded'
|
||||||
timer = TimedProgress(timeout, prefix=' ')
|
timer = TimedProgress(timeout, prefix=' ')
|
||||||
|
|
Loading…
Reference in a new issue