def _get_streams(self):
        http.mount('https://', HTTPAdapter(max_retries=99))
        http.headers.update({'user-agent': useragents.CHROME})
        match = _url_re.match(self.url)
        channel = match.group("channel")
        res_room_id = http.get(ROOM_API.format(channel))
        room_id_json = http.json(res_room_id, schema=_room_id_schema)
        room_id = room_id_json['room_id']
        if room_id_json['live_status'] != SHOW_STATUS_ONLINE:
            return

        ts = int(time.time() / 60)
        sign = hashlib.md5(("{0}{1}".format(channel, API_SECRET,
                                            ts)).encode("utf-8")).hexdigest()

        res = http.get(API_URL.format(room_id, sign))
        room = http.json(res)
        if not room:
            return

        for stream_list in room["durl"]:
            name = "source"
            url = stream_list["url"]
            stream = HTTPStream(self.session, url)
            yield name, stream
Beispiel #2
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': useragents.CHROME})
        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        #Thanks to @ximellon for providing method.
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel == 0:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        res = http.get(MAPI_URL.format(channel))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        ts = int(time.time() / 60)
        did = uuid.uuid4().hex.upper()
        sign = hashlib.md5(
            ("{0}{1}{2}{3}".format(channel, did, LAPI_SECRET,
                                   ts)).encode("utf-8")).hexdigest()

        data = {"cdn": "ws", "rate": "0", "tt": ts, "did": did, "sign": sign}

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "source", stream

        data = {"cdn": "ws", "rate": "2", "tt": ts, "did": did, "sign": sign}

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "middle", stream

        data = {"cdn": "ws", "rate": "1", "tt": ts, "did": did, "sign": sign}

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "low", stream
Beispiel #3
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        subdomain = match.group("subdomain")

        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        if subdomain == 'v':
            vid = match.group("vid")
            headers = {
                "User-Agent": useragents.ANDROID,
                "X-Requested-With": "XMLHttpRequest"
            }
            res = http.get(VAPI_URL.format(vid), headers=headers)
            room = http.json(res, schema=_vapi_schema)
            yield "source", HLSStream(self.session, room["video_url"])
            return

        #Thanks to @ximellon for providing method.
        channel = match.group("channel")
        http.headers.update({'User-Agent': useragents.CHROME})
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel is None:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        ts = int(time.time() / 60)
        sign = hashlib.md5(
            ("{0}{1}{2}".format(channel, WAPI_SECRET,
                                ts)).encode("utf-8")).hexdigest()

        res = http.get(WAPI_URL.format(channel, ts, sign))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        did = uuid.uuid4().hex.upper()
        sign = stupidMD5(("{0}{1}{2}{3}".format(channel, did, LAPI_SECRET,
                                                ts)))

        rate = [0, 2, 1]
        quality = ['source', 'medium', 'low']
        for i in range(0, 3, 1):
            room = self._get_room_json(channel, rate[i], ts, did, sign)
            url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
            if 'rtmp:' in url:
                stream = RTMPStream(self.session, {"rtmp": url, "live": True})
                yield quality[i], stream
            else:
                yield quality[i], HTTPStream(self.session, url)
Beispiel #4
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        subdomain = match.group("subdomain")

        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        if subdomain == 'v':
            vid = match.group("vid")
            headers = {
                "User-Agent": useragents.ANDROID,
                "X-Requested-With": "XMLHttpRequest"
            }
            res = http.get(VAPI_URL.format(vid), headers=headers)
            room = http.json(res, schema=_vapi_schema)
            yield "source", HLSStream(self.session, room["video_url"])
            return

        #Thanks to @ximellon for providing method.
        channel = match.group("channel")
        http.headers.update({'User-Agent': useragents.CHROME})
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel == 0:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        res = http.get(MAPI_URL.format(channel))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        rate = [0, 2, 1]
        quality = ['source', 'medium', 'low']
        for i in range(0, 3, 1):
            room = self._get_room_json(channel, rate[i])
            url = room["live_url"]
            if 'rtmp:' in url:
                stream = RTMPStream(self.session, {"rtmp": url, "live": True})
                yield quality[i], stream
            else:
                yield quality[i], HTTPStream(self.session, url)
            yield quality[i], HLSStream(self.session, room["hls_url"])
Beispiel #5
0
    def _get_streams(self):
        http.mount('https://', HTTPAdapter(max_retries=99))
        http.headers.update({'user-agent': useragents.CHROME})
        match = _url_re.match(self.url)
        channel = match.group("channel")
        res_room_id = http.get(ROOM_API.format(channel))
        room_id_json = http.json(res_room_id, schema=_room_id_schema)
        room_id = room_id_json['room_id']

        ts = int(time.time() / 60)
        sign = hashlib.md5(("{0}{1}".format(channel, API_SECRET, ts)).encode("utf-8")).hexdigest()

        res = http.get(API_URL.format(room_id, sign))
        room = http.json(res)
        if not room:
            return

        for stream_list in room["durl"]:
            name = "source"
            url = stream_list["url"]
            stream = HTTPStream(self.session, url)
            yield name, stream
Beispiel #6
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': useragents.CHROME})
        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        #Thanks to @ximellon for providing method.
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel == 0:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        res = http.get(MAPI_URL.format(channel))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        room_source = self._get_room_json(channel, 0)
        yield "source", HTTPStream(self.session, room_source['live_url'])
        yield "source", HLSStream(self.session, room_source['hls_url'])

        room_medium = self._get_room_json(channel, 2)
        yield "medium", HTTPStream(self.session, room_medium['live_url'])
        yield "medium", HLSStream(self.session, room_medium['hls_url'])

        room_low = self._get_room_json(channel, 1)
        yield "low", HTTPStream(self.session, room_low['live_url'])
        yield "low", HLSStream(self.session, room_low['hls_url'])
Beispiel #7
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")

        http.headers.update({'User-Agent': USER_AGENT})
        http.verify=False
        http.mount('https://', HTTPAdapter(max_retries=99))

        #Thanks to @ximellon for providing method.
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel == 0:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        res = http.get(MAPI_URL.format(channel))
        room = http.json(res, schema=_room_schema)
        if not room:
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            return

        ts = int(time.time() / 60)
        did = uuid.uuid4().hex.upper()
        sign = hashlib.md5(("{0}{1}{2}{3}".format(channel, did, LAPI_SECRET, ts)).encode("utf-8")).hexdigest()

        data = {
            "cdn": "ws",
            "rate": "0",
            "tt": ts,
            "did": did,
            "sign": sign
        }

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "source", stream

        data = {
            "cdn": "ws",
            "rate": "2",
            "tt": ts,
            "did": did,
            "sign": sign
        }

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "middle", stream

        data = {
            "cdn": "ws",
            "rate": "1",
            "tt": ts,
            "did": did,
            "sign": sign
        }

        res = http.post(LAPI_URL.format(channel), data=data)
        room = http.json(res, schema=_lapi_schema)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        stream = HTTPStream(self.session, url)
        yield "low", stream
Beispiel #8
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        subdomain = match.group("subdomain")

        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        if subdomain == 'v':
            vid = match.group("vid")
            headers = {
                "User-Agent": useragents.ANDROID,
                "X-Requested-With": "XMLHttpRequest"
            }
            res = http.get(VAPI_URL.format(vid), headers=headers)
            room = http.json(res, schema=_vapi_schema)
            yield "source", HLSStream(self.session, room["video_url"])
            return

        channel = match.group("channel")
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel is None:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        http.headers.update({'User-Agent': useragents.WINDOWS_PHONE_8})
        cdns = ["ws", "tct", "ws2", "dl"]
        ts = int(time.time())
        suffix = "room/{0}?aid=wp&cdn={1}&client_sys=wp&time={2}".format(channel, cdns[0], ts)
        sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()

        res = http.get(API_URL.format(suffix, sign))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        url = room["hls_url"]
        yield "source", HLSStream(self.session, url)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        if 'rtmp:' in url:
            stream = RTMPStream(self.session, {
                "rtmp": url,
                "live": True
            })
            yield "source", stream
        else:
            yield "source", HTTPStream(self.session, url)

        multi_streams = {
            "middle": "low",
            "middle2": "medium"
        }
        for name, url in room["rtmp_multi_bitrate"].items():
            url = "{room[rtmp_url]}/{url}".format(room=room, url=url)
            name = multi_streams[name]
            if 'rtmp:' in url:
                stream = RTMPStream(self.session, {
                    "rtmp": url,
                    "live": True
                })
                yield name, stream
            else:
                yield name, HTTPStream(self.session, url)
Beispiel #9
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        subdomain = match.group("subdomain")

        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))

        if subdomain == 'v':
            vid = match.group("vid")
            headers = {
                "User-Agent": useragents.ANDROID,
                "X-Requested-With": "XMLHttpRequest"
            }
            res = http.get(VAPI_URL.format(vid), headers=headers)
            room = http.json(res, schema=_vapi_schema)
            yield "source", HLSStream(self.session, room["video_url"])
            return

        channel = match.group("channel")
        try:
            channel = int(channel)
        except ValueError:
            channel = http.get(self.url, schema=_room_id_schema)
            if channel is None:
                channel = http.get(self.url, schema=_room_id_alt_schema)

        http.headers.update({'User-Agent': useragents.ANDROID})
        cdns = ["ws", "tct", "ws2", "dl"]
        ts = int(time.time())
        suffix = "room/{0}?aid=androidhd1&cdn={1}&client_sys=android&time={2}".format(
            channel, cdns[0], ts)
        sign = hashlib.md5((suffix + API_SECRET).encode()).hexdigest()

        res = http.get(API_URL.format(suffix, sign))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        url = room["hls_url"]
        yield "source", HLSStream(self.session, url)

        url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
        if 'rtmp:' in url:
            stream = RTMPStream(self.session, {"rtmp": url, "live": True})
            yield "source", stream
        else:
            yield "source", HTTPStream(self.session, url)

        multi_streams = {"middle": "low", "middle2": "medium"}
        for name, url in room["rtmp_multi_bitrate"].items():
            url = "{room[rtmp_url]}/{url}".format(room=room, url=url)
            name = multi_streams[name]
            if 'rtmp:' in url:
                stream = RTMPStream(self.session, {"rtmp": url, "live": True})
                yield name, stream
            else:
                yield name, HTTPStream(self.session, url)
Beispiel #10
0
    def _get_streams(self):
        match = _url_re.match(self.url)
        subdomain = match.group("subdomain")

        http.verify = False
        http.mount('https://', HTTPAdapter(max_retries=99))
        http.headers.update({
            'User-Agent': useragents.CHROME,
            'Referer': self.url
        })
        dir = os.path.dirname(os.path.abspath(__file__))
        node_modules = os.path.join(dir, 'douyutv')
        os.environ['NODE_PATH'] = node_modules
        did = uuid.uuid4().hex
        env = os.environ.copy()
        self.logger.debug(env['PATH'])
        try:
            Popen(['node', '-v'], stdout=PIPE, stderr=PIPE,
                  env=env).communicate()
        except (OSError, IOError) as err:
            self.logger.info(
                str(err) + "\n"
                "Please install Node.js first.\n"
                "If you have installed Node.js but still show this message,\n"
                "please reboot computer.")
            if is_win32:
                self.logger.info(
                    "If you are using windows portable version,\n"
                    "you can copy node.exe to the same folder as streamlink.exe."
                )
            return

        if subdomain == 'v':
            vid = match.group("vid")
            tt = int(time.time())
            process = Popen([
                'node', node_modules + '/douyutv_vsigner.js',
                str(vid),
                str(tt), did
            ],
                            stdout=PIPE,
                            stderr=PIPE,
                            env=env)
            res = process.communicate()[0].decode()
            sign = _sign_re.search(res).group(1)
            data = {"vid": vid, "did": did, "tt": tt, "sign": sign}
            if args.http_cookie:
                res = http.post(VAPI_URL, data=data)
            else:
                cookie = dict(acf_auth='')
                res = http.post(VAPI_URL, data=data, cookies=cookie)
            if _supern_re.search(res.text):
                self.logger.info(
                    "This video has source quality, but need logged-in cookie.\n"
                    "Copy acf_auth value in cookie with option '--http-cookie acf_auth=value'."
                )
                if is_win32:
                    self.logger.info(
                        "If you are using windows version,\n"
                        "The percent symbol '%' in cookie must be modified to '%%' in command-line and batch file."
                    )
            if _super_re.search(res.text):
                room = http.json(res, schema=_vapi_schema)
                yield "source", HLSStream(self.session,
                                          room["thumb_video"]["super"]["url"])
                yield "medium", HLSStream(self.session,
                                          room["thumb_video"]["high"]["url"])
                yield "low", HLSStream(self.session,
                                       room["thumb_video"]["normal"]["url"])
            else:
                room = http.json(res, schema=_vapin_schema)
                try:
                    yield "medium", HLSStream(
                        self.session, room["thumb_video"]["high"]["url"])
                except:
                    pass
                yield "low", HLSStream(self.session,
                                       room["thumb_video"]["normal"]["url"])
            return

        channel = match.group("channel")
        try:
            channel = int(channel)
        except ValueError:
            res = http.get(self.url)
            try:
                channel = _room_id_re.search(res.text).group(1)
            except AttributeError:
                room_list = _room_id_alt_re.findall(res.text)
                try:
                    ops = _index_re.search(self.url).group(1)
                    channel = room_list[int(ops)]
                except AttributeError:
                    try:
                        self.logger.info(
                            "Available sub-channels: {0}".format(room_list))
                        ops = _channel_re.search(self.url).group(1)
                        channel = room_list[int(ops) - 1]
                    except AttributeError:
                        self.logger.info(
                            "You can add '?ch=number' after url to choose channel,\n"
                            "if no query string, default use '?ch=1' for first channel in list."
                        )
                        channel = room_list[0]

        ts = int(time.time() / 60)
        sign = hashlib.md5(("{0}{1}{2}".format(channel, API_SECRET,
                                               ts)).encode()).hexdigest()
        res = http.get(API_URL.format(channel, ts, sign))
        room = http.json(res, schema=_room_schema)
        if not room:
            self.logger.info("Not a valid room url.")
            return

        if room["show_status"] != SHOW_STATUS_ONLINE:
            self.logger.info("Stream currently unavailable.")
            return

        cdns = room["cdns"]
        try:
            self.logger.info("Available cdns: {0}".format(cdns))
            cdn = _cdn_re.search(self.url).group(1)
        except AttributeError:
            self.logger.info(
                "You can add '?cdn=CDN_name' after url to choose CDN,\n"
                "if no query string, default use '?cdn=ws' for ws CDN.")
            cdn = "ws"

        h5js = http.get(H5JS_URL)
        ver = _h5ver_re.search(h5js.text).group(1)
        tt = int(time.time() / 60)
        process = Popen([
            'node', node_modules + '/douyutv1_signer.js',
            str(channel),
            str(tt), did
        ],
                        stdout=PIPE,
                        stderr=PIPE,
                        env=env)
        res = process.communicate()[0].decode()
        sign = _sign_re.search(res).group(1)
        cptl = _sign_re.search(res).group(2)
        self.logger.info("Now channel: {0}, CDN: {1}".format(channel, cdn))
        rate = [0, 4, 2, 1]
        quality = ["source", "high", "medium", "low"]
        for i in range(0, 4, 1):
            room = self._get_room_json(channel, cdn, rate[i], ver, tt, did,
                                       sign, cptl)
            url = "{room[rtmp_url]}/{room[rtmp_live]}".format(room=room)
            if 'rtmp:' in url:
                stream = RTMPStream(self.session, {"rtmp": url, "live": True})
                yield quality[i], stream
            else:
                yield quality[i], HTTPStream(self.session, url)

        if room["is_mixed"]:
            url = "{room[mixed_url]}/{room[mixed_live]}".format(room=room)
            yield "mix", HTTPStream(self.session, url)