-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
129 lines (90 loc) · 2.98 KB
/
utils.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import json
from pygame import mixer
class Music():
def __init__(self,path):
self.mixer = mixer
self.music = self.mixer.music
self.path = path
self.IS_PLAY = False
self.IS_PLAYED = False
self.mixer.init()
self.music.load(self.path)
def play(self):
self.music.play()
self.IS_PLAYED = True
self.IS_PLAY = True
def change_path(self,path):
self.stop()
self.IS_PLAYED = False
self.IS_PLAY = False
self.path = path
self.music.load(self.path)
def pause(self):
self.music.pause()
self.IS_PLAY = False
def unpause(self):
self.music.unpause()
self.IS_PLAY = True
def stop(self,fade=False):
self.IS_PLAY = False
if fade:
self.music.fadeout(800)
else:
self.music.stop()
def set_volum(self,volum):
# 0 to 1
self.music.set_volume(volum)
def set_pos(self,secound):
self.music.set_pos(secound)
def get_volum(self):
return self.music.get_volume()
def get_pos(self):
return self.music.get_pos()
def is_play(self):
return self.IS_PLAY
def is_played(self):
return self.IS_PLAYED
def read_data_setting():
with open('config.json', 'r') as file:
json_config = json.load(file)
return json_config
def write_data_setting(key, value):
settings = read_data_setting()
settings[key] = value
new_settings = json.dumps(settings, indent=4)
with open("config.json", "w") as file:
file.write(new_settings)
return True
def set_defualt_setting(page):
defualt_setting = {
"active_song": ["play list name","path"],
"them": "dark",
"play_lists": [{"title": "favorite","songs": []}]
}
configs = json.dumps(defualt_setting, indent=4)
with open("config.json", "w") as file:
file.write(configs)
return True
def _remove_play_list(play_list_name):
play_lists = read_data_setting()['play_lists']
for play_list in play_lists:
if play_list['title'] == play_list_name:
play_lists.remove(play_list)
write_data_setting("play_lists",play_lists)
def _add_play_list(play_list_name):
play_lists = read_data_setting()['play_lists']
play_lists.append({"title":play_list_name,"songs":[]})
write_data_setting("play_lists",play_lists)
def _add_new_song(play_list_name,songs_list):
play_lists = read_data_setting()['play_lists']
for play_list in play_lists:
if play_list["title"] == play_list_name:
theree_song = play_list["songs"]
for song in songs_list.copy():
if song in theree_song:
songs_list.remove(song)
print('have repet')
play_list["songs"].extend(songs_list)
break
write_data_setting("play_lists",play_lists)
return songs_list