优酷youku 1080P 视频下载方法

news/2024/11/15 1:59:39/

> PC端下载优酷视频方法,以下是优酷视频下载地址解析python脚本 

import re, requests, time, subprocess, json, base64
from hashlib import md5class YouKu:def __init__(self, cookie):self.cookie = cookiedef youku_sign(self, t, data, token):appKey = '24679788'     # 固定值'''token值在cookie中'''sign = token + '&' + t + '&' + appKey + '&' + datamd = md5()md.update(sign.encode('UTF-8'))sign = md.hexdigest()return signdef 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.urldef 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)print('开启播放器')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 = 'cna=hXDyGqtYgloCAW887r8gThdy; _m_h5_tk=ad861ebf4756a39bbf90ca837ba6cec5_1660894819245; _m_h5_tk_enc=5175f8feb05a54b29d1eedaa0cfdf623; __ysuid=16608903198401Ay; __ayft=1660890319842; __aysid=1660890319842GSn; __ayscnt=1; modalFrequency={"UUID":"10"}; xlly_s=1;'youku = YouKu(cookie)youku.start()

1. 登录优酷 ,按F12获取你登录后的COOKIE,将自己的COOKIE替换掉源代码中的COOKIE

 

2. 运行这个python,将youku的播放URL地址复制进去 就可以获取到视频1080P的M3U8下载链接

 3. 在52pojie找到 "M3U8批量下载器"  ,使用M3U8下载器将视频下载回来,

 


http://www.ppmy.cn/news/355171.html

相关文章

视频工具--下载[优酷]

How to Download Tencent/QQ Video Online? | Universal Tencent/QQ Video Downloader 使用客户端下载 使用ffmpeg转换 \YouKu\YoukuClient\nplayer> .\ffmpeg.exe -i "D:\Program Files (x86)\YouKu\Youku Files\download\张三mp4_1080p.kux" -acodec copy -v…

在线影视平台优酷视频 v7.8.7.10120 绿色便携版

优酷视频,具有 “我的桌面优酷” 之称,为您推荐更多精选热门视频,通过多条件筛选快速定位匹配结果,猜你喜欢频道更了解你的兴趣。优酷视频提供视频播放、视频发布、视频搜索,通过多条件筛选快速定位匹配结果&#xff0…

优酷官方下载2015 v6.0.0 电脑版

优酷官方下载2015 v6.0.0 电脑版 软件大小:28.7MB 软件语言:简体中文 软件类别:影音播放

Tube Downloader(视频下载工具)

Tube Downloader(视频下载工具)是一款优秀的视频下载软件,它可以将网站视频下载到本地。支持全球主流视频网站。 使用方法: 1.在浏览器中可以播放视频,此时浏览器上的地址就是视频地址。复制视频地址 2.粘贴到“请输入要下载的视频地址”框框…

优酷下载的视频保存在哪里

打开我们客户端软件,进入首页,点击右上角的菜单图标 优酷下载的视频保存在哪里?如何修改保存位置? 02、 找到列表中的设置选项,点击进入 优酷下载的视频保存在哪里?如何修改保存位置? 03、 …

飞利浦电视进入工程模式以及安装apk的方法

我的飞利浦电视型号:50PFF5661/T3 进入工程模式方法: 开机状态下,依次按下遥控器如下按键: “选项”-“1”-“9”-“9”-“9”-“返回” 安装apk文件 电脑下载APK,并拷贝到U盘,将U盘插入电视的USB接口。 在电视主页…

电视hdr测试软件,短路三分钟 | 你家电视、显示器真的支持HDR么?

坑爹的电视解码 有了支持HDR的显示器、电视只是第一步,还得支持解码HDR视频。与SDR视频不同,HDR视频是一个半成品,它就像相机/摄像机拍摄的Log风格视频一样,有了初步调色,但画面饱和度、对比度很低,有一种发…

飞利浦中高端智能电视被曝存安全缝隙

智能电视如今现已在许多消费者客厅中的扮演着重要的人物,可是已然作为智能设备,那么安全性就相同十分重要。依据最新的陈述显现,飞利浦智能电视的最新版别固件当前存在了一个并不安全的Miracast无线网络缝隙,能够让潜在进犯者经过…