use config to play from a/show title

This commit is contained in:
j 2017-10-12 18:45:57 +02:00
parent 3529e01aba
commit 34f447b42d
3 changed files with 23 additions and 14 deletions

16
cdoseaplay/config.py Normal file
View file

@ -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']

View file

@ -6,6 +6,7 @@ import sys
from .utils import update_playlist, get_player from .utils import update_playlist, get_player
from .subtitleserver import SubtitleServer from .subtitleserver import SubtitleServer
from . import config
import logging import logging
logger = logging.getLogger('cdosea') logger = logging.getLogger('cdosea')
@ -28,9 +29,10 @@ def main():
parser.add_argument('--prefix', help='video location', default=prefix) 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('-a', '--always-a', action='store_true', help='start from A', default=False)
args = parser.parse_args() args = parser.parse_args()
shift = config.start != 'a'
DEBUG = args.debug DEBUG = args.debug
if DEBUG: if DEBUG:
log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s' log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
@ -47,10 +49,10 @@ def main():
player.pause = True player.pause = True
player.register_key_binding('r', restart) 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) sub = SubtitleServer(player, args.playlist)
player.loadlist(args.playlist) player.loadlist(args.playlist)
if args.always_a: if not shift:
player.pause = True player.pause = True
while True: while True:

View file

@ -13,7 +13,8 @@ import ox
socket.setdefaulttimeout(10) socket.setdefaulttimeout(10)
base = 'https://cdosea.0x2620.org/static/render/' from .config import base, lang
lock = '/tmp/update.lock' lock = '/tmp/update.lock'
prefix = os.path.expanduser('~/Videos/CDOSEA') prefix = os.path.expanduser('~/Videos/CDOSEA')
@ -21,16 +22,6 @@ if not os.path.exists(prefix):
os.makedirs(prefix) os.makedirs(prefix)
os.chdir(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): def get_subtitle(url, name):
try: try:
r = requests.get(url) r = requests.get(url)