-
Notifications
You must be signed in to change notification settings - Fork 0
/
editInfo.py
68 lines (58 loc) · 2.33 KB
/
editInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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)