B站大会员视频解析接口逆向之Python一键获取视频真实地址+下载完整代码
视频教程
https://www.bilibili.com/video/BV1iL411P7fK/
完整代码:
# -*- coding: utf-8 -*-
# @Author: Null119
# @Desc: { 某vip解析2 }
# @Date: 2022/03/16 12:59
import requests, urllib3, base64, os, time,re
from Crypto.Cipher import AES
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def validateTitle(title):
rstr = r"[\/\\\:\*\?\"\\|]" # '/ \ : * ? " < > |'
new_title = re.sub(rstr, "_", title) # 替换为下划线
return new_title
def aesEcbDecode(data, key):
decrpytBytes = base64.b64decode(data)
key = bytes(key, encoding='utf-8')
naes = AES.new(key, AES.MODE_ECB)
return naes.decrypt(decrpytBytes).decode('utf-8')
def aesEcbEncode(data, key):
padded = pad_byte(data.encode('utf-8'))
key = bytes(key, encoding='utf-8')
naes = AES.new(key, AES.MODE_ECB)
en_text = naes.encrypt(padded)
return base64.b64encode(en_text).decode()
def pad_byte(b):
bytes_num_to_pad = 16 - (len(b) % 16)
byte_to_pad = bytes([bytes_num_to_pad])
padding = byte_to_pad * bytes_num_to_pad
padded = b + padding
return padded
def enStr(url):
return aesEcbEncode(url, 'yourme@nxflv@com')
def deStr(enurl):
return aesEcbDecode(enurl.replace('AINX', ''), 'loveme@nxflv@com')
def proDown(url, path,vtitle, headers):
if not os.path.exists(path):
os.mkdir(path)
start = time.time()
response = requests.get(url, headers=headers, stream=True, verify=False)
size = 0
chunk_size = 1024
content_size = int(response.headers['content-length'])
try:
if response.status_code == 200:
print('开始下载,[文件大小]:{size:.2f} MB'.format(size=content_size / chunk_size / 1024))
if vtitle!='':filepath = path + vtitle+ '.' +os.path.basename(url).split('?')[0].split('.')[1]
else:filepath = path + os.path.basename(url).split('?')[0]
with open(filepath, 'wb') as file:
for data in response.iter_content(chunk_size=chunk_size):
file.write(data)
size += len(data)
print('\r' + '[下载进度]:%s%.2f%%' % (
'>' * int(size * 50 / content_size), float(size / content_size * 100)), end=' ')
end = time.time()
print('\r下载完成!,耗时: %.2f秒' % (end - start))
except:
pass
def getVIP(url, arg):
html = requests.get(url, verify=False).text
try:
vTitle = re.search(r'<h1 title="(.*?)">', html).group(1)
print(f'【{vTitle}】')
except:
vTitle = ''
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
'Referer': 'https://www.nxflv.com/?url=' + url,
'Origin': 'https://www.nxflv.com'
}
vkey = enStr(url)
pdat = {
'url': url,
'wap': '0',
'ios': '0',
'vkey': vkey,
'type': ''
}
html = requests.post('https://www.nxflv.com/Api.php', data=pdat, headers=headers, verify=False)
enurl = html.json()['url']
deurl = deStr(enurl)
print('视频URL:', deurl)
if int(arg) > 0: proDown(deurl, './',validateTitle(vTitle), headers)
if __name__ == '__main__':
url = 'https://www.bilibili.com/bangumi/play/ss41074?from_spmid=666.22.0.0'
getVIP(url, 1)
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习使用,请在下载后24小时内删除,严禁商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
【注意:本站发布资源来源于网络搜集,均有较强时效性,请在下载前注意查看文章资源发布或更新时间,距离当前时间太久的资源不建议下载,特别是安卓专区相关资源,会有大概率失效无法使用】
评论(16)
怎么用啊,小白
非常不错
不错 学习了
学习
1
来了
大佬的地盘要常来看看
为什么还是看不了啊
看看学习下
123123
123
顶
顶
求求了
好耶ヾ(^▽^*)))
1