使用JS 下载m3u8 文件
function downloadUrl(fileName,fileUrl) { var link = document.createElement('a'); //设置下载的文件名 link.download = fileName; link.style.display = 'none'; //设置下载路径 link.href = fileUrl; //触发点击 document.body.appendChild(link); link.click(); //移除节点 document.body.removeChild(link); } function sleep(time){ var timeStamp = new Date().getTime(); var endTime = timeStamp + time; while(true){ if (new Date().getTime() > endTime){ return; } } } var m3u8Url = "https://xxxx.m3u8"; $.get(m3u8Url,function(res) { var aa = res.replaceAll(/#.*[\n\r]/ig,""); aa = aa.split("\n"); console.log(aa); for(i=0;i<=aa.length;i++) { if(aa[i]) { // console.log(aa[i]); let a1 = aa[i].lastIndexOf('/')+1; let name = aa[i].substr(a1).replace(/\?.*/ig,''); let url = aa[i]; console.log(name); downloadUrl(name,aa[i]); sleep(1000) } } },"text");