Skip to content

Instantly share code, notes, and snippets.

@cocoastorm
Created October 3, 2022 05:38
Show Gist options
  • Save cocoastorm/2ae33dcef1964958bdc4820863918ae9 to your computer and use it in GitHub Desktop.
Save cocoastorm/2ae33dcef1964958bdc4820863918ae9 to your computer and use it in GitHub Desktop.
twitch clips manager - grab download urls of clips
(function() {
function findClips() {
const rows = document.querySelectorAll('[data-a-target=clips-manager-table-row-container]');
if (!rows.length) {
console.error('no clip rows found');
}
const clips = [];
for (let i = 0; i < rows.length; i += 1) {
const clip = rows[i];
const link = clip.querySelector('a[download^="https://production.assets.clips.twitchcdn.net"');
if (link.download && link.download.length) {
clips.push(link.download);
}
}
return clips;
}
function encode(jsonifiable) {
const metadata = JSON.stringify(jsonifiable, null, 2);
return new Blob([metadata], { type: 'application/json' });
}
// main code here:
const twitchClips = findClips();
const encodedJSONBlob = encode(twitchClips);
// download as json file
const downloadEl = document.createElement('a');
downloadEl.setAttribute('href', URL.createObjectURL(encodedJSONBlob));
downloadEl.setAttribute('download', 'clips.json');
document.body.appendChild(downloadEl);
downloadEl.click();
document.body.removeChild(downloadEl);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment