Announcements

Help Wizard

Step 1

NEXT STEP

An issue that I couldn’t find my playlist that I’m looking for

Solved!

An issue that I couldn’t find my playlist that I’m looking for

  • Plan

Free/Premium

Country

 

Device

(iPhone 8, Samsung Galaxy 9, Macbook Pro late 2016)

Operating System

(iOS 10, Android Oreo, Windows 10,etc.)

 

My Question or Issue

hi I got an issue as I mentioned in the title above. Like even though I have a playlist named “Discover Weekly”, the Session keeps returning “Discover Weekly not found”.
Do y’all have any idea for this

 

Here are the codes below:

 

import spotipy
import time
from spotipy.oauth2 import SpotifyOAuth

from flask import Flask, request, url_for, session, redirect

app = Flask('_name__')

app.config['SESSION_COOKIE_NAME'] = 'Spotify Cookie'
app.secret_key = 'sdjqedkj'
TOKEN_INFO = 'token_info'

@app.route('/')
def login():
auth_url = create_spotify_oauth().get_authorize_url()
return redirect(auth_url)
@app.route('/redirect')
def redirect_page():
session.clear()
code = request.args.get('code')
token_info = create_spotify_oauth().get_access_token(code)
session[TOKEN_INFO] = token_info
return redirect(url_for('save_discover_weekly', external = True))


@app.route('/saveDiscoverWeekly')
def save_discover_weekly():

try:
token_info = get_token()
except:
print("User not logged in")
return redirect('/')

sp = spotipy.Spotify(auth=token_info['access_token'])
user_id = sp.current_user()['id']

saved_weekly_playlist_id = None
discover_weekly_playlist_id = None

current_playlists = sp.current_user_playlists()['items']
for playlist in current_playlists:
if(playlist['name'] == "Discover Weekly"):
discover_weekly_playlist_id = playlist['id']
if (playlist['name'] == "Saved Weekly"):
saved_weekly_playlist_id = playlist['id']

if not discover_weekly_playlist_id:
return 'Discover Weekly playlist not found'

if not saved_weekly_playlist_id:
new_playlist = sp.user_playlist_create(user_id, 'Saved Weekly', True)
saved_weekly_playlist_id = new_playlist['id']

discover_weekly_playlist = sp.playlist_items(discover_weekly_playlist_id)
song_uris = []
for song in discover_weekly_playlist['items']:
song_uri = song['track']['uri']
song_uris.append(song_uri)

sp.user_playlist_add_tracks(user_id, saved_weekly_playlist_id, song_uris, None)
return ("SUCCESSS!!!!")

def get_token():
token_info = session.get(TOKEN_INFO, None)
if not token_info:
redirect(url_for('login', external=False))

now = int(time.time())

is_expired = token_info['expires_at'] - now < 60
if(is_expired):
spotify_oauth = create_spotify_oauth()
tokenb_info = spotify_oauth.refresh_access_token(token_info['refresh_token'])

return token_info

def create_spotify_oauth():
return SpotifyOAuth(
client_id="458ba58e639947c8b6f465644faea437",
client_secret="00654b89cfb24ea2ae98f480a25081c8",
redirect_uri = url_for('redirect_page', _external=True),
scope='user-library-read playlist-modify-public playlist-modify-private'
)

app.run(debug=True)

 

 

 

Reply

Accepted Solutions
Marked as solution

Hi @Hammyi 

Thank you for posting in the Spotify Community, and Welcome!

 

Due to the changes of November 27, 2024, it is no longer possible to get playlist data from Spotify that have Spotify as its owner. This is the case with the Discover Weekly playlist.

Here is a link with info about all the changes.

 

I hope this answers your question. If you have further questions, feel free to ask.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

View solution in original post

2 Replies
Marked as solution

Hi @Hammyi 

Thank you for posting in the Spotify Community, and Welcome!

 

Due to the changes of November 27, 2024, it is no longer possible to get playlist data from Spotify that have Spotify as its owner. This is the case with the Discover Weekly playlist.

Here is a link with info about all the changes.

 

I hope this answers your question. If you have further questions, feel free to ask.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Hi Thank you for your answear 👍 It helps me a lot 

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random