Skip to content

Commit

Permalink
Update for 0.4
Browse files Browse the repository at this point in the history
New hashing because old one wasn't working well
Caching
Action with selected playlist is now in another file so you can go back to playlist selection instead of restarting the playlist manger each time
  • Loading branch information
OwOchle authored Mar 30, 2021
1 parent d6826a6 commit 475fa94
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 75 deletions.
11 changes: 5 additions & 6 deletions getHash.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import hashlib
import json
from requests import get
import sys


def gethash(path):
try:
# Open the file to use it in hash encoding and difficulties
f = open(path + '/info.dat', encoding='utf-8').read()
f = open(path + '/info.dat', 'rb').read()
tohash = f
jsonf = json.loads(f)
jsonf = json.loads(f.decode('utf-8'))

# Check all the BeatMaps Sets and All difficulties to add files in the tohash string
for cat in jsonf["_difficultyBeatmapSets"]:
for item in cat["_difficultyBeatmaps"]:
tohash += open(path + '/' + item['_beatmapFilename'], encoding='utf-8').read()
tohash += open(path + '/' + item['_beatmapFilename'],'rb').read()

# Encoding and decoding to have the final hash
hash = hashlib.sha1(tohash.encode('utf-8')).hexdigest()
hashcode = hashlib.sha1(tohash).hexdigest()

return hash
return hashcode

except Exception as e:
print(path)
Expand Down
99 changes: 35 additions & 64 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import getHash
import json
from plDownloading import *
from checkPath import *
from newPl import *
from editInfo import *
from os import mkdir
from addMap import addmap
from remMap import *
from storedHashesManagement import *
from plSel import plsel

try:
mkdir('Images')
Expand All @@ -27,9 +24,17 @@
maps = []

# Get all maps hashes
print('Loading all your maps, please wait (can take several minutes depending on your map count)')
for item in CMdirs:
maps.append(getHash.gethash(CMpath + item))

if settings["cacheMaps"]:
if not os.path.isfile('./Settings/maps.txt'):
refresh(CMpath, CMdirs)
maps = loadmaps()

else:
print('Loading all your maps, please wait (can take several minutes depending on your map count)')
for item in CMdirs:
maps.append(getHash.gethash(CMpath + item))


PLpath = BSpath + 'Playlists/'
PLfiles = os.listdir(PLpath)
Expand All @@ -49,63 +54,29 @@
n += 1

loop = True
selpl = input('Type the number of the playlist you want to select, type "new" to create a new playlist or type "refresh" to refresh all your songs\n')
while loop:
n = 1
print('Select the playlist you want :')
for item in playlists:
print(f'{n}: {item["title"]}')
n += 1
selpl = input('Type the number of the playlist you want to select, type "new" to create a new playlist or type "refresh" to refresh all your songs\n')
try:
while loop:
if selpl.upper() == 'EXIT':
exit(0)
if selpl.upper() != 'NEW':
selpl = int(selpl) - 1
if selpl + 1 <= 0 or selpl + 1 >= n:
print('The number you entered is not in range.')
selpl = input('Please retry\n')
else:
loop = False
if selpl.upper() == 'EXIT':
exit(0)
elif selpl.upper() == 'REFRESH':
maps = refresh(CMpath, CMdirs)
print('Song Refreshed')
elif selpl.upper() == 'NEW':
pl_create(PLpath)
elif selpl.upper() != 'NEW':
selpl = int(selpl) - 1
if selpl + 1 <= 0 or selpl + 1 >= n:
print('The number you entered is not in range.')
selpl = input('Please retry\n')
else:
loop = False
except ValueError:
selpl = input('Please enter a correct value\n')


if selpl == 'new':
pl_create(PLpath)
else:
while True:
print('\n\nWhat do you want to do with this playlist :')
print('delete, addmap, removemap, editinfo, download, exit')
commands = ['DELETE', 'ADDMAP', 'REMOVEMAP', 'EDITINFO', 'DOWNLOAD', 'EXIT', 'REFRESH']
incom = input()
if incom.upper() not in commands:
print('The command doesn\'t seem right')
plsel(PLpath, playlists, CMdirs, CMpath, settings, maps, selpl)
else:
if incom.upper() == 'DOWNLOAD':
pldownload(maps, playlists, selpl, PLpath, CMpath)

elif incom.upper() == 'DELETE':
while True:
delcheck = input(f'Are you sure you want to delete "{playlists[selpl]["title"]}" (y/n)')
if delcheck.upper() == 'Y':
os.remove(PLpath + f'{playlists[selpl]["fileName"]}')
print('Playlist deleted\nPress Enter to close.')
input()
exit()
elif delcheck.upper() == 'N':
break
else:
print('Please enter a correct letter\n\n')

elif incom.upper() == 'EXIT':
exit(0)

elif incom.upper() == 'EDITINFO':
edit_info(PLpath, playlists[selpl]['fileName'])

elif incom.upper() == 'ADDMAP':
addmap(PLpath, playlists[selpl]['fileName'])

elif incom.upper() == 'REMOVEMAP':
remmap(PLpath, playlists[selpl]['fileName'])

else:
print('This command is not yet implemented')
loop = False
except ValueError:
print('Please enter a correct value\n')
19 changes: 14 additions & 5 deletions plDownloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ def pldownload(maps, playlists, pldl, PLpath, CMpath):

# opens playlist file
pldl = PLpath + playlists[pldl]['fileName']
pldl = open(pldl).read()
pldl = open(pldl, encoding='utf-8').read()
pldl = json.loads(pldl)
todl = []

# Checks if maps in playlists are already downloaded
print(pldl['songs'])
for item in pldl['songs']:
if item['hash'].lower() not in maps:
todl.append(item)
try:
if item['hash'].lower() not in maps:
todl.append(item)
except Exception as e:
print('------------------------------')
print(pldl['songs'])
print(e)
print(item)
print('------------------------------')
print('An error occurs, send the text between ----------- to Moréo#1809 on discord')
input('Press enter to close')
exit(1)

ndl = 1

Expand All @@ -27,8 +38,6 @@ def pldownload(maps, playlists, pldl, PLpath, CMpath):
download_beatmap(item['hash'], CMpath)
ndl += 1
print(f'\n\nPlaylist {title} downloaded')
input('Press Enter to close')

else:
print('\n\nAll songs are already downloaded')
input('Press Enter to close')
51 changes: 51 additions & 0 deletions plSel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from plDownloading import *
from editInfo import *
from storedHashesManagement import *
from addMap import addmap
from remMap import remmap


def plsel(PLpath, playlists, CMdirs, CMpath, settings, maps, selpl):
while True:
print('\n\nWhat do you want to do with this playlist :')
print('delete, addmap, removemap, editinfo, download, exit')
commands = ['DELETE', 'ADDMAP', 'REMOVEMAP', 'EDITINFO', 'DOWNLOAD', 'EXIT']
incom = input()
if incom.upper() not in commands:
print('The command doesn\'t seem right')
else:
if incom.upper() == 'DOWNLOAD':
pldownload(maps, playlists, selpl, PLpath, CMpath)
if settings["cacheMaps"]:
print('Refreshing maps')
refresh(CMpath, CMdirs)
maps = loadmaps()
print('Maps refreshed')

elif incom.upper() == 'DELETE':
while True:
delcheck = input(f'Are you sure you want to delete "{playlists[selpl]["title"]}" (y/n)')
if delcheck.upper() == 'Y':
os.remove(PLpath + f'{playlists[selpl]["fileName"]}')
print('Playlist deleted\nPress Enter to close.')
input()
exit()
elif delcheck.upper() == 'N':
break
else:
print('Please enter a correct letter\n\n')

elif incom.upper() == 'EXIT':
break

elif incom.upper() == 'EDITINFO':
edit_info(PLpath, playlists[selpl]['fileName'])

elif incom.upper() == 'ADDMAP':
addmap(PLpath, playlists[selpl]['fileName'])

elif incom.upper() == 'REMOVEMAP':
remmap(PLpath, playlists[selpl]['fileName'])

else:
print('This command is not yet implemented')
16 changes: 16 additions & 0 deletions storedHashesManagement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from getHash import gethash


def loadmaps():
with open('./Settings/maps.txt', 'r+') as f:
maps = f.read()
maps = maps.split('\n')
return maps


def refresh(CMpath, CMdirs):
maps = ''
for item in CMdirs:
maps += gethash(CMpath + item) + '\n'
with open('./Settings/maps.txt', 'w+', encoding='utf-8') as f:
f.write(maps)

0 comments on commit 475fa94

Please sign in to comment.