moyada / stealer

抖音、快手、火山、皮皮虾,视频去水印程序
MIT License
973 stars 274 forks source link

获取作品信息的解析函数不能用了需要更新解析规则哪位大佬看下 #101

Closed a943512 closed 6 months ago

a943512 commented 1 year 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)