-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.3 Update : Playlists map edition (beta)
- Loading branch information
Showing
9 changed files
with
333 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
from requests import get | ||
|
||
|
||
def getmap(code): | ||
headers = { | ||
'User-Agent': 'Playlist Manager DOS/0.1 (https://github.com/Moreo18/Playlist-Manager-DOS)'} | ||
url = 'https://beatsaver.com/api/maps/detail/' | ||
req = get(url + code, headers=headers) | ||
if req.status_code == 404: | ||
print(f'Sorry, the map {code} seems to be inaccessible, either it does not exist, either Beat Saver is unavailable.\n') | ||
return None, None | ||
|
||
mapinf = json.loads(req.content) | ||
print(f'\nAdded {mapinf["name"]}, Mapper : {mapinf["metadata"]["levelAuthorName"]}, Rating : {int((mapinf["stats"]["rating"] * 100))}%') | ||
return mapinf['metadata']['songName'], mapinf['hash'] | ||
|
||
|
||
def addmap(PLpath, playlistfile): | ||
pl = open(PLpath + playlistfile).read() | ||
pl = json.loads(pl) | ||
if not 'songs' in pl: | ||
pl['songs'] = [] | ||
print(' ') | ||
print(pl['playlistTitle'] + ' :') | ||
while True: | ||
nmap = input('Enter the code of the map you want to add to your playlist or type Exit to stop editing the playlist (you can add multiple maps by separating codes with commas)\n') | ||
if nmap.upper() == 'EXIT': | ||
break | ||
else: | ||
nmap = nmap.replace(' ', '').split(',') | ||
for item in nmap: | ||
title, hashm = getmap(item) | ||
if not title or not hashm: | ||
continue | ||
for item2 in pl['songs']: | ||
if item2['hash'] == hashm.upper(): | ||
print('The map is already in playlist') | ||
pl['songs'].append({'songName': title, 'hash': hashm.upper()}) | ||
with open(PLpath + playlistfile, 'w') as f: | ||
json.dump(pl, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import json | ||
import os | ||
from base64 import b64encode | ||
from ShowB64Image import * | ||
|
||
|
||
def edit_info(PLpath, plfilepath): | ||
plfile = open(PLpath + plfilepath, 'r', encoding='utf-8') | ||
pl = json.loads(plfile.read()) | ||
plfile.close() | ||
print(f'\n\nThe current playlist title is "{pl["playlistTitle"]}"') | ||
name = input('Type the new title or press Enter to keep the old one\n') | ||
if name != '': | ||
pl["playlistTitle"] = name | ||
|
||
print(f'The current playlist author is "{pl["playlistAuthor"]}"') | ||
author = input('Type the new author or press Enter to keep the old one\n') | ||
|
||
if author != '': | ||
pl["playlistAuthor"] = author | ||
|
||
print(f'The current description is "{pl["playlistDescription"]}"') | ||
desc = input('Type the new description or press Enter to keep the old one\n') | ||
|
||
if desc != '': | ||
pl["playlistDescription"] = desc | ||
|
||
images = os.listdir('./Images') | ||
print('\n') | ||
print('If there is one, the current image should open in your default image gallery') | ||
if pl['image']: | ||
try: | ||
show_base64_image(pl['image']) | ||
except Exception: | ||
print('Something went wrong when trying to open the image') | ||
for item in range(len(images)): | ||
print(f'{item + 1}: {images[item - 1]}') | ||
cim = input('Type the number of the image you want, leave empty if you want to keep the old one or type 0 to delete the cover : ') | ||
if cim == '': | ||
im = '' | ||
|
||
else: | ||
cont = True | ||
while cont: | ||
try: | ||
cim = int(cim) - 1 | ||
if cim + 1 == 0: | ||
pl.pop('image') | ||
print('Cover removed') | ||
cont = False | ||
elif cim + 1 <= 0 or cim + 1 > len(images): | ||
print('The number you entered is not in range\nPlease enter another one : ') | ||
input() | ||
else: | ||
cont = False | ||
except ValueError: | ||
print('Please enter a correct value : ') | ||
input() | ||
if cim != -1: | ||
im = b64encode(open(f'./Images/{images[item]}', 'rb').read()) | ||
else: | ||
im = '' | ||
|
||
if im != '': | ||
pl['image'] = f'data:image/png;base64,{im}' | ||
|
||
plfile = open(PLpath + plfilepath, 'w', encoding='utf-8') | ||
json.dump(pl, plfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import io | ||
import zipfile | ||
from requests import get | ||
import json | ||
import sys | ||
|
||
|
||
def download_beatmap(hash, CMpath): | ||
# headers and getting directDownload link | ||
headers = { | ||
'User-Agent': 'Playlist Manager DOS/0.1 (https://github.com/Moreo18/Playlist-Manager-DOS)'} | ||
url1 = 'https://beatsaver.com/api/maps/by-hash/' | ||
req = get(url1 + hash, headers=headers) | ||
|
||
try: | ||
dD = json.loads(req.content) | ||
|
||
except json.decoder.JSONDecodeError as e: | ||
print('request code : ' + str(req.status_code)) | ||
print(e) | ||
print("line : " + str(sys.exc_info()[2].tb_lineno)) | ||
print(req.content) | ||
|
||
except Exception as e: | ||
print(e) | ||
print(sys.exc_info()[2].tb_lineno) | ||
|
||
dD = json.loads(req.content) | ||
name = dD["name"].replace(':', ' ').replace('*', ' ').replace('/', ' ').replace('\\', ' ').replace('<', ' ')\ | ||
.replace('>', ' ').replace('|', ' ').replace('?', ' ').replace('"', ' ') | ||
req2 = get(f'https://beatsaver.com{dD["directDownload"]}', headers=headers) | ||
path = CMpath + f'{dD["key"]} ({name} - {dD["uploader"]["username"]})' | ||
|
||
# try to extract zip to beat saber folder | ||
try: | ||
zip = zipfile.ZipFile(io.BytesIO(req2.content)) | ||
zip.extractall(path) | ||
|
||
except zipfile.BadZipfile as e: | ||
print('request code : ' + str(req2.status_code)) | ||
print(e) | ||
print("line : " + str(sys.exc_info()[2].tb_lineno)) | ||
print(req2.content) | ||
print(f'https://beatsaver.com{dD["directDownload"]}') | ||
|
||
except Exception as e: | ||
print(e) | ||
print(sys.exc_info()[2].tb_lineno) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
import os | ||
from base64 import b64encode | ||
|
||
|
||
def pl_create(PLpath): | ||
# Creating the file and starting writing in it | ||
name = input('Enter the name of the playlist you want to create : ') | ||
file = open(f'{PLpath}{name}.json', 'w+', encoding='utf-8') | ||
playlist = {"playlistTitle": name, 'playlistAuthor': input('Enter author\'s name : '), | ||
'playlistDescription': input('Enter description : ')} | ||
images = os.listdir('./Images') | ||
print('\n') | ||
for item in range(len(images)): | ||
print(f'{item + 1}: {images[item - 1]}') | ||
cim = input('Type the number of the image you want (leave empty if you don\'t want an image) : ') | ||
if cim == '': | ||
pass | ||
else: | ||
cont = True | ||
while cont: | ||
try: | ||
cim = int(cim)-1 | ||
if cim + 1 <= 0 or cim + 1 > len(images): | ||
print('The number you entered is not in range\nPlease enter another one : ') | ||
input() | ||
else: | ||
cont = False | ||
except ValueError: | ||
print('Please enter a correct value : ') | ||
input() | ||
im = b64encode(open(f'./Images/{images[item]}', 'rb').read()) | ||
playlist['image'] = f'data:image/png;base64,{im}' | ||
json.dump(playlist, file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.