trigger lights
This commit is contained in:
parent
64718a7c61
commit
02b06c6581
7 changed files with 100 additions and 29 deletions
|
@ -1,16 +1,17 @@
|
|||
import os
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
base = 'https://cdosea.0x2620.org/static/render/'
|
||||
lang = '1080p'
|
||||
start = ''
|
||||
lights = False
|
||||
|
||||
|
||||
conf = os.path.expanduser('~/.config/cdosea.json')
|
||||
if os.path.exists(conf):
|
||||
with open(conf) as fd:
|
||||
config = json.load(fd)
|
||||
if 'lang' in config:
|
||||
lang = config['lang']
|
||||
if 'base' in config:
|
||||
base = config['base']
|
||||
if 'start' in config:
|
||||
start = config['start']
|
||||
_this = sys.modules[__name__]
|
||||
for key in config:
|
||||
setattr(_this, key, config[key])
|
||||
|
|
|
@ -5,22 +5,67 @@ import os
|
|||
import time
|
||||
|
||||
import ox
|
||||
from pi import random
|
||||
import lanbox
|
||||
|
||||
from .pi import random
|
||||
|
||||
|
||||
# Screen 1-5, Control, 6,7
|
||||
'''
|
||||
> _*10 patterns / cues that correspond to 10 digit:*_
|
||||
> 0 = Screen LED @ 100% fade time = 9s (cue list 1)
|
||||
> 1 = LED Control @ 10% fade time = 8s (cue list 2)
|
||||
> 2 = LED Control @ 20% fade time = 7s (cue list 3)
|
||||
> 3 = LED Control @ 30% fade time = 6s (cue list 4)
|
||||
> 4 = LED Control @ 40% fade time = 5s (cue list 5)
|
||||
> 5 = LED Control @ 50% fade time = 4s (cue List 6)
|
||||
> 6 = LED Control @ 60% fade time = 3s (cue list 7)
|
||||
> 7 = LED Control @ 70% fade time = 2s (cue list 8)
|
||||
> 8 = LED Control @ 80% fade time = 1s (cue list 9)
|
||||
> 9 = LED Control @ 90% fade time = 0s (cue list 10)
|
||||
'''
|
||||
def channels(screen, control):
|
||||
screen = int(screen * 255)
|
||||
control = int(control * 255)
|
||||
return {'1': screen, '2': screen, '3': screen, '4': screen, '5': screen, '6': control, '7': control}
|
||||
|
||||
|
||||
LIGHTS = {
|
||||
0: (channels(1, 0.0), 9),
|
||||
1: (channels(0, 0.1), 8),
|
||||
2: (channels(0, 0.2), 7),
|
||||
3: (channels(0, 0.3), 6),
|
||||
4: (channels(0, 0.4), 5),
|
||||
5: (channels(0, 0.5), 4),
|
||||
6: (channels(0, 0.6), 3),
|
||||
7: (channels(0, 0.7), 2),
|
||||
8: (channels(0, 0.8), 1),
|
||||
9: (channels(0, 0.9), 0.1),
|
||||
}
|
||||
|
||||
|
||||
def switch(state):
|
||||
lights, fade = LIGHTS[state]
|
||||
lb = lanbox.LanboxMethods()
|
||||
#lb.getChannels(lights)
|
||||
lb.fadeTo(lights, fade)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
path = sys.argv[1]
|
||||
|
||||
n = int(os.path.getctime(path) - 1495280000)
|
||||
duration = ox.avinfo(path)['duration']
|
||||
info = ox.avinfo(path)
|
||||
duration = info.get('duration', 0)
|
||||
|
||||
seq = random(n * 1000)
|
||||
pos = 0
|
||||
lights = []
|
||||
while pos < duration - 15:
|
||||
sleep = seq() + 15
|
||||
light = seq() + 1
|
||||
light = seq()
|
||||
if pos + sleep > duration:
|
||||
break
|
||||
time.sleep(sleep)
|
||||
cmd = ['/opt/LanBox-JSONRPC/fade.py', str(light)]
|
||||
subprocess.Popen(cmd)
|
||||
switch(light)
|
||||
pos += sleep
|
||||
|
|
20
cdoseaplay/pi.py
Normal file
20
cdoseaplay/pi.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from mpmath import mp
|
||||
mp.dps = 10000
|
||||
PI = str(mp.pi).replace('.', '')
|
||||
|
||||
class random(object):
|
||||
PI = str(mp.pi).replace('.', '')
|
||||
|
||||
def __init__(self, offset=0):
|
||||
self.position = offset
|
||||
self.numbers = list(map(int, self.PI[offset:]))
|
||||
|
||||
def __call__(self):
|
||||
if not self.numbers:
|
||||
offset = mp.dps
|
||||
mp.dps += 1000
|
||||
self.PI = str(mp.pi).replace('.', '')
|
||||
self.numbers = list(map(int, self.PI[offset:]))
|
||||
self.position += 1
|
||||
return self.numbers.pop(0)
|
||||
|
|
@ -4,7 +4,7 @@ from glob import glob
|
|||
import os
|
||||
import sys
|
||||
|
||||
from .utils import update_playlist, get_player
|
||||
from .utils import update_playlist, get_player, trigger_lights
|
||||
from .subtitleserver import SubtitleServer
|
||||
from . import config
|
||||
|
||||
|
@ -57,6 +57,8 @@ def main():
|
|||
player.pause = True
|
||||
|
||||
while True:
|
||||
if config.lights and player.path:
|
||||
trigger_lights(player.path.decode())
|
||||
try:
|
||||
player.wait_for_playback()
|
||||
except:
|
||||
|
|
|
@ -13,7 +13,7 @@ from queue import Queue
|
|||
from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler
|
||||
from threading import Thread
|
||||
|
||||
from .utils import mpv_log, update_playlist
|
||||
from .utils import mpv_log, update_playlist, trigger_lights
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger('cdosea')
|
||||
|
@ -22,10 +22,6 @@ DEFAULT_PORT = 2680
|
|||
DEBUG = False
|
||||
|
||||
|
||||
def trigger_lights(path):
|
||||
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
|
||||
subprocess.Popen(cmd)
|
||||
|
||||
class ThreadingUDPServer(ThreadingMixIn, UDPServer):
|
||||
pass
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import datetime
|
|||
import time
|
||||
import string
|
||||
import random
|
||||
import subprocess
|
||||
|
||||
import ox
|
||||
|
||||
|
@ -78,3 +79,7 @@ def update_playlist(playlist, prefix, position=None, shift=True):
|
|||
f.write('\n'.join(files))
|
||||
f.write('\n')
|
||||
return position, len(files)
|
||||
|
||||
def trigger_lights(path):
|
||||
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
|
||||
subprocess.Popen(cmd)
|
||||
|
|
2
setup.py
2
setup.py
|
@ -18,6 +18,8 @@ setup(
|
|||
'ox >= 2.1.541,<3',
|
||||
'requests >= 1.1.0',
|
||||
'tornado',
|
||||
'mpmath',
|
||||
'lanbox',
|
||||
],
|
||||
keywords=[],
|
||||
classifiers=[
|
||||
|
|
Loading…
Reference in a new issue