def __getResolutionList__(self, url): ret = [] txt = requests.get(url).text array = txt.split("#EXT-X-STREAM-INF") for item in array: if "RESOLUTION=" not in item: continue stream = VideoStreamUrl() stream.codec = stringHelper.getSub(item, "CODECS=\"", "\"") stream.m3u8Url = "http" + stringHelper.getSubOnlyStart(item, "http").strip() stream.resolution = stringHelper.getSub(item, "RESOLUTION=", "http").strip() stream.resolution = stream.resolution.split(',')[0] stream.resolutions = stream.resolution.split("x") ret.append(stream) return ret
def getVideoStreamUrl(self, video_id, quality): paras = { "videoquality": "HIGH", "playbackmode": "STREAM", "assetpresentation": "FULL" } msg, data = self.api.__get__( 'videos/' + str(video_id) + "/playbackinfopostpaywall", paras) if msg is not None: return msg, None if "vnd.tidal.emu" in data['manifestMimeType']: manifest = json.loads( base64.b64decode(data['manifest']).decode('utf-8')) url = manifest['urls'][0] qualityArray = [] txt = requests.get(url).text array = txt.split("#EXT-X-STREAM-INF") for item in array: if "RESOLUTION=" not in item: continue stream = {} stream['codec'] = stringHelper.getSub(item, "CODECS=\"", "\"") stream['m3u8Url'] = "http" + stringHelper.getSubOnlyStart( item, "http").strip() stream['resolution'] = stringHelper.getSub( item, "RESOLUTION=", "http").strip() if ',FRAME-RATE' in stream['resolution']: stream['resolution'] = stream[ 'resolution'][:stream['resolution'].find(',FRAME-RATE' )] stream['resolutions'] = stream['resolution'].split("x") qualityArray.append(stream) icmp = int(quality) index = 0 for item in qualityArray: if icmp >= int(item['resolutions'][1]): break index += 1 if index >= len(qualityArray): index = len(qualityArray) - 1 return "", qualityArray[index] return "", None