01月26日, 2020 1,062 views

有MJJ突发奇想发现图床可以这么用~了解一点m3u8的同学会知道,一大段视频是由很多个小段 .ts文件组成的,那摩如果某个图床接口没能正确过滤文件格式仅是以后缀判断的话,这事情就好办了,你可以将大视频切片成ts——伪装成jpg图片——通过接口上传——包装成M3u8 就可以成功完成整个步骤啦~
粘帖了某大佬写的php代码,完整使用步骤请参考大佬原文 视频完美切片存储方案 附自动化处理脚本
<?php $v_path = $argv[1]; //切片路径 $v_name = $argv[2]; //带切片的视频路径名称 $s = 5; //切片秒 ts 切片必须小于 5MB if (empty($v_path) || empty($v_name)) { echo "请填写完整参数"; exit; } if ($v_path == '/' || $v_path == '\') { $v_path = ''; } else { mkFolder($v_path); $v_path = $v_path . "/"; } //这是 FFmpeg 处理命令大家自行更改 exec("ffmpeg -i $v_name -c copy -map 0 -f segment -segment_list " . $v_path . "playlist.m3u8 -segment_time $s " . $v_path . "player%03d.ts"); $m = file_get_contents('./' . $v_path . 'playlist.m3u8'); preg_match_all('/player(.*?).ts/', $m, $arr); foreach ($arr[1] as $key => $value) {
echo "处理第" . $value . '个切片' . "n";
$ali = upload('./' . $v_path . 'player' . $value . '.ts');
$m = str_replace('player' . $value . '.ts', $ali, $m);
file_put_contents('./' . $v_path . 'play.m3u8', $m);
}
echo "处理完毕" . "n";
echo "播放链接为:/" . $v_path . 'play.m3u8';
function upload($file) {
$post['file'] = file_path($file);
$post['scene'] = 'aeMessageCenterV2ImageRule';
$post['name'] = 'player.jpg';
$rel = get_curl('https://kfupload.alibaba.com/mupload', $post, 'iAliexpress/6.22.1 (iPhone; iOS 12.1.2; Scale/2.00)');
$rel = json_decode($rel, true);
return $rel['url'];
}
function get_curl($url, $post = 0, $ua = 0) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// 不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// 最大执行时间
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
$httpheader[] = "Accept:application/json";
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
$ip = mt_rand(48, 140) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240); //随机 ip
$httpheader[] = 'CLIENT-IP:' . $ip;
$httpheader[] = 'X-FORWARDED-FOR:' . $ip;
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function mkFolder($path) {
if (!is_readable($path)) {
is_file($path) or mkdir($path, 0700);
}
}
function file_path($file) {
if (class_exists('CURLFile')) {
return $post['file'] = new CURLFile(realpath($file));
} else {
return $post['file'] = '@' . realpath($file);
}
}更新,又有大佬分.py版本,看来被玩坏已是板上钉钉了 链接点这里
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import requests, os
from urllib3 import encode_multipart_formdata
from concurrent.futures import ThreadPoolExecutor, as_completed
def m_upload(filename):
fakename = os.path.splitext(filename)[0] + '.jpg'
payload = {'scene':'aeMessageCenterV2ImageRule', 'name':fakename, 'file': (fakename,open(filename,'rb').read())}
encode_data = encode_multipart_formdata(payload)
data = encode_data[0]
headers['Content-Type'] = encode_data[1]
for _ in range(3):
try:
r = requests.post(url, headers=headers, data=data, timeout = 20)
except:
print('Failed to upload ' + filename)
continue
if r and 'url' in r.text:
print(filename + " upload")
return r.json()['url']
else:
print('Failed to upload ' + filename)
return filename + ' ERROR'
if __name__ == '__main__':
for file in os.listdir():
if '.m3u8' in file:
m3u8 = open(file)
break
new_m3u8 = open('output.m3u8', 'w')
headers = {'user-agent':'iAliexpress/6.22.1 (iPhone; iOS 12.1.2; Scale/2.00)', 'Accept':'application/json', 'Accept-Encoding':'gzip,deflate,sdch', 'Connection':'close'}
url = 'https://kfupload.alibaba.com/mupload'
file_upload = {t.strip():'' for t in m3u8.readlines() if t[0]!='#'}
m3u8.seek(0)
executor = ThreadPoolExecutor(max_workers=8)
futures = {executor.submit(m_upload, filename):filename for filename in file_upload.keys()}
for future in as_completed(futures):
file_upload[futures[future]] = future.result()
for line in m3u8:
if line[0] != '#':
new_m3u8.write(file_upload[line.strip()] + 'n')
else:
new_m3u8.write(line)
print("Complete")题外话,自从大佬公开了滥用步骤,小破站真的该准备迁移全站图片到其他图床了。。。MMP
如非特别注明,转载可随意~注意留个链接。万分感谢