mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 17:36:18 -05:00
Creating perpetual funciton which checks if the internet is accessible. This is used to prevent downloads from starting when no internet exists.
This commit is contained in:
parent
2aebb7c406
commit
0fbbd36297
11 changed files with 171 additions and 46 deletions
|
|
@ -304,7 +304,7 @@ class VideoDownloader(Downloader, ABC):
|
|||
file_name_format = '%(uploader)s_%(upload_date)s_%(id)s_%(title)s.%(ext)s'
|
||||
cmd = (
|
||||
str(YT_DLP_BIN),
|
||||
'-cw', # Continue downloads, do not clobber existing files.
|
||||
'-c', # Continue downloads
|
||||
'-f', PREFERRED_VIDEO_FORMAT,
|
||||
'--match-filter', '!is_live', # Do not attempt to download Live videos.
|
||||
'--write-subs',
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ from sqlalchemy.orm.collections import InstrumentedList
|
|||
|
||||
from modules.videos.errors import UnknownVideo, UnknownChannel
|
||||
from wrolpi.captions import read_captions
|
||||
from wrolpi.common import Base, ModelHelper, logger, get_media_directory, background_task, truncate_object_bytes
|
||||
from wrolpi.common import Base, ModelHelper, logger, get_media_directory, background_task
|
||||
from wrolpi.db import get_db_curs, get_db_session, optional_session
|
||||
from wrolpi.downloader import Download, download_manager
|
||||
from wrolpi.files.lib import refresh_files, split_path_stem_and_suffix
|
||||
from wrolpi.files.lib import refresh_files, split_path_stem_and_suffix, replace_file
|
||||
from wrolpi.files.models import FileGroup
|
||||
from wrolpi.media_path import MediaPathType
|
||||
from wrolpi.tags import Tag, TagFile
|
||||
|
|
@ -487,7 +487,8 @@ class Video(ModelHelper, Base):
|
|||
def replace_info_json(self, info_json: dict):
|
||||
"""Replace the info json file with the new json dict. Handles adding new info_json file, if necessary."""
|
||||
info_json_path = self.info_json_path or self.video_path.with_suffix('.info.json')
|
||||
info_json_path.write_text(json.dumps(info_json, indent=2))
|
||||
info_json = json.dumps(info_json, indent=2)
|
||||
replace_file(info_json_path, info_json, missing_ok=True)
|
||||
|
||||
if not self.info_json_path:
|
||||
self.file_group.append_files(info_json_path)
|
||||
|
|
|
|||
|
|
@ -222,6 +222,8 @@ async def get_missing_videos_comments(limit: int = VIDEO_COMMENTS_FETCH_COUNT):
|
|||
download_manager.add_to_skip_list(video_url)
|
||||
|
||||
for url in video_urls:
|
||||
logger.info(f'Getting comments for: {url}')
|
||||
|
||||
# Sleep to catch cancel.
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
|
@ -241,42 +243,42 @@ async def get_missing_videos_comments(limit: int = VIDEO_COMMENTS_FETCH_COUNT):
|
|||
download_manager.add_to_skip_list(url)
|
||||
continue
|
||||
|
||||
tries = 5
|
||||
info = None
|
||||
while tries > 0:
|
||||
try:
|
||||
tries -= 1
|
||||
# Get info json about the video. Retry until we have a list of comments.
|
||||
info = download_video_info_json(url)
|
||||
if info and isinstance(info.get('comments'), list):
|
||||
break
|
||||
except Exception as e:
|
||||
if 'no longer available' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video does not exist: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Comments are turned off' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because comments are disabled: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Private video' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is private: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Video unavailable' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is unavailable: {url=}', exc_info=e)
|
||||
break
|
||||
logger.error(f'Got error when attempting to download video comments: {url=}', exc_info=e)
|
||||
await asyncio.sleep(random.randint(1, 5))
|
||||
try:
|
||||
# Get info json about the video. Retry until we have a list of comments.
|
||||
info = download_video_info_json(url)
|
||||
|
||||
if not info or not isinstance(info.get('comments'), list):
|
||||
logger.error(f'Never got comments for video: {url=}')
|
||||
add_video_to_skip_list(url)
|
||||
if not info or not isinstance(info.get('comments'), list):
|
||||
logger.error(f'Unable to get comments for video: {url=}')
|
||||
add_video_to_skip_list(url)
|
||||
continue
|
||||
except Exception as e:
|
||||
if 'no longer available' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video does not exist: {url=}', exc_info=e)
|
||||
elif 'Comments are turned off' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because comments are disabled: {url=}', exc_info=e)
|
||||
elif 'Private video' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is private: {url=}', exc_info=e)
|
||||
elif 'Video unavailable' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is unavailable: {url=}', exc_info=e)
|
||||
elif ' members ' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is members-only: {url=}', exc_info=e)
|
||||
else:
|
||||
logger.error(f'Got error when attempting to download video comments: {url=}', exc_info=e)
|
||||
continue
|
||||
|
||||
logger.debug(f'Got {len(info["comments"])} comments for Video: {url=}')
|
||||
logger.info(f'Got {len(info["comments"])} comments for Video: {url=}')
|
||||
|
||||
with get_db_session(commit=True) as session:
|
||||
for video in session.query(Video).join(FileGroup).filter_by(url=url).all():
|
||||
video.replace_info_json(info)
|
||||
video.have_comments = True
|
||||
videos = list(session.query(Video).join(FileGroup).filter_by(url=url).all())
|
||||
for video in videos:
|
||||
if video.video_path.is_file():
|
||||
video.replace_info_json(info)
|
||||
video.have_comments = True
|
||||
else:
|
||||
logger.error(f'Attempting to replace comments for non-existent video! {video}')
|
||||
if len(videos) == 1:
|
||||
download_manager.add_to_skip_list(video.url)
|
||||
video.comments_failed = True
|
||||
|
||||
# Sleep a random amount of time, so we don't spam.
|
||||
await asyncio.sleep(random.randint(2, 20))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue