def fetch(cls, url: str, mode=0) -> Result: url = cls.get_url(url) if url is None: return ErrorResult.URL_NOT_INCORRECT res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) try: id = re.findall(r"(?<=item\/)(\d+)(?=\?)", res.url)[0] except IndexError: return Result.failed(res.reason) url = "https://h5.pipix.com/bds/webapi/item/detail/?item_id=" + id + "&source=share" info_res = http_utils.get(url, header=share_headers) if http_utils.is_error(info_res): return Result.error(info_res) data = json.loads(str(info_res.text)) try: video = data['data']['item']['comments'][0]['item']['video'] url = cls.get_video(video) except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT return Result.success(url)
def fetch(cls, url: str, mode=0) -> Result: url = cls.get_url(url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId和dytk res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) html = res.text try: url = re.findall(r"(?<=\"srcNoMark\":\"https://)(.*?)(?=.mp4)", html)[0] except IndexError: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT if not url: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT url = "https://" + url + ".mp4" result = Result.success(url) if mode != 0: result.ref = res.url return result
def fetch(cls, url: str, model=0) -> Result: """ 获取视频详情 :param url: :param model: :return: """ url = analyzer.get_url(vtype, url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId和dytk res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) html = str(res.content) url = re.findall(r"(?<=type=\"video\/mp4\" src=\")(.*?)(?=\")", html)[0] if not url: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT result = Result.success(url) if model != 0: result.ref = res.url return result
def fetch(cls, url: str, model=0) -> Result: """ 获取视频详情 :param url: :param model: :return: """ url = analyzer.get_url(vtype, url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId和dytk res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) html = res.text try: url = re.findall(r"(?<=srcNoMark":")(.*?)(?=&)", html)[0] except IndexError: return Result.failed(res.text) if not url: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT result = Result.success(url) if model != 0: result.ref = res.url return result
def fetch(cls, url: str, model=0) -> Result: """ 获取视频详情 :param url: :param model: :return: """ url = analyzer.get_url(vtype, url) if url is None: return ErrorResult.URL_NOT_INCORRECT res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) try: id = re.findall(r"(?<=item\/)(\d+)(?=\?)", res.url)[0] except IndexError: return Result.failed(res.reason) url = "https://h5.pipix.com/bds/webapi/item/detail/?item_id=" + id + "&source=share" info_res = http_utils.get(url, header=share_headers) if http_utils.is_error(info_res): return Result.error(info_res) data = json.loads(str(info_res.text)) try: url = data['data']['item']['origin_video_download']['url_list'][0][ 'url'] except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT return Result.success(url)
def fetch(cls, url: str, mode=0) -> Result: url = cls.get_url(url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId和dytk res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) try: props = re.findall(r"(?<=<script id=\"__NEXT_DATA__\" type=\"application\/json\" crossorigin=\"anonymous\">)" r"(.*?)" r"(?=<\/script><script crossorigin=\"anonymous\")", res.text) except IndexError: return Result.failed(res.reason) data = json.loads(str(props[0])) try: video_url = data['props']['pageProps']['videoData']['itemInfos']['video']['urls'][0] except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT res = http_utils.get(video_url) text = res.content.decode('utf-8', 'ignore') index = text.index('vid:') vid = text[index+4: index+36] download_url = 'https://api2.musical.ly/aweme/v1/playwm/?video_id=' + vid result = Result.success(download_url) if mode == 1: result.ref = res.url return result
def fetch(cls, url: str, mode=0) -> Result: burl = cls.get_url(url) if burl is None: return ErrorResult.URL_NOT_INCORRECT bvid = cls.get_bvid(burl) if bvid is None: return ErrorResult.URL_NOT_INCORRECT res = http_utils.get('https://api.bilibili.com/x/player/pagelist', param={ 'bvid': bvid, 'jsonp': 'jsonp' }, header=headers) if http_utils.is_error(res): return Result.error(res) data = json.loads(str(res.text)) p = re.findall(r"(?<=p=)(\d)", url) if len(p) == 0: index = 0 else: index = int(p[0]) - 1 try: cid = data['data'][index]['cid'] except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT # http://api.bilibili.com/x/player/playurl?cid=227539569&bvid=BV1cD4y1m7ce&qn=112&fnval=16 res = http_utils.get('http://api.bilibili.com/x/player/playurl', param={ 'cid': cid, 'bvid': bvid, 'qn': 112, 'fnval': 0, 'fnver': 0, 'fourk': 1, }, header=user_headers) if http_utils.is_error(res): return Result.error(res) data = json.loads(str(res.text)) try: url = data['data']['durl'][0]['url'] # url = data['data']['dash']['video'][0]['baseUrl'] except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT result = Result.success(url) if mode != 0: result.ref = res.url return result
def fetch(cls, url: str, mode=0) -> Result: url = cls.get_url(url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) html = res.text try: data = re.findall(r"(?<=window\.__INITIAL_STATE__=)(.*?)(?=;\(function\(\))", html)[0] except IndexError: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT data = json.loads(data) try: bvid = data['epInfo']['bvid'] cid = data['epInfo']['cid'] except Exception as e: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT # http://api.bilibili.com/x/player/playurl?cid=227539569&bvid=BV1cD4y1m7ce&qn=112&fnval=16 res = http_utils.get('http://api.bilibili.com/x/player/playurl', param={ 'cid': cid, 'bvid': bvid, 'qn': 112, 'fnval': 0, 'fnver': 0, 'fourk': 1, }, header=user_headers) if http_utils.is_error(res): return Result.error(res) data = json.loads(str(res.text)) try: url = data['data']['durl'][0]['url'] except (KeyError, IndexError): return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT result = Result.success(url) if mode != 0: result.ref = res.url return result
def fetch(cls, url: str, model=0) -> Result: """ 获取视频详情 :param url: :param model: :return: """ url = analyzer.get_url(vtype, url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId和dytk res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) html = str(res.content) try: item_id = re.findall(r"(?<=itemId:\s\")\d+", html)[0] dytk = re.findall(r"(?<=dytk:\s\")(.*?)(?=\")", html)[0] except IndexError: return Result.failed(res.reason) # 组装视频长链接 infourl = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + item_id + "&dytk=" + dytk # 请求长链接,获取play_addr url_res = http_utils.get(infourl, header=headers) if http_utils.is_error(url_res): return Result.error(url_res) vhtml = str(url_res.text) try: uri = re.findall(r'(?<=\"uri\":\")\w{32}(?=\")', vhtml)[0] except IndexError: return Result.failed(url_res.reason) if not uri: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT link = "https://aweme.snssdk.com/aweme/v1/play/?video_id=" + uri + \ "&line=0&ratio=540p&media_type=4&vr_type=0&improve_bitrate=0" \ "&is_play_url=1&is_support_h265=0&source=PackSourceEnum_PUBLISH" result = Result.success(link) if model != 0: result.ref = res.url return result
def fetch(cls, url: str, model=0) -> Result: """ 获取视频详情 :param url: :param model: :return: """ url = analyzer.get_url(vtype, url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) try: item_id = re.findall(r"(?<=item_id=)\d+(?=\&)", res.url)[0] except IndexError: return Result.failed(res.reason) # 视频信息链接 infourl = "https://share.huoshan.com/api/item/info?item_id=" + item_id # 请求长链接,获取play_addr url_res = http_utils.get(infourl, header=info_headers) if http_utils.is_error(url_res): return Result.error(url_res) vhtml = str(url_res.text) try: video_id = re.findall(r'(?<=video_id\=)\w+(?=\&)', vhtml)[0] except IndexError: return Result.failed(url_res.reason) if not video_id: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT link = "https://api.huoshan.com/hotsoon/item/video/_source/?video_id=" + video_id + "&line=0&app_id=0&vquality=normal" result = Result.success(link) if model != 0: result.ref = res.url return result
def fetch(cls, url: str, mode=0) -> Result: url = cls.get_url(url) if url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId res = http_utils.get(url, header=headers) if http_utils.is_error(res): return Result.error(res) # html = str(res.content) try: item_id = re.findall(r"(?<=video/)\d+", res.url)[0] except IndexError: return Result.failed(res.reason) # 组装视频长链接 infourl = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=" + item_id + "&dytk="# + dytk # 请求长链接,获取play_addr url_res = http_utils.get(infourl, header=headers) if http_utils.is_error(url_res): return Result.error(url_res) data = json.loads(str(url_res.text)) if not data['status_code'] == 0: return Result.failed(data['status_msg']) item = data['item_list'][0] if item['aweme_type'] == 4: result = DouyinService.get_video(item) elif item['aweme_type'] == 2: result = DouyinService.get_image(item) result.extra = ".zip" else: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT if mode == 1: result.ref = res.url return result
def get_video(data) -> Result: try: vid = data['video']['vid'] except Exception as e: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT try: ratio = data['video']['ratio'] except Exception as e: ratio = "540p" link = "https://aweme.snssdk.com/aweme/v1/play/?video_id=" + vid + \ "&line=0&ratio="+ratio+"&media_type=4&vr_type=0&improve_bitrate=0" \ "&is_play_url=1&is_support_h265=0&source=PackSourceEnum_PUBLISH" return Result.success(link)
def get_image(data) -> Result: try: images = data['images'] except Exception as e: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT image_urls = [] for image in images: urls = image['url_list'] url = urls[-1] image_urls.append(url) result = Result.success(image_urls) result.type = 1 return result