forked from callsmusic/vcpb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
135 lines (111 loc) · 3.09 KB
/
player.py
File metadata and controls
135 lines (111 loc) · 3.09 KB
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
import threading
import queue
from subprocess import Popen, PIPE
from helpers import State
q = queue.Queue()
q_list = []
process = None
STATE = State.NothingSpecial
def worker():
global process, q_list, STATE
while True:
item = q.get()
log = None
if "stream_url" in item:
STATE = State.Streaming
if "log" in item:
if item["log"]:
log = item["log"][0](
*item["log"][1]
)
process = Popen(["mplayer", item["stream_url"]], stdin=PIPE)
process.wait()
else:
STATE = State.Playing
item["on_start"][0](
*item["on_start"][1],
quote=True
)
if "log" in item:
if item["log"]:
args = item["log"][1]
args[1] = args[1].format(
item["url"],
item["title"],
item["sent_by_id"],
item["sent_by_name"],
item["dur"]
)
log = item["log"][0](
*args
)
process = Popen(["mplayer", item["file"]], stdin=PIPE)
process.wait()
if STATE == State.Playing:
item["on_end"][0](
*item["on_end"][1],
quote=True
)
elif STATE == State.Skipped:
item["on_skip"][0](
*item["on_skip"][1],
quote=True
)
if q_list:
if q_list[0] == item:
del q_list[0]
if log:
log.delete()
STATE = State.NothingSpecial
process = None
if q:
q.task_done()
threading.Thread(target=worker, daemon=True).start()
def play(file, on_start, on_end, title, url, sent_by_id, sent_by_name, log, dur, on_skip):
args = {
"file": file,
"on_start": on_start,
"on_end": on_end,
"title": title,
"url": url,
"sent_by_id": sent_by_id,
"sent_by_name": sent_by_name,
"log": log,
"dur": dur,
"on_skip": on_skip
}
q.put(
args
)
q_list.append(
args
)
return q.qsize()
def stream(stream_url, log):
q.put(
{
"stream_url": stream_url,
"log": log
}
)
return q.qsize()
def currently_playing():
return q_list[0] if q_list else []
def abort():
if process:
process.terminate()
del q_list[0]
return True
return False
def pause_resume():
if process:
process.stdin.write(b"p")
process.stdin.flush()
return True
return False
def sf():
if process:
process.stdin.write(b"\x1B[D")
process.stdin.flush()
return True
return False