-
-
Notifications
You must be signed in to change notification settings - Fork 95
Creating playlists not working as expected #179
Comments
When you've edited a playlist, you need to run |
Also, |
Thanks, I will incorporate that into the code. |
Hey, thanks again @jodal , but I am still having some issues. I am guessing when you said session.playlists_container.has_pending_changes you meant just playlist.has_pending_changes? I added that and my playlists are consistently showing up in the list, but they don't seem to be added at the index I indicate, specifically within a folder. They are all being added to the first position. See code here: import datetime
import spotify
import getpass
import threading
import sys
def create_playlist(session, name, tracks, index):
new_playlist = session.playlist_container.add_new_playlist(name, index)
new_playlist.add_tracks(tracks)
while new_playlist.has_pending_changes:
session.process_events();
############Session Setup
logged_in_event = threading.Event()
playlist_created_event = threading.Event()
logout_event = threading.Event()
def connection_state_listener(session):
if session.connection.state is spotify.ConnectionState.LOGGED_IN:
logged_in_event.set()
def logged_out_listener(session):
logout_event.set()
session = spotify.Session()
loop = spotify.EventLoop(session)
loop.start()
session.on(spotify.SessionEvent.CONNECTION_STATE_UPDATED, connection_state_listener)
session.on(spotify.SessionEvent.LOGGED_OUT, logged_out_listener)
print "Enter Spotfify User Name:"
uname = raw_input()
pw = getpass.getpass()
session.login(uname, pw)
logged_in_event.wait()
###############End session setup
session.playlist_container.load()
nmf_playlist = 0
discover_playlist = 0
archive_folder = 0
archive_index = -1
index = 0
session.playlist_container.load()
#Look through playlists for one to make a copy of
#Find index of folder to insert playlist into
for playlist in session.playlist_container:
if type(playlist) is spotify.PlaylistFolder:
if playlist.name == "Archive":
archive_folder = playlist
archive_index = index
else:
playlist.load()
if playlist.name == 'New Music Friday':
nmf_playlist = playlist
elif playlist.name == 'Discover Weekly':
discover_playlist = playlist
index += 1
#If we found the original and a folder to copy to make a copy
if archive_index >= 0 and nmf_playlist != 0:
create_playlist(session, 'New Music Friday Archive ' + str(datetime.datetime.today()), nmf_playlist.tracks, archive_index + 1)
if archive_index >= 0 and discover_playlist != 0:
create_playlist(session, uname + ' Discover Weekly Archive ' + str(datetime.datetime.today()), discover_playlist.tracks, archive_index + 1)
session.logout()
logout_event.wait()
|
Closing on the assumption that you haven't been waiting for my answer for 4y. If anyone else have the same issue, shout out. |
I am trying to create a playlist that is a copy of another playlist and add it to a folder.
When I create the playlist it works fine and I get no error, but when I open the Spotify client the playlist is nowhere to be found. I can grab the uri of the playlist when I create it and use that to find the playlist through search, but it never shows up in my list of playlists in the side bar. It seems like the playlist is created but never associated to my users account. Any help is much appreciated, see the code below.
The text was updated successfully, but these errors were encountered: