mirror of
https://github.com/Death916/deathsite.git
synced 2026-04-10 03:04:41 -07:00
get last 5 yt videos to add to video page
This commit is contained in:
parent
da3288b015
commit
8bcee63280
1 changed files with 25 additions and 3 deletions
|
|
@ -20,7 +20,8 @@ class Youtube:
|
|||
def get_newest_video(self):
|
||||
# get the newest video from the youtube channel
|
||||
keys = self.get_api_key()
|
||||
#use basic auth to get newest video
|
||||
|
||||
#use basic auth to get newest video
|
||||
youtube = build("youtube", "v3", developerKey=keys["youtube_api_key"])
|
||||
# get the channel id
|
||||
id = keys["channel_id"]
|
||||
|
|
@ -43,8 +44,29 @@ class Youtube:
|
|||
# get the current youtube video
|
||||
self.get_newest_video()
|
||||
return self.current_yt_video
|
||||
|
||||
|
||||
def get_last_5_yt_videos(self):
|
||||
# get the last 5 videos from the youtube channel
|
||||
keys = self.get_api_key()
|
||||
youtube = build("youtube", "v3", developerKey=keys["youtube_api_key"])
|
||||
id = keys["channel_id"]
|
||||
request = youtube.search().list(
|
||||
part="snippet",
|
||||
channelId=id,
|
||||
order="date",
|
||||
maxResults=5,
|
||||
type="video"
|
||||
)
|
||||
response = request.execute()
|
||||
items = response.get("items", [])
|
||||
videos = []
|
||||
for item in items:
|
||||
video_id = item["id"]["videoId"]
|
||||
video_url = f"https://www.youtube.com/watch?v={video_id}"
|
||||
videos.append(video_url)
|
||||
return videos
|
||||
|
||||
if __name__ == "__main__":
|
||||
yt = Youtube()
|
||||
yt.get_current_yt_video()
|
||||
print(yt.current_yt_video)
|
||||
print(yt.current_yt_video)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue