def check_stream(self): if self.raw_stream_url: self.opt_args = [] return True channel_name = match1(self.url, VALID_URL_BASE) r = requests.get( f'https://api.twitch.tv/api/channels/{channel_name}/access_token', headers={ 'Accept': 'application/vnd.twitchtv.v5+json; charset=UTF-8', 'Client-ID': _CLIENT_ID, }, timeout=10) r.close() access_token = r.json() token = access_token['token'] query = { 'allow_source': 'true', 'allow_audio_only': 'true', 'allow_spectre': 'true', 'p': random.randint(1000000, 10000000), 'player': 'twitchweb', 'playlist_include_framerate': 'true', 'segment_preference': '4', 'sig': access_token['sig'], 'token': token, } self.opt_args = ['-ss', "00:00:16"] self.raw_stream_url = f'https://usher.ttvnw.net/api/channel/hls/{channel_name}.m3u8?{urlencode(query)}' return True
def check_stream(self): logger.debug(self.fname) res = requests.get(self.url, timeout=5, headers=fake_headers) res.close() huya = match1(res.text, '"stream": "([a-zA-Z0-9+=/]+)"') if huya: huyajson = json.loads(base64.b64decode(huya).decode())['data'][0]['gameStreamInfoList'][0] absurl = u'{}/{}.{}?{}'.format(huyajson["sFlvUrl"], huyajson["sStreamName"], huyajson["sFlvUrlSuffix"], huyajson["sFlvAntiCode"]) self.ydl_opts["absurl"] = html.unescape(absurl) return True
def check_stream(self): # check_url = re.sub(r'.*douyu.com', 'http://open.douyucdn.cn/api/RoomApi/room', self.url) # res = requests.get(check_url, timeout=5) # res.close() # s = res.json() # logger.debug(self.fname) # status = s['data']['room_status'] # if status == '2': # return False # else: # return True logger.debug(self.fname) url = re.sub(r'.*douyu.com', 'https://m.douyu.com/room', self.url) res = requests.get(url, timeout=5) res.close() html = res.text room_id_patt = r'"rid"\s*:\s*(\d+),' room_id = match1(html, room_id_patt) if room_id == "0": room_id = url[url.rfind('/') + 1:] args = "room/%s?aid=wp&client_sys=wp&time=%d" % (room_id, int(time.time())) auth_md5 = (args + "zNzMV1y4EMxOHS6I5WKm").encode("utf-8") auth_str = hashlib.md5(auth_md5).hexdigest() json_request_url = "%s%s&auth=%s" % (_API_URL, args, auth_str) # print(json_request_url) content = requests.get(json_request_url, headers=headers, timeout=5) content.close() # content = get_content(json_request_url, headers) # print(content.text) json_content = json.loads(content.text) data = json_content['data'] server_status = json_content.get('error', 0) if server_status is not 0: raise ValueError("Server returned error:%s" % server_status) title = data.get('room_name') logger.debug(title) show_status = data.get('show_status') if show_status is not "1": # raise ValueError("The live stream is not online! (Errno:%s)" % server_status) return self.ydl_opts['absurl'] = data.get('rtmp_url') + '/' + data.get( 'rtmp_live') return True
def check_stream(self): if not list(Twitch.BatchCheck([self.url]).check()): return channel_name = match1(self.url, VALID_URL_BASE) # r = requests.get(f'https://api.twitch.tv/api/channels/{channel_name}/access_token', # headers={ # 'Accept': 'application/vnd.twitchtv.v5+json; charset=UTF-8', # 'Client-ID': _CLIENT_ID, # }, timeout=10) # r.close() # access_token = r.json() # token = access_token['token'] # query = { # 'allow_source': 'true', # 'allow_audio_only': 'true', # 'allow_spectre': 'true', # 'p': random.randint(1000000, 10000000), # 'player': 'twitchweb', # 'playlist_include_framerate': 'true', # 'segment_preference': '4', # 'sig': access_token['sig'], # 'token': token, # } self.opt_args = ['-ss', "00:00:20"] # # r = requests.get( f'https://usher.ttvnw.net/api/channel/hls/{channel_name}.m3u8?{urlencode(query)}') # r.close() # nums = r.text.split("#") # for i in range(len(nums)): # part = re.search(',VIDEO="720p60",', nums[i]) # if part : # url = nums[i].split('\n') # real_url = url[-2] streams = streamlink.streams(f'https://www.twitch.tv/{channel_name}') if channel_name == 'root_supernova': stream = streams["720p60"].url else: stream = streams["best"].url # self.raw_stream_url = f'https://usher.ttvnw.net/api/channel/hls/{channel_name}.m3u8?{urlencode(query)}' self.raw_stream_url = stream return True
def check_stream(self): logger.debug(self.fname) username = match1(self.url, VALID_URL_BASE) res_bno = requests.post(CHANNEL_API_URL, data={ "bid": username, "mode": "landing", "player_type": "html5" }, timeout=5) res_bno.close() if res_bno.json()["CHANNEL"]["RESULT"] == 0: return bno = res_bno.json()["CHANNEL"]["BNO"] cdn = res_bno.json()["CHANNEL"]["CDN"] rmd = res_bno.json()["CHANNEL"]["RMD"] res_aid = requests.post(CHANNEL_API_URL, data={ "bid": username, "bno": bno, "pwd": "", "quality": QUALITIES[0], "type": "pwd" }, timeout=5) res_aid.close() aid = res_aid.json()["CHANNEL"]["AID"] params = { "return_type": cdn, "broad_key": "{broadcast}-flash-{quality}-hls".format(broadcast=bno, quality=QUALITIES[0]) } res = requests.get(STREAM_INFO_URLS.format(rmd=rmd), params=params, timeout=5) res.close() self.raw_stream_url = res.json()["view_url"] + "?aid=" + aid return True