Add files via upload
initial backend upload
This commit is contained in:
parent
2756a93231
commit
a71876c717
1 changed files with 68 additions and 0 deletions
68
csrv.py
Normal file
68
csrv.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
from twisted.web.static import File
|
||||||
|
from klein import run, route
|
||||||
|
from klein import Klein
|
||||||
|
import pychromecast
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
app = Klein()
|
||||||
|
|
||||||
|
chromecasts = pychromecast.get_chromecasts()
|
||||||
|
[cc.device.friendly_name for cc in chromecasts]
|
||||||
|
cast = next(cc for cc in chromecasts if cc.device.friendly_name == "living room")
|
||||||
|
cast.wait()
|
||||||
|
print(cast.status) # Has display name and status text
|
||||||
|
mc = cast.media_controller
|
||||||
|
|
||||||
|
@route('/movies/', branch=True)
|
||||||
|
def static(request):
|
||||||
|
return File("./movies")
|
||||||
|
|
||||||
|
@route('/devices/')
|
||||||
|
def dlist(request):
|
||||||
|
|
||||||
|
return mc
|
||||||
|
|
||||||
|
@route('/play/<fn>')
|
||||||
|
def crun(request,fn):
|
||||||
|
mc.play_media('http://192.168.1.158:8080/movies/' + fn, 'video/mp4')
|
||||||
|
mc.block_until_active()
|
||||||
|
mc.pause()
|
||||||
|
time.sleep(2)
|
||||||
|
mc.play()
|
||||||
|
return 'Play'
|
||||||
|
|
||||||
|
@route('/pause/')
|
||||||
|
def cpause(request):
|
||||||
|
mc.pause()
|
||||||
|
return 'Pause'
|
||||||
|
|
||||||
|
@route('/resume/')
|
||||||
|
def cres(request):
|
||||||
|
mc.play()
|
||||||
|
return 'Resuming'
|
||||||
|
|
||||||
|
@route('/stop/')
|
||||||
|
def cstop(request):
|
||||||
|
mc.stop()
|
||||||
|
return 'STOP!!!'
|
||||||
|
|
||||||
|
@route('/list/')
|
||||||
|
def clist(request):
|
||||||
|
path = './movies'
|
||||||
|
files = os.listdir\
|
||||||
|
(path)
|
||||||
|
e = []
|
||||||
|
d = {'data' : e }
|
||||||
|
for x in range(len(files)):
|
||||||
|
#e.append("movie")
|
||||||
|
e.append(files[x])
|
||||||
|
return json.dumps(d)
|
||||||
|
|
||||||
|
@route('/')
|
||||||
|
def home(request):
|
||||||
|
return 'Welcome to the RPI Python based Chromecast Media Service! Please use the HTTP API!'
|
||||||
|
|
||||||
|
run("192.168.1.158", 8080)
|
Loading…
Add table
Add a link
Reference in a new issue