Script + requirements
This commit is contained in:
commit
9baa8d9a2e
55
main.py
Normal file
55
main.py
Normal file
@ -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)
|
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user