some improvements, new install
This commit is contained in:
25
shuffler.py
25
shuffler.py
@@ -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 = {}
|
||||
|
Reference in New Issue
Block a user