-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartCmd.py
75 lines (57 loc) · 1.87 KB
/
startCmd.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
__author__ = 'bison'
import os
import pychromecast
from pychromecast.controllers.media import MediaController
import time
if os.path.isfile('conf_local.py'):
import conf_local as conf
else:
import conf
#import subprocess
#proc = subprocess.Popen(['./startHttpServer.sh', conf.pathWithImages])
#tmp = input('wait')
#exit()
print('start discovery')
allCastNames = pychromecast.get_chromecasts_as_dict().keys()
allCasts = {}
print('end discovery')
if len(allCastNames) == 0:
raise Exception('NO CHROMECASTS FOUND!')
castIndex = {}
for castName in allCastNames:
cast = pychromecast.get_chromecast(friendly_name=castName)
allCasts[castName] = cast
castIndex[castName] = len(castIndex)
if conf.closeCurrentApp:
for castName, cast in allCasts.items():
cast.quit_app()
print(castIndex)
onlyfiles = []
soup = None
soupNext = None
if conf.imageSource == 'local':
onlyfiles = [ f for f in os.listdir(conf.pathWithImages) if os.path.isfile(os.path.join(conf.pathWithImages,f)) ]
elif conf.imageSource == 'soup':
import souper
soup = souper.souperDuper(conf.soup)
soupNext = soup.grabPart()
while True:
if soupNext != None:
soupNext.__next__()
onlyfiles = list(soup.knownUrls.keys())
from os import listdir
from os.path import isfile, join
import random
imgFile = random.choice(onlyfiles)
for castName, cast in allCasts.items():
if not castName in conf.blacklist:
castMc = cast.media_controller
mc = MediaController()
cast.register_handler(mc)
if conf.castmode == 'different':
imgFile = random.choice(onlyfiles)
if conf.imageSource == 'soup':
mc.play_media(imgFile, 'Image/jpg')
else:
mc.play_media('http://'+ conf.localIp +':8000/'+ imgFile, 'Image/jpg')
time.sleep(conf.showImageTime)