Last active
June 2, 2020 10:39
-
-
Save vyach-vasiliev/d5c681c415e01408ff8ff60f83a8321d to your computer and use it in GitHub Desktop.
Kinopub bookmarklet (m3u8-playlist downloader, one season at a time)
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
// ver 20200601 | |
function getM3U8() { | |
// parsing and building playlist | |
var blocks = []; | |
for (var i = 0; i < playlist.length; i++) { | |
// var block = '#EXTINF:%duration logo="%cover",%title %status\n%url\n#EXTALB:%album\n#EXTIMG:%image\n'; // alt version | |
var block = '#EXTINF:%duration,%title %status\n%url\n'; | |
var item = playlist[i]; | |
block = block | |
.replace('%duration', item.duration) | |
// .replace('%cover', item.image).replace('%image', item.image) // alt version | |
.replace('%title', item.title) | |
.replace('%url', item.sources[0].file) | |
// .replace('%album', 'season '+item.snumber+', episode '+item.vnumber) // alt version | |
.replace('%status', item.view.completed ? '(viewed)' : ''); | |
blocks.push(block); | |
} | |
// getting playlist | |
var a = window.document.createElement('a'); | |
a.href = window.URL.createObjectURL(new Blob(['#EXTM3U\n' + blocks.join('\n')], {type: 'text/csv;charset=utf-8;'})); | |
a.download = '%title %first-%last.m3u8' | |
.replace('%title', document.title) | |
.replace('%first', playlist[0].title.split(' ')[0]) | |
.replace('%last', playlist[playlist.length-1].title.split(' ')[0]); | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
} | |
getM3U8(); // run |
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
javascript:function getM3U8(){for(var t=[],e=0;e<playlist.length;e++){var l="#EXTINF:%duration,%title %status\n%url\n",i=playlist[e],l=l.replace("%duration",i.duration).replace("%title",i.title).replace("%url",i.sources[0].file).replace("%status",i.view.completed?"(viewed)":"");t.push(l)}var a=window.document.createElement("a");a.href=window.URL.createObjectURL(new Blob(["#EXTM3U\n"+t.join("\n")],{type:"text/csv;charset=utf-8;"})),a.download="%title %first-%last.m3u8".replace("%title",document.title).replace("%first",playlist[0].title.split(" ")[0]).replace("%last",playlist[playlist.length-1].title.split(" ")[0]),document.body.appendChild(a),a.click(),document.body.removeChild(a)}getM3U8(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment