Refreshing vidoes removes any that don't exist.

This commit is contained in:
Roland 2019-10-11 15:39:19 -06:00
parent ec0d11b35a
commit 6225add524
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 14 additions and 0 deletions

View file

@ -181,6 +181,15 @@ def refresh_videos(db: DictDB):
logger.info('Refreshing video list')
Channel = db['channel']
# Remove any videos that don't exist
curs = db.get_cursor()
curs.execute('SELECT id, video_path FROM video')
existing_videos = curs.fetchall()
for video in existing_videos:
if not pathlib.Path(video['video_path']).is_file():
curs.execute('DELETE FROM video WHERE id = %s', (video['id'],))
return
for channel in Channel.get_where():
with db.transaction(commit=True):
refresh_channel_videos(db, channel)

View file

@ -48,6 +48,11 @@ class TestAPI(unittest.TestCase):
with get_db_context() as (db_conn, db):
Video, Channel = db['video'], db['channel']
import_settings_config()
# Insert a bogus video, it should be removed
bogus = Video(video_path='bar').flush()
assert bogus['id'], 'Failed to insert a bogus video for removal'
api.settings.refresh.GET(db)
self.assertEqual(Channel.count(), 1)
self.assertEqual(Video.count(), 1)