refactor
This commit is contained in:
parent
4c3a6a8c2d
commit
7fec0d2dae
5 changed files with 139 additions and 115 deletions
|
@ -3,7 +3,7 @@ if [ "x$1" == "xupdate" ]; then
|
||||||
shift
|
shift
|
||||||
exec python3 -m cdoseaplay.update $@
|
exec python3 -m cdoseaplay.update $@
|
||||||
else
|
else
|
||||||
shift
|
if [ "x$1" == "xautostart" ]; then
|
||||||
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
|
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
|
||||||
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
||||||
gsettings set org.gnome.desktop.session idle-delay 0
|
gsettings set org.gnome.desktop.session idle-delay 0
|
||||||
|
@ -13,9 +13,12 @@ else
|
||||||
gsettings set org.gnome.desktop.background primary-color '#888888'
|
gsettings set org.gnome.desktop.background primary-color '#888888'
|
||||||
gsettings set org.gnome.desktop.background secondary-color '#888888'
|
gsettings set org.gnome.desktop.background secondary-color '#888888'
|
||||||
gsettings set org.gnome.desktop.background picture-options 'none'
|
gsettings set org.gnome.desktop.background picture-options 'none'
|
||||||
|
shift
|
||||||
|
fi
|
||||||
if [ "x$1" == "xsync" ]; then
|
if [ "x$1" == "xsync" ]; then
|
||||||
exec python3 -m cdoseaplay.sync $@
|
shift
|
||||||
|
exec python3 -m cdoseaplay.sync "$@"
|
||||||
else
|
else
|
||||||
exec python3 -m cdoseaplay.play $@
|
exec python3 -m cdoseaplay.play "$@"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
8
cdosea-play.desktop
Normal file
8
cdosea-play.desktop
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Exec=cdosea-play autostart
|
||||||
|
Hidden=false
|
||||||
|
NoDisplay=false
|
||||||
|
X-GNOME-Autostart-enabled=true
|
||||||
|
Name=cdosea-play
|
||||||
|
Comment=
|
|
@ -1,26 +1,15 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
import argparse
|
||||||
|
from glob import glob
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from glob import glob
|
|
||||||
import datetime
|
|
||||||
import time
|
|
||||||
import string
|
|
||||||
import random
|
|
||||||
|
|
||||||
import ox
|
from .utils import update_playlist, get_player
|
||||||
from . import mpv
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger('cdosea')
|
||||||
|
|
||||||
def my_log(loglevel, component, message):
|
player = None
|
||||||
print('[{}] {}: {}'.format(loglevel, component, message))
|
|
||||||
|
|
||||||
|
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
os.chdir(base)
|
|
||||||
player = mpv.MPV(log_handler=my_log, input_default_bindings=True, input_vo_keyboard=True)
|
|
||||||
#player.observe_property('time-pos', lambda pos: print('Now playing at {:.2f}s'.format(pos)))
|
|
||||||
player.fullscreen = True
|
|
||||||
player.loop = 'inf'
|
|
||||||
|
|
||||||
def q_binding(*args):
|
def q_binding(*args):
|
||||||
global player
|
global player
|
||||||
|
@ -28,37 +17,31 @@ def q_binding(*args):
|
||||||
del player
|
del player
|
||||||
|
|
||||||
|
|
||||||
player.register_key_binding('q', q_binding)
|
def main():
|
||||||
|
global player
|
||||||
playlist = os.path.expanduser('~/Videos/cdosea.m3u')
|
playlist = os.path.expanduser('~/Videos/cdosea.m3u')
|
||||||
prefix = os.path.expanduser('~/Videos/CDOSEA')
|
prefix = os.path.expanduser('~/Videos/CDOSEA')
|
||||||
|
|
||||||
today = datetime.date.today()
|
parser = argparse.ArgumentParser(description='play 2 screens in sync')
|
||||||
seconds_since_midnight = time.time() - time.mktime(today.timetuple())
|
parser.add_argument('--playlist', help='play.m3u', default=playlist)
|
||||||
|
parser.add_argument('--prefix', help='video location', default=prefix)
|
||||||
|
parser.add_argument('--window', action='store_true', help='run in window', default=False)
|
||||||
|
parser.add_argument('--debug', action='store_true', help='debug', default=False)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
files = []
|
DEBUG = args.debug
|
||||||
videos = {}
|
if DEBUG:
|
||||||
for letter in string.ascii_uppercase:
|
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
|
||||||
videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower()))
|
logging.basicConfig(level=logging.DEBUG, format=log_format)
|
||||||
random.shuffle(videos[letter])
|
base = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
os.chdir(base)
|
||||||
|
|
||||||
for i in range(10):
|
player = get_player()
|
||||||
for letter in string.ascii_uppercase:
|
player.register_key_binding('q', q_binding)
|
||||||
files.append(videos[letter][i])
|
|
||||||
|
|
||||||
position = 0
|
update_playlist(args.playlist, args.prefix)
|
||||||
while position < seconds_since_midnight:
|
player.loadlist(args.playlist)
|
||||||
f = files.pop(0)
|
|
||||||
try:
|
|
||||||
position += ox.avinfo(f)['duration']
|
|
||||||
files.append(f)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
with open(playlist, 'w') as f:
|
|
||||||
f.write('\n'.join(files))
|
|
||||||
|
|
||||||
player.loadlist(playlist)
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
player.wait_for_playback()
|
player.wait_for_playback()
|
||||||
|
@ -66,3 +49,6 @@ while True:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
del player
|
del player
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
|
@ -13,8 +13,7 @@ from queue import Queue
|
||||||
from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler
|
from socketserver import UDPServer, ThreadingMixIn, BaseRequestHandler
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import ox
|
from .utils import mpv_log, update_playlist
|
||||||
import mpv
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger('cdosea')
|
logger = logging.getLogger('cdosea')
|
||||||
|
@ -22,45 +21,6 @@ logger = logging.getLogger('cdosea')
|
||||||
DEFAULT_PORT = 2680
|
DEFAULT_PORT = 2680
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
|
||||||
def update_playlist(playlist, prefix='video/', position=None):
|
|
||||||
playlist = os.path.expanduser('~/Videos/cdosea.m3u')
|
|
||||||
prefix = os.path.expanduser('~/Videos/CDOSEA')
|
|
||||||
|
|
||||||
files = []
|
|
||||||
videos = {}
|
|
||||||
for letter in string.ascii_uppercase:
|
|
||||||
videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower()))
|
|
||||||
random.shuffle(videos[letter])
|
|
||||||
|
|
||||||
for i in range(10):
|
|
||||||
for letter in string.ascii_uppercase:
|
|
||||||
files.append(videos[letter][i])
|
|
||||||
|
|
||||||
if position is None:
|
|
||||||
today = datetime.date.today()
|
|
||||||
seconds_since_midnight = time.time() - time.mktime(today.timetuple())
|
|
||||||
offset = 0
|
|
||||||
position = 0
|
|
||||||
|
|
||||||
while offset < seconds_since_midnight:
|
|
||||||
f = files.pop(0)
|
|
||||||
try:
|
|
||||||
offset += ox.avinfo(f)['duration']
|
|
||||||
files.append(f)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
position += 1
|
|
||||||
else:
|
|
||||||
pos = position
|
|
||||||
while pos:
|
|
||||||
f = files.pop(0)
|
|
||||||
files.append(f)
|
|
||||||
pos -= 1
|
|
||||||
|
|
||||||
with open(playlist, 'w') as f:
|
|
||||||
f.write('\n'.join(files))
|
|
||||||
f.write('\n')
|
|
||||||
return position, len(files)
|
|
||||||
|
|
||||||
def trigger_lights(path):
|
def trigger_lights(path):
|
||||||
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
|
cmd = ['python3', '-m', 'cdoseaplay.lights', path]
|
||||||
|
@ -99,9 +59,10 @@ class Player(Thread):
|
||||||
current = ''
|
current = ''
|
||||||
playlist_items = 260
|
playlist_items = 260
|
||||||
|
|
||||||
def __init__(self, peer, player, playlist, lights=False):
|
def __init__(self, peer, player, playlist, prefix, lights=False):
|
||||||
self.peer = peer
|
self.peer = peer
|
||||||
self.playlist = playlist
|
self.playlist = playlist
|
||||||
|
self.prefix = prefix
|
||||||
self.player = player
|
self.player = player
|
||||||
self.lights = lights
|
self.lights = lights
|
||||||
self.queue = Queue()
|
self.queue = Queue()
|
||||||
|
@ -111,7 +72,7 @@ class Player(Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger.debug("update playlist")
|
logger.debug("update playlist")
|
||||||
self.position, self.playlist_items = update_playlist(self.playlist, position=self.get_position())
|
self.position, self.playlist_items = update_playlist(self.playlist, self.prefix, position=self.get_position())
|
||||||
logger.debug("load playlist")
|
logger.debug("load playlist")
|
||||||
self.player.loadlist(self.playlist)
|
self.player.loadlist(self.playlist)
|
||||||
self.player.pause = True
|
self.player.pause = True
|
||||||
|
@ -160,14 +121,15 @@ class Player(Thread):
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
|
|
||||||
def my_log(loglevel, component, message):
|
|
||||||
logger.debug('[{}] {}: {}'.format(loglevel, component, message))
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
playlist = os.path.expanduser('~/Videos/cdosea.m3u')
|
||||||
|
prefix = os.path.expanduser('~/Videos/CDOSEA')
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='play 2 screens in sync')
|
parser = argparse.ArgumentParser(description='play 2 screens in sync')
|
||||||
parser.add_argument('--peer', help='ip[:port] of peer', required=True)
|
parser.add_argument('--peer', help='ip[:port] of peer', required=True)
|
||||||
parser.add_argument('--port', type=int, help='local port', default=DEFAULT_PORT)
|
parser.add_argument('--port', type=int, help='local port', default=DEFAULT_PORT)
|
||||||
parser.add_argument('--playlist', help='play.m3u', default='play.m3u')
|
parser.add_argument('--playlist', help='play.m3u', default=playlist)
|
||||||
|
parser.add_argument('--prefix', help='video location', default=prefix)
|
||||||
parser.add_argument('--window', action='store_true', help='run in window', default=False)
|
parser.add_argument('--window', action='store_true', help='run in window', default=False)
|
||||||
parser.add_argument('--debug', action='store_true', help='debug', default=False)
|
parser.add_argument('--debug', action='store_true', help='debug', default=False)
|
||||||
parser.add_argument('--lights', action='store_true', help='lights', default=False)
|
parser.add_argument('--lights', action='store_true', help='lights', default=False)
|
||||||
|
@ -188,16 +150,10 @@ def main():
|
||||||
if args.lights:
|
if args.lights:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# 42 max
|
player = get_player(fullscreen=not args.window)
|
||||||
player = mpv.MPV(
|
|
||||||
log_handler=my_log, input_default_bindings=True,
|
|
||||||
input_vo_keyboard=True, sub_text_font_size=28, sub_text_font='Menlo'
|
|
||||||
)
|
|
||||||
player.fullscreen = not args.window
|
|
||||||
player.loop = 'inf'
|
|
||||||
|
|
||||||
server = ThreadingUDPServer(('0.0.0.0', args.port), Handler)
|
server = ThreadingUDPServer(('0.0.0.0', args.port), Handler)
|
||||||
server.player = Player(peer, player, args.playlist, args.lights)
|
server.player = Player(peer, player, args.playlist, args.prefix, args.lights)
|
||||||
player.register_key_binding('q', server.q_binding)
|
player.register_key_binding('q', server.q_binding)
|
||||||
|
|
||||||
logger.debug("listen on %s...", args.port)
|
logger.debug("listen on %s...", args.port)
|
||||||
|
|
71
cdoseaplay/utils.py
Normal file
71
cdoseaplay/utils.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from glob import glob
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
|
||||||
|
import ox
|
||||||
|
|
||||||
|
from . import mpv
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger('cdosea')
|
||||||
|
|
||||||
|
def mpv_log(loglevel, component, message):
|
||||||
|
logger.info('[{}] {}: {}'.format(loglevel, component, message))
|
||||||
|
|
||||||
|
def get_player(fullscreen=True):
|
||||||
|
# 42 max
|
||||||
|
player = mpv.MPV(
|
||||||
|
log_handler=mpv_log, input_default_bindings=True,
|
||||||
|
input_vo_keyboard=True, sub_text_font_size=28, sub_text_font='Menlo'
|
||||||
|
)
|
||||||
|
#player.observe_property('time-pos', lambda pos: print('Now playing at {:.2f}s'.format(pos)))
|
||||||
|
player.fullscreen = fullscreen
|
||||||
|
player.loop = 'inf'
|
||||||
|
|
||||||
|
return player
|
||||||
|
|
||||||
|
def update_playlist(playlist, prefix, position=None):
|
||||||
|
|
||||||
|
files = []
|
||||||
|
videos = {}
|
||||||
|
if not prefix.endswith('/'):
|
||||||
|
prefix += '/'
|
||||||
|
for letter in string.ascii_uppercase:
|
||||||
|
videos[letter] = glob('%s%s*.mp4' % (prefix, letter.lower()))
|
||||||
|
random.shuffle(videos[letter])
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
for letter in string.ascii_uppercase:
|
||||||
|
files.append(videos[letter][i])
|
||||||
|
|
||||||
|
if position is None:
|
||||||
|
today = datetime.date.today()
|
||||||
|
seconds_since_midnight = time.time() - time.mktime(today.timetuple())
|
||||||
|
offset = 0
|
||||||
|
position = 0
|
||||||
|
|
||||||
|
while offset < seconds_since_midnight:
|
||||||
|
f = files.pop(0)
|
||||||
|
try:
|
||||||
|
offset += ox.avinfo(f)['duration']
|
||||||
|
files.append(f)
|
||||||
|
except:
|
||||||
|
logger.debug('WTF', exc_info=True)
|
||||||
|
pass
|
||||||
|
position += 1
|
||||||
|
else:
|
||||||
|
pos = position
|
||||||
|
while pos:
|
||||||
|
f = files.pop(0)
|
||||||
|
files.append(f)
|
||||||
|
pos -= 1
|
||||||
|
|
||||||
|
with open(playlist, 'w') as f:
|
||||||
|
f.write('\n'.join(files))
|
||||||
|
f.write('\n')
|
||||||
|
return position, len(files)
|
||||||
|
|
Loading…
Reference in a new issue