1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00
svtplay-dl/lib/svtplay_dl/__init__.py

79 lines
2.2 KiB
Python
Raw Normal View History

2013-03-23 15:02:41 +01:00
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
from __future__ import absolute_import, unicode_literals
2013-03-23 15:02:41 +01:00
import sys
import logging
2018-05-13 13:06:45 +02:00
from svtplay_dl.utils.parser import setup_defaults, parser, mergeparseroption
2018-01-30 22:11:35 +01:00
from svtplay_dl.utils.getmedia import get_media, get_multiple_media
2017-09-16 23:45:29 +02:00
from svtplay_dl.service.cmore import Cmore
2018-05-13 13:06:45 +02:00
2018-03-11 23:40:02 +01:00
__version__ = "1.9.11"
2013-03-23 15:02:41 +01:00
2018-03-13 00:34:39 +01:00
log = logging.getLogger('svtplay_dl')
2013-03-23 15:02:41 +01:00
2018-01-30 20:11:37 +01:00
2014-01-05 16:30:45 +01:00
def setup_log(silent, verbose=False):
logging.addLevelName(25, "INFO")
2018-03-13 00:34:39 +01:00
fmt = '%(levelname)s: %(message)s'
2013-03-23 15:02:41 +01:00
if silent:
stream = sys.stderr
level = 25
2014-01-05 16:30:45 +01:00
elif verbose:
stream = sys.stderr
level = logging.DEBUG
2018-03-13 00:34:39 +01:00
fmt = '%(levelname)s [%(created)s] %(filename)s/%(funcName)s: %(message)s'
2013-03-23 15:02:41 +01:00
else:
stream = sys.stdout
level = logging.INFO
2018-03-13 00:34:39 +01:00
logging.basicConfig(level=level, format=fmt)
2013-03-23 15:02:41 +01:00
hdlr = logging.StreamHandler(stream)
2018-03-13 00:34:39 +01:00
log.addHandler(hdlr)
2013-03-23 15:02:41 +01:00
2015-09-15 20:10:32 +02:00
2013-03-23 15:02:41 +01:00
def main():
""" Main program """
2018-01-14 00:39:16 +01:00
parse, options = parser(__version__)
if options.require_subtitle:
if options.merge_subtitle:
options.merge_subtitle = True
else:
options.subtitle = True
if options.merge_subtitle:
options.remux = True
if options.silent_semi:
options.silent = True
2013-03-23 15:02:41 +01:00
2017-09-19 00:30:11 +02:00
if options.cmoreoperatorlist:
c = Cmore(options, None)
2017-09-19 00:30:11 +02:00
c.operatorlist()
sys.exit(0)
if options.proxy:
options.proxy = options.proxy.replace("socks5", "socks5h", 1)
options.proxy = dict(http=options.proxy,
https=options.proxy)
2013-03-23 18:26:48 +01:00
if options.flexibleq and not options.quality:
logging.error("flexible-quality requires a quality")
if len(options.urls) == 0:
parse.print_help()
sys.exit(0)
urls = options.urls
2018-05-13 13:06:45 +02:00
options = mergeparseroption(setup_defaults(), options)
if len(urls) < 1:
parse.error("Incorrect number of arguments")
2018-05-13 13:06:45 +02:00
setup_log(options.get("silent"), options.get("verbose"))
try:
if len(urls) == 1:
2018-01-14 00:49:26 +01:00
get_media(urls[0], options, __version__)
else:
get_multiple_media(urls, options)
except KeyboardInterrupt:
2014-05-02 12:06:53 +02:00
print("")