Storing video download_datetime.

This commit is contained in:
Roland 2024-03-12 11:06:30 -06:00
parent 2ec267a65b
commit ce0ae66a9e
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
6 changed files with 14 additions and 7 deletions

View file

@ -98,6 +98,7 @@ function VideosPage() {
{value: 'size', text: 'Size'},
{value: 'view_count', text: 'Views'},
{value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'},
{value: 'download_datetime', text: 'Download Date', short: 'D.Date'},
]
if (searchStr) {

View file

@ -113,7 +113,7 @@ def video_factory(test_session, test_directory):
info_json_path = None
if with_info_json:
# Use the provided object as the json.
with_info_json = {'duration': 5} if with_info_json is True else with_info_json
with_info_json = {'duration': 5, 'epoch': 12345678} if with_info_json is True else with_info_json
info_json_path = path.with_suffix('.info.json')
info_json_path.write_text(json.dumps(with_info_json))

View file

@ -14,7 +14,7 @@ from yt_dlp import YoutubeDL
from wrolpi import before_startup, dates
from wrolpi.captions import extract_captions
from wrolpi.common import ConfigFile, get_media_directory, register_refresh_cleanup, limit_concurrent
from wrolpi.dates import Seconds
from wrolpi.dates import Seconds, from_timestamp
from wrolpi.db import get_db_curs, get_db_session, optional_session
from wrolpi.errors import UnknownDirectory
from wrolpi.vars import PYTEST
@ -34,6 +34,7 @@ class VideoInfoJSON(object):
title = None
url = None
view_count = None
epoch = None
def process_video_info_json(video: Video) -> VideoInfoJSON:
@ -49,6 +50,8 @@ def process_video_info_json(video: Video) -> VideoInfoJSON:
video_info_json.view_count = info_json.get('view_count') or None
video_info_json.url = info_json.get('webpage_url') or info_json.get('url') or None
video_info_json.channel_source_id = info_json.get('channel_id') or None
video_info_json.epoch = info_json.get('epoch')
video_info_json.epoch = int(video_info_json.epoch) if video_info_json.epoch else None
return video_info_json
@ -78,13 +81,14 @@ def validate_video(video: Video, channel_generate_poster: bool):
"""
info_json_path = video.info_json_path
json_data_missing = bool(video.file_group.title) and bool(video.file_group.length) and bool(video.view_count) \
and bool(video.file_group.url)
and bool(video.file_group.url) and bool(video.file_group.download_datetime)
if info_json_path and json_data_missing is False:
# These properties can be found in the info json.
video_info_json = process_video_info_json(video)
video.file_group.title = video_info_json.title
video.file_group.length = video_info_json.duration
video.file_group.url = video_info_json.url
video.file_group.download_datetime = from_timestamp(video_info_json.epoch) if video_info_json.epoch else None
# View count will probably be overwritten by more recent data when this Video's Channel is
# updated.
video.view_count = video.view_count or video_info_json.view_count

View file

@ -67,7 +67,7 @@ async def test_video_factory(test_session, video_factory, channel_factory):
def test_validate_video(test_directory, video_factory, image_bytes_factory, video_file):
"""A video poster will be generated only if the channel permits."""
video_file = video_file.rename(test_directory / 'Channel Name_20050607_1234567890_The Title.mp4')
vid1 = video_factory(with_video_file=video_file)
vid1 = video_factory(with_video_file=video_file, with_info_json=True)
# Clear source_id so source_id in the file will be extracted.
vid1.source_id = None
assert not vid1.poster_path
@ -80,6 +80,7 @@ def test_validate_video(test_directory, video_factory, image_bytes_factory, vide
assert vid1.poster_path.suffix == '.jpg'
# File name date is assumed to be local timezone.
assert vid1.file_group.published_datetime and vid1.file_group.published_datetime.year == 2005
assert vid1.file_group.download_datetime
assert vid1.source_id == '1234567890'
assert vid1.file_group.title == 'The Title'

View file

@ -52,6 +52,8 @@ VIDEO_ORDERS = {
'-viewed': 'fg.viewed DESC',
'view_count': 'v.view_count ASC',
'-view_count': 'v.view_count DESC',
'download_datetime': 'fg.download_datetime ASC, LOWER(fg.primary_path) ASC',
'-download_datetime': 'fg.download_datetime DESC NULLS LAST, LOWER(fg.primary_path) ASC',
}
NO_NULL_ORDERS = {
'viewed': 'fg.viewed IS NOT NULL',
@ -63,8 +65,7 @@ NO_NULL_ORDERS = {
'view_count': 'v.view_count IS NOT NULL',
'-view_count': 'v.view_count IS NOT NULL',
}
JOIN_ORDERS = ('published_datetime', '-published_datetime', 'viewed', '-viewed', 'view_count', '-view_count',
'length', '-length')
JOIN_ORDERS = ('view_count', '-view_count')
DEFAULT_VIDEO_ORDER = 'rank'
VIDEO_QUERY_LIMIT = 24

View file

@ -1699,6 +1699,6 @@ def get_title_from_html(html: str, url: str = None) -> str:
"""
soup = get_html_soup(html)
try:
return soup.title.string
return soup.title.string.strip()
except Exception: # noqa
logger.debug(f'Unable to extract title {url}')