mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 20:59:56 -05:00
Creatind download manager config which will store skipped urls.
This commit is contained in:
parent
7ac3fbea2b
commit
43709ac9e7
5 changed files with 110 additions and 81 deletions
|
|
@ -11,10 +11,11 @@ from yt_dlp import YoutubeDL
|
|||
from yt_dlp.extractor import YoutubeTabIE
|
||||
from yt_dlp.utils import UnsupportedError, DownloadError
|
||||
|
||||
from wrolpi.cmd import which
|
||||
from wrolpi.common import logger, sanitize_link, extract_domain
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.db import get_db_session, get_db_curs
|
||||
from wrolpi.downloader import Downloader, Download
|
||||
from wrolpi.downloader import Downloader, Download, DOWNLOAD_MANAGER_CONFIG
|
||||
from wrolpi.errors import UnknownChannel, ChannelURLEmpty, UnrecoverableDownloadError
|
||||
from wrolpi.vars import PYTEST
|
||||
from .channel.lib import create_channel, get_channel
|
||||
|
|
@ -78,6 +79,9 @@ class ChannelDownloader(Downloader, ABC):
|
|||
with get_db_session(commit=True) as session:
|
||||
for video_id, source_id, missing_video in missing_videos:
|
||||
url = video_url_resolver(domain, missing_video)
|
||||
if url in DOWNLOAD_MANAGER_CONFIG.skip_urls:
|
||||
# Don't try to download skipped videos.
|
||||
continue
|
||||
# Schedule any missing videos for download.
|
||||
download = self.manager.get_or_create_download(url, session)
|
||||
download.downloader = 'video'
|
||||
|
|
@ -90,11 +94,12 @@ class ChannelDownloader(Downloader, ABC):
|
|||
return True
|
||||
|
||||
|
||||
YT_DLP_BIN = pathlib.Path('/usr/local/bin/yt-dlp') # Location in docker container
|
||||
if not YT_DLP_BIN.is_file():
|
||||
YT_DLP_BIN = pathlib.Path('/opt/wrolpi/venv/bin/yt-dlp') # Use virtual environment location
|
||||
if not YT_DLP_BIN.is_file() and not PYTEST:
|
||||
logger.error('COULD NOT FIND YT-DLP!!!')
|
||||
YT_DLP_BIN = which(
|
||||
'yt-dlp',
|
||||
'/usr/local/bin/yt-dlp', # Location in docker container
|
||||
'/opt/wrolpi/venv/bin/yt-dlp', # Use virtual environment location
|
||||
warn=True,
|
||||
)
|
||||
|
||||
|
||||
class VideoDownloader(Downloader, ABC):
|
||||
|
|
@ -221,8 +226,6 @@ class VideoDownloader(Downloader, ABC):
|
|||
options = get_downloader_config().dict()
|
||||
options['outtmpl'] = f'{out_dir}/{options["file_name_format"]}'
|
||||
options['merge_output_format'] = PREFERRED_VIDEO_EXTENSION
|
||||
# We don't need "format" when getting the filename.
|
||||
del options['format']
|
||||
|
||||
logger.debug(f'Downloading {url} to {out_dir}')
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import html
|
|||
import pathlib
|
||||
import re
|
||||
from collections import defaultdict
|
||||
from typing import Tuple, Optional
|
||||
from typing import Tuple, Optional, List
|
||||
from uuid import uuid1
|
||||
|
||||
from sqlalchemy.exc import InvalidRequestError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from wrolpi.common import logger, chunks, ConfigFile, WROLPiConfig
|
||||
from wrolpi.common import logger, chunks, ConfigFile
|
||||
from wrolpi.dates import from_timestamp, Seconds
|
||||
from wrolpi.db import get_db_curs, get_db_session, optional_session
|
||||
from wrolpi.media_path import MediaPath
|
||||
|
|
@ -340,13 +340,12 @@ def set_test_channels_config(enable: bool):
|
|||
TEST_CHANNELS_CONFIG = None
|
||||
|
||||
|
||||
class DownloaderConfig(ConfigFile):
|
||||
file_name = 'downloader.yaml'
|
||||
class VideoDownloaderConfig(ConfigFile):
|
||||
file_name = 'videos_downloader.yaml'
|
||||
default_config = dict(
|
||||
continue_dl=True,
|
||||
dateafter='19900101',
|
||||
file_name_format='%(uploader)s_%(upload_date)s_%(id)s_%(title)s.%(ext)s',
|
||||
format='22 / 135 / 18 / 43',
|
||||
nooverwrites=True,
|
||||
quiet=False,
|
||||
writeautomaticsub=True,
|
||||
|
|
@ -380,14 +379,6 @@ class DownloaderConfig(ConfigFile):
|
|||
def file_name_format(self, value: str):
|
||||
self.update({'file_name_format': value})
|
||||
|
||||
@property
|
||||
def format(self) -> str:
|
||||
return self._config['format']
|
||||
|
||||
@format.setter
|
||||
def format(self, value: str):
|
||||
self.update({'format': value})
|
||||
|
||||
@property
|
||||
def nooverwrites(self) -> bool:
|
||||
return self._config['nooverwrites']
|
||||
|
|
@ -445,25 +436,25 @@ class DownloaderConfig(ConfigFile):
|
|||
self.update({'youtube_include_dash_manifest': value})
|
||||
|
||||
|
||||
DOWNLOADER_CONFIG: DownloaderConfig = DownloaderConfig(global_=True)
|
||||
TEST_DOWNLOADER_CONFIG: DownloaderConfig = None
|
||||
VIDEO_DOWNLOADER_CONFIG: VideoDownloaderConfig = VideoDownloaderConfig(global_=True)
|
||||
TEST_VIDEO_DOWNLOADER_CONFIG: VideoDownloaderConfig = None
|
||||
|
||||
|
||||
def get_downloader_config():
|
||||
global TEST_DOWNLOADER_CONFIG
|
||||
if isinstance(TEST_DOWNLOADER_CONFIG, DownloaderConfig):
|
||||
return TEST_DOWNLOADER_CONFIG
|
||||
global TEST_VIDEO_DOWNLOADER_CONFIG
|
||||
if isinstance(TEST_VIDEO_DOWNLOADER_CONFIG, VideoDownloaderConfig):
|
||||
return TEST_VIDEO_DOWNLOADER_CONFIG
|
||||
|
||||
global DOWNLOADER_CONFIG
|
||||
return DOWNLOADER_CONFIG
|
||||
global VIDEO_DOWNLOADER_CONFIG
|
||||
return VIDEO_DOWNLOADER_CONFIG
|
||||
|
||||
|
||||
def set_test_downloader_config(enabled: bool):
|
||||
global TEST_DOWNLOADER_CONFIG
|
||||
global TEST_VIDEO_DOWNLOADER_CONFIG
|
||||
if enabled:
|
||||
TEST_DOWNLOADER_CONFIG = DownloaderConfig()
|
||||
TEST_VIDEO_DOWNLOADER_CONFIG = VideoDownloaderConfig()
|
||||
else:
|
||||
TEST_DOWNLOADER_CONFIG = None
|
||||
TEST_VIDEO_DOWNLOADER_CONFIG = None
|
||||
|
||||
|
||||
def get_channels_config_from_db(session: Session) -> dict:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue