コード例 #1
0
ファイル: __init__.py プロジェクト: wirretheman/svtplay-dl
    def __init__(self, config, _url, http=None):
        self._url = _url
        self._urldata = None
        self._error = False
        self.subtitle = None
        self.cookies = {}
        self.auto_name = None
        self.output = {
            "title": None,
            "season": None,
            "episode": None,
            "episodename": None,
            "id": None,
            "service": self.__class__.__name__.lower(),
            "tvshow": None,
            "title_nice": None,
            "showdescription": None,
            "episodedescription": None,
            "showthumbnailurl": None,
            "episodethumbnailurl": None,
            "publishing_datetime": None,
        }
        if not http:
            self.http = HTTP(config)
        else:
            self.http = http

        #  Config
        if config.get("configfile") and os.path.isfile(config.get("configfile")):
            self.config = merge(
                readconfig(setup_defaults(), config.get("configfile"), service=self.__class__.__name__.lower()).get_variable(), config.get_variable()
            )
        else:
            self.config = config
        logging.debug("service: {}".format(self.__class__.__name__.lower()))
コード例 #2
0
ファイル: __init__.py プロジェクト: toran4/svtplay-dl
 def __init__(self, config, subtype, url, subfix=None, **kwargs):
     self.url = url
     self.subtitle = None
     self.config = config
     self.subtype = subtype
     self.http = HTTP(config)
     self.subfix = subfix
     self.bom = False
     self.output = kwargs.pop("output", None)
     self.kwargs = kwargs
コード例 #3
0
 def __init__(self, config, url, bitrate=0, **kwargs):
     self.config = config
     self.url = url
     self.bitrate = int(bitrate)
     self.kwargs = kwargs
     self.http = HTTP(config)
     self.finished = False
     self.audio = kwargs.pop("audio", None)
     self.files = kwargs.pop("files", None)
     self.keycookie = kwargs.pop("keycookie", None)
     self.authorization = kwargs.pop("authorization", None)
     self.output = kwargs.pop("output", None)
     self.segments = kwargs.pop("segments", None)
     self.output_extention = None
コード例 #4
0
 def __init__(self, config, url, bitrate, output, **kwargs):
     self.config = config
     self.url = url
     self.bitrate = int(bitrate) if bitrate else 0
     self.kwargs = kwargs
     self.http = HTTP(config)
     self.finished = False
     self.audio = kwargs.pop("audio", None)
     self.files = kwargs.pop("files", None)
     self.keycookie = kwargs.pop("keycookie", None)
     self.authorization = kwargs.pop("authorization", None)
     self.output = output
     self.segments = kwargs.pop("segments", None)
     self.output_extention = None
     channels = kwargs.pop("channels", None)
     codec = kwargs.pop("codec", "h264")
     self.format = f"{codec}-{channels}" if channels else codec
コード例 #5
0
ファイル: stream.py プロジェクト: wirretheman/svtplay-dl
def select_quality(config, streams):
    high = 0
    if isinstance(config.get("quality"), str):
        try:
            quality = int(config.get("quality").split("-")[0])
            if len(config.get("quality").split("-")) > 1:
                high = int(config.get("quality").split("-")[1])
        except ValueError:
            raise error.UIException(
                "Requested quality is invalid. use a number or range lowerNumber-higherNumber"
            )
    else:
        quality = config.get("quality")
    try:
        optq = int(quality)
    except ValueError:
        raise error.UIException("Requested quality needs to be a number")

    try:
        optf = int(config.get("flexibleq"))
    except ValueError:
        raise error.UIException("Flexible-quality needs to be a number")

    if optf == 0 and high:
        optf = (high - quality) / 2
        optq = quality + (high - quality) / 2

    # Extract protocol prio, in the form of "hls,hds,http",
    # we want it as a list

    if config.get("stream_prio"):
        proto_prio = config.get("stream_prio").split(",")
    elif config.get("live") or streams[0].config.get("live"):
        proto_prio = LIVE_PROTOCOL_PRIO
    else:
        proto_prio = DEFAULT_PROTOCOL_PRIO

    # Filter away any unwanted protocols, and prioritize
    # based on --stream-priority.
    streams = protocol_prio(streams, proto_prio)

    if len(streams) == 0:
        raise error.NoRequestedProtocols(requested=proto_prio,
                                         found=list({s.name
                                                     for s in streams}))

    # Build a dict indexed by bitrate, where each value
    # is the stream with the highest priority protocol.
    stream_hash = {}
    for s in streams:
        if s.bitrate not in stream_hash:
            stream_hash[s.bitrate] = s

    avail = sorted(stream_hash.keys(), reverse=True)

    # wanted_lim is a two element tuple defines lower/upper bounds
    # (inclusive). By default, we want only the best for you
    # (literally!).
    wanted_lim = (avail[0], ) * 2
    if optq:
        wanted_lim = (optq - optf, optq + optf)

    # wanted is the filtered list of available streams, having
    # a bandwidth within the wanted_lim range.
    wanted = [a for a in avail if a >= wanted_lim[0] and a <= wanted_lim[1]]

    # If none remains, the bitrate filtering was too tight.
    if len(wanted) == 0:
        data = sort_quality(streams)
        quality = ", ".join("{} ({})".format(str(x), str(y)) for x, y in data)
        raise error.UIException("Can't find that quality. Try one of: %s (or "
                                "try --flexible-quality)" % quality)

    http = HTTP(config)
    # Test if the wanted stream is available. If not try with the second best and so on.
    for w in wanted:
        res = http.get(stream_hash[w].url,
                       cookies=stream_hash[w].kwargs.get("cookies", None))
        if res is not None and res.status_code < 404:
            return stream_hash[w]

    raise error.UIException("Streams not available to download.")