-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathriddim.py
More file actions
executable file
·65 lines (58 loc) · 2.22 KB
/
riddim.py
File metadata and controls
executable file
·65 lines (58 loc) · 2.22 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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
import codecs
from multiprocessing import Pool
from lib.args import Args
from lib.control import Control
from lib.playlist import Playlist
from lib.config import Config
from lib.util import init_worker
from lib.logger import log
# needed if LANG=en_US.UTF-8
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
def main():
args = Args()
if args.signal:
c = Control(args.port)
if args.signal == u"start" : c.start()
elif args.signal == u"stop" : c.stop()
elif args.signal == u"restart" : c.restart()
else:
pool = Pool(Config.pool_size, init_worker)
playlist = Playlist(args.port, pool)
if args.query :
try: print playlist.query()
except IOError: pass # don't puke if quitting less(1)
elif args.shuffle : print playlist.shuffle()
elif args.repeat : print playlist.repeat()
elif args.kontinue : print playlist.kontinue()
elif args.next_album : print playlist.next_album()
elif args.next_artist : print playlist.next_artist()
else:
limit_to_extensions = args.args_dict.get('extensions', None)
for action, arg in args.args_dict.items():
try:
print {
u"clear" : playlist.clear,
u"index" : playlist.index,
u"enqueue" : playlist.enqueue
}[ action ]( arg, limit_to_extensions )
except KeyError: pass
except KeyboardInterrupt:
pool.terminate()
pool.join()
# except Exception, e:
# import traceback
# traceback.print_exc()
# print 'e', e
# sys.stderr.write( str(e) )
else:
pool.close()
pool.join()
try: sys.stdout.close()
except: pass
try: sys.stderr.close()
except: pass
if __name__ == u"__main__":
main()