From 34f447b42dfb3b4dbd3b2c0915580481745a6d8b Mon Sep 17 00:00:00 2001 From: j Date: Thu, 12 Oct 2017 18:45:57 +0200 Subject: [PATCH] use config to play from a/show title --- cdoseaplay/config.py | 16 ++++++++++++++++ cdoseaplay/play.py | 8 +++++--- cdoseaplay/update.py | 13 ++----------- 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 cdoseaplay/config.py diff --git a/cdoseaplay/config.py b/cdoseaplay/config.py new file mode 100644 index 0000000..f09ac61 --- /dev/null +++ b/cdoseaplay/config.py @@ -0,0 +1,16 @@ +import os +import json + +base = 'https://cdosea.0x2620.org/static/render/' +lang = '1080p' +start = '' +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'] diff --git a/cdoseaplay/play.py b/cdoseaplay/play.py index ac2f46a..1a356c5 100755 --- a/cdoseaplay/play.py +++ b/cdoseaplay/play.py @@ -6,6 +6,7 @@ import sys from .utils import update_playlist, get_player from .subtitleserver import SubtitleServer +from . import config import logging logger = logging.getLogger('cdosea') @@ -28,9 +29,10 @@ def main(): 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) - parser.add_argument('-a', '--always-a', action='store_true', help='start from A', default=False) args = parser.parse_args() + shift = config.start != 'a' + DEBUG = args.debug if DEBUG: log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s' @@ -47,10 +49,10 @@ def main(): player.pause = True player.register_key_binding('r', restart) - update_playlist(args.playlist, args.prefix, shift=not args.always_a) + update_playlist(args.playlist, args.prefix, shift=shift) sub = SubtitleServer(player, args.playlist) player.loadlist(args.playlist) - if args.always_a: + if not shift: player.pause = True while True: diff --git a/cdoseaplay/update.py b/cdoseaplay/update.py index fd243e1..d2c5f04 100755 --- a/cdoseaplay/update.py +++ b/cdoseaplay/update.py @@ -13,7 +13,8 @@ import ox socket.setdefaulttimeout(10) -base = 'https://cdosea.0x2620.org/static/render/' +from .config import base, lang + lock = '/tmp/update.lock' prefix = os.path.expanduser('~/Videos/CDOSEA') @@ -21,16 +22,6 @@ if not os.path.exists(prefix): os.makedirs(prefix) os.chdir(prefix) -lang = '1080p' -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'] - def get_subtitle(url, name): try: r = requests.get(url)