Forked from drowsy-probius/tewind_m3u8_downloader.user.js
Created
May 22, 2023 14:56
-
-
Save Lastorder-DC/7171e34893b8541fec4df0fe567e69fb to your computer and use it in GitHub Desktop.
Tewind m3u8 downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Download tewind m3u8 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://tewind.kr/rewind/* | |
// @match https://tewind.kr/liveback/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tewind.kr | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
const downloadPlaylist = () =>{ | |
alert('m3u8 다운로드를 시도합니다.', true); | |
if(!liveback) { | |
alert('작동하지 않네요'); | |
return; | |
} | |
liveback.downloadPlaylist = async function () { | |
const donwloadBlob = (function () { | |
const a = document.createElement("a"); | |
document.body.appendChild(a); | |
a.style = "display: none"; | |
return function (objectUrl, fileName) { | |
try { | |
a.href = objectUrl; | |
a.download = fileName; | |
a.click(); | |
window.URL.revokeObjectURL(objectUrl) | |
} catch (_) { | |
alert('파일 다운로드 에러'); | |
} | |
}; | |
}()); | |
let infor = await server.jsonRequest(`/API/vod/${this.type}`, server.makeParam({ | |
key: this.key | |
})) | |
if (infor.response !== 200) { | |
alert(infor.message); | |
return; | |
} | |
const playlistFilenameRaw = `[${infor.content.channel}][${infor.content.category}] ${infor.content.title}`; | |
const playlistFilename = `${playlistFilenameRaw.slice(0, 250)}.m3u8`; | |
switch (this.type) { | |
case 'liveback':{ | |
if (infor.content.tsDuration == null) { | |
return; | |
} | |
let m3u8 = [ | |
'#EXTM3U', | |
'#EXT-X-VERSION:3', | |
'#EXT-X-PLAYLIST-TYPE:VOD', | |
'#EXT-X-TARGETDURATION:6', | |
'#EXT-X-MEDIA-SEQUENCE:0' | |
] | |
for (let i = 0; i < infor.content.list.length; i++) { | |
m3u8.push(`#EXTINF:${infor.content.tsDuration}`); | |
m3u8.push(`${env.cdn.segment}/${infor.content.bid}/${infor.content.list[i]}.ts`); | |
} | |
m3u8.push('#EXT-X-ENDLIST'); | |
const obj = new Blob([m3u8.join('\n')]) | |
donwloadBlob(URL.createObjectURL(obj), playlistFilename); | |
//URL.revokeObjectURL(objectURL) | |
break; | |
} | |
case 'rewind':{ | |
const playlistUrl = `${env.cdn.segment}/${this.key}/${infor.content.src}`; | |
const res = await fetch(playlistUrl); | |
const content = await res.blob(); | |
donwloadBlob(URL.createObjectURL(content), playlistFilename); | |
break; | |
} | |
} | |
}; | |
liveback.downloadPlaylist(); | |
} | |
const buttonParent = document.getElementById('streamInfo'); | |
const playlistDownloadButton = document.createElement('button'); | |
playlistDownloadButton.id = 'downloadPlaylist'; | |
playlistDownloadButton.onclick = downloadPlaylist | |
playlistDownloadButton.classList = "button primary small display"; | |
playlistDownloadButton.style = "width: 100px; float: right; " | |
playlistDownloadButton.innerText = 'm3u8'; | |
buttonParent.appendChild(playlistDownloadButton); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment