目录

一 破解优酷VIP视频

import requests
import re
import json HEADERS = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'
} '''
破解优酷VIP视频
'''
class web():
def __init__(self):
self.api = "http://y.mt2t.com/lines?url=" # 在线解析视频平台
self.url = "https://v.youku.com/v_show/id_XNDEwNTMzMzM2OA==.html" # 需要解析的VIP视频网站
self.name = None
self.post_url1 = "http://y.mt2t.com/lines/getdata" # 解析平台上获取的1号端口,用于收集video的地址
self.post_url2 = 'http://y2.mt2t.com:91/ifr/api' # 解析平台上获取的m3u8视频段提供端口 # 发送解析请求通过re正则获取key的值
def find_key(self): # 通过访问解析平台api与需要解析的VIP视频网站
res = requests.get(self.api + self.url)
# 获取文本
html = res.text key = re.search(r'key:"(.*?)"', html).group(1) # 通过解析平台找到ajax请求中的data中的key
# print(key)
return key # 对原来的url进行修改,得出完整的url
def url_spilt(self, url): # 将拿到的viedo视频段进行转码,再做切分获得类型和所需的data体中的视频地址 ''' <script type="text/javascript">
var url="usZehnz38ibymr+ghLS1yGrU7tBqDcTQETbMfdhmceJxo2Y1QIbrmjQElPgxaXjmVIzB0qqL9GoUYCXdSd8GYA==";
var type="m3u8";
var api="/ifr/api";
var device="";
player(api,url,type,device,0);
</script> # 访问这个链接,内部会有上述ajax请求获取视频
usZehnz38ibymr+ghLS1yGrU7tBqDcTQETbMfdhmceJxo2Y1QIbrmjQElPgxaXjmVIzB0qqL9GoUYCXdSd8GYA==
http://y2.mt2t.com:91/ifr?url=usZehnz38ibymr%2bghLS1yGrU7tBqDcTQETbMfdhmceJxo2Y1QIbrmjQElPgxaXjmVIzB0qqL9GoUYCXdSd8GYA%3d%3d&type=m3u8'
'''
# 对列表中的第一个url里面的字符进行特换
# 有些视频的链接是有 %2f 需要替换成 /
url_param = url.split("?url=")[1].split("&")[0].replace("%2b", "+").replace("%3d", "=").replace("%2f", "/") # 获取 m3u8
movie_type = url.split("type=")[1]
return url_param, movie_type # 采集视频
def get_playlist(self):
'''# 飞驰人生:
<script type="text/javascript">
$(document).ready(
function () {
$.ajax({
type: "post",
dataType: "json",
url: "/lines/getdata", # 1.需要获取的url http://y.mt2t.com/lines/getdata # 2.获取key值
data:{url:"http://v.youku.com/v_show/id_XNDEwNTMzMzM2OA==.html",type:"",key:"a0b923820dcc509a"},
success:ShowMenu
});}
);
</script>
''' # 调用find_key方法获取vip视频中data的key
key = self.find_key() data = {
"url": self.url,
"key": key,
}
# 获取VIP所需的KEY之后向1号端口发送data包来获取所需的viedo视频段
html = requests.post(self.post_url1, data=data).text
dic = json.loads(html)
print(dic)
''' # 往解析平台发送post请求获取的是一个json数据,里面有整部电影分切成的几个视频链接 # 第一个链接就是全部的视频了!!! 凡是m3u8后缀的链接都隐藏着视频
[{'Url': 'http://y2.mt2t.com:91/ifr?url=usZehnz38ibymr%2bghLS1yGrU7tBqDcTQETbMfdhmceJxo2Y1QIbrmjQElPgxaXjmVIzB0qqL9GoUYCXdSd8GYA%3d%3d&type=m3u8',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}, {'Url': 'http://y2.mt2t.com:91/ifr?url=usZehnz38ibymr%2bghLS1yBx%2fLeW6zBPvlnirzwVAPb22uUqY7Lurs2njqvy41H%2fP56dP%2bJxZNyUrXMTBI9wDCg%3d%3d',
'Video_type': '1',
'Vid': None, 'Scheme': 'auto'},
{'Url': 'http://y2.mt2t.com:91/ifr?url=a6tgiq6l1aQQZzObpXfOZ8U46WROtjYnUG5ZzktCdBFLPGVOTRFWXddcBGY61OgLBMh9uvHbmq7StHt5J1YqsQ%3d%3d',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}, {'Url': 'http://y2.mt2t.com:91/ifr?url=KuT7Bg63M9X8euMJDPneBFvHMMyUaXi9G3Pu5CiJRWLODtsR9maZGFrrtetCrKTE',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}, {'Url': 'http://y2.mt2t.com:91/ifr?url=HAoUzVAntrQdCkvIryzh%2bCLfbHCa6F1N%2fdmTpLCjBpzarEGkP6zvW36iGCLJ1Qt9',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}, {'Url': 'http://y2.mt2t.com:91/ifr?url=4v6ceQdhfTwrhJ5xfngkjQST%2fCa1dsHxOZXRmFQSiLRQIv6FZ58v%2fW1%2b53Zkfz0uy30gLudsy1Cd9GAYjVudWp5x4z8EBN7C1NDeLNGpUmE%3d',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}, {'Url': 'http://y2.mt2t.com:91/ifr?url=4v6ceQdhfTwrhJ5xfngkjQST%2fCa1dsHxOZXRmFQSiLRQIv6FZ58v%2fW1%2b53Zkfz0utK4DajZZFp2swCbcqN1J3w%3d%3d',
'Video_type': '1',
'Vid': None,
'Scheme': 'auto'}]
'''
# 把列表中的第一个视频链接去做处理,获取完整的url
url_param, type = self.url_spilt(dic[0]["Url"]) '''
<script type="text/javascript">
var url="usZehnz38ibymr+ghLS1yGrU7tBqDcTQETbMfdhmceJxo2Y1QIbrmjQElPgxaXjmVIzB0qqL9GoUYCXdSd8GYA==";
var type="m3u8";
var api="/ifr/api";
var device="";
player(api,url,type,device,0);
</script>
'''
# 往此地址发送ajax请求获取视频数据
res = requests.post(self.post_url2,
data={
"url": url_param,
"type": '',
"from": "mt2t.com",
"device": "",
"up": 0
}) # 返回json视频数据
play = json.loads(res.text)
self.save_movie(play) def save_movie(self, play):
with open('%s.mp4' % self.name, 'wb') as f:
f.write(play) # if __name__ == '__main__':
# vip = web()
# vip.get_playlist() ''' 批量获取电影所有的名称与链接. 电影详情接口:
https://list.youku.com/category/page?c=96&pt=2&type=show&p=1
https://list.youku.com/category/page?c=96&pt=2&type=show&p=2
https://list.youku.com/category/page?c=96&pt=2&type=show&p=3
https://list.youku.com/category/page?c=96&pt=2&type=show&p=4
https://list.youku.com/category/page?c=96&pt=2&type=show&p=5 每个接口的所有详情信息: {'success': True,
'message': '',
'data': # 数据
[{'summaryType': 'UPDATE_STATUS',
'access': 'allow',
'type': 'vertical',
'img': '//r1.ykimg.com/051640005C8B7F56859B5D5D300E06C1',
'summary': '正片',
'title': '篮球冠军', # 电影名称
'subTitle': '傲慢教练与怪异球队',
'videoId': 'XNDE4MzY4NjUzNg==',
'videoLink': '//v.youku.com/v_show/id_XNDE4MzY4NjUzNg==.html'} # 电影详情链接
...
] vip电影链接div:
<div id="dramaFixedWrap" class="drama-fixed-wrap">
<div class="item item-cover item-cover-fixed active" item-id="item_XNDE4MzY4NjUzNg==" title="篮球冠军">
<a href="//v.youku.com/v_show/id_XNDE4MzY4NjUzNg==.html?&amp;s=eccc9254a71842e09356"> # 需要解析的链接
<a href="(.*?)"> <div class="cover"><img src="https://vthumb.ykimg.com/054102015CDD1E950000017A690856DF"></div>
<div class="title">篮球冠军</div>
</a>
</div>
<i class="scroll-fixed"></i>
</div> ''' import requests # 获取全部电影主页的json数据
def parse_index(url):
res = requests.get(url)
data = res.json()
return data.get('data') # 保留 电影名称 与 电影链接 放进生成器内
def get_vip_movie(datas):
# print(data)
for data in datas:
# print(data)
# 电影名称
title = data.get('title')
# 拼接完整的电影链接
video_link = 'https:' + data.get('videoLink')
yield title, video_link # url = 'https://list.youku.com/category/show/c_96_pt_2.html?spm=a2ha1.12701310.app.5~5!2~5~5~5~DL!6~DD~A!3' if __name__ == '__main__':
base_url = 'https://list.youku.com/category/page?c=96&pt=2&type=show&p={}'
vip = web()
for line in range(1, 11):
url = base_url.format(line)
# 解析电影的每一个接口,获取所有电影接口的json数据
data = parse_index(url)
# 接收到N个电影名字与电影链接的生成器
vip_movies = get_vip_movie(data)
# print(vip_movies)
for movies in vip_movies: # 电影名称与电影url
name, link = movies vip.name = name
vip.url = link vip.get_playlist() print(name, link) # parse_link(name, link)

OOP

import requests
import re
import json def parse_url(list1):
for line in list1:
line = line + '.ts'
res = requests.get(line)
print(res.text)
yield line api = "http://y.mt2t.com/lines?url=" # 在线解析视频平台
# # 正义联盟
url = "https://v.youku.com/v_show/id_XNDA0MjYzNzgyMA==.html?spm=a2h03.12024492.drawer7.dzj1_4&scm=20140719.rcmd.1698.show_cc129064962411de83b1" # 需要解析的VIP视频网站 # 比悲伤更悲伤的故事
# url = "https://v.youku.com/v_show/id_XNDE3NjQ2MTQ0OA==.html?spm=a2h0j.11185381.listitem_page1.5~A&&s=0bfa8c056436451c9d47" # 需要解析的VIP视频网站
api_url_2 = 'http://y2.mt2t.com:91/ifr/api' # 解析平台上获取的m3u8视频段提供端口 api_url = api + url
api_res = requests.get(api_url) # 往解析平台发送请求获取的响应文本中我们发现里面包含了一个ajax请求
# print(api_res.text)
'''
<script type="text/javascript">
$(document).ready(
function () {
$.ajax({
type: "post",
dataType: "json",
url: "/lines/getdata",
data:{url:"http://v.youku.com/v_show/id_XNDA0MjYzNzgyMA==.html",type:"",key:"a0b923820dcc509a"},
success:ShowMenu
});}
);
</script> 接下来我们获取这地址的相关数据,然后模拟这个ajax请求
''' # 通过解析平台找到ajax请求中POST请求url、data中的url、data中的key
post_url, movie_url, key = re.findall(r'url: "(.*?)".*?data:{url:"(.*?)".*?key:"(.*?)"', api_res.text, re.S)[0] # 拼接解析平台上获取的1号端口,用于收集video的地址
post_url = "http://y.mt2t.com" + post_url
# print(post_url) # print(post_url, movie_url, key) data = {
'url': movie_url,
'key': key
} # 发送post请求返回的是一个响应文本
response = requests.post(post_url, data=data) # print(response.text)
# 需要对文本进行一个反序列化成json格式的数据
json_data = json.loads(response.text) # 发现发送完ajax请求以后还得发送第二次
'''
请求url:
http://y2.mt2t.com:91/ifr/api 请求方式:
POST 请求体:
需要对请求参数进行格式化 h9MjvCpkvRUdjqRNwPyEzm6lVb74WEQWtduwJ3qhTv9moH9hcwtf61EG67N17Wyjh85y8GwYRlvozCiftcdTQg%3d%3d&type=m3u8
url: h9MjvCpkvRUdjqRNwPyEzm6lVb74WEQWtduwJ3qhTv9moH9hcwtf61EG67N17Wyjh85y8GwYRlvozCiftcdTQg==
type: m3u8
from: mt2t.com
device:
up: 0
''' for line in json_data:
# print(line['Url'])
url = line['Url'] # 需要对请求参数进行格式化
url_param = url.split("?url=")[1].split("&")[0].replace("%2b", "+").replace("%3d", "=").replace("%2f", "/")
print(url_param) data = {
'url': url_param,
'type': '',
'from': 'mt2t.com',
'device': '',
'up': 0
} res = requests.post(api_url_2, data=data)
# print(res.text)
# json_data2 = json.loads(res.text)
json_data2 = res.json()
print(json_data2)
if json_data2:
if json_data2['url'].endswith('.mp4'):
movie_url = json_data2['url']
print(movie_url)

function

 
 
04-02 00:59