-
Notifications
You must be signed in to change notification settings - Fork 2
/
fifocontrol.py
203 lines (177 loc) · 6.49 KB
/
fifocontrol.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# oyster - a python-based jukebox and web-frontend
#
# Copyright (C) 2004 Benjamin Hanzelmann <ben@nabcos.de>,
# Stephan Windmüller <windy@white-hawk.de>, Stefan Naujokat <git@ethric.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
fifocontrol provides functions to use the oyster-FIFO
"""
__revision__ = 1
import common
import config
import os
import os.path
import time
myconfig = config.get_config()
def do_action(action, filename):
"""
Parses the action parameter and writes the
needed commands into the FIFO
"""
filename = os.path.normpath(str(filename))
filename = filename.replace('//', '/')
filename = filename.replace('../', '')
if filename == '..':
filename = ''
mediadir = myconfig['mediadir'][:-1]
status = ''
if action != 'start' and not common.is_show_admin_controls():
# Only allow start of oyster for non-admins in party mode
return
if os.path.isfile(myconfig['basedir'] + 'status'):
statusfile = open(myconfig['basedir'] + 'status')
status = statusfile.readline()
statusfile.close()
if action != 'start' and action != 'addnewlist':
control = open(myconfig['basedir'] + 'control', 'w')
if os.path.exists(myconfig['basedir']) and action == 'start' and status != 'paused':
# Do not start Oyster multiple times
return
# Someone wants to start a paused oyster
if action == 'start' and status == 'paused':
control = open(myconfig['basedir'] + 'control', 'w')
if action[:12] == 'changerandom':
nextskip = int(action[12:])
filenum = -1
allnextfiles = open(myconfig['basedir'] + 'nextfile', 'r')
nextfiles = allnextfiles.readlines()
allnextfiles.close()
while nextskip > -1:
if nextfiles[nextskip].rstrip() == mediadir + filename:
filenum = nextskip
break
else:
nextskip -= 1
if filenum > -1:
control.write("CHANGERANDOM " + str(filenum) + "\n")
control.close()
time.sleep(1)
elif action[:9] == 'delrandom':
nextskip = int(action[9:])
filenum = -1
allnextfiles = open(myconfig['basedir'] + 'nextfile', 'r')
nextfiles = allnextfiles.readlines()
allnextfiles.close()
while nextskip > -1:
if nextfiles[nextskip].rstrip() == mediadir + filename:
filenum = nextskip
break
else:
nextskip -= 1
if filenum > -1:
control.write("DELRANDOM " + str(filenum) + "\n")
control.close()
time.sleep(1)
elif action == 'next':
control.write("NEXT\n")
control.close()
time.sleep(4)
elif action == 'prev':
control.write("PREV\n")
control.close()
time.sleep(4)
elif action == 'start':
if status == 'paused':
control.write("PAUSE\n")
control.close()
time.sleep(4)
else:
os.system('python oyster.py &')
waitmax = 100
while waitmax > 0:
if os.path.isfile(myconfig['basedir'] + 'info'):
waitmax = 0
else:
time.sleep (1)
waitmax = waitmax - 1
elif action == 'stop':
control.write("QUIT\n")
control.close()
elif action == 'pause':
control.write("PAUSE\n")
control.close()
elif action == 'scoreup' and filename:
control.write("SCORE + " + mediadir + filename + "\n")
control.close()
elif action == 'scoredown' and filename:
control.write("SCORE - " + mediadir + filename + "\n")
control.close()
elif action == 'unvote' and filename:
control.write("UNVOTE " + mediadir + filename + "\n")
control.close()
elif action == 'loadlist' and filename:
control.write("LOAD " + filename + "\n")
control.close()
elif action == 'enqueue' and filename:
filename = filename[1:]
control.write("ENQUEUE " + myconfig['mediadir'] + filename + "\n")
control.close()
elif action == 'addnewlist' and filename:
filename = os.path.basename(filename)
if not os.path.exists(myconfig['savedir'] + "lists/" + filename):
newlist = open(myconfig['savedir'] + "lists/" + filename, 'w')
newlist.close()
newlist = open(myconfig['savedir'] + "logs/" + filename, 'w')
newlist.close()
elif action == 'delete' and filename:
filename = os.path.basename(filename)
for dirname in ['blacklists/', 'lists/', 'logs/', 'scores/']:
if os.path.exists(myconfig['savedir'] + dirname + filename):
os.unlink(myconfig['savedir'] + dirname + filename)
elif action == 'favmode':
control.write("FAVMODE\n")
control.close()
elif action == 'nofavmode':
control.write("NOFAVMODE\n")
control.close()
elif action.startswith('vol'):
if action == 'voldown':
control.write("VOLDOWN\n")
elif action == 'volup':
control.write("VOLUP\n")
elif action.startswith('volset'):
control.write("VOLSET " + action[7:] + "\n")
control.close()
def do_vote(votefile):
"""
Votes a single file
"""
votefile = myconfig['mediadir'] + votefile[1:]
control = open(myconfig['basedir'] + "control",'w')
control.write("VOTE " + votefile + "\n")
control.close()
time.sleep(1)
def do_votelist(votelist):
"""
Enqueues a complete playlist in m3u-format
"""
votelist = myconfig['mediadir'] + votelist[1:]
control = open(myconfig['basedir'] + "control", 'w')
control.write("ENQLIST " + votelist + "\n")
control.close()
time.sleep(1)