Search
from googleapiclient.discovery import build
YOUTUBE_API_KEY="***"
youtube = build("youtube", "v3", developerKey=YOUTUBE_API_KEY)
_ _ _
___ ___ __ _ _ __ ___| |__ __ _(_) __| | ___ ___ ___
/ __|/ _ \/ _` | '__/ __| '_ \ \ \ / / |/ _` |/ _ \/ _ \/ __|
\__ \ __/ (_| | | | (__| | | | \ V /| | (_| | __/ (_) \__ \
|___/\___|\__,_|_| \___|_| |_| \_/ |_|\__,_|\___|\___/|___/
def search_videos(query,limit=1):
return json.dumps(youtube.search().list(part="snippet",q=query,type="video",maxResults=limit,order="relevance").execute()['items'],indent=4)
_ __ ___ ___ _ __ ___ _ __ ___ ___
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \
| | | __/\__ \ |_) | (_) | | | \__ \ __/
|_| \___||___/ .__/ \___/|_| |_|___/\___|
|_|
[
{
"kind": "youtube#searchResult",
"etag": "z8GMojuBuPisfrSuoPoqdt3hBmg",
"id": {
"kind": "youtube#video",
"videoId": "VEl5XhlUKLk"
},
"snippet": {
"publishedAt": "2021-07-27T09:03:54Z",
"channelId": "UCqUGJJcQoXIZI0STu44JT0g",
"title": "Why (Lyrics Video) - Tiggy",
"description": "ONE OF OUR FAVORITE SONGS: (Relaxing, Enjoyable, and Memorable) WHY (Tiggy) Popular Disco Hits. This lyrics video ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Rodolfo Albaytar",
"liveBroadcastContent": "none",
"publishTime": "2021-07-27T09:03:54Z"
}
}
]
_ _ _
___ ___ __ _ _ __ ___| |__ ___| |__ __ _ _ __ _ __ ___| |___
/ __|/ _ \/ _` | '__/ __| '_ \ / __| '_ \ / _` | '_ \| '_ \ / _ \ / __|
\__ \ __/ (_| | | | (__| | | | | (__| | | | (_| | | | | | | | __/ \__ \
|___/\___|\__,_|_| \___|_| |_| \___|_| |_|\__,_|_| |_|_| |_|\___|_|___/
def search_channels(query,limit=1):
return json.dumps(youtube.search().list(q=query,type="channel",part="snippet",maxResults=1).execute()['items'],indent=4)
_ __ ___ ___ _ __ ___ _ __ ___ ___
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \
| | | __/\__ \ |_) | (_) | | | \__ \ __/
|_| \___||___/ .__/ \___/|_| |_|___/\___|
|_|
[
{
"kind": "youtube#searchResult",
"etag": "iIkWMOpwp0492f2n8zUKjt5yMfg",
"id": {
"kind": "youtube#channel",
"channelId": "UCIFk2uvCNcEmZ77g0ESKLcQ"
},
"snippet": {
"publishedAt": "2020-09-16T20:38:56Z",
"channelId": "UCIFk2uvCNcEmZ77g0ESKLcQ",
"title": "The Why Files",
"description": "The Why Files is a channel for people who are fascinated (obsessed) with mysteries, myths, legends and conspiracies. We tell ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/DUUYgkoiYIqiSeCBct3K_RtDbq_veVmcja2Ve0mOF12ozGtEgqF5sP0ITq5UMcbaW-9W4MLcDg=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/DUUYgkoiYIqiSeCBct3K_RtDbq_veVmcja2Ve0mOF12ozGtEgqF5sP0ITq5UMcbaW-9W4MLcDg=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/DUUYgkoiYIqiSeCBct3K_RtDbq_veVmcja2Ve0mOF12ozGtEgqF5sP0ITq5UMcbaW-9W4MLcDg=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "The Why Files",
"liveBroadcastContent": "none",
"publishTime": "2020-09-16T20:38:56Z"
}
}
]
_ _ _
__ _ ___| |_ ___| |__ __ _ _ __ _ __ ___| |
/ _` |/ _ \ __| / __| '_ \ / _` | '_ \| '_ \ / _ \ |
| (_| | __/ |_ | (__| | | | (_| | | | | | | | __/ |
\__, |\___|\__| \___|_| |_|\__,_|_| |_|_| |_|\___|_|
|___/
def channel(id):
return json.dumps(youtube.channels().list(id=id,part="contentDetails,id,snippet,statistics,topicDetails",maxResults=1).execute()['items'],indent=4)
_ __ ___ ___ _ __ ___ _ __ ___ ___
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \
| | | __/\__ \ |_) | (_) | | | \__ \ __/
|_| \___||___/ .__/ \___/|_| |_|___/\___|
|_|
[
{
"kind": "youtube#channel",
"etag": "cAz17O_QDKX-qECaAj0aWMiL2qo",
"id": "UCwdUu2Dlp7vMb4XUoAfF-Zg",
"snippet": {
"title": "The Why Files - Backstage",
"description": "Behind the scenes and inside scoop on The Why Files. If you're here, you're a superfan. And I appreciate you.",
"customUrl": "@thewhyfilesbackstage",
"publishedAt": "2020-10-03T06:15:05.092417Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/UlpU0K6iFT4HPvAtLa4FkpwSiDVLcDZP_8Y5tJX8cCBi5GsO6Dg7zJHuPp5aiCzr93o27fVoxg=s88-c-k-c0x00ffffff-no-rj",
"width": 88,
"height": 88
},
"medium": {
"url": "https://yt3.ggpht.com/UlpU0K6iFT4HPvAtLa4FkpwSiDVLcDZP_8Y5tJX8cCBi5GsO6Dg7zJHuPp5aiCzr93o27fVoxg=s240-c-k-c0x00ffffff-no-rj",
"width": 240,
"height": 240
},
"high": {
"url": "https://yt3.ggpht.com/UlpU0K6iFT4HPvAtLa4FkpwSiDVLcDZP_8Y5tJX8cCBi5GsO6Dg7zJHuPp5aiCzr93o27fVoxg=s800-c-k-c0x00ffffff-no-rj",
"width": 800,
"height": 800
}
},
"localized": {
"title": "The Why Files - Backstage",
"description": "Behind the scenes and inside scoop on The Why Files. If you're here, you're a superfan. And I appreciate you."
},
"country": "US"
},
"contentDetails": {
"relatedPlaylists": {
"likes": "",
"uploads": "UUwdUu2Dlp7vMb4XUoAfF-Zg"
}
},
"statistics": {
"viewCount": "40488636",
"subscriberCount": "235000",
"hiddenSubscriberCount": false,
"videoCount": "116"
},
"topicDetails": {}
}
]
_ _ _
__ _ ___| |_ __ _(_) __| | ___ ___
/ _` |/ _ \ __| \ \ / / |/ _` |/ _ \/ _ \
| (_| | __/ |_ \ V /| | (_| | __/ (_) |
\__, |\___|\__| \_/ |_|\__,_|\___|\___/
|___/
def video(id):
return json.dumps(youtube.videos().list(id=id,part="contentDetails,id,snippet,statistics,topicDetails",maxResults=1).execute()['items'],indent=4)
_ __ ___ ___ _ __ ___ _ __ ___ ___
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \
| | | __/\__ \ |_) | (_) | | | \__ \ __/
|_| \___||___/ .__/ \___/|_| |_|___/\___|
|_|
[
{
"kind": "youtube#video",
"etag": "whvAFTttLNcly-EEgy0tuR4xaSg",
"id": "VEl5XhlUKLk",
"snippet": {
"publishedAt": "2021-07-27T09:03:54Z",
"channelId": "UCqUGJJcQoXIZI0STu44JT0g",
"title": "Why (Lyrics Video) - Tiggy",
"description": "ONE OF OUR FAVORITE SONGS:\n(Relaxing, Enjoyable, and Memorable)\n\nWHY\n(Tiggy)\nPopular Disco Hits.\n\nThis lyrics video contains copyright material like the melody of the original song from the real owners.\n\n#Tiggy",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/VEl5XhlUKLk/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Rodolfo Albaytar",
"tags": [
"Rodolfo Albaytar",
"Song Lyrics",
"Music Lyrics",
"Lyrics Video",
"Why",
"Tiggy Songs",
"Disco Hits"
],
"categoryId": "24",
"liveBroadcastContent": "none",
"defaultLanguage": "en",
"localized": {
"title": "Why (Lyrics Video) - Tiggy",
"description": "ONE OF OUR FAVORITE SONGS:\n(Relaxing, Enjoyable, and Memorable)\n\nWHY\n(Tiggy)\nPopular Disco Hits.\n\nThis lyrics video contains copyright material like the melody of the original song from the real owners.\n\n#Tiggy"
},
"defaultAudioLanguage": "zxx"
},
"contentDetails": {
"duration": "PT3M44S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"contentRating": {},
"projection": "rectangular"
},
"statistics": {
"viewCount": "15713163",
"likeCount": "43387",
"favoriteCount": "0",
"commentCount": "717"
},
"topicDetails": {
"topicCategories": [
"https://en.wikipedia.org/wiki/Electronic_music",
"https://en.wikipedia.org/wiki/Music",
"https://en.wikipedia.org/wiki/Pop_music"
]
}
}
]
_ _ _ _ _
__ _ ___| |_ ___| |__ __ _ _ __ _ __ ___| | __ _(_) __| | ___ ___ ___
/ _` |/ _ \ __| / __| '_ \ / _` | '_ \| '_ \ / _ \ | \ \ / / |/ _` |/ _ \/ _ \/ __|
| (_| | __/ |_ | (__| | | | (_| | | | | | | | __/ | \ V /| | (_| | __/ (_) \__ \
\__, |\___|\__| \___|_| |_|\__,_|_| |_|_| |_|\___|_| \_/ |_|\__,_|\___|\___/|___/
|___/
def get_channel_videos(channel_id, limit=1):
#youtube = build("youtube", "v3", developerKey=YOUTUBE_API_KEY)
response = youtube.channels().list(part="contentDetails",id=channel_id).execute()
if not response.get("items"):
return []
uploads_id = response["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"]
videos = []
page_token = None
while limit is None or len(videos) < limit:
params = {
"part": "snippet",
"playlistId": uploads_id,
"maxResults": min(50, limit - len(videos))
if limit is not None else 50,
"pageToken": page_token
}
response = youtube.playlistItems().list(**params).execute()
for item in response.get("items", []):
video_id = item['snippet']["resourceId"].get("videoId")
videos.append(get_video(video_id))
if not video_id:
continue
page_token = response.get("nextPageToken")
if not page_token:
break
return videos
_ _ _ _ _ _
__ _(_) __| | ___ ___ __| | ___| |_ __ _(_) |___
\ \ / / |/ _` |/ _ \/ _ \ / _` |/ _ \ __/ _` | | / __|
\ V /| | (_| | __/ (_) | | (_| | __/ || (_| | | \__ \
\_/ |_|\__,_|\___|\___/ \__,_|\___|\__\__,_|_|_|___/
def get_video(video_id):
return youtube.videos().list(part="snippet,contentDetails,statistics",id=video_id).execute()['items'][0]
_ __ ___ ___ _ __ ___ _ __ ___ ___
| '__/ _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \
| | | __/\__ \ |_) | (_) | | | \__ \ __/
|_| \___||___/ .__/ \___/|_| |_|___/\___|
|_|
[
{
"kind": "youtube#video",
"etag": "HZT67Vju-sBoex6doVzyPrWY2Bc",
"id": "W89qyvXSWXs",
"snippet": {
"publishedAt": "2026-09-11T15:05:43Z",
"channelId": "UCqUGJJcQoXIZI0STu44JT0g",
"title": "SOFT EMOTION - Cherry Simons ",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/W89qyvXSWXs/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/W89qyvXSWXs/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/W89qyvXSWXs/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/W89qyvXSWXs/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "Rodolfo Albaytar",
"tags": [
"Soft Emotion",
"Cherry Simons",
"RSA2TV",
"Albaytar",
"Lyrics Video"
],
"categoryId": "24",
"liveBroadcastContent": "none",
"defaultLanguage": "en",
"localized": {
"title": "SOFT EMOTION - Cherry Simons ",
"description": ""
},
"defaultAudioLanguage": "zxx"
},
"contentDetails": {
"duration": "PT3M45S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": false,
"contentRating": {},
"projection": "rectangular"
},
"statistics": {
"viewCount": "3027",
"likeCount": "13",
"favoriteCount": "0",
"commentCount": "1"
}
}
]