Skip to content

Commit

Permalink
Fixing minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FindMalek committed Feb 21, 2022
1 parent 35003fe commit e418b33
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 32 deletions.
70 changes: 41 additions & 29 deletions Functions/systemFunctions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import json, os, shutil
import json, os, shutil, platform
from datetime import datetime
from os import listdir
from os.path import isfile, join



#read JSON and TXT files
def ReadFILE(path):
if(path[-3:] == "txt"):
with open(path, "r") as file:
return file.readlines()
else:
with open(path, 'r') as file:
return json.load(file)

#Outputs the stored data inside a json file, i.e:
#jsonPath = "dir1/dir2" it will output file[dir1][dir2]
def getDataJSON(filePath, jsonPath):
file = ReadFILE(filePath)
for element in jsonPath.split('/'):
file = file[element] #each element enters a new path
return file

#Handle the windows path and Linux path
def convertPath(path):
sysos = getDataJSON(setting_path, "System Os")
if(sysos.lower() == 'linux'):
return path
else:
return path.replace('/', '\\')

#Write on JSON files
def WriteJSON(filePath, toWrite, mode):
with open(filePath, mode) as outfile:
Expand All @@ -10,8 +38,13 @@ def WriteJSON(filePath, toWrite, mode):
#Create "Playlists Informations.json" and "Settings.json"
def SettingUp():
currentPath = os.path.abspath(os.getcwd())
if('/' in currentPath):
currentPath += '/'
else:
currentPath += '\\'

Settings = {
"System Os": "",
"System Os": str(platform.system()),
"Settings": {
"Quality": "BEST",
"Format": "MP3",
Expand All @@ -22,41 +55,20 @@ def SettingUp():
}
}
}
WriteJSON(currentPath + "Settings.json", Settings, "w")
onlyfiles = [f for f in listdir(currentPath) if isfile(join(currentPath, f))]
if("Settings.json" not in onlyfiles):
WriteJSON(currentPath + "Settings.json", Settings, 'w')

playlistInformations = {
"Playlists Informations" : [],
"Playlists links": []
}
WriteJSON(currentPath + "Playlists Informations.json", playlistInformations, 'w')
onlyfiles = [f for f in listdir(convertPath(currentPath + "Data/")) if isfile(join(convertPath(currentPath + "Data/"), f))]
if("Playlists Informations.json" not in onlyfiles):
WriteJSON(convertPath(currentPath + "Data/Playlists Informations.json") , playlistInformations, 'w')

setting_path = "Settings.json"

#read JSON and TXT files
def ReadFILE(path):
if(path[-3:] == "txt"):
with open(path, "r") as file:
return file.readlines()
else:
with open(path, 'r') as file:
return json.load(file)

#Outputs the stored data inside a json file, i.e:
#jsonPath = "dir1/dir2" it will output file[dir1][dir2]
def getDataJSON(filePath, jsonPath):
file = ReadFILE(filePath)
for element in jsonPath.split('/'):
file = file[element] #each element enters a new path
return file

#Handle the windows path and Linux path
def convertPath(path):
sysos = getDataJSON(setting_path, "System Os")
if(sysos.lower() == 'linux'):
return path
else:
return path.replace('/', '\\')

#Set outdated path
def SetOutdatedPath(settingFile):
settingFile["Settings"]["Paths"]["Outdated Playlists"] = convertPath(settingFile["Settings"]["Paths"]["Playlist"] + 'Outdated Playlists/')
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import logging, json, shutil, os, fnmatch
from Functions.systemFunctions import *

#Setting up needed files
SettingUp()

#Importing playlistHandeling
from Functions.playlistHandeling import *


#Setting up needed files
SettingUp()

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

Expand Down

0 comments on commit e418b33

Please sign in to comment.