Skip to content

Commit

Permalink
Removed the use of the library Spotipy. (It caused so many errors and…
Browse files Browse the repository at this point in the history
… inconsistesy in the code)
  • Loading branch information
FindMalek committed Apr 30, 2022
1 parent ff2248a commit 2aa7e5b
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 346 deletions.
226 changes: 0 additions & 226 deletions Data/Playlists Informations.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed Functions/__pycache__/systemFunctions.cpython-39.pyc
Binary file not shown.
Binary file removed Functions/__pycache__/trackHandeling.cpython-39.pyc
Binary file not shown.
18 changes: 0 additions & 18 deletions Functions/spotifyHandenler/requestsHandeling.py

This file was deleted.

11 changes: 0 additions & 11 deletions Settings.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,60 +1,51 @@
import time

#importing Spotipy
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

#importing systemFunctions
from Functions.SyncifyFunctions.systemFunctions import *
from SyncifyFunctions.systemFunctions import *

#Importing spotifyHandeler
from spotifyHandenler.requestsHandeling import *


setting_path = "Settings.json"
playlist_path = convertPath("Data/Playlists Informations.json")

#Log in Spotipy_Session
def SpotipySession():
client_credentials_manager = SpotifyClientCredentials()#Spotify Client
return spotipy.Spotify(client_credentials_manager = client_credentials_manager)

Spotipy_Session = SpotipySession()

#get the needed informations to fill up the Playlist JSON file
def getPlaylistInformation(Spotipy_Session, toGet, link, playlist_ID=""):
if(toGet == "ID"):
if(isLinkAlbum(link)):
return "spotify:album:" + link[link.find("album/") + len("album/"):]
else:
return "spotify:playlist:" + link[link.find("playlist/") + len("playlist/"):]

if(isLinkAlbum(link)):
spotipyResult = Spotipy_Session.album(link[link.find("album/") + len("album/"):])
def getPlaylistInformation(syncifyToken, objId=""):
if(isLinkAlbum(objId)):
spotipyResult = album(syncifyToken, objId)
else:
spotipyResult = Spotipy_Session.playlist(playlist_ID)

if(toGet == "Name"):
return spotipyResult["name"]
elif(toGet == "Image URL"):
return spotipyResult["images"][0]["url"]
elif(toGet == "Playlist URL"):
return spotipyResult["external_urls"]["spotify"]
spotipyResult = playlist(syncifyToken, objId)

return spotipyResult

#Updates and Add Playlists from the Playlist JSON file
def RefreshPlaylistFile(Spotipy_Session):
def RefreshPlaylistFile(syncifyToken):
SyncifySettings = getDataJSON(setting_path, "Settings")

playlistFile = ReadFILE(playlist_path)
playlist_list = []
for link in playlistFile["Playlists links"]:
playlist_ID = getPlaylistInformation(Spotipy_Session, "ID", link)
playlist_Name = getPlaylistInformation(Spotipy_Session, "Name", link, playlist_ID)
playlist_Image = getPlaylistInformation(Spotipy_Session, "Image URL", link, playlist_ID)
playlist_URL = getPlaylistInformation(Spotipy_Session, "Playlist URL", link, playlist_ID)
if(isLinkAlbum(link)):
spotifyObjId = link[link.find("album/") + len("album/"):]
else:
spotifyObjId = link[link.find("playlist/") + len("playlist/"):]

#Structure of the
spotipyResult = getPlaylistInformation(syncifyToken, spotifyObjId)

#Structure of the playlist
playlist_list.append(
{
playlist_Name : {
"Image": playlist_Image,
spotipyResult["name"] : {
"Image": spotipyResult["images"][0]["url"],
"Links": {
"URL": playlist_URL,
"ID": playlist_ID
"URL": spotipyResult["external_urls"]["spotify"],
"ID": spotifyObjId
}
}
}
Expand All @@ -76,19 +67,19 @@ def CreatePlaylist(order):
for line in order["Order"]:
playlistm3a.write(musicPath + line + "\n")


#Manage .m3u playlists
def PlaylistManager(Spotipy_Session, playlist_id):
def PlaylistManager(syncifyToken, playlist_id):
SavifySettings = getDataJSON(setting_path, "Settings")
downloadLocation = getDataJSON(setting_path, "Settings/Paths/Downloads")
playlist = Spotipy_Session.playlist(playlist_id)
playlistList = playlist(syncifyToken, playlist_id)

pl_order = {
"Name": playlist["name"],
"Name": playlistList["name"],
"Order": []
}

#ALBUM*TRACKLOCATION+TrackName
for track in playlist["tracks"]["items"]:
for track in playlistList["tracks"]["items"]:
trackName = (
track["track"]["artists"][0]["name"] + ' - ' +
track["track"]["name"] + '.' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def deleteTemporaryFiles(path):
os.remove(convertPath(path + '/.cache'))
except OSError:
pass
try:
shutil.rmtree(convertPath(path + '/Functions/__pycache__'))
except:
pass
try:
shutil.rmtree(convertPath(path + '/Functions/SyncifyFunctions/__pycache__'))
except:
pass

#Checks if a link is playlist or album
def isLinkAlbum(link):
Expand Down
Loading

0 comments on commit 2aa7e5b

Please sign in to comment.