From 9baa8d9a2ebeeddcb6f546df92261a00213db8c1 Mon Sep 17 00:00:00 2001 From: sevi-kun Date: Thu, 3 Aug 2023 22:45:20 +0200 Subject: [PATCH] Script + requirements --- main.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 7 ++++++ 2 files changed, 62 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..f129165 --- /dev/null +++ b/main.py @@ -0,0 +1,55 @@ +import sys +import os +import subprocess +import re +import scrapetube + + +# cleanup + +for file in os.listdir('./out/'): + print('Cleanup ./out/' + file) + os.remove('./out/' + file) + + +#scraping + +channel1_videos = scrapetube.get_channel("UCuefh-IW_h0HemxTUOA2PEA") +channel2_videos = scrapetube.get_channel("UC-pBFf-6YwMt3P5Lx6FbJbQ") + +video_ids = [video.get('videoId') for video in channel1_videos] # online +video_ids += [video.get('videoId') for video in channel2_videos] # online + +file_ids = [f.replace('_extra.png','') for f in os.listdir('/mnt/omv3/picture/YouTube Pics') if 'extra' in f] # already downloaded + +new_vids = ['https://youtu.be/' + str(id) for id in video_ids if id not in file_ids] + + +# dl and processing + +os.chdir('./out/') + +for url in new_vids: + print('Downloading ' + url) + subprocess.call(["yt-dlp", "--write-thumbnail", "-f", "best", "--external-downloader", "ffmpeg", "--external-downloader-args", "ffmpeg_i:-ss 1 -t 11", url], + stdout=subprocess.DEVNULL, + stderr=subprocess.STDOUT) + +for dl in os.listdir('.'): + print('Processing ' + dl) + match = re.search(r"\[([A-Za-z0-9_-]+)\]", dl) + #match = re.search(r"\[.*\]", dl) + if '.webp' in dl: + os.rename(dl, match.group(1) + '_extra.webp') + if '.mp4' in dl: + subprocess.call(["ffmpeg", "-sseof", "-3", "-i", dl, "-update", "1", "-q:v", "1", dl.replace('.mp4','') + ".jpg"], + stdout=subprocess.DEVNULL, + stderr=subprocess.STDOUT) + os.rename(dl.replace('.mp4','') + ".jpg", match.group(1) + '.jpg') + + +# cleanup +for file in os.listdir('.'): + if '[' in file: + print('Cleaning up ' + file) + os.remove(file) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..df75fc6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +certifi==2023.5.7 +charset-normalizer==3.1.0 +idna==3.4 +requests==2.31.0 +scrapetube==2.4.0 +typing_extensions==4.7.0 +urllib3==2.0.3