File tree 1 file changed +36
-5
lines changed
1 file changed +36
-5
lines changed Original file line number Diff line number Diff line change 1
1
import sys
2
+ import argparse
3
+ import subprocess
4
+ import urllib
2
5
sys .path .append ('../' ) # Just to make the GIT source more cleaner without creating a module. In YOUR project you DON'T have to do that
3
6
from extended_BaseHTTPServer import serve ,route
4
7
5
- @route ("/" ,["GET" ])
6
- def main (** kwargs ):
7
- return "TODO"
8
+ current_playing = []
8
9
10
+ @route ("/play" ,["GET" ])
11
+ def play (file = "" ):
12
+ if current_playing :
13
+ current_playing .pop ().kill ()
9
14
10
- if __name__ == '__main__' :
11
- serve (ip = "0.0.0.0" , port = 5000 )
15
+ try :
16
+ current_playing .append (subprocess .Popen ("{0} '{1}' vlc://quit" .format (args .player , file [0 ]), shell = True ))
17
+ return "{'stream':true}"
18
+ except :
19
+ return "{'stream':false}"
20
+
21
+ @route ("/stop" ,["GET" ])
22
+ def stop ():
23
+ if current_playing :
24
+ current_playing .pop ().kill ()
25
+ return "{'stop':true}"
26
+
27
+ @route ("/say" ,["GET" ])
28
+ def say (text = "Bonjour" ):
29
+ try :
30
+ url = "http://translate.google.com/translate_tts?tl=fr&q={0}" .format (urllib .quote (text [0 ]))
31
+ current_playing .append (subprocess .Popen ("{0} '{1}' vlc://quit" .format (args .player , url ), shell = True ))
32
+ return "{'say':true}"
33
+ except :
34
+ return "{'say':false}"
35
+
36
+
37
+ parser = argparse .ArgumentParser (description = 'Simple Nabz.' )
38
+ parser .add_argument ('--player' , action = 'store' ,help = 'Path to VLC command line (/usr/bin/cvlc)' )
39
+ args = parser .parse_args ()
40
+
41
+
42
+ serve (ip = "0.0.0.0" , port = 5000 )
You can’t perform that action at this time.
0 commit comments