some improvements, new install

This commit is contained in:
2023-04-06 10:06:24 -05:00
parent 4955e744eb
commit 30960d1923
3 changed files with 153 additions and 71 deletions

View File

@@ -1,7 +1,8 @@
import json
import datetime as dt
import sys
import numpy as np
import numpy
import time
from ytmusicapi import YTMusic
ytmusic = YTMusic("config.json")
# created a config file following the docs here: https://ytmusicapi.readthedocs.io/en/latest/setup.html
@@ -26,27 +27,29 @@ try:
bkup_title = to_shuffle + ' autobackup'
if get_playlistID(bkup_title):
ytmusic.delete_playlist(get_playlistID(bkup_title))
backup = {}
backup['source_playlist'] = to_shuffleID
backup['title'] = bkup_title
now = dt.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M")
backup['description'] = 'Created ' + now
ytmusic.create_playlist(**backup)
print(f'{bkup_title} created')
backup = {}
backup['source_playlist'] = to_shuffleID
backup['title'] = bkup_title
now = dt.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M")
backup['description'] = 'Created ' + now
ytmusic.create_playlist(**backup)
print(f'{bkup_title} created')
except:
track_ids = [] # Python needs SOMETHING here, whatever.
playlist = ytmusic.get_playlist(to_shuffleID, limit=1000) #get the songs in the playlist
playlist = ytmusic.get_playlist(to_shuffleID) #get the songs in the playlist
track_ids = []
for i in playlist['tracks']:
track_ids.append(i['videoId'])
np.random.shuffle(track_ids)
numpy.random.shuffle(track_ids)
ytmusic.remove_playlist_items(to_shuffleID, playlist['tracks'])
time.sleep(5) # having the requests too close together was causing errors
ytmusic.add_playlist_items(to_shuffleID, track_ids)
now = dt.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M")
shuffled = {}