Created
October 3, 2022 05:38
-
-
Save cocoastorm/2ae33dcef1964958bdc4820863918ae9 to your computer and use it in GitHub Desktop.
twitch clips manager - grab download urls of clips
This file contains 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
(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