mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
Attaching Channel's info_json even if the download is a playlist.
This commit is contained in:
parent
568f58615a
commit
0152b8648e
5 changed files with 38 additions and 8 deletions
|
|
@ -266,8 +266,12 @@ async def test_download_channel_no_refresh(test_session, download_channel, video
|
|||
assert not d.next_download
|
||||
|
||||
def assert_refreshed(expected: bool):
|
||||
channel = test_session.query(Channel).one()
|
||||
channel: Channel = test_session.query(Channel).one()
|
||||
assert channel.refreshed == expected
|
||||
if expected:
|
||||
assert channel.info_json
|
||||
else:
|
||||
assert not channel.info_json
|
||||
|
||||
assert_refreshed(False)
|
||||
test_session.commit()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from modules.videos import Channel
|
||||
|
||||
|
||||
def test_delete_channel_no_url(test_session, test_client, channel_factory):
|
||||
"""
|
||||
|
|
@ -29,12 +31,16 @@ async def test_channel_refresh_censored(test_session, channel_factory, video_fac
|
|||
vid3 = video_factory(channel_id=channel.id, source_id='three')
|
||||
test_session.commit()
|
||||
|
||||
assert channel.refreshed is False
|
||||
assert vid1.censored is False and vid1.view_count is None
|
||||
assert vid2.censored is False and vid1.view_count is None
|
||||
assert vid3.censored is False and vid1.view_count is None
|
||||
|
||||
await channel.refresh_files()
|
||||
|
||||
channel = test_session.query(Channel).one()
|
||||
|
||||
assert channel.refreshed is True
|
||||
assert vid1.censored is False and vid1.view_count == 100
|
||||
assert vid2.censored is False and vid2.view_count == 200
|
||||
assert vid3.censored is True and vid3.view_count is None
|
||||
|
|
|
|||
|
|
@ -79,8 +79,6 @@ class ChannelDownloader(Downloader, ABC):
|
|||
|
||||
@staticmethod
|
||||
def is_a_playlist(info: dict):
|
||||
if '_type' in info:
|
||||
return info['_type'] == 'playlist'
|
||||
# A playlist may have an id different from its channel.
|
||||
return info['id'] != info['channel_id']
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ from sqlalchemy import Column, Integer, String, Boolean, JSON, Date, ARRAY, Fore
|
|||
from sqlalchemy.orm import relationship, Session
|
||||
from sqlalchemy.orm.collections import InstrumentedList
|
||||
|
||||
from wrolpi.common import Base, ModelHelper, logger, get_media_directory
|
||||
from wrolpi.common import Base, ModelHelper, logger, get_media_directory, background_task
|
||||
from wrolpi.dates import now, TZDateTime
|
||||
from wrolpi.db import get_db_curs
|
||||
from wrolpi.db import get_db_curs, get_db_session
|
||||
from wrolpi.downloader import Download, download_manager
|
||||
from wrolpi.errors import UnknownVideo
|
||||
from wrolpi.files.lib import refresh_directory_files_recursively, glob_shared_stem, split_path_stem_and_suffix
|
||||
from wrolpi.files.models import File
|
||||
from wrolpi.media_path import MediaPathType
|
||||
from wrolpi.vars import PYTEST
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
||||
|
|
@ -480,7 +481,25 @@ class Channel(ModelHelper, Base):
|
|||
|
||||
async def refresh_files(self):
|
||||
"""Refresh all files within this Channel's directory. Mark this channel as refreshed."""
|
||||
from modules.videos.common import apply_info_json
|
||||
logger.debug('Channel.refresh_files refresh_files')
|
||||
# Get this Channel's ID for later. Refresh may take a long time.
|
||||
self_id = self.id
|
||||
|
||||
# Refresh all files within this channel's directory first.
|
||||
await refresh_directory_files_recursively(self.directory)
|
||||
apply_info_json(self.id)
|
||||
self.refreshed = True
|
||||
|
||||
# Apply any info_json (discover censored videos, etc.) second.
|
||||
from modules.videos.common import apply_info_json
|
||||
if PYTEST:
|
||||
apply_info_json(self_id)
|
||||
self.refreshed = True
|
||||
else:
|
||||
|
||||
# Perform info_json in background task. Channel will be marked as refreshed after this completes.
|
||||
async def _():
|
||||
apply_info_json(self_id)
|
||||
with get_db_session(commit=True) as session:
|
||||
channel: Channel = session.query(Channel).filter(Channel.id == self_id).one()
|
||||
channel.refreshed = True
|
||||
|
||||
background_task(_())
|
||||
|
|
|
|||
|
|
@ -194,6 +194,9 @@ async def test_download_channel(test_session, simple_channel, video_download_man
|
|||
with mock.patch('modules.videos.downloader.get_channel') as mock_get_channel:
|
||||
mock_get_channel.return_value = simple_channel
|
||||
video_download_manager.create_download(url)
|
||||
# Download channel.
|
||||
await video_download_manager.wait_for_all_downloads()
|
||||
# Download videos.
|
||||
await video_download_manager.wait_for_all_downloads()
|
||||
|
||||
# Let background tasks run.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue