fixed issues
This commit is contained in:
parent
502959d83b
commit
10d13e04f9
3 changed files with 28 additions and 18 deletions
|
@ -19,8 +19,8 @@ class SessionData():
|
||||||
self.__creation_date = __creation_date or datetime.datetime.now()
|
self.__creation_date = __creation_date or datetime.datetime.now()
|
||||||
|
|
||||||
def nearly_expired(self, before=30):
|
def nearly_expired(self, before=30):
|
||||||
delta_time = datetime.datetime.now() - self.__creation_date - before
|
delta_time = datetime.datetime.now() - self.__creation_date
|
||||||
return delta_time.seconds > self.__expires_in
|
return delta_time.seconds > self.__expires_in - before
|
||||||
|
|
||||||
def is_expired(self):
|
def is_expired(self):
|
||||||
return self.nearly_expired(0)
|
return self.nearly_expired(0)
|
||||||
|
|
|
@ -54,26 +54,34 @@ def search(query: str):
|
||||||
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
return requests.get(url, headers=header).json()
|
response = requests.get(url, headers=header)
|
||||||
|
|
||||||
|
return response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@music_router.get("/play")
|
@music_router.get("/play")
|
||||||
def play(song_id: str):
|
def play(song_id: str):
|
||||||
|
try:
|
||||||
url = SPOTIFY_PLAY_URL + "me/player/play"
|
url = SPOTIFY_PLAY_URL + "me/player/play"
|
||||||
body = { "uris": [f"spotify:track:{song_id}"] }
|
body = { "uris": [f"spotify:track:{song_id}"] }
|
||||||
header = {
|
header = {
|
||||||
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
requests.put(url, data=body, headers=header).json()
|
response = requests.put(url, data=body, headers=header)
|
||||||
|
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
@music_router.get("/current-song")
|
@music_router.get("/current-song")
|
||||||
def current_song():
|
def current_song():
|
||||||
|
try:
|
||||||
url = SPOTIFY_PLAY_URL + f"me/player/currently-playing?marketing=IT"
|
url = SPOTIFY_PLAY_URL + f"me/player/currently-playing?marketing=IT"
|
||||||
header = {
|
header = {
|
||||||
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
"Authorization": "Bearer " + SessionManager.instance().get_current_session().access_tokens,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
return requests.get(url, headers=header).json()
|
return requests.get(url, headers=header).json()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
@ -7,7 +10,6 @@ from endpoints.queue import queue_router
|
||||||
from routes import router
|
from routes import router
|
||||||
from endpoints.spotify_api import music_router
|
from endpoints.spotify_api import music_router
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
app = FastAPI(title="Simple Fullstack API")
|
app = FastAPI(title="Simple Fullstack API")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue