-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytmusicPlaylistWXRT.py
43 lines (37 loc) · 1.13 KB
/
ytmusicPlaylistWXRT.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
from requests import get
import lxml.html
from ytmusicapi import YTMusic
from ytmusicFunctions import GetSongVideoIds
year = "2021"
month = "3"
day = "6"
url = (
"http://www.mediabase.com/whatsong/whatsong.asp?var_s=087088082084045070077&MONDTE="
+ month
+ "%2F"
+ day
+ "%2F"
+ year
)
ytmusic = YTMusic("oauth.json")
playlistTitle = "WXRT Playlist from " + year + "-" + month.zfill(2) + "-" + day.zfill(2)
playlistDescription = ""
playlistPrivacyStatus = "PUBLIC"
page = get(url)
doc = lxml.html.fromstring(page.content)
trs = doc.xpath("//tr")
songsToAdd = []
for tr in trs[5:]:
if len(tr) == 6:
songsToAdd.append(
tr[2].text_content().lower() + " " + tr[4].text_content().lower()
)
songsToAdd.reverse()
videoResults = GetSongVideoIds(ytmusic, songsToAdd)
newPlaylist = ytmusic.create_playlist(
playlistTitle, playlistDescription, playlistPrivacyStatus, videoResults["videoIds"]
)
print("playlistId:", newPlaylist)
print("Found", videoResults["searchCount"], "songs")
print(videoResults["uniqueCount"], "songs were unique")
print("YTMusic matched", videoResults["matchedCount"], "songs")