Using new methods in download_channel.

This commit is contained in:
Roland 2022-01-27 20:47:52 -07:00
parent 8e47d2a9a0
commit 8b0196ede3
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 13 additions and 11 deletions

View file

@ -2,6 +2,7 @@ from collections import defaultdict
from datetime import timedelta
from typing import List, Dict, Union, Generator
from sqlalchemy.orm import Session
from sqlalchemy.orm.exc import NoResultFound
from wrolpi.common import sanitize_link, run_after, get_relative_to_media_directory, make_media_directory, logger
@ -116,7 +117,8 @@ def _spread_by_frequency(channels: List[Channel]) -> Generator[Dict, None, None]
@run_after(save_channels_config)
def update_channel(data, link):
def update_channel(data: dict, link: str) -> Channel:
"""Update a Channel's DB record"""
with get_db_session(commit=True) as session:
try:
channel: Channel = session.query(Channel).filter_by(link=link).one()
@ -217,12 +219,12 @@ def delete_channel(link):
def download_channel(link: str):
"""
Create a Download record for a Channel's entire catalog.
"""
"""Create a Download record for a Channel's entire catalog. Start downloading."""
channel = get_channel(link=link, return_dict=False)
with get_db_session(commit=True) as session:
if not download_manager.get_download(session, channel.url):
raise InvalidDownload(f'Channel {channel.name} does not have a download!')
download_manager.create_download(channel.url, session, downloader='video_channel')
session = Session.object_session(channel)
download = channel.get_download()
if not download:
raise InvalidDownload(f'Channel {channel.name} does not have a download!')
download.renew(reset_attempts=True)
session.commit()
download_manager.start_downloads()

View file

@ -12,7 +12,7 @@ from wrolpi.common import Base, tsvector, ModelHelper, logger, get_media_directo
from wrolpi.dates import now, TZDateTime
from wrolpi.db import get_db_curs
from wrolpi.downloader import Download, download_manager
from wrolpi.errors import UnknownVideo, UnknownFile, UnknownDirectory
from wrolpi.errors import UnknownVideo, UnknownFile, UnknownDirectory, InvalidDownload
from wrolpi.media_path import MediaPathType, MediaPath
logger = logger.getChild(__name__)
@ -345,7 +345,7 @@ class Channel(ModelHelper, Base):
Get the Download row for this Channel. If there isn't a Download, return None.
"""
if not self.url:
raise ValueError(f'Channel {self.name} does not have a URL to download!')
raise InvalidDownload(f'Channel {self.name} does not have a URL to download!')
session = Session.object_session(self)
download = session.query(Download).filter_by(url=self.url).one_or_none()