Closed a943512 closed 9 months ago
def get_info(cls, url: str) -> Result: share_url = cls.get_url(url) if share_url is None: return ErrorResult.URL_NOT_INCORRECT # 请求短链接,获得itemId res = http_utils.get(share_url, header=headers, redirect=True) if http_utils.is_error(res): return ErrorResult.VIDEO_INFO_NOT_FOUNT try: # item_id = re.findall(r"(?<=video/)\d+", res.headers['location'])[0] item_id = re.findall(r"(?<=\w/)\d+", res.url)[0] except IndexError: return ErrorResult.VIDEO_INFO_NOT_FOUNT share_url = f'https://www.douyin.com/video/{item_id}?previous_page=app_code_link' res = http_utils.get(share_url, header=web_headers) if http_utils.is_error(res): return ErrorResult.VIDEO_INFO_NOT_FOUNT json_data = re.findall(r'(?<=<script id=\"RENDER_DATA\" type=\"application\/json\">)(.*?)(?=<\/script>)', res.text) if len(json_data) == 0: return ErrorResult.VIDEO_INFO_ERROR aweme_data = json.loads(parse.unquote(json_data[0])) with open("1.txt","w") as w: w.write(str(aweme_data)) data = None for k, v in aweme_data.items(): if isinstance(v, str): continue if 'awemeId' in v: # print(0,"++++"*100) data = v['aweme'] if data is None or data['statusCode'] != 0: return ErrorResult.VIDEO_ADDRESS_NOT_FOUNT data = data['detail'] info = Info(platform=vtype) info.desc = DouyinService.get_desc(data) info.cover = DouyinService.get_cover(data) if data['awemeType'] == 0: info.video = DouyinService.get_video(data) info.filename = data['awemeId'] + ".mp4" else: info.images = DouyinService.get_image(data) info.filename = data['awemeId'] + ".zip" return Result.success(info)