Skip to content

Commit eadf681

Browse files
committed
Ajout d'un exemple
Ajout d'un exemple tout simple.
1 parent d557b55 commit eadf681

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

SAMPLE/nabz.py

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11
import sys
2+
import argparse
3+
import subprocess
4+
import urllib
25
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
36
from extended_BaseHTTPServer import serve,route
47

5-
@route("/",["GET"])
6-
def main(**kwargs):
7-
return "TODO"
8+
current_playing = []
89

10+
@route("/play",["GET"])
11+
def play(file=""):
12+
if current_playing:
13+
current_playing.pop().kill()
914

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)

0 commit comments

Comments
 (0)