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 -*-
|
2016-04-30 13:54:26 +02:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
2013-03-23 15:02:41 +01:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import logging
|
2014-02-18 18:56:28 +01:00
|
|
|
import copy
|
2018-01-14 22:23:58 +01:00
|
|
|
import re
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2014-02-09 15:40:02 +01:00
|
|
|
from svtplay_dl.error import UIException
|
2013-03-23 15:02:41 +01:00
|
|
|
from svtplay_dl.log import log
|
2018-01-13 20:27:40 +01:00
|
|
|
from svtplay_dl.utils import select_quality, list_quality, ensure_unicode
|
2018-01-14 00:39:16 +01:00
|
|
|
from svtplay_dl.utils.parser import parser, mergeparseroption
|
2013-03-23 16:11:36 +01:00
|
|
|
from svtplay_dl.service import service_handler, Generic
|
2014-04-21 20:05:36 +02:00
|
|
|
from svtplay_dl.fetcher import VideoRetriever
|
2014-08-19 15:21:27 +02:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
2015-04-30 11:02:18 +02:00
|
|
|
from svtplay_dl.output import filename
|
2016-03-22 22:36:39 +01:00
|
|
|
from svtplay_dl.postprocess import postprocess
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2017-09-01 20:53:04 +02:00
|
|
|
from svtplay_dl.service.aftonbladet import Aftonbladet, Aftonbladettv
|
2018-01-27 20:10:30 +01:00
|
|
|
from svtplay_dl.service.atg import Atg
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.bambuser import Bambuser
|
|
|
|
from svtplay_dl.service.bigbrother import Bigbrother
|
2017-09-16 23:45:29 +02:00
|
|
|
from svtplay_dl.service.cmore import Cmore
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.dbtv import Dbtv
|
|
|
|
from svtplay_dl.service.disney import Disney
|
2015-10-04 14:40:00 +02:00
|
|
|
from svtplay_dl.service.dplay import Dplay
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.dr import Dr
|
2015-07-05 21:08:11 +02:00
|
|
|
from svtplay_dl.service.efn import Efn
|
2018-02-12 00:55:51 +01:00
|
|
|
from svtplay_dl.service.eurosport import Eurosport
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.expressen import Expressen
|
2015-03-31 20:49:08 +02:00
|
|
|
from svtplay_dl.service.facebook import Facebook
|
2016-08-17 19:53:56 +02:00
|
|
|
from svtplay_dl.service.filmarkivet import Filmarkivet
|
2016-08-23 00:59:57 +02:00
|
|
|
from svtplay_dl.service.flowonline import Flowonline
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.hbo import Hbo
|
2015-08-24 18:40:59 +02:00
|
|
|
from svtplay_dl.service.twitch import Twitch
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.lemonwhale import Lemonwhale
|
2018-01-27 00:03:42 +01:00
|
|
|
from svtplay_dl.service.mtvnn import MtvMusic
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.mtvnn import Mtvnn
|
|
|
|
from svtplay_dl.service.mtvservices import Mtvservices
|
2017-02-18 21:13:01 +01:00
|
|
|
from svtplay_dl.service.nhl import NHL
|
2018-05-02 00:12:36 +02:00
|
|
|
from svtplay_dl.service.npo import Npo
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.nrk import Nrk
|
|
|
|
from svtplay_dl.service.oppetarkiv import OppetArkiv
|
|
|
|
from svtplay_dl.service.picsearch import Picsearch
|
2016-09-04 20:44:25 +02:00
|
|
|
from svtplay_dl.service.pokemon import Pokemon
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.qbrick import Qbrick
|
|
|
|
from svtplay_dl.service.radioplay import Radioplay
|
2016-09-02 01:20:54 +02:00
|
|
|
from svtplay_dl.service.riksdagen import Riksdagen
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.ruv import Ruv
|
|
|
|
from svtplay_dl.service.raw import Raw
|
2015-09-10 23:40:48 +02:00
|
|
|
from svtplay_dl.service.solidtango import Solidtango
|
2018-01-04 00:49:33 +01:00
|
|
|
from svtplay_dl.service.sportlib import Sportlib
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.sr import Sr
|
2017-05-08 00:14:05 +02:00
|
|
|
from svtplay_dl.service.svt import Svt
|
2018-01-08 20:38:20 +01:00
|
|
|
from svtplay_dl.service.barnkanalen import Barnkanalen
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.svtplay import Svtplay
|
|
|
|
from svtplay_dl.service.tv4play import Tv4play
|
|
|
|
from svtplay_dl.service.urplay import Urplay
|
|
|
|
from svtplay_dl.service.vg import Vg
|
|
|
|
from svtplay_dl.service.viaplay import Viaplay
|
2016-08-20 14:17:54 +02:00
|
|
|
from svtplay_dl.service.viasatsport import Viasatsport
|
2015-01-28 18:26:50 +01:00
|
|
|
from svtplay_dl.service.vimeo import Vimeo
|
|
|
|
from svtplay_dl.service.youplay import Youplay
|
|
|
|
|
2018-03-11 23:40:02 +01:00
|
|
|
__version__ = "1.9.11"
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2015-01-28 18:26:50 +01:00
|
|
|
sites = [
|
|
|
|
Aftonbladet,
|
2017-09-01 20:53:04 +02:00
|
|
|
Aftonbladettv,
|
2018-01-27 20:10:30 +01:00
|
|
|
Atg,
|
2015-01-28 18:26:50 +01:00
|
|
|
Bambuser,
|
2018-01-08 20:38:20 +01:00
|
|
|
Barnkanalen,
|
2015-01-28 18:26:50 +01:00
|
|
|
Bigbrother,
|
2017-09-16 23:45:29 +02:00
|
|
|
Cmore,
|
2015-01-28 18:26:50 +01:00
|
|
|
Dbtv,
|
|
|
|
Disney,
|
2015-10-04 14:40:00 +02:00
|
|
|
Dplay,
|
2015-01-28 18:26:50 +01:00
|
|
|
Dr,
|
2015-07-05 21:08:11 +02:00
|
|
|
Efn,
|
2018-02-12 00:55:51 +01:00
|
|
|
Eurosport,
|
2015-01-28 18:26:50 +01:00
|
|
|
Expressen,
|
2015-03-31 20:49:08 +02:00
|
|
|
Facebook,
|
2016-08-17 19:53:56 +02:00
|
|
|
Filmarkivet,
|
2016-08-23 00:59:57 +02:00
|
|
|
Flowonline,
|
2015-01-28 18:26:50 +01:00
|
|
|
Hbo,
|
2015-08-24 18:40:59 +02:00
|
|
|
Twitch,
|
2015-01-28 18:26:50 +01:00
|
|
|
Lemonwhale,
|
|
|
|
Mtvservices,
|
2018-01-27 00:03:42 +01:00
|
|
|
MtvMusic,
|
2015-01-28 18:26:50 +01:00
|
|
|
Mtvnn,
|
2017-02-18 21:13:01 +01:00
|
|
|
NHL,
|
2018-05-02 00:12:36 +02:00
|
|
|
Npo,
|
2015-01-28 18:26:50 +01:00
|
|
|
Nrk,
|
|
|
|
Qbrick,
|
|
|
|
Picsearch,
|
2016-09-04 20:44:25 +02:00
|
|
|
Pokemon,
|
2015-01-28 18:26:50 +01:00
|
|
|
Ruv,
|
|
|
|
Radioplay,
|
2015-09-10 23:40:48 +02:00
|
|
|
Solidtango,
|
2018-01-04 00:49:33 +01:00
|
|
|
Sportlib,
|
2015-01-28 18:26:50 +01:00
|
|
|
Sr,
|
2017-05-08 00:14:05 +02:00
|
|
|
Svt,
|
2015-01-28 18:26:50 +01:00
|
|
|
Svtplay,
|
|
|
|
OppetArkiv,
|
|
|
|
Tv4play,
|
|
|
|
Urplay,
|
|
|
|
Viaplay,
|
2016-08-20 14:17:54 +02:00
|
|
|
Viasatsport,
|
2015-01-28 18:26:50 +01:00
|
|
|
Vimeo,
|
|
|
|
Vg,
|
2016-08-23 00:59:57 +02:00
|
|
|
Youplay,
|
2016-09-02 01:20:54 +02:00
|
|
|
Riksdagen,
|
2016-08-23 00:59:57 +02:00
|
|
|
Raw]
|
2015-01-28 18:26:50 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-08-12 00:08:51 +02:00
|
|
|
class Options(object):
|
2013-03-23 15:02:41 +01:00
|
|
|
"""
|
|
|
|
Options used when invoking the script from another Python script.
|
|
|
|
|
|
|
|
Simple container class used when calling get_media() from another Python
|
|
|
|
script. The variables corresponds to the command line parameters parsed
|
|
|
|
in main() when the script is called directly.
|
|
|
|
|
|
|
|
When called from a script there are a few more things to consider:
|
|
|
|
|
|
|
|
* Logging is done to 'log'. main() calls setup_log() which sets the
|
|
|
|
logging to either stdout or stderr depending on the silent level.
|
|
|
|
A user calling get_media() directly can either also use setup_log()
|
|
|
|
or configure the log manually.
|
|
|
|
|
|
|
|
* Progress information is printed to 'progress_stream' which defaults to
|
|
|
|
sys.stderr but can be changed to any stream.
|
|
|
|
|
|
|
|
* Many errors results in calls to system.exit() so catch 'SystemExit'-
|
|
|
|
Exceptions to prevent the entire application from exiting if that happens.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.output = None
|
|
|
|
self.resume = False
|
|
|
|
self.live = False
|
2017-09-10 12:36:46 +02:00
|
|
|
self.capture_time = -1
|
2013-03-23 15:02:41 +01:00
|
|
|
self.silent = False
|
2014-02-09 15:40:02 +01:00
|
|
|
self.force = False
|
2013-12-11 17:22:46 +01:00
|
|
|
self.quality = 0
|
2017-01-28 12:10:50 +01:00
|
|
|
self.flexibleq = 0
|
2015-01-05 22:40:40 +01:00
|
|
|
self.list_quality = False
|
2013-03-23 15:02:41 +01:00
|
|
|
self.other = None
|
|
|
|
self.subtitle = False
|
|
|
|
self.username = None
|
|
|
|
self.password = None
|
2014-01-19 14:26:48 +01:00
|
|
|
self.thumbnail = False
|
2014-02-18 18:56:28 +01:00
|
|
|
self.all_episodes = False
|
2014-12-26 00:39:54 +01:00
|
|
|
self.all_last = -1
|
2016-06-20 18:33:42 +02:00
|
|
|
self.merge_subtitle = False
|
2014-03-21 20:59:58 +01:00
|
|
|
self.force_subtitle = False
|
2015-09-18 21:47:07 +02:00
|
|
|
self.require_subtitle = False
|
2016-05-09 15:10:58 +02:00
|
|
|
self.get_all_subtitles = False
|
|
|
|
self.get_raw_subtitles = False
|
|
|
|
self.convert_subtitle_colors = False
|
2014-05-01 17:13:46 +02:00
|
|
|
self.preferred = None
|
2014-08-11 21:00:19 +02:00
|
|
|
self.verbose = False
|
2014-08-11 21:24:35 +02:00
|
|
|
self.output_auto = False
|
2014-08-27 22:40:31 +02:00
|
|
|
self.service = None
|
2014-11-25 18:43:40 +01:00
|
|
|
self.cookies = None
|
2014-12-22 17:41:40 +01:00
|
|
|
self.exclude = None
|
2015-10-25 18:16:30 +01:00
|
|
|
self.get_url = False
|
2015-12-26 12:14:14 +01:00
|
|
|
self.ssl_verify = True
|
2015-12-26 13:38:36 +01:00
|
|
|
self.http_headers = None
|
2016-01-03 16:15:27 +01:00
|
|
|
self.stream_prio = None
|
2016-03-22 22:36:39 +01:00
|
|
|
self.remux = False
|
2016-05-04 14:16:59 +02:00
|
|
|
self.silent_semi = False
|
2018-01-09 23:33:21 +01:00
|
|
|
self.proxy = None
|
2018-01-20 11:31:43 +01:00
|
|
|
self.hls_time_stamp = False
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2018-01-14 00:31:00 +01:00
|
|
|
|
2017-01-04 04:20:50 +01:00
|
|
|
def get_multiple_media(urls, options):
|
|
|
|
if options.output and os.path.isfile(options.output):
|
|
|
|
log.error("Output must be a directory if used with multiple URLs")
|
|
|
|
sys.exit(2)
|
|
|
|
elif options.output and not os.path.exists(options.output):
|
|
|
|
try:
|
|
|
|
os.makedirs(options.output)
|
|
|
|
except OSError as e:
|
|
|
|
log.error("%s: %s", e.strerror, e.filename)
|
|
|
|
return
|
|
|
|
|
|
|
|
for url in urls:
|
2017-01-22 10:49:43 +01:00
|
|
|
get_media(url, copy.copy(options))
|
2017-01-04 04:20:50 +01:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2013-03-23 15:02:41 +01:00
|
|
|
def get_media(url, options):
|
2015-09-03 22:05:48 +02:00
|
|
|
if "http" not in url[:4]:
|
|
|
|
url = "http://%s" % url
|
2015-12-26 11:46:14 +01:00
|
|
|
|
2016-05-04 14:16:59 +02:00
|
|
|
if options.silent_semi:
|
|
|
|
options.silent = True
|
2017-11-24 21:49:37 +01:00
|
|
|
if options.verbose:
|
2018-01-30 20:11:37 +01:00
|
|
|
log.debug("version: {0}".format(__version__))
|
2015-12-26 11:46:14 +01:00
|
|
|
stream = service_handler(sites, options, url)
|
2013-09-04 15:02:58 +02:00
|
|
|
if not stream:
|
2015-12-26 11:46:14 +01:00
|
|
|
generic = Generic(options, url)
|
2015-09-06 16:03:26 +02:00
|
|
|
url, stream = generic.get(sites)
|
2013-03-23 15:02:41 +01:00
|
|
|
if not stream:
|
2018-02-11 21:04:13 +01:00
|
|
|
if re.search(".f4m", url) or re.search(".m3u8", url) or re.search(".mpd", url):
|
2015-12-26 11:46:14 +01:00
|
|
|
stream = Raw(options, url)
|
2015-01-28 19:00:31 +01:00
|
|
|
if not stream:
|
|
|
|
log.error("That site is not supported. Make a ticket or send a message")
|
|
|
|
sys.exit(2)
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2014-02-18 18:56:28 +01:00
|
|
|
if options.all_episodes:
|
2017-01-22 10:49:43 +01:00
|
|
|
get_all_episodes(stream, copy.copy(options), url)
|
2016-03-26 13:08:45 +01:00
|
|
|
else:
|
2017-01-22 10:49:43 +01:00
|
|
|
get_one_media(stream, copy.copy(options))
|
2016-03-26 13:08:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_all_episodes(stream, options, url):
|
|
|
|
if options.output and os.path.isfile(options.output):
|
|
|
|
log.error("Output must be a directory if used with --all-episodes")
|
|
|
|
sys.exit(2)
|
|
|
|
elif options.output and not os.path.exists(options.output):
|
|
|
|
try:
|
|
|
|
os.makedirs(options.output)
|
|
|
|
except OSError as e:
|
2016-04-03 19:06:45 +02:00
|
|
|
log.error("%s: %s", e.strerror, e.filename)
|
2014-12-25 23:55:53 +01:00
|
|
|
return
|
2014-02-18 18:56:28 +01:00
|
|
|
|
2016-03-26 13:08:45 +01:00
|
|
|
episodes = stream.find_all_episodes(options)
|
|
|
|
if episodes is None:
|
|
|
|
return
|
|
|
|
for idx, o in enumerate(episodes):
|
|
|
|
if o == url:
|
|
|
|
substream = stream
|
|
|
|
else:
|
2016-04-26 23:18:45 +02:00
|
|
|
substream = service_handler(sites, copy.copy(options), o)
|
2014-02-18 18:56:28 +01:00
|
|
|
|
2016-03-26 13:08:45 +01:00
|
|
|
log.info("Episode %d of %d", idx + 1, len(episodes))
|
2018-01-30 20:11:37 +01:00
|
|
|
log.info("Url: %s", o)
|
2016-03-26 13:08:45 +01:00
|
|
|
|
|
|
|
# get_one_media overwrites options.output...
|
|
|
|
get_one_media(substream, copy.copy(options))
|
2014-02-18 18:56:28 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-02-18 18:56:28 +01:00
|
|
|
def get_one_media(stream, options):
|
2015-04-30 11:02:18 +02:00
|
|
|
# Make an automagic filename
|
2015-12-26 11:46:14 +01:00
|
|
|
if not filename(stream):
|
2015-04-30 11:02:18 +02:00
|
|
|
return
|
2014-03-24 21:54:03 +01:00
|
|
|
|
2016-06-20 18:33:42 +02:00
|
|
|
if options.merge_subtitle:
|
|
|
|
from svtplay_dl.utils import which
|
|
|
|
if not which('ffmpeg'):
|
|
|
|
log.error("--merge-subtitle needs ffmpeg. Please install ffmpeg.")
|
|
|
|
log.info("https://ffmpeg.org/download.html")
|
|
|
|
sys.exit(2)
|
|
|
|
|
2014-04-21 20:05:36 +02:00
|
|
|
videos = []
|
|
|
|
subs = []
|
2016-06-20 20:22:11 +02:00
|
|
|
subfixes = []
|
2015-09-06 14:19:10 +02:00
|
|
|
error = []
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = stream.get()
|
2015-09-06 14:56:54 +02:00
|
|
|
try:
|
|
|
|
for i in streams:
|
|
|
|
if isinstance(i, VideoRetriever):
|
|
|
|
if options.preferred:
|
|
|
|
if options.preferred.lower() == i.name():
|
|
|
|
videos.append(i)
|
|
|
|
else:
|
2014-07-13 16:03:03 +02:00
|
|
|
videos.append(i)
|
2015-09-06 14:56:54 +02:00
|
|
|
if isinstance(i, subtitle):
|
|
|
|
subs.append(i)
|
|
|
|
if isinstance(i, Exception):
|
|
|
|
error.append(i)
|
|
|
|
except Exception as e:
|
|
|
|
if options.verbose:
|
2016-01-26 00:13:07 +01:00
|
|
|
raise
|
2015-09-06 14:56:54 +02:00
|
|
|
else:
|
2016-01-01 18:17:53 +01:00
|
|
|
log.error("svtplay-dl crashed")
|
|
|
|
log.error("Run again and add --verbose as an argument, to get more information")
|
|
|
|
log.error("If the error persists, you can report it at https://github.com/spaam/svtplay-dl/issues")
|
|
|
|
log.error("Include the URL used, the stack trace and the output of svtplay-dl --version in the issue")
|
2015-09-06 14:56:54 +02:00
|
|
|
sys.exit(3)
|
2015-09-06 14:19:10 +02:00
|
|
|
|
2015-09-18 21:47:07 +02:00
|
|
|
if options.require_subtitle and not subs:
|
|
|
|
log.info("No subtitles available")
|
|
|
|
return
|
2014-06-18 21:10:05 +02:00
|
|
|
|
2016-04-27 10:37:47 +02:00
|
|
|
if options.subtitle and options.get_url:
|
2016-05-05 10:38:43 +02:00
|
|
|
if subs:
|
|
|
|
if options.get_all_subtitles:
|
|
|
|
for sub in subs:
|
|
|
|
print(sub.url)
|
|
|
|
else:
|
|
|
|
print(subs[0].url)
|
2018-01-30 20:11:37 +01:00
|
|
|
if options.force_subtitle:
|
2016-04-27 10:37:47 +02:00
|
|
|
return
|
2016-06-20 20:22:11 +02:00
|
|
|
|
|
|
|
def options_subs_dl(subfixes):
|
2014-10-12 21:17:18 +02:00
|
|
|
if subs:
|
2016-04-27 10:37:47 +02:00
|
|
|
if options.get_all_subtitles:
|
2016-04-27 19:37:32 +02:00
|
|
|
for sub in subs:
|
2016-04-27 10:37:47 +02:00
|
|
|
sub.download()
|
2016-06-20 18:33:42 +02:00
|
|
|
if options.merge_subtitle:
|
2016-08-01 20:54:57 +02:00
|
|
|
if sub.subfix:
|
2016-06-24 05:49:34 +02:00
|
|
|
subfixes += [sub.subfix]
|
2016-08-01 20:54:57 +02:00
|
|
|
else:
|
|
|
|
options.get_all_subtitles = False
|
2018-01-30 20:11:37 +01:00
|
|
|
else:
|
2016-04-27 10:37:47 +02:00
|
|
|
subs[0].download()
|
2016-06-20 20:22:11 +02:00
|
|
|
elif options.merge_subtitle:
|
|
|
|
options.merge_subtitle = False
|
2016-04-27 10:37:47 +02:00
|
|
|
|
2018-01-14 00:04:07 +01:00
|
|
|
if options.subtitle and not options.get_url:
|
2016-06-20 20:22:11 +02:00
|
|
|
options_subs_dl(subfixes)
|
2014-10-12 21:17:18 +02:00
|
|
|
if options.force_subtitle:
|
|
|
|
return
|
2014-06-18 21:10:05 +02:00
|
|
|
|
2016-06-20 18:33:42 +02:00
|
|
|
if options.merge_subtitle and not options.subtitle:
|
2016-06-20 20:22:11 +02:00
|
|
|
options_subs_dl(subfixes)
|
2016-06-20 18:33:42 +02:00
|
|
|
|
2017-10-07 14:24:12 +02:00
|
|
|
if not videos:
|
|
|
|
log.error("No videos found.")
|
2015-11-15 15:20:16 +01:00
|
|
|
for exc in error:
|
|
|
|
log.error(str(exc))
|
2014-10-12 23:53:42 +02:00
|
|
|
else:
|
2015-01-05 22:40:40 +01:00
|
|
|
if options.list_quality:
|
|
|
|
list_quality(videos)
|
|
|
|
return
|
2014-10-12 23:53:42 +02:00
|
|
|
try:
|
2016-03-29 20:01:24 +02:00
|
|
|
stream = select_quality(options, videos)
|
|
|
|
if options.get_url:
|
|
|
|
print(stream.url)
|
|
|
|
return
|
2016-06-20 20:22:11 +02:00
|
|
|
log.info("Selected to download %s, bitrate: %s",
|
|
|
|
stream.name(), stream.bitrate)
|
2014-10-12 23:53:42 +02:00
|
|
|
stream.download()
|
|
|
|
except UIException as e:
|
|
|
|
if options.verbose:
|
|
|
|
raise e
|
2015-09-10 21:39:51 +02:00
|
|
|
log.error(e)
|
2014-10-12 23:53:42 +02:00
|
|
|
sys.exit(2)
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2014-10-12 23:53:42 +02:00
|
|
|
if options.thumbnail and hasattr(stream, "get_thumbnail"):
|
2018-01-14 00:04:07 +01:00
|
|
|
stream.get_thumbnail(options)
|
2016-06-20 18:33:42 +02:00
|
|
|
post = postprocess(stream, options, subfixes)
|
2017-09-20 11:22:57 +02:00
|
|
|
|
2018-02-04 22:59:38 +01:00
|
|
|
if stream.name() == "dash" or (stream.name() == "hls" and stream.options.segments) and post.detect:
|
2016-03-26 21:38:31 +01:00
|
|
|
post.merge()
|
2018-03-06 21:49:23 +01:00
|
|
|
elif (stream.name() == "dash" or (stream.name() == "hls" and stream.options.segments)) and not post.detect and stream.finished:
|
2016-03-26 21:38:31 +01:00
|
|
|
log.warning("Cant find ffmpeg/avconv. audio and video is in seperate files. if you dont want this use -P hls or hds")
|
2018-03-06 21:49:23 +01:00
|
|
|
elif stream.name() == "hls" or options.remux:
|
2017-09-20 11:22:57 +02:00
|
|
|
if post.detect:
|
|
|
|
post.remux()
|
|
|
|
else:
|
|
|
|
log.warning("Cant find ffmpeg/avconv. File may be unplayable.")
|
|
|
|
|
2016-05-04 14:16:59 +02:00
|
|
|
if options.silent_semi and stream.finished:
|
|
|
|
log.log(25, "Download of %s was completed" % stream.options.output)
|
2016-03-22 22:36:39 +01:00
|
|
|
|
2013-03-23 15:02:41 +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")
|
2014-02-09 15:38:51 +01:00
|
|
|
fmt = logging.Formatter('%(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
|
2014-10-12 23:41:44 +02:00
|
|
|
fmt = logging.Formatter('%(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
|
|
|
|
|
|
|
|
hdlr = logging.StreamHandler(stream)
|
|
|
|
hdlr.setFormatter(fmt)
|
|
|
|
|
|
|
|
log.addHandler(hdlr)
|
|
|
|
log.setLevel(level)
|
|
|
|
|
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__)
|
2018-01-14 00:35:28 +01:00
|
|
|
|
2018-01-13 20:53:02 +01:00
|
|
|
if len(options.urls) == 0:
|
2018-01-14 00:39:16 +01:00
|
|
|
parse.print_help()
|
2013-07-25 21:01:57 +02:00
|
|
|
sys.exit(0)
|
2018-01-13 20:53:02 +01:00
|
|
|
urls = options.urls
|
|
|
|
if len(urls) < 1:
|
2018-01-14 00:39:16 +01:00
|
|
|
parse.error("Incorrect number of arguments")
|
2014-12-22 17:41:40 +01:00
|
|
|
if options.exclude:
|
|
|
|
options.exclude = options.exclude.split(",")
|
2015-09-18 21:47:07 +02:00
|
|
|
if options.require_subtitle:
|
2016-06-20 18:33:42 +02:00
|
|
|
if options.merge_subtitle:
|
|
|
|
options.merge_subtitle = True
|
|
|
|
else:
|
|
|
|
options.subtitle = True
|
2016-06-24 05:49:34 +02:00
|
|
|
if options.merge_subtitle:
|
|
|
|
options.remux = True
|
2018-01-14 00:31:00 +01:00
|
|
|
options = mergeparseroption(Options(), options)
|
2016-05-04 14:16:59 +02:00
|
|
|
if options.silent_semi:
|
|
|
|
options.silent = True
|
2014-01-05 16:30:45 +01:00
|
|
|
setup_log(options.silent, options.verbose)
|
2013-03-23 15:02:41 +01:00
|
|
|
|
2017-09-19 00:30:11 +02:00
|
|
|
if options.cmoreoperatorlist:
|
2018-01-13 20:53:02 +01:00
|
|
|
c = Cmore(options, urls)
|
2017-09-19 00:30:11 +02:00
|
|
|
c.operatorlist()
|
|
|
|
sys.exit(0)
|
|
|
|
|
2017-11-22 00:36:50 +01:00
|
|
|
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:
|
|
|
|
log.error("flexible-quality requires a quality")
|
|
|
|
sys.exit(4)
|
|
|
|
|
2014-04-02 19:32:35 +02:00
|
|
|
try:
|
2017-01-04 04:20:50 +01:00
|
|
|
if len(urls) == 1:
|
|
|
|
get_media(urls[0], options)
|
|
|
|
else:
|
|
|
|
get_multiple_media(urls, options)
|
2014-04-02 19:32:35 +02:00
|
|
|
except KeyboardInterrupt:
|
2014-05-02 12:06:53 +02:00
|
|
|
print("")
|
2014-08-11 21:00:19 +02:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|