Skip to content

Commit 2c826ef

Browse files
Add files via upload
1 parent 5c30eae commit 2c826ef

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

get_url.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# importing pafy
2+
import pafy
3+
import os
4+
import csv
5+
6+
# url of playlist
7+
url = "https://www.youtube.com/watch?v=eDUSn1M3dLM&list=PLQvvxnU2-Itfz2v8jeVJYybgyifBvJjZy"
8+
9+
10+
class Playlist_Scraper():
11+
def __init__(self):
12+
self.url_list = {
13+
"01": "https://www.youtube.com/playlist?list=PL152bjytsMC4Goscddi5bS9xjHB_2mDUx",
14+
}
15+
16+
# self.save_directory = os.path.join(os.getcwd(), 'Video')
17+
# if not os.path.exists(self.save_directory):
18+
# os.makedirs(self.save_directory)
19+
20+
self.csv_writer = csv.writer(open("playlist.csv", "w", encoding='utf-8', newline=''))
21+
22+
def start_scraping(self):
23+
for season, url in self.url_list.items():
24+
self.get_playlist_urls(season, url)
25+
26+
def get_playlist_urls(self, season, url):
27+
# getting playlist
28+
playlist = pafy.get_playlist(url)
29+
30+
# getting playlist items
31+
items = playlist["items"]
32+
33+
for item in items:
34+
# getting pafy object
35+
i_pafy = item['pafy']
36+
37+
# getting watch url
38+
title = i_pafy.title
39+
videoid = i_pafy.videoid
40+
41+
row = [season, url, title, videoid]
42+
43+
self.csv_writer.writerow(row)
44+
print(row)
45+
46+
47+
if __name__ == '__main__':
48+
app = Playlist_Scraper()
49+
app.start_scraping()

0 commit comments

Comments
 (0)