Add column last_refresh to channels.

This commit is contained in:
voussoir 2022-11-11 15:24:47 -08:00
parent cc7c88abc9
commit 4d7b396e0c
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
4 changed files with 49 additions and 2 deletions

View file

@ -314,6 +314,39 @@ def upgrade_9_to_10(ycdldb):
m.go()
def upgrade_10_to_11(ycdldb):
'''
In this version, the `last_refresh` column was added to the channels table.
'''
m = Migrator(ycdldb)
m.tables['channels']['create'] = '''
CREATE TABLE IF NOT EXISTS channels(
id TEXT,
name TEXT,
uploads_playlist TEXT,
download_directory TEXT COLLATE NOCASE,
queuefile_extension TEXT COLLATE NOCASE,
automark TEXT,
autorefresh INT,
last_refresh INT
);
'''
m.tables['channels']['transfer'] = '''
INSERT INTO channels SELECT
id,
name,
uploads_playlist,
download_directory,
queuefile_extension,
automark,
autorefresh,
NULL
FROM channels_old;
'''
m.go()
def upgrade_all(data_directory):
'''
Given the directory containing a ycdl database, apply all of the

View file

@ -1,6 +1,6 @@
from voussoirkit import sqlhelpers
DATABASE_VERSION = 10
DATABASE_VERSION = 11
DB_INIT = f'''
CREATE TABLE IF NOT EXISTS channels(
@ -10,7 +10,8 @@ CREATE TABLE IF NOT EXISTS channels(
download_directory TEXT COLLATE NOCASE,
queuefile_extension TEXT COLLATE NOCASE,
automark TEXT,
autorefresh INT
autorefresh INT,
last_refresh INT
);
CREATE INDEX IF NOT EXISTS index_channel_id on channels(id);
----------------------------------------------------------------------------------------------------

View file

@ -4,6 +4,7 @@ import typing
from voussoirkit import pathclass
from voussoirkit import stringtools
from voussoirkit import timetools
from voussoirkit import vlogging
from voussoirkit import worms
@ -244,6 +245,12 @@ class Channel(ObjectBase):
for video in self.ycdldb.youtube.get_videos(refresh_ids):
self.ycdldb.ingest_video(video)
pairs = {
'id': self.id,
'last_refresh': timetools.now().timestamp(),
}
self.ycdldb.update(table='channels', pairs=pairs, where_key='id')
def reset_uploads_playlist_id(self):
'''
Reset the stored uploads_playlist id with current data from the API.

View file

@ -5,6 +5,7 @@ from voussoirkit import cacheclass
from voussoirkit import configlayers
from voussoirkit import lazychain
from voussoirkit import pathclass
from voussoirkit import timetools
from voussoirkit import vlogging
from voussoirkit import worms
@ -130,6 +131,11 @@ class YCDLDBChannelMixin:
try:
most_recent_video = channel.get_most_recent_video_id()
new_ids = ytrss.get_user_videos_since(channel.id, most_recent_video)
pairs = {
'id': channel.id,
'last_refresh': timetools.now().timestamp(),
}
self.update(table='channels', pairs=pairs, where_key='id')
yield from new_ids
except (exceptions.NoVideos, exceptions.RSSAssistFailed) as exc:
log.debug(