61 lines
1.5 KiB
Python
Raw Normal View History

2017-10-07 18:41:22 +02:00
import requests
class API:
def __init__(self, youtube_api_key, channel_id):
self.api_key = youtube_api_key
self.channel_id = channel_id
2017-10-07 20:42:04 +02:00
def is_not_used(self):
pass
2017-10-07 18:41:22 +02:00
def get_video_items(self):
request = 'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + \
self.channel_id + '&maxResults=10&order=date&type=video&key=' + \
self.api_key
return requests.get(request).json()
def get_newest_video(self, items_json):
2017-10-07 20:42:04 +02:00
self.is_not_used()
2017-10-07 18:41:22 +02:00
return items_json['items'][0]
def get_url(self, video_json):
2017-10-07 20:42:04 +02:00
self.is_not_used()
2017-10-07 18:41:22 +02:00
return video_json['id']['videoId']
def get_title(self, video_json):
2017-10-07 20:42:04 +02:00
self.is_not_used()
2017-10-07 18:41:22 +02:00
return video_json['snippet']['title']
2017-10-07 20:42:04 +02:00
def start_find_video_process(self):
self.is_not_used()
video_items_json = var.get_video_items()
new_video_json = var.get_newest_video(video_items_json)
2017-10-07 18:41:22 +02:00
2017-10-07 20:42:04 +02:00
video_url_snippet = var.get_url(new_video_json)
video_url = 'https://www.youtube.com/watch?v=' + video_url_snippet
video_title = var.get_title(new_video_json)
2017-10-07 18:41:22 +02:00
2017-10-07 20:42:04 +02:00
return video_title, video_url
# Add your Youtube Data API V3 Key here
2017-10-07 20:42:16 +02:00
API_KEY = ''
2017-10-07 18:41:22 +02:00
# Add the Channel IDs here
# When you only know the channel name you can get the ID from here https://commentpicker.com/youtube-channel-id.php
CHANNEL_ID = [
'ID1',
'ID2'
]
2017-10-07 18:41:22 +02:00
2017-10-07 20:42:04 +02:00
videos = []
2017-10-07 18:41:22 +02:00
2017-10-07 20:42:04 +02:00
for item in CHANNEL_ID:
var = API(API_KEY, item)
videos.append(var.start_find_video_process())
2017-10-07 20:42:04 +02:00
print(videos)