-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
220 lines (147 loc) · 6.11 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import flet as ft
import music
def main(page: ft.Page):
#COLORS
bgcolor = "#100017"
primary = "#41005E"
secondary = "#F1DEFA"
tertiary = "#B19FF9"
#PAGE SETUP
page.title = "Geet"
page.horizontal_alignment = "center"
page.bgcolor = bgcolor
page.theme_mode = "dark"
#ACTIONS
music.createcache()
def play(e):
loadbar.width = 450
page.update()
#Release resources and clear cache
song.release()
music.resetcache()
#Download via videoId, set the new song src & display duration
music.dmusic(e.control.data[2])
song.src = music.getaudio()
#Update music player
current_song.title = ft.Text(e.control.data[0], max_lines=2, overflow="ellipsis", color=ft.colors.WHITE)
current_song.subtitle = ft.Text(f"{e.control.data[3]} - {e.control.data[1]}", max_lines=1, overflow="ellipsis", color=ft.colors.WHITE70)
#Auto-Play the song
if page.platform != "ios" and page.platform != "macos":
song.autoplay = True
playpausebtn.icon = ft.icons.PAUSE_CIRCLE_ROUNDED
#Update music player
music_player.disabled = False
loadbar.width = 0
page.update()
def listsongs(e):
if search_box.value != "":
loadbar.width = 450
page.update()
songdict = music.searchsong(search_box.value)
song_list.controls.clear()
for song in songdict['songs']:
song_item = ft.ListTile(width=450)
song_item.title = ft.Text(song['name'], color=secondary)
song_item.subtitle = ft.Text(f"{song['duration']} - {song['isExplicit']}{song['artists']}", color=tertiary)
song_item.data = [song['name'], song['artists'], song['videoId'], song['duration']]
song_item.on_click = play
song_list.controls.append(song_item)
page.update()
print("Updated List")
loadbar.width = 0
page.update()
def play_pause_song(e):
if playpausebtn.icon == ft.icons.PLAY_CIRCLE_ROUNDED:
playpausebtn.icon = ft.icons.PAUSE_CIRCLE_ROUNDED
song.resume()
elif playpausebtn.icon == ft.icons.PAUSE_CIRCLE_ROUNDED:
playpausebtn.icon = ft.icons.PLAY_CIRCLE_ROUNDED
song.pause()
page.update()
def repeat_song(e):
if playpausebtn.icon == ft.icons.PLAY_CIRCLE_ROUNDED:
playpausebtn.icon = ft.icons.PAUSE_CIRCLE_ROUNDED
song.play()
else:
song.play()
page.update()
def checkstatus(e):
if e.data == "completed":
playpausebtn.icon = ft.icons.PLAY_CIRCLE_ROUNDED
page.update()
def track_progress(e):
if song.get_duration() != 0:
duration_progress.value = int(e.data)/song.get_duration()
page.update()
#UI COMPONENTS
#Audio
song = ft.Audio(src=music.getaudio(), autoplay=False, on_state_changed=checkstatus, on_position_changed=track_progress)
page.overlay.append(song)
#App Bar
app_bar = ft.AppBar(center_title=True, bgcolor=bgcolor)
app_bar.title = ft.Text("geet", style=ft.TextThemeStyle.HEADLINE_LARGE, color=ft.colors.WHITE,
weight="bold", italic=True, size=40)
app_bar.actions= [ft.TextButton(icon=ft.icons.CODE, icon_color=secondary ,on_click=lambda e: page.launch_url("https://github.com/redromnon/Geet"))]
#Loading bar
loadbar = ft.ProgressBar(width=0, color=secondary)
#Song List
song_list = ft.Column([], spacing=10, scroll="always", expand=True, horizontal_alignment="stretch")
#Search Box
search_box = ft.TextField(filled=True, border_width=2, border_radius=20,
hint_text="Enter a song name", width=400, prefix_icon=ft.icons.SEARCH_ROUNDED,
on_submit=listsongs, focused_border_color=secondary, focused_color=secondary,
bgcolor=bgcolor, cursor_color=secondary, selection_color=secondary)
#Music Player
duration_progress = ft.ProgressRing(stroke_width=5, width=45, height=45, value=0, color=secondary, bgcolor=bgcolor)
current_duration = ft.Stack(
[
ft.Container(content=ft.Icon(name=ft.icons.MUSIC_NOTE_ROUNDED, size=30, color=secondary), left=8, top=7),
duration_progress,
]
)
current_song = ft.ListTile(
leading=current_duration,
title=ft.Text("...", color=ft.colors.WHITE),
subtitle=ft.Text("...", color=tertiary), expand=True
)
playpausebtn = ft.IconButton(icon=ft.icons.PLAY_CIRCLE_ROUNDED, icon_size=30, on_click=play_pause_song, icon_color=secondary, tooltip="Play/Pause")
repeatbtn = ft.IconButton(icon=ft.icons.REPEAT_ROUNDED, icon_size=30, on_click=repeat_song, icon_color=secondary, tooltip="Repeat")
forwardbtn = ft.IconButton(
icon=ft.icons.FAST_FORWARD_ROUNDED, icon_size=30,
on_click=lambda e: song.seek(song.get_current_position()+5000),
icon_color=secondary,
tooltip="Move forward 5 sec"
)
rewindbtn = ft.IconButton(
icon=ft.icons.FAST_REWIND_ROUNDED, icon_size=30,
on_click=lambda e: song.seek(song.get_current_position()-5000),
icon_color=secondary,
tooltip="Move back 5 sec"
)
player_button = ft.Row(
[
playpausebtn, rewindbtn, forwardbtn, repeatbtn
],
alignment="end", spacing=0
)
music_player = ft.Container(content=ft.Row(
[
current_song,
player_button,
],
alignment="spaceBetween"
), border_radius=20, disabled=True, bgcolor=primary, padding=ft.padding.only(right=10)
)
#LAYOUT
page.add(
app_bar,
ft.Column(
[
search_box, loadbar, song_list,
],
horizontal_alignment="center",
spacing=20, expand=True
),
music_player
)
ft.app(target=main, assets_dir="cache", view=ft.WEB_BROWSER, port=8080)