Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

取资源的正则规则在某些有点问题 #1

Open
Xxx-Bin opened this issue Aug 20, 2017 · 0 comments
Open

取资源的正则规则在某些有点问题 #1

Xxx-Bin opened this issue Aug 20, 2017 · 0 comments

Comments

@Xxx-Bin
Copy link

Xxx-Bin commented Aug 20, 2017

document.body.innerHTML.replace(/[\s\S]appsrc : '([\s\S]?)movie([\s\S]?)-list.m3u8'[\s\S]/, "$1mobilev$2.mp4");

下面代码来自直接用 monkey-videos
懒得分析 我自己直接用了

var mp4Url
//拿到视频资源的MP4地址
var scripts = document.querySelectorAll('script'),
script,
reg = /<source[\s\S]+src="([^"]+)"/,
match,
m3u8Reg = /appsrc\s:\s*'([\s\S]+).m3u8'/,
m3u8Match,
i;

for (i = 0; script = scripts[i]; i += 1) {
match = reg.exec(script.innerHTML);
console.log(match);
if (match && match.length > 1) {
mp4Url = match[1].replace('-mobile.mp4', '.flv');
return mp4Url;
}
m3u8Match = m3u8Reg.exec(script.innerHTML);
console.log(m3u8Match);
if (m3u8Match && m3u8Match.length > 1) {
mp4Url = m3u8Match[1].replace('-list', '') + '.mp4';
return mp4Url;
}
}
return mp4Url;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants