Ordering video/archive results when no published_datetime exists. Adding Video.location property which returns the App location of the video.

This commit is contained in:
Roland 2024-02-26 13:40:39 -07:00
parent 13421c24aa
commit df849ffb42
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 17 additions and 15 deletions

View file

@ -418,8 +418,8 @@ def get_domains():
ARCHIVE_ORDERS = {
'published_datetime': (date := 'fg.published_datetime ASC, fg.download_datetime ASC'),
'-published_datetime': (_date := 'fg.published_datetime DESC NULLS LAST, fg.download_datetime DESC NULLS LAST'),
'published_datetime': (date := 'COALESCE(fg.published_datetime, fg.download_datetime) ASC'),
'-published_datetime': (_date := 'COALESCE(fg.published_datetime, fg.download_datetime) DESC NULLS LAST'),
'published_modified_datetime': f'fg.published_modified_datetime ASC NULLS LAST, {date}',
'-published_modified_datetime': f'fg.published_modified_datetime DESC, {_date}',
'download_datetime': 'fg.download_datetime ASC',

View file

@ -209,14 +209,9 @@ class VideoDownloader(Downloader, ABC):
url = normalize_video_url(download.url)
# Video may have been downloaded previously, get its location for error reporting.
location = None
with get_db_session() as session:
videos = session.query(Video).join(FileGroup).filter_by(url=url).all()
video = videos[0] if videos else None
if video and video.channel_id:
location = f'/videos/channel/{video.channel_id}/video/{video.id}'
elif video:
location = f'/videos/video/{video.id}'
location = videos[0].location if videos else None
try:
download.info_json = download.info_json or extract_info(url)
@ -391,6 +386,7 @@ class VideoDownloader(Downloader, ABC):
if name not in existing_names:
video.add_tag(name)
need_commit = True
location = video.location
if need_commit:
session.commit()
@ -439,11 +435,6 @@ class VideoDownloader(Downloader, ABC):
error = str(traceback.format_exc())
return DownloadResult(success=False, error=error, location=location)
if channel_id:
location = f'/videos/channel/{channel_id}/video/{video_id}'
else:
location = f'/videos/video/{video_id}'
logger.debug(f'Downloaded video {location=}')
logger.info(f'Successfully downloaded video {url} {video}')

View file

@ -467,6 +467,16 @@ class Video(ModelHelper, Base):
return True
@property
def location(self) -> str:
"""The href of the video in the App."""
if not self.id:
raise RuntimeError('Video id not set. Flush to DB.')
if self.channel_id:
return f'/videos/channel/{self.channel_id}/video/{self.id}'
return f'/videos/video/{self.id}'
class Channel(ModelHelper, Base):
__tablename__ = 'channel'

View file

@ -30,8 +30,9 @@ def get_video_for_app(video_id: int) -> Tuple[dict, Optional[dict], Optional[dic
VIDEO_ORDERS = {
'published_datetime': 'fg.published_datetime ASC, LOWER(fg.primary_path) ASC',
'-published_datetime': 'fg.published_datetime DESC NULLS LAST, LOWER(fg.primary_path) ASC',
'published_datetime': 'COALESCE(fg.published_datetime, fg.download_datetime) ASC, LOWER(fg.primary_path) ASC',
'-published_datetime': 'COALESCE(fg.published_datetime, fg.download_datetime) DESC NULLS LAST,'
' LOWER(fg.primary_path) ASC',
'rank': '2 DESC, LOWER(fg.primary_path) DESC',
'-rank': '2 ASC, LOWER(fg.primary_path) ASC',
'size': 'fg.size ASC, LOWER(fg.primary_path) ASC',