-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_playlist.py
More file actions
42 lines (30 loc) · 1.08 KB
/
fetch_playlist.py
File metadata and controls
42 lines (30 loc) · 1.08 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
37
38
39
40
41
42
import googleapiclient.discovery
from urllib.parse import parse_qs, urlparse
YT_KEY = "AIzaSyAM4kPNhMkWRY7GMz7WFlk8gpGDseo57ns"
def get_all_links(play_list_url: str):
query = parse_qs(urlparse(play_list_url).query, keep_blank_values=True)
playlist_id = query["list"][0]
print(f'Getting all links from {playlist_id}')
youtube = googleapiclient.discovery.build(
"youtube", "v3", developerKey=YT_KEY)
request = youtube.playlistItems().list(
part="snippet",
playlistId=playlist_id,
maxResults=50
)
response = request.execute()
playlist_items = []
while request:
response = request.execute()
playlist_items += response["items"]
request = youtube.playlistItems().list_next(request, response)
abc = [
f'https://www.youtube.com/watch?v={t["snippet"]["resourceId"]["videoId"]}&list={playlist_id}&t=0s'
for t in playlist_items
]
return abc
url = """
https://youtube.com/playlist?list=PLzMcBGfZo4-lSq2IDrA6vpZEV92AmQfJK
""".strip()
if __name__ == "__main__":
print(get_all_links(url))