I'm trying to check if a list of 4 YouTube videos still online. I know one of them is offline, and from time to time I want to see if any action was made upon the others. Searching through the web and with a little coding (I'm a beginner) I made this:
import requests
from pprint import pprint
videos = ["id1","id2","id3","id4"]
for i in videos:
id_of_video = i
your_api_key = 'myapi'
url = 'https://www.googleapis.com/youtube/v3/videos?id={}&key={}&part=status'.format(id_of_video, your_api_key)
url_get = requests.get(url)
pprint(url_get.json())
The code runs well and I receive something like this (I copied just two results):
{'etag': 'somenumbersandcharactershere',
'items': [{'etag': 'somenumbersandcharactershere',
'id': 'videoid',
'kind': 'youtube#video',
'status': {'embeddable': True,
'license': 'youtube',
'madeForKids': False,
'privacyStatus': 'public',
'publicStatsViewable': True,
'uploadStatus': 'processed'}}],
'kind': 'youtube#videoListResponse',
'pageInfo': {'resultsPerPage': 1, 'totalResults': 1}}
{'etag': 'somenumbersandcharactershere',
'items': [],
'kind': 'youtube#videoListResponse',
'pageInfo': {'resultsPerPage': 0, 'totalResults': 0}}
One of them is online and the other one is not. Great.
But I want to create a code that check it for me from time to time and says: "This video ID is not available anymore". But I don't know how.
My main task right now is to print a message for each video ID! So, let's say: "ID1 is on-line" and "ID2 is offline".
I thought about creating an if statement to check the results of the "url_get.json()" tag but it only holds the last video ID...
If I run
url_get.json()
I get only the last ID from the list.