import json

import requests


def get_video_detail(vid, userad, cate):
    # URL and payload
    url = "https://gkvxwq2023.we-media.cn/app/index.php"
    payload = {
        "i": "1",
        "t": "0",
        "m": "jyt_txvideo",
        "v": "1.0.0",
        "from": "wxapp",
        "c": "entry",
        "a": "wxapp",
        "do": "videodetail",
        "vid": vid,
        "userad": userad,
        "cate": cate,
    }
    headers = {
        "Host": "gkvxwq2023.we-media.cn",
        "xweb_xhr": "1",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/6.8.0(0x16080000) NetType/WIFI MiniProgramEnv/Mac MacWechat/WMPF MacWechat/3.8.5(0x13080510)XWEB/1100",
        "content-type": "application/x-www-form-urlencoded",
        "accept": "*/*",
        "referer": "https://servicewechat.com/wx49f06df06becc7fa/2/page-frame.html",
        "accept-language": "en-US,en;q=0.9",
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    print(json.dumps(response.json(), ensure_ascii=False, indent=4))


def get_video_list():
    url = "https://gkvxwq2023.we-media.cn/app/index.php"
    payload = {
        "i": "1",
        "t": "0",
        "m": "jyt_txvideo",
        "v": "1.0.0",
        "from": "wxapp",
        "c": "entry",
        "a": "wxapp",
        "do": "videotui",
        "city": "",
        "category": "494",
    }
    headers = {
        "Host": "gkvxwq2023.we-media.cn",
        "xweb_xhr": "1",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/6.8.0(0x16080000) NetType/WIFI MiniProgramEnv/Mac MacWechat/WMPF MacWechat/3.8.5(0x13080510)XWEB/1100",
        "content-type": "application/x-www-form-urlencoded",
        "accept": "*/*",
        "referer": "https://servicewechat.com/wx49f06df06becc7fa/2/page-frame.html",
        "accept-language": "en-US,en;q=0.9",
    }
    response = requests.post(url, data=payload, headers=headers)
    return response.json()



if __name__ == "__main__":
    result = get_video_list()
    # print(json.dumps(result, ensure_ascii=False, indent=4))
    for video_obj in result["data"]:
        vid = video_obj['vid']
        cate = video_obj['category']
        userad = ''
        get_video_detail(vid=vid, userad=userad, cate=cate)
