mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 22:16:37 +00:00
Create a set of keys for cleanup_removed_media
This commit is contained in:
parent
8109d6a836
commit
ed55710f26
@ -255,7 +255,7 @@ def cleanup_old_media():
|
|||||||
schedule_media_servers_update()
|
schedule_media_servers_update()
|
||||||
|
|
||||||
|
|
||||||
def cleanup_removed_media(source, videos):
|
def cleanup_removed_media(source, video_keys):
|
||||||
if not source.delete_removed_media:
|
if not source.delete_removed_media:
|
||||||
return
|
return
|
||||||
log.info(f'Cleaning up media no longer in source: {source}')
|
log.info(f'Cleaning up media no longer in source: {source}')
|
||||||
@ -265,8 +265,7 @@ def cleanup_removed_media(source, videos):
|
|||||||
source=source,
|
source=source,
|
||||||
)
|
)
|
||||||
for media in qs_gen(mqs):
|
for media in qs_gen(mqs):
|
||||||
matching_source_item = [video['id'] for video in videos if video['id'] == media.key]
|
if media.key not in video_keys:
|
||||||
if not matching_source_item:
|
|
||||||
log.info(f'{media.name} is no longer in source, removing')
|
log.info(f'{media.name} is no longer in source, removing')
|
||||||
with atomic():
|
with atomic():
|
||||||
media.delete()
|
media.delete()
|
||||||
@ -317,6 +316,7 @@ def index_source_task(source_id):
|
|||||||
)
|
)
|
||||||
tvn_format = '{:,}' + f'/{num_videos:,}'
|
tvn_format = '{:,}' + f'/{num_videos:,}'
|
||||||
vn = 0
|
vn = 0
|
||||||
|
video_keys = set()
|
||||||
while len(videos) > 0:
|
while len(videos) > 0:
|
||||||
vn += 1
|
vn += 1
|
||||||
video = videos.popleft()
|
video = videos.popleft()
|
||||||
@ -325,6 +325,7 @@ def index_source_task(source_id):
|
|||||||
if not key:
|
if not key:
|
||||||
# Video has no unique key (ID), it can't be indexed
|
# Video has no unique key (ID), it can't be indexed
|
||||||
continue
|
continue
|
||||||
|
video_keys.add(key)
|
||||||
update_task_status(task, tvn_format.format(vn))
|
update_task_status(task, tvn_format.format(vn))
|
||||||
# media, new_media = Media.objects.get_or_create(key=key, source=source)
|
# media, new_media = Media.objects.get_or_create(key=key, source=source)
|
||||||
try:
|
try:
|
||||||
@ -379,7 +380,7 @@ def index_source_task(source_id):
|
|||||||
# Reset task.verbose_name to the saved value
|
# Reset task.verbose_name to the saved value
|
||||||
update_task_status(task, None)
|
update_task_status(task, None)
|
||||||
# Cleanup of media no longer available from the source
|
# Cleanup of media no longer available from the source
|
||||||
cleanup_removed_media(source, videos)
|
cleanup_removed_media(source, video_keys)
|
||||||
videos = video = None
|
videos = video = None
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user