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, 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, 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