I no longer have YouTube Premium, so I would like to write a Python script to simply look at the number of videos YouTubers I follow have uploaded, and when that number changes (a new video is posted), I would like the program to return the URL of the new video as a string. Then, with that string, I'd like to download the video, but I've already figured out that part.
Here's what I've got (in multiple files, but I'll write them in one file to make it more readable):
from os import system
from googleapiclient.discovery import build
from secret_stuff import api_key
def bash_command(user_input):
_ = system(user_input)
def check_for_updates():
youtube = build('youtube', 'v3', developerKey=api_key)
request = youtube.channels().list(
part='statistics',
forUsername='RandomYouTuberNumberOneOrSomething'
)
response = request.execute()
bash_command('rm test_file.py')
bash_command(f"""echo 'yt_data = "{response}"' >> test_file.py""")
from test_file import yt_data
string_data = str(yt_data)
video_count = int(string_data[-8:-4])
print(video_count)
starting_video_count = check_for_updates()
while True:
new_video_count = check_for_updates()
if new_video_count == starting_video_count:
print(f'Still {starting_video_count} videos.')
else:
print(f'There are now {new_video_count} videos!')
So from here, I am able to check for updates, and it seems to work pretty well. I've been going through the documentation (granted, this is my very first project where I've used an API), but I can't seem to find a way to extract the URL for the most recent (public) video posted by any given YouTuber. Any suggestions? Any help is greatly appreciated.