-
-
Save greysondn/ed8167c273b3617099c813cabac2901d to your computer and use it in GitHub Desktop.
Check YoutubeVids (tasvideos)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use python 3 | |
import json | |
# youtube_dl - written against version 2021.4.17 | |
import youtube_dl | |
# output file for json final listing of ones grey thought needed update | |
# set to None to disable (no quotes eg; OUTPUT_FILE_UPDATE = None) | |
OUTPUT_FILE_UPDATE = "out_vidstoupdate.json" | |
# output file for json final listing of all videos, even if grey didn't think | |
# they needed update | |
# set to None to disable (no quotes eg; OUTPUT_FILE_ALL = None) | |
OUTPUT_FILE_ALL = "out_vidsall.json" | |
# if you know the video format string itags, they goe here | |
WANT_FORMATS = [ | |
# 4320p at 60fps | |
# included in case someone is insane enough to get there early | |
# (ie; as far as I understand, not a current target) | |
"402", | |
"571", | |
"272", | |
"138", | |
# 2160p at 60fps | |
"305", | |
"315", | |
"337", | |
"401", | |
#2160p at 30 fps | |
"313", | |
"266" | |
] | |
# feel free to change channel address, default is tasvideos official yt | |
CHANNEL_ADDRESS = "https://www.youtube.com/channel/UCFKeJVmqdApqOS8onQWznfA/videos" | |
# I'm tired and lazy, let's just make it as a class | |
class TVYTChecker(): | |
def do(self): | |
# point for ytdl class | |
ytdl = youtube_dl.YoutubeDL() | |
# quite loud, but I wanted to leave some sort of progress indicator | |
# this can be controllered; ytdl needs given a logger to do so | |
# python3 logging.logger, param "logger" on YoutubeDL() | |
out = ytdl.extract_info(CHANNEL_ADDRESS, download=False) | |
# moving right along | |
final_list_update = [] | |
final_list_all = [] | |
for entry in out["entries"]: | |
# we'll check this | |
needsUpdate = True | |
swp = { | |
"name" : entry["title"], | |
"url" : entry["webpage_url"], | |
"needs_update" : False, | |
"best" : { | |
"width" : -1, | |
"height" : -1, | |
"fps" : -1 | |
} | |
} | |
# checking | |
for format_ in entry["formats"]: | |
# for update reasons, you know | |
if (format_["format_id"] in WANT_FORMATS): | |
needsUpdate = False | |
print(f'{entry["title"]} has format {format_["format_id"]}, considered up to date') | |
if (format_["width"] is not None): | |
if (format_["width"] > swp["best"]["width"]): | |
swp["best"]["width"] = format_["width"] | |
if (format_["height"] is not None): | |
if (format_["height"] > swp["best"]["height"]): | |
swp["best"]["height"] = format_["height"] | |
if (format_["fps"] is not None): | |
if (format_["fps"] > swp["best"]["fps"]): | |
swp["best"]["fps"] = format_["fps"] | |
# check is done | |
final_list_all.append(swp) | |
if (needsUpdate): | |
print(f'Needs update: {entry["title"]}') | |
swp["needs_update"] = True | |
final_list_update.append(swp) | |
# output? | |
if (OUTPUT_FILE_UPDATE is not None): | |
with open(OUTPUT_FILE_UPDATE, "w") as f: | |
json.dump(final_list_update, f, indent=4) | |
if (OUTPUT_FILE_ALL is not None): | |
with open(OUTPUT_FILE_ALL, "w") as f: | |
json.dump(final_list_all, f, indent=4) | |
if (__name__ == "__main__"): | |
t = TVYTChecker() | |
t.do() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment