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 -*-
|
|
|
|
import logging
|
2019-08-25 00:40:39 +02:00
|
|
|
import sys
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2019-08-25 00:40:39 +02:00
|
|
|
import yaml
|
2017-09-16 23:45:29 +02:00
|
|
|
from svtplay_dl.service.cmore import Cmore
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.utils.getmedia import get_media
|
|
|
|
from svtplay_dl.utils.getmedia import get_multiple_media
|
|
|
|
from svtplay_dl.utils.parser import parser
|
|
|
|
from svtplay_dl.utils.parser import parsertoconfig
|
|
|
|
from svtplay_dl.utils.parser import setup_defaults
|
2015-01-28 18:26:50 +01:00
|
|
|
|
2018-07-10 21:32:54 +02:00
|
|
|
from .__version__ import get_versions
|
2019-08-25 00:27:31 +02:00
|
|
|
|
|
|
|
__version__ = get_versions()["version"]
|
2018-07-10 21:32:54 +02:00
|
|
|
del get_versions
|
|
|
|
|
2018-05-13 13:06:45 +02:00
|
|
|
|
2019-08-25 00:27:31 +02: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):
|
2016-05-04 14:16:59 +02:00
|
|
|
logging.addLevelName(25, "INFO")
|
2019-08-25 00:27:31 +02:00
|
|
|
fmt = "%(levelname)s: %(message)s"
|
2013-03-23 15:02:41 +01:00
|
|
|
if silent:
|
|
|
|
stream = sys.stderr
|
2016-05-04 14:16:59 +02:00
|
|
|
level = 25
|
2014-01-05 16:30:45 +01:00
|
|
|
elif verbose:
|
|
|
|
stream = sys.stderr
|
|
|
|
level = logging.DEBUG
|
2019-08-25 00:27:31 +02:00
|
|
|
fmt = "%(levelname)s [%(created)s] %(pathname)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():
|
2021-12-18 21:37:09 +01:00
|
|
|
"""Main program"""
|
2018-01-14 00:39:16 +01:00
|
|
|
parse, options = parser(__version__)
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2013-03-23 18:26:48 +01:00
|
|
|
if options.flexibleq and not options.quality:
|
2018-01-30 21:46:39 +01:00
|
|
|
logging.error("flexible-quality requires a quality")
|
2020-12-06 18:56:52 +01:00
|
|
|
if options.only_audio and options.only_video:
|
|
|
|
logging.error("Only use one of them, not both at the same time")
|
|
|
|
sys.exit(2)
|
2018-01-30 21:46:39 +01:00
|
|
|
|
|
|
|
if len(options.urls) == 0:
|
|
|
|
parse.print_help()
|
|
|
|
sys.exit(0)
|
|
|
|
urls = options.urls
|
2018-05-20 13:16:00 +02:00
|
|
|
config = parsertoconfig(setup_defaults(), options)
|
2018-01-30 21:46:39 +01:00
|
|
|
if len(urls) < 1:
|
|
|
|
parse.error("Incorrect number of arguments")
|
2018-05-20 13:16:00 +02:00
|
|
|
setup_log(config.get("silent"), config.get("verbose"))
|
|
|
|
|
2018-09-05 17:11:28 +02:00
|
|
|
if options.cmoreoperatorlist:
|
|
|
|
config = parsertoconfig(setup_defaults(), options)
|
|
|
|
c = Cmore(config, urls)
|
|
|
|
c.operatorlist()
|
|
|
|
sys.exit(0)
|
|
|
|
|
2014-04-02 19:32:35 +02:00
|
|
|
try:
|
2017-01-04 04:20:50 +01:00
|
|
|
if len(urls) == 1:
|
2018-05-20 13:16:00 +02:00
|
|
|
get_media(urls[0], config, __version__)
|
2017-01-04 04:20:50 +01:00
|
|
|
else:
|
2018-05-20 13:16:00 +02:00
|
|
|
get_multiple_media(urls, config)
|
2014-04-02 19:32:35 +02:00
|
|
|
except KeyboardInterrupt:
|
2014-05-02 12:06:53 +02:00
|
|
|
print("")
|
2018-05-20 18:21:40 +02:00
|
|
|
except (yaml.YAMLError, yaml.MarkedYAMLError) as e:
|
2021-12-18 21:36:16 +01:00
|
|
|
logging.error("Your settings file(s) contain invalid YAML syntax! Please fix and restart!, %s", str(e))
|
2018-05-20 18:21:40 +02:00
|
|
|
sys.exit(2)
|