-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeta.py
More file actions
36 lines (30 loc) · 1.29 KB
/
meta.py
File metadata and controls
36 lines (30 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import discord
from dotenv import load_dotenv
from googleapiclient.discovery import build
import os
# .env 파일에서 환경변수를 로드할 경우 주석 제거
load_dotenv()
youtube_api_key = os.getenv('YOUTUBE_API_KEY')
async def get_latest_meta():
youtube = build('youtube', 'v3', developerKey=youtube_api_key)
request = youtube.search().list(
part="snippet",
q="PS표 티어리스트",
maxResults=10,
order="date",
type="video"
)
response = request.execute()
for item in response['items']:
video_info = item['snippet']
title = video_info['title']
if "PS표 티어리스트" in title: # "PS표 티어리스트" 라는 문구가 들어간 영상들 중 가장 최신 영상 탐색
thumbnail_url = video_info['thumbnails']['high']['url']
video_id = item['id']['videoId']
video_url = f"https://www.youtube.com/watch?v={video_id}"
embed = discord.Embed(title=title, url=video_url)
embed.set_thumbnail(url="https://i.ibb.co/4f1nw7T/P-S.webp?type=w800")
embed.add_field(name="영상 링크", value=video_url, inline=False)
embed.set_image(url=thumbnail_url) # 썸네일을 제목 아래에 세팅
return embed
return None