-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlccontroller.py
106 lines (81 loc) · 2.58 KB
/
vlccontroller.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
import os
# import subprocess
import vlc
import time
source = "https://www.youtube.com/watch?v=bd2B6SjMh_w"
source2 = "https://www.youtube.com/watch?v=E4yjpT8dkLw"
PIPENAME = "piipe"
b = 1
def play():
time.sleep(4)
# os.system("cat < " + PIPENAME)
print("mui")
p = vlc.MediaPlayer("Gnarls Barkley - Crazy-bd2B6SjMh_w.webm") # 'fd://{}'.format(PIPENAME))
input()
b = 1
p.play()
c = {"p": p.pause,
"s": p.stop,
"y": p.play
}
while 1:
afg = input("give command")
if afg in c:
c[afg]()
else:
print("p: pause/unpause", "s: stop", "y: play")
class PlayerController:
"""Class to handle playlists, control VLC player using vlc.py and stream videos using youtube-dl"""
# todo: rename
PIPENAME = "piipe"
YTDL = "youtube-dl -o - "
stream_process = None
def __init__(self, playlist=[].copy(), player=None):
self.playlist = playlist
if not player:
self.player = vlc.MediaPlayer()
def append(self, link):
# todo: Make work with users so that after f.ex. three songs playlist prefers users with fever songs on list
self.playlist.append(link)
def stream_to_pipe(self, source):
""":param source: link to start streaming with youtube-dl"""
if self.stream_process:
self.stream_process.stop()
self.stream_process = os.popen("youtube-dl -o - {} > {} ".format(source, PIPENAME))
def play_next(self):
# todo: test and
link = self.playlist.pop[0]
self.stream_to_pipe(link)
#instance = vlc.Instance()
#media = instance.media_new("fd://"+self.PIPENAME)
#self.player.set_media(media)
self.player.play()
def override_play_local(self,song):
instance = vlc.Instance()
media = instance.media_new(song)
self.player.set_media(media)
def override_play_song(self, song):
instance = vlc.Instance()
media = instance.media_new("test.webm")
self.player.set_media(media)
self.player.play()
def override_stop(self):
self.player.stop()
def override_quit_player(self):
self.__exit__()
def pause(self):
self.player.pause()
def __enter__(self):
pass
def __exit__(self):
if self.stream_process:
self.stream_process.close()
if self.player:
self.player.stop()
del self.player
self.player = None
def main():
with PlayerController() as player:
player.play()
if __name__ == "__main__":
main()