-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytmusicPlaylistLikedSongsSorted.py
49 lines (42 loc) · 1.33 KB
/
ytmusicPlaylistLikedSongsSorted.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
from ytmusicFunctions import AddToPlaylist, ClearPlaylist
from bson.objectid import ObjectId
from pymongo.database import Database
from ytmusicapi import YTMusic
from pymongo import MongoClient
from secretsFile import mongoString
from datetime import datetime
def UpdateLikeSongsSorted(databaseConnectionString:str):
ytmusic = YTMusic("oauth.json")
mongoClient = MongoClient(databaseConnectionString)
db = mongoClient['scrobble']
playlistId = "PLJpUfuX6t6dScH3Ua2f2EsmRC4PolZp8I"
likedSongs = db['scrobbleCount'].find(
{"likeStatus": 1, "ytmusicPlayable": {"$ne": False}},
sort=[("time", 1)],
limit=100
)
videoIds = [
song['ytmusicId'] for song in likedSongs
]
ClearPlaylist(ytmusic=ytmusic, playlistId=playlistId)
results = [
AddToPlaylist(
ytmusic=ytmusic,
playlistId=playlistId,
videoId=videoId
) for videoId in videoIds
]
if results:
nowFormatted = datetime.now().strftime(
"%Y-%m-%d at %H:%M"
)
ytmusic.edit_playlist(
playlistId=playlistId,
description=f"Updated on {nowFormatted}"
)
return
if __name__ == "__main__":
# cProfile.run("UpdateLikeSongsSorted(db)")
UpdateLikeSongsSorted(
databaseConnectionString=mongoString
)