-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio.py
56 lines (44 loc) · 1.21 KB
/
radio.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
import rumps
import pafy
import vlc
class Funkkopf(rumps.App):
playing = False
v = vlc.Instance("--novideo")
player = v.media_player_new()
station = 0
source = [
"https://www.youtube.com/watch?v=5qap5aO4i9A",
"https://www.youtube.com/watch?v=DWcJFNfaw9c",
]
def __init__(self):
super(Funkkopf, self).__init__("lofi radio")
@rumps.clicked("Play/Pause")
def play_pause(self, _):
if self.playing:
self.pause()
else:
self.play()
def play(self):
self.prepare_media()
self.playing = True
print("Starting lofi radio")
self.player.play()
def pause(self):
self.playing = False
print("Stopping lofi radio")
self.player.stop()
def prepare_media(self):
media = pafy.new(self.source[self.station])
url = media.streams[3].url
media = self.v.media_new(url)
self.player.set_media(media)
@rumps.clicked("Next Station")
def next(self, _):
self.player.stop()
if self.station == 0:
self.station = 1
else:
self.station = 0
self.play()
if __name__ == "__main__":
Funkkopf().run()