吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 27820|回复: 195
上一主题 下一主题
收起左侧

[Python 转载] 获取优酷视频真实m3u8播放链接,非vip也可得到原视频最高画质

    [复制链接]
跳转到指定楼层
楼主
yanshiqi 发表于 2021-7-22 01:02 回帖奖励
直接上代码吧。。。

import re, requests, time, subprocess, json, base64
from hashlib import md5

class YouKu:
    def __init__(self, cookie):
        self.cookie = cookie

    def youku_sign(self, t, data, token):
        appKey = '24679788'     # 固定值
        '''token值在cookie'''
        sign = token + '&' + t + '&' + appKey + '&' + data
        md = md5()
        md.update(sign.encode('UTF-8'))
        sign = md.hexdigest()
        return sign

    def utid(self):
        cna = re.compile("cna=(.*?);")
        _m_h5_tk = re.compile("_m_h5_tk=(.*?)_.*?;")
        token = _m_h5_tk.findall(self.cookie+";")
        utid_ = cna.findall(self.cookie+";")
        return {"utid": utid_[0], "token": token[0]}

    # 若直接在首页小窗口上复制的视频网址,是重定向的网址。
    def redirect(self, url):
        headers = {
            "referer": "https://www.youku.com/",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }
        resp = requests.get(url=url, headers=headers)
        return resp.url

    def page_parser(self, url):
        headers = {
            "authority": "v.youku.com",
            "method": "GET",
            "path": url.replace("https://v.youku.com/",""),
            "scheme": "https",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-encoding": "gzip, deflate, br",
            "accept-language": "zh-CN,zh;q=0.9",
            "cache-control": "max-age=0",
            "cookie": self.cookie,
            "referer": "https://www.youku.com/",
            "sec-fetch-dest": "document",
            "sec-fetch-mode": "navigate",
            "sec-fetch-site": "none",
            "sec-fetch-user": "?1",
            "upgrade-insecure-requests": "1",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }
        resp = requests.get(url=url, headers=headers)
        html = resp.content.decode("utf-8")
        # print(html)
        videoId = re.compile("videoId: '(.*?)'")
        showid = re.compile("showid: '(.*?)'")
        currentEncodeVid = re.compile("currentEncodeVid: '(.*?)'")
        videoId = videoId.findall(html, re.S | re.M | re.I)
        current_showid = showid.findall(html, re.S | re.M | re.I)
        vid = currentEncodeVid.findall(html, re.S | re.M | re.I)
        return {"current_showid": current_showid[0], "videoId": videoId[0], "vid": vid[0]}

    def get_emb(self, videoId):
        emb = base64.b64encode(("%swww.youku.com/" % videoId).encode('utf-8')).decode('utf-8')
        return emb

    # 这个函数用来获取元素的第一个值
    def takeOne(self, elem):
        return float(elem[0])

    def m3u8_url(self, t, params_data, sign):
        url = "https://acs.youku.com/h5/mtop.youku.play.ups.appinfo.get/1.1/"

        params = {
            "jsv": "2.5.8",
            "appKey": "24679788",
            "t": t,
            "sign": sign,
            "api": "mtop.youku.play.ups.appinfo.get",
            "v": "1.1",
            "timeout": "20000",
            "YKPid": "20160317PLF000211",
            "YKLoginRequest": "true",
            "AntiFlood": "true",
            "AntiCreep": "true",
            "type": "jsonp",
            "dataType": "jsonp",
            "callback": "mtopjsonp1",
            "data": params_data,
        }

        headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Connection": "keep-alive",
            "Cookie": self.cookie,
            "Host": "acs.youku.com",
            "Referer": "https://v.youku.com/v_show/id_XNTA1MTYwMzU0OA==.html?spm=a2h0c.8166622.PhoneSokuUgc_3.dscreenshot",
            "Sec-Fetch-Dest": "script",
            "Sec-Fetch-Mode": "no-cors",
            "Sec-Fetch-Site": "same-site",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }

        resp = requests.get(url=url, params=params, headers=headers)
        result =resp.text
        # print(result)
        data = json.loads(result[12:-1])
        # print(data)
        ret = data["ret"]
        video_lists = []
        if ret == ["SUCCESS::调用成功"]:
            stream = data["data"]["data"]["stream"]
            title = data["data"]["data"]["video"]["title"]
            print("解析成功:")
            for video in stream:
                m3u8_url = video["m3u8_url"]
                width = video["width"]
                height = video["height"]
                size = video["size"]
                size = '{:.1f}'.format(float(size) / 1048576)
                video_lists.append([size, width, height, title, m3u8_url])
                # print(f">>>  {title} 分辨率:{width}x{height} 视频大小:{size}M \tm3u8播放地址:{m3u8_url}")

            video_lists.sort(key=self.takeOne)
            for video_list in video_lists:
                print(f">>>  {title} 分辨率:{video_list[1]}x{video_list[2]} 视频大小:{video_list[0]}M \tm3u8播放地址:{video_list[4]}")
            self.play(video_lists[-1][4])    # 选择播放列表最后一个视频(经过sort排序后,最后一个即为清晰度最高的一个)
        elif ret == ["FAIL_SYS_ILLEGAL_ACCESS::非法请求"]:
            print("请求参数错误")
        elif ret == ["FAIL_SYS_TOKEN_EXOIRED::令牌过期"]:
            print("Cookie过期")
        else:
            print(ret[0])


    def play(self, x):
        text = 'ffplay -protocol_whitelist "file,http,https,rtp,udp,tcp,tls" -loglevel quiet -i "%s"' % x
        subprocess.call(text, shell=True)

    def start(self):
        t = str(int(time.time() * 1000))
        user_info = self.utid()
        userid = user_info["utid"]
        url = input("请将优酷视频播放链接粘贴到这:\n")
        url = self.redirect(url)
        page_info = self.page_parser(url)
        emb = self.get_emb(page_info["videoId"])
        params_data = r'''{"steal_params":"{\"ccode\":\"0502\",\"client_ip\":\"192.168.1.1\",\"utid\":\"%s\",\"client_ts\":%s,\"version\":\"2.1.69\",\"ckey\":\"DIl58SLFxFNndSV1GFNnMQVYkx1PP5tKe1siZu/86PR1u/Wh1Ptd+WOZsHHWxysSfAOhNJpdVWsdVJNsfJ8Sxd8WKVvNfAS8aS8fAOzYARzPyPc3JvtnPHjTdKfESTdnuTW6ZPvk2pNDh4uFzotgdMEFkzQ5wZVXl2Pf1/Y6hLK0OnCNxBj3+nb0v72gZ6b0td+WOZsHHWxysSo/0y9D2K42SaB8Y/+aD2K42SaB8Y/+ahU+WOZsHcrxysooUeND\"}","biz_params":"{\"vid\":\"%s\",\"play_ability\":16782592,\"current_showid\":\"%s\",\"preferClarity\":99,\"extag\":\"EXT-X-PRIVINF\",\"master_m3u8\":1,\"media_type\":\"standard,subtitle\",\"app_ver\":\"2.1.69\",\"h265\":1}","ad_params":"{\"vs\":\"1.0\",\"pver\":\"2.1.69\",\"sver\":\"2.0\",\"site\":1,\"aw\":\"w\",\"fu\":0,\"d\":\"0\",\"bt\":\"pc\",\"os\":\"win\",\"osv\":\"10\",\"dq\":\"auto\",\"atm\":\"\",\"partnerid\":\"null\",\"wintype\":\"interior\",\"isvert\":0,\"vip\":1,\"emb\":\"%s\",\"p\":1,\"rst\":\"mp4\",\"needbf\":2,\"avs\":\"1.0\"}"}'''% (userid, t[:10], page_info["vid"], page_info["current_showid"], emb)
        sign = self.youku_sign(t, params_data, user_info["token"])
        self.m3u8_url(t, params_data, sign)

if __name__ == '__main__':    # 首先在这里设置自己的cookie  非vip只能解析到免费视频。
    cookie = '__ysuid=21059a310000087e5fcbb3ee0000a58b; __yscnt=1; P_gck=NA%7CMvLpuothPGV815HV%2B4HBtQ%3D%3D%7CNA%7C1622106293483; disrd=26765; UM_distinctid=179ebdf5fdf38-053a25f2c96ee7-3e604809-1fa400-179ebdf5fe0376; cna=rQ1fGTsJrDcCAXO/hcGilGH2; __aysid=1625988129582bId; youku_history_word=%5B%22mv%22%2C%22%25E6%25A2%25A6%25E5%25B9%25BB%25E8%2583%258C%25E6%2599%25AF%25E7%25B4%25A0%25E6%259D%2590%22%2C%22%25E5%2585%2589%25E6%2599%2595%25E6%2595%2588%25E6%259E%259C%22%2C%22%25E5%2587%25AD%25E6%259C%25AC%25E4%25BA%258B%22%5D; P_pck_rm=fCj4xhhC086e9d5dafc44cZBc5UiiyUyR3DRaThifoJ0gOGm8ZOO%2BUMCE0pqY%2BjUMdFwZCWJGNZyfpRDiuFsjU05f1Wxunk5LO6fCSR%2BRxZx6X3lqIEceioFT64UeSgWuwpeRZYq5Xx4ZQBJDZbY1rIy57hFGCr0v0asOU0A3ItzovUbUqLMrwhu8mg%3D_V2; ysestep=1; yseidcount=1; ystep=1; juid=01faf0ro0ll51; xlly_s=1; ctoken=TwV5wIfcJQnCpzKOqQz8ISZd; _m_h5_tk=925b5e7437862a512deb2fedd0f5a385_1626890538888; _m_h5_tk_enc=5b83dbbea7e7b91e3ad88244c709814c; __ayft=1626885496557; __ayscnt=1; P_ck_ctl=707B8AC23F1FDFD594965F78DE614599; isg=BFdXdtc1-1a4AkDpLbeWc0ME5suhnCv-yBmpK6mE4yax2HUasW_8TA6wPnhGMAN2; l=eBOegfIlOee8pmAsBO5aFurza77OmIRbzsPzaNbMiInca6wlGUErbNCBWaiHPdtjgtfj4etPkdi_7d39Sya_WjDDBeYCyHEOAxv9-; tfstk=c1k1BOTkJNb_l2RVQctFgX01VQwdaqS7cCaifb21raThuImaJs4VUzaG4jbv3zEC.; __arpvid=1626885539497WCtEjY-1626885539597; __arycid=dv-3-00; __arcms=dv-3-00; __aypstp=2; __ayspstp=91; modalFrequency={"UUID":"2"}; __ayvstp=1; __aysvstp=4'
    youku = YouKu(cookie)
    youku.start()


请将优酷视频播放链接粘贴到这:https://v.youku.com/v_show/id_XNTE2MDI5MzY4NA==.html?spm=a2ha1.14919748_WEBHOME_GRAY.drawer9.d_zj1_7&scm=20140719.manual.2559.video_XNTE2MDI5MzY4NA%3D%3D解析成功:>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:480x270 视频大小:175.5M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/6572C31866231714AFDA146F9/030003000060F55280F4A7FDAC94661C14E521-E691-4537-B090-DE897B8293E6-1-4595380.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=Bd2d7afd559c4f98ed02358f7cae73eba&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=3gphdv3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=20000000CF7DB25B908C1A26D5EB93CBA01C0D1602000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:640x360 视频大小:229.0M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/65727C74CA13D719DBD09291A/050007000060F55280F4A7FDAC9466FC2BD451-740F-4B5B-9EE7-43184D02892E-1-4595531.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B173b6cf90fc7e84e62e92d2fc2443acc&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp5sdv3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=200000007BFDDBF1055450A433E7A00576C6751B02000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:640x360 视频大小:327.6M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/6774653640A31714AFDA13136/030005000060F55280F4A7FDAC94665A591E5B-4E9B-43C0-BB53-39F2A978D08A-1-4595380.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=Bcdd7f9e8762f3f102969efb6b7620504&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=flvhdv3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=2000000036AB6C01CD9683766718E6AE9D2A07E802000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:960x540 视频大小:369.4M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/67745E343FF4D720C1194362A/050009000060F55280F4A7FDAC946688550912-F9EF-4906-BA28-A8ECA6FF150D-1-4595531.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B2ba50a7cf6d6515f9cbcc3631d862138&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp5hdv3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=20000000610ABD09905B5EDA8B9BF81B6F624A2A02000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:960x540 视频大小:536.2M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/697584F86974871E997294E4C/030006000060F55280F4A7FDAC9466CCC96995-7708-422F-B069-A845409F959A-1-4595380.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B32d25f893a48a7f2a6bc85f7372186d0&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp4hdv3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=20000000CAE1BFED8FD7217C2698D10ACF18B4C102000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:1280x720 视频大小:643.6M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/677340C842F4871E997292D34/05000A000060F55280F4A7FDAC9466EF63D6DC-119D-46AF-8A96-5E2B674423E9-1-4595531.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B2d250933db4ed4eff2aba9eb9333f482&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp5hd2v3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=20000000EA67EC7E62A5A072110D38155BEED36002000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:1280x720 视频大小:876.2M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/6974FD40C234B71FE47032942/030007000060F55280F4A7FDAC9466C2322AE5-D8F6-4474-9F72-7B926E27E5FF-1-4595380.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B8f8779fa459b34957b5516d442281674&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp4hd2v3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=200000006690E46956BCA114EB040F160B16325702000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:1920x1080 视频大小:1164.2M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/67739C545554671DBCC974DA8/05000B000060F55280F4A7FDAC94664DFEF253-8301-4884-99D8-C869BA440DB7-1-4595531.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B283a853aac6293291e55210c99257f70&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp5hd3v3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=2000000045AEC9D82118B873A22BEB3B1001C19102000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:1920x1080 视频大小:1581.2M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/697577408173A71890D2F5975/030009000060F55280F4A7FDAC946611E49A9D-B00D-438B-AEB2-F90988AE898D-1-4595380.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=B849bf982cc8d8b425a3eebaf4f21b8f3&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp4hd3v3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=2000000072E5636009F8C9975F4E63E64C06F5A102000000>>>  罢工啦!跑男团终极对抗制作组,谁要承担超大水炮惩罚 分辨率:3840x2160 视频大小:2626.5M         m3u8播放地址:http://valipl.cp31.ott.cibntv.net/65729F4C4244B71FE47034073/05000C000060F55280F4A7FDAC9466E62F3A0D-3978-45A4-A79D-DE63E148D97A-1-4595531.m3u8?ccode=0502&duration=6682&expire=18000&psid=d74b73fd87ca4cb68b4b45cd25d4a7de43346&ups_client_netip=73be7bfb&ups_ts=1626885698&ups_userid=63205403&utid=rQ1fGTsJrDcCAXO%2FhcGilGH2&vid=XNTE2MDI5MzY4NA&vkey=Ba5163edbfef57762beb9b8e2a9d17c43&sm=1&operate_type=1&dre=u37&si=73&eo=1&dst=1&iv=0&s=cbcad844c5894d209b9f&type=mp5hd4v3&bc=2&hotvt=1&t=f572919a196d235&cug=1&rid=20000000A067C6439AF28250A512489B8A6A5BE202000000进程已结束,退出代码为 0



'''使用前须知:  我设置了解析完成后,立即播放。 利用的是 ffmpeg  .   自行百度安装一下。    不装应该也可以用,只是播放报错而已!!!
     这里先放出优酷视频的解析。。。。。   看看反应先,如果大家都想学习,  后续再放出 腾讯视频、爱奇艺的解析。。。
    先这样吧。   不懂的再留言。。。



'''

































点评

就差腾讯的了!  发表于 2021-7-23 15:51

免费评分

参与人数 32吾爱币 +28 热心值 +26 收起 理由
pjbl + 1 + 1 此乃稀缺人才也
lvlianjia + 1 问下默认粤语的港剧如何下载国语的版本 谢谢
多情自古空余恨 + 1 + 1 谢谢@Thanks!
Dark_Forest + 1 + 1 我很赞同!
jia2319885955 + 1 + 1 用心讨论,共获提升!
XMQ + 1 热心回复!
520ping + 1 + 1 鼓励转贴优秀软件安全工具和文档!
Roar520 + 1 + 1 热心回复!
saisai0102 + 1 + 1 有使用教程就更完美了,想看看怎么用的。
5t5yyds + 1 学习了!
winpire + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
zhangchr + 1 正在学python,看了很有益处
hybin + 1 + 1 热心回复!
chendeshen + 1 谢谢@Thanks!
阿成155 + 1 + 1 热心回复!
fuwenyue + 1 + 1 热心回复!
stable111 + 1 谢谢@Thanks!
sxflzyg + 1 + 1 <font style="vertical-align: inherit;"><font style=
12692873 + 1 + 1 谢谢@Thanks!
贾东平 + 1 + 1 要是制作成软件就好了。
zshq1 + 1 + 1 热心回复!
lvaule + 1 + 1 谢谢@Thanks!
zhb8616246 + 1 + 1 谢谢@Thanks!
叫我小王叔叔 + 1 + 1 老铁,分都给你,估计学会了,路子也就黄了
aighsn + 1 谢谢@Thanks!
科西嘉滕 + 1 谢谢@Thanks!
min_x91 + 1 + 1 我很赞同!
mrtcc + 1 + 1 我很赞同!
tianbukongbai + 1 + 1 谢谢@Thanks!
aedelnz + 1 ❛‿˂̵✧
冰海无涯 + 1 + 1 用心讨论,共获提升!
wqx520 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

  • · Aarow|主题: 988, 订阅: 304

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

来自 2#
叶凯 发表于 2021-7-22 01:32
看着难受,给你放到代码框里

[Python] 纯文本查看 复制代码
import re, requests, time, subprocess, json, base64
from hashlib import md5

class YouKu:
    def __init__(self, cookie):
        self.cookie = cookie

    def youku_sign(self, t, data, token):
        appKey = '24679788'     # 固定值
        '''token值在cookie中'''
        sign = token + '&' + t + '&' + appKey + '&' + data
        md = md5()
        md.update(sign.encode('UTF-8'))
        sign = md.hexdigest()
        return sign

    def utid(self):
        cna = re.compile("cna=(.*?);")
        _m_h5_tk = re.compile("_m_h5_tk=(.*?)_.*?;")
        token = _m_h5_tk.findall(self.cookie+";")
        utid_ = cna.findall(self.cookie+";")
        return {"utid": utid_[0], "token": token[0]}

    # 若直接在首页小窗口上复制的视频网址,是重定向的网址。
    def redirect(self, url):
        headers = {
            "referer": "https://www.youku.com/",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }
        resp = requests.get(url=url, headers=headers)
        return resp.url

    def page_parser(self, url):
        headers = {
            "authority": "v.youku.com",
            "method": "GET",
            "path": url.replace("https://v.youku.com/",""),
            "scheme": "https",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-encoding": "gzip, deflate, br",
            "accept-language": "zh-CN,zh;q=0.9",
            "cache-control": "max-age=0",
            "cookie": self.cookie,
            "referer": "https://www.youku.com/",
            "sec-fetch-dest": "document",
            "sec-fetch-mode": "navigate",
            "sec-fetch-site": "none",
            "sec-fetch-user": "?1",
            "upgrade-insecure-requests": "1",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }
        resp = requests.get(url=url, headers=headers)
        html = resp.content.decode("utf-8")
        # print(html)
        videoId = re.compile("videoId: '(.*?)'")
        showid = re.compile("showid: '(.*?)'")
        currentEncodeVid = re.compile("currentEncodeVid: '(.*?)'")
        videoId = videoId.findall(html, re.S | re.M | re.I)
        current_showid = showid.findall(html, re.S | re.M | re.I)
        vid = currentEncodeVid.findall(html, re.S | re.M | re.I)
        return {"current_showid": current_showid[0], "videoId": videoId[0], "vid": vid[0]}

    def get_emb(self, videoId):
        emb = base64.b64encode(("%swww.youku.com/" % videoId).encode('utf-8')).decode('utf-8')
        return emb

    # 这个函数用来获取元素的第一个值
    def takeOne(self, elem):
        return float(elem[0])

    def m3u8_url(self, t, params_data, sign):
        url = "https://acs.youku.com/h5/mtop.youku.play.ups.appinfo.get/1.1/"

        params = {
            "jsv": "2.5.8",
            "appKey": "24679788",
            "t": t,
            "sign": sign,
            "api": "mtop.youku.play.ups.appinfo.get",
            "v": "1.1",
            "timeout": "20000",
            "YKPid": "20160317PLF000211",
            "YKLoginRequest": "true",
            "AntiFlood": "true",
            "AntiCreep": "true",
            "type": "jsonp",
            "dataType": "jsonp",
            "callback": "mtopjsonp1",
            "data": params_data,
        }

        headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Connection": "keep-alive",
            "Cookie": self.cookie,
            "Host": "acs.youku.com",
            "Referer": "https://v.youku.com/v_show/id_XNTA1MTYwMzU0OA==.html?spm=a2h0c.8166622.PhoneSokuUgc_3.dscreenshot",
            "Sec-Fetch-Dest": "script",
            "Sec-Fetch-Mode": "no-cors",
            "Sec-Fetch-Site": "same-site",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
        }

        resp = requests.get(url=url, params=params, headers=headers)
        result =resp.text
        # print(result)
        data = json.loads(result[12:-1])
        # print(data)
        ret = data["ret"]
        video_lists = []
        if ret == ["SUCCESS::调用成功"]:
            stream = data["data"]["data"]["stream"]
            title = data["data"]["data"]["video"]["title"]
            print("解析成功:")
            for video in stream:
                m3u8_url = video["m3u8_url"]
                width = video["width"]
                height = video["height"]
                size = video["size"]
                size = '{:.1f}'.format(float(size) / 1048576)
                video_lists.append([size, width, height, title, m3u8_url])
                # print(f">>>  {title} 分辨率:{width}x{height} 视频大小:{size}M \tm3u8播放地址:{m3u8_url}")

            video_lists.sort(key=self.takeOne)
            for video_list in video_lists:
                print(f">>>  {title} 分辨率:{video_list[1]}x{video_list[2]} 视频大小:{video_list[0]}M \tm3u8播放地址:{video_list[4]}")
            self.play(video_lists[-1][4])    # 选择播放列表最后一个视频(经过sort排序后,最后一个即为清晰度最高的一个)
        elif ret == ["FAIL_SYS_ILLEGAL_ACCESS::非法请求"]:
            print("请求参数错误")
        elif ret == ["FAIL_SYS_TOKEN_EXOIRED::令牌过期"]:
            print("Cookie过期")
        else:
            print(ret[0])


    def play(self, x):
        text = 'ffplay -protocol_whitelist "file,http,https,rtp,udp,tcp,tls" -loglevel quiet -i "%s"' % x
        subprocess.call(text, shell=True)

    def start(self):
        t = str(int(time.time() * 1000))
        user_info = self.utid()
        userid = user_info["utid"]
        url = input("请将优酷视频播放链接粘贴到这:\n")
        url = self.redirect(url)
        page_info = self.page_parser(url)
        emb = self.get_emb(page_info["videoId"])
        params_data = r'''{"steal_params":"{\"ccode\":\"0502\",\"client_ip\":\"192.168.1.1\",\"utid\":\"%s\",\"client_ts\":%s,\"version\":\"2.1.69\",\"ckey\":\"DIl58SLFxFNndSV1GFNnMQVYkx1PP5tKe1siZu/86PR1u/Wh1Ptd+WOZsHHWxysSfAOhNJpdVWsdVJNsfJ8Sxd8WKVvNfAS8aS8fAOzYARzPyPc3JvtnPHjTdKfESTdnuTW6ZPvk2pNDh4uFzotgdMEFkzQ5wZVXl2Pf1/Y6hLK0OnCNxBj3+nb0v72gZ6b0td+WOZsHHWxysSo/0y9D2K42SaB8Y/+aD2K42SaB8Y/+ahU+WOZsHcrxysooUeND\"}","biz_params":"{\"vid\":\"%s\",\"play_ability\":16782592,\"current_showid\":\"%s\",\"preferClarity\":99,\"extag\":\"EXT-X-PRIVINF\",\"master_m3u8\":1,\"media_type\":\"standard,subtitle\",\"app_ver\":\"2.1.69\",\"h265\":1}","ad_params":"{\"vs\":\"1.0\",\"pver\":\"2.1.69\",\"sver\":\"2.0\",\"site\":1,\"aw\":\"w\",\"fu\":0,\"d\":\"0\",\"bt\":\"pc\",\"os\":\"win\",\"osv\":\"10\",\"dq\":\"auto\",\"atm\":\"\",\"partnerid\":\"null\",\"wintype\":\"interior\",\"isvert\":0,\"vip\":1,\"emb\":\"%s\",\"p\":1,\"rst\":\"mp4\",\"needbf\":2,\"avs\":\"1.0\"}"}'''% (userid, t[:10], page_info["vid"], page_info["current_showid"], emb)
        sign = self.youku_sign(t, params_data, user_info["token"])
        self.m3u8_url(t, params_data, sign)

if __name__ == '__main__':    # 首先在这里设置自己的cookie  非vip只能解析到免费视频。 
    cookie = '__ysuid=21059a310000087e5fcbb3ee0000a58b; __yscnt=1; P_gck=NA%7CMvLpuothPGV815HV%2B4HBtQ%3D%3D%7CNA%7C1622106293483; disrd=26765; UM_distinctid=179ebdf5fdf38-053a25f2c96ee7-3e604809-1fa400-179ebdf5fe0376; cna=rQ1fGTsJrDcCAXO/hcGilGH2; __aysid=1625988129582bId; youku_history_word=%5B%22mv%22%2C%22%25E6%25A2%25A6%25E5%25B9%25BB%25E8%2583%258C%25E6%2599%25AF%25E7%25B4%25A0%25E6%259D%2590%22%2C%22%25E5%2585%2589%25E6%2599%2595%25E6%2595%2588%25E6%259E%259C%22%2C%22%25E5%2587%25AD%25E6%259C%25AC%25E4%25BA%258B%22%5D; P_pck_rm=fCj4xhhC086e9d5dafc44cZBc5UiiyUyR3DRaThifoJ0gOGm8ZOO%2BUMCE0pqY%2BjUMdFwZCWJGNZyfpRDiuFsjU05f1Wxunk5LO6fCSR%2BRxZx6X3lqIEceioFT64UeSgWuwpeRZYq5Xx4ZQBJDZbY1rIy57hFGCr0v0asOU0A3ItzovUbUqLMrwhu8mg%3D_V2; ysestep=1; yseidcount=1; ystep=1; juid=01faf0ro0ll51; xlly_s=1; ctoken=TwV5wIfcJQnCpzKOqQz8ISZd; _m_h5_tk=925b5e7437862a512deb2fedd0f5a385_1626890538888; _m_h5_tk_enc=5b83dbbea7e7b91e3ad88244c709814c; __ayft=1626885496557; __ayscnt=1; P_ck_ctl=707B8AC23F1FDFD594965F78DE614599; isg=BFdXdtc1-1a4AkDpLbeWc0ME5suhnCv-yBmpK6mE4yax2HUasW_8TA6wPnhGMAN2; l=eBOegfIlOee8pmAsBO5aFurza77OmIRbzsPzaNbMiInca6wlGUErbNCBWaiHPdtjgtfj4etPkdi_7d39Sya_WjDDBeYCyHEOAxv9-; tfstk=c1k1BOTkJNb_l2RVQctFgX01VQwdaqS7cCaifb21raThuImaJs4VUzaG4jbv3zEC.; __arpvid=1626885539497WCtEjY-1626885539597; __arycid=dv-3-00; __arcms=dv-3-00; __aypstp=2; __ayspstp=91; modalFrequency={"UUID":"2"}; __ayvstp=1; __aysvstp=4'
    youku = YouKu(cookie)
    youku.start()



免费评分

参与人数 3吾爱币 +2 热心值 +2 收起 理由
xiaochengQT + 1 + 1 诶,舒服多了
QingYi. + 1 我很赞同!
BOSS123 + 1 热心回复!

查看全部评分

来自 #
 楼主| yanshiqi 发表于 2021-7-24 01:59 |楼主
后面测试,发现大部分视频还是只能解析出720P的视频,  因为我测试的时候,用到的都是几分钟的那种视频, 有时甚至解析得到4K视频,  所在这个帖子标题,还是有误的!!!
推荐
moonswamp 发表于 2021-7-22 01:18
这个厉害了,不过不懂操作,谁给整成个网页或者小软件 ?
推荐
QRQF001 发表于 2021-7-22 18:03
楼主,能不能解析到最高画质?我刚从朋友那里借来的优酷VIP,发现还是只能最高720P
推荐
陌生人88 发表于 2021-7-22 10:44
小白弄不明白,可以教一下具体怎么操作码
头像被屏蔽
5#
一只小木木 发表于 2021-7-22 01:15
提示: 作者被禁止或删除 内容自动屏蔽
6#
isdola 发表于 2021-7-22 01:20
要是 php 写的就好了,可以学习一下哈哈
7#
叶凯 发表于 2021-7-22 01:35
顺便问下,像这种优酷、爱奇艺解析播放地址是不是都根据有会员的账号cookie,再进行数据捉取
8#
xiaofengshushu 发表于 2021-7-22 01:45
这个不错、要是可以打包个源码或者做成个小软件我觉得会更方便
9#
ID88512 发表于 2021-7-22 02:05
开始还以为解析接口和源码, 后来一看要获取cookie。
自己搭个服务器或者找个接口放到浏览器扩展里面几行代码加持下,直接跳转 不香吗?
10#
丶FollowYou 发表于 2021-7-22 02:34
jinlaixuexiyixia
11#
hj170520 发表于 2021-7-22 05:38
这个视频没有加密的吗?就离谱~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 20:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表