-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotiscratch.py
114 lines (99 loc) · 4.13 KB
/
spotiscratch.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import requests
from bs4 import BeautifulSoup
playlists = ["https://open.spotify.com/playlist/2a4YUDpE5KQRDbPT0E9tJ2",
"https://open.spotify.com/playlist/0eLED3QLJRWDSb6pTW0zy4",
"https://open.spotify.com/playlist/1XbaN56zIWH5HlBhbcFPGe",
"https://open.spotify.com/playlist/6Mcta0SrXUh6RQJxZKBD8Y", # 3
"https://open.spotify.com/playlist/3Yoekg61qdZYYe6svontIR",
"https://open.spotify.com/playlist/5NBtRIkykvSvSV1y1S1XXH",
"https://open.spotify.com/playlist/5qnC6nYRLUoPMSqHH93C5L",
"https://open.spotify.com/playlist/5DwCADSp8YDO4IOazBMIvx",
"https://open.spotify.com/playlist/4OohxMENTJpMJYUy60LV8Q",
"https://open.spotify.com/playlist/4kgY11b72mpkbNmyrvBRrK",
"https://open.spotify.com/playlist/0FnWquh2lijOZcHqK3UhhC", # 10
"https://open.spotify.com/playlist/0t1SdiLXjJEBQsy0GQQuE7",
"https://open.spotify.com/playlist/42VoiulLsyXGHHL4Xi5shf",
"https://open.spotify.com/playlist/48DCmv7Jr9h8zHUG3cQ6ot",
"https://open.spotify.com/playlist/0ylsLGS4PdmkvBWgOFGb4W",
"https://open.spotify.com/playlist/3GEWx7EwDDiOMZ9wf8eEFB",
"https://open.spotify.com/playlist/0Nw0bzsuihDd1tvAswqOQo",
"https://open.spotify.com/playlist/0D2jhjjLba0AFmxrLrn7lw",
"https://open.spotify.com/playlist/1yVBgQsd3D7HphwvqNST5r",
"https://open.spotify.com/playlist/5UJgK6GlMH9lc3qKssGEnC",
"https://open.spotify.com/playlist/0dvjiEDQneQrUiTGjpHb7W", # 20 bad playlist
"https://open.spotify.com/playlist/0rgBrrXSUNVfwheUD9IPUd",
"https://open.spotify.com/playlist/04t1plohJT1caZZ2z5LBuP",
"https://open.spotify.com/playlist/2R7slbNNZWKsmXjivbScwn",
"https://open.spotify.com/playlist/5sj85p0DBgtP5GJr7tpAwH" # Uh-uh bad playlist
] # Uh- uh and 20 bad playlists
badplaylists = ["https://open.spotify.com/playlist/5sj85p0DBgtP5GJr7tpAwH", "https://open.spotify.com/playlist/0dvjiEDQneQrUiTGjpHb7W"] # Uh-uh & 20
artistURL = "/user/1153971537"
url = playlists[24]
res = requests.get(url)
html_page = res.content
soup = BeautifulSoup(html_page, 'html.parser')
text = soup.find_all(text=True)
output = ''
blacklist = [
'[document]',
'noscript',
'header',
'html',
'meta',
'head',
'input',
'script',
# there may be more elements you don't want, such as "style", etc.
]
for t in text:
if t.parent.name not in blacklist:
output += '{} '.format(t)
lines = output.split('\n')
namePlaylist = lines[0].split(" ")
result = ""
for i in namePlaylist[:-3]:
result = result + i + " "
namePlaylist = result
print(namePlaylist)
playlist = lines[len(lines) - 1]
comment = playlist.split("more-icon-android")[0]
for i in comment.split(" ")[:-4]:
result = result + i + " "
commentary = result
#print(commentary)
result = ""
firstPosition = comment.split(" ")[3:][-4:][:3]
result = " "
for i in firstPosition:
result = result + i + " "
firstPosition = result
playlistList = playlist.split("more-icon-android")
playlistList[0] = firstPosition
el = soup.find_all(href=True)
linesURL = str(el)
myList = []
if url in badplaylists:
index = 0
for i in range(len(playlistList[:-1])):
trackURL = linesURL.split(artistURL)[1].split("href")[index].split('"')[1]
if "https://" not in trackURL:
trackURL = linesURL.split(artistURL)[1].split("href")[i + 3].split('"')[1]
if "https://" not in trackURL:
trackURL = linesURL.split(artistURL)[1].split("href")[i + 1].split('"')[1]
# TODO: Correct 1st track name
playlist = playlistList[:-1]
content = playlist[i] + ", " + trackURL
myList.append(content)
index += 2
else:
index = 1
for i in playlistList[:-1]:
trackURL = linesURL.split(artistURL)[1].split("href")[index].split('"')[1]
content = i + ", " + trackURL
myList.append(content)
index += 2
for song in range(len(myList)):
name = myList[song].split(",")[0]
songURL = myList[song].split(",")[1]
print(name)
print(songURL)