Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zegnat/25044638e8b01b8cfbcb to your computer and use it in GitHub Desktop.
Save Zegnat/25044638e8b01b8cfbcb to your computer and use it in GitHub Desktop.
Userscript: Generate a playlist link for Twitch Tools’s Download Videos feature, for easy playing of video source files in your media player.
// ==UserScript==
// @name Twitch Tools Playlist Generator
// @namespace http://zegnat.net/
// @version 2.0
// @description Generate a playlist link for Twitch Tools’s Download Videos feature, for easy playing of video source files in your media player.
// @author Martijn van der Ven
// @license MIT <http://opensource.org/licenses/MIT>
// @match https://twitchtools.com/video-download
// @grant none
// @noframes
// ==/UserScript==
/*globals MutationObserver, document, btoa */
(function () {
"use strict";
(new MutationObserver(function (mutations) {
var div = mutations[0].addedNodes[0],
name = div.getElementsByTagName('h3')[0].innerText.trim().substr(12),
tables = div.getElementsByTagName('table'),
tables_length = tables.length,
i,
j,
rows,
rows_length,
cell,
table,
playlist,
runningtime;
for (i = 0; tables_length > i; i += 1) {
table = tables[i];
rows = table.rows;
rows_length = rows.length;
playlist = "#EXTM3U\n";
for (j = 0; rows_length > j; j += 1) {
runningtime = rows[j].cells[2].textContent.trim().match(/(?:(\d+) hours?(?:, )?)?(?:(\d+) minutes?(?:, )?)?(?:(\d+) seconds?)?/);
runningtime = ((runningtime[1] || 0) * 60 + (runningtime[2] || 0)) * 60 + parseInt(runningtime[3] || 0, 10);
playlist += '#EXTINF:' + runningtime + ',' + name + ' - Part ' + (j + 1) + "\n";
playlist += rows[j].getElementsByTagName('a')[0].href.trim() + "\n";
}
cell = tables[i].insertRow().insertCell();
cell.setAttribute('colspan', '4');
cell.className = 'links';
cell.innerHTML = '<a download="playlist.m3u" href="data:application/x-mpegurl;base64,' + btoa(playlist) + '">Playlist</a>';
}
})).observe(document.querySelector('.content'), { childList: true });
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment