Spaces:
Sleeping
Sleeping
adewopova
commited on
Create Youtube.ipynb
Browse files- Youtube.ipynb +34 -0
Youtube.ipynb
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install googleapiclient
|
2 |
+
import googleapiclient.discovery
|
3 |
+
from urllib.parse import parse_qs, urlparse
|
4 |
+
|
5 |
+
#extract playlist id from url
|
6 |
+
url = input("Enter your Youtube Playlist URL : ")
|
7 |
+
query = parse_qs(urlparse(url).query, keep_blank_values=True)
|
8 |
+
playlist_id = query["list"][0]
|
9 |
+
|
10 |
+
print(f'get all playlist items links from {playlist_id}')
|
11 |
+
youtube = googleapiclient.discovery.build("youtube", "v3", developerKey = "AIzaSyBCpVB3QmXOiW4ivM8TyGl98mZ7mt7ddbM")
|
12 |
+
|
13 |
+
request = youtube.playlistItems().list(
|
14 |
+
part = "snippet",
|
15 |
+
playlistId = playlist_id,
|
16 |
+
maxResults = 50
|
17 |
+
)
|
18 |
+
response = request.execute()
|
19 |
+
|
20 |
+
playlist_items = []
|
21 |
+
while request is not None:
|
22 |
+
response = request.execute()
|
23 |
+
playlist_items += response["items"]
|
24 |
+
request = youtube.playlistItems().list_next(request, response)
|
25 |
+
|
26 |
+
print(f"total: {len(playlist_items)}")
|
27 |
+
urllists=('\n'.join([
|
28 |
+
f'https://www.youtube.com/watch?v={t["snippet"]["resourceId"]["videoId"]}&list={playlist_id}&t=0s'
|
29 |
+
for t in playlist_items
|
30 |
+
]))
|
31 |
+
|
32 |
+
MyFile=open("C:/Users/Adewo/OneDrive - University of Cincinnati/Independent_Study/Dr.Nelly/Accident Video/playlist.txt",'w')
|
33 |
+
MyFile.writelines(urllists)
|
34 |
+
MyFile.close()
|