fixed issues

This commit is contained in:
Matteo Baldi 2025-08-02 05:31:20 +02:00
parent 502959d83b
commit 10d13e04f9
3 changed files with 28 additions and 18 deletions

View file

@ -19,8 +19,8 @@ class SessionData():
self.__creation_date = __creation_date or datetime.datetime.now()
def nearly_expired(self, before=30):
delta_time = datetime.datetime.now() - self.__creation_date - before
return delta_time.seconds > self.__expires_in
delta_time = datetime.datetime.now() - self.__creation_date
return delta_time.seconds > self.__expires_in - before
def is_expired(self):
return self.nearly_expired(0)

View file

@ -54,26 +54,34 @@ def search(query: str):
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
"Content-Type": "application/json"
}
return requests.get(url, headers=header).json()
response = requests.get(url, headers=header)
return response.json()
except Exception as e:
print(e)
@music_router.get("/play")
def play(song_id: str):
url = SPOTIFY_PLAY_URL + "me/player/play"
body = { "uris": [f"spotify:track:{song_id}"] }
header = {
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
"Content-Type": "application/json"
}
requests.put(url, data=body, headers=header).json()
try:
url = SPOTIFY_PLAY_URL + "me/player/play"
body = { "uris": [f"spotify:track:{song_id}"] }
header = {
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
"Content-Type": "application/json"
}
response = requests.put(url, data=body, headers=header)
return response.json()
except Exception as e:
print(e)
@music_router.get("/current-song")
def current_song():
url = SPOTIFY_PLAY_URL + f"me/player/currently-playing?marketing=IT"
header = {
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
"Content-Type": "application/json"
}
return requests.get(url, headers=header).json()
try:
url = SPOTIFY_PLAY_URL + f"me/player/currently-playing?marketing=IT"
header = {
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
"Content-Type": "application/json"
}
return requests.get(url, headers=header).json()
except Exception as e:
print(e)

View file

@ -1,4 +1,7 @@
from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@ -7,7 +10,6 @@ from endpoints.queue import queue_router
from routes import router
from endpoints.spotify_api import music_router
load_dotenv()
app = FastAPI(title="Simple Fullstack API")