mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
Refreshing vidoes removes any that don't exist.
This commit is contained in:
parent
ec0d11b35a
commit
6225add524
2 changed files with 14 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue