这样就抓到包了。 找到首页的包, 点击一下, 如图所示, 复制这里的 cookie
然后再粘贴到 解析工具里面!!! 最后找到需要解析的视频链接, 粘贴进去。。。。
接下来,就解析完成了。
接下来, 就是复制m3u8地址, 找个下载工具就能下载了。
完整源码
====
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}")
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)
ert/6c361282296f86381401c05e862fe4e9.png)
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)