From 5ef903010c8bbf71fe23df66b57636ba5c306402 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 May 2023 16:55:24 +0200 Subject: [PATCH] fixed thumbnails --- channel_archiver/yt-dlp-channels.txt | 2 ++ channel_archiver/yt-dlp.conf | 5 +++-- import.py | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/channel_archiver/yt-dlp-channels.txt b/channel_archiver/yt-dlp-channels.txt index 8232d6d..7c7584e 100644 --- a/channel_archiver/yt-dlp-channels.txt +++ b/channel_archiver/yt-dlp-channels.txt @@ -1,2 +1,4 @@ # UnusualVideos https://www.youtube.com/channel/UCpnkp_D4FLPCiXOmDhoAeYA +# UUM Archive +https://www.youtube.com/@unusualvideos_archive diff --git a/channel_archiver/yt-dlp.conf b/channel_archiver/yt-dlp.conf index 2a7718b..fa314e0 100644 --- a/channel_archiver/yt-dlp.conf +++ b/channel_archiver/yt-dlp.conf @@ -4,9 +4,10 @@ # Archive Settings --download-archive yt-dlp-archive.txt -a yt-dlp-channels.txt --f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' ---write-description +#-f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' --write-thumbnail +--skip-download +--restrict-filenames # Debug -v diff --git a/import.py b/import.py index 0e66e23..93cc0ee 100644 --- a/import.py +++ b/import.py @@ -4,6 +4,7 @@ import sys import fnmatch from datetime import datetime + sys.path.append('./') os.environ['DJANGO_SETTINGS_MODULE'] = 'ragnarok.settings' import django @@ -35,9 +36,9 @@ def find_image_file(name_pattern, folder): return os.path.join(root, filename) return None - -for filename in os.listdir(folder_path): - if filename.endswith('.mp4'): +files = os.listdir(folder_path) +for filename in files: + if filename.endswith('.mp4'): # Create a new Video object video = Video() id = extract_version(filename) @@ -53,11 +54,12 @@ for filename in os.listdir(folder_path): # Open the file and save it to the Video object with open(os.path.join(folder_path, filename), 'rb') as f: video.file.save(filename, f) - - #filepath = find_image_file("V"+str(id), folder_path) - with open(filepath, 'rb') as f: - video.thumbnail.save(filename, f) - + index = [idx for idx, s in enumerate(files) if bool(re.search('V'+str(video.id)+'( |_)', s)) and '.webp' in s] + if not index: + continue + index = index[0] + with open(os.path.join(folder_path, files[index]), 'rb') as f: + video.thumbnail.save(files[index], f) # Save the Video object to the database video.save()