Created
January 2, 2024 18:07
-
-
Save masterflitzer/421775744fcacc8a7ae8d8e249923604 to your computer and use it in GitHub Desktop.
Convert your Prime Video Library to JSON!
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
// https://amazon.de/gp/video/mystuff/library/all | |
// adjust based on connection speed | |
let counter = 3; | |
if (document.readyState === "complete") await mainPrimeVideoLibrary(counter); | |
else alert("Please run this script after the webpage finished loading!"); | |
async function mainPrimeVideoLibrary(counter) { | |
const sleep = async (ms) => | |
new Promise((resolve) => setTimeout(resolve, ms)); | |
const getEntityType = (it) => it.getAttribute("data-card-entity-type"); | |
const getPosition = (it) => it.getAttribute("data-card-position"); | |
const getTitle = (it) => it.getAttribute("data-card-title"); | |
const tileContainer = document.querySelector( | |
"[data-testid=grid-mini-details-controller]" | |
); | |
const tiles = []; | |
let scroll = true; | |
do { | |
const scrollTiles = Array.from( | |
tileContainer.querySelectorAll("[data-testid=card]") | |
).filter( | |
(it) => !tiles.some((tile) => getPosition(tile) == getPosition(it)) | |
); | |
tiles.push(...scrollTiles); | |
if (scrollTiles.length == 0) { | |
counter--; | |
if (counter == 0) scroll = false; | |
} | |
window.scrollBy({ | |
top: document.documentElement.clientHeight, | |
left: 0, | |
behavior: "smooth", | |
}); | |
await sleep(1000); | |
} while (scroll); | |
const movieTiles = tiles.filter( | |
(it) => getEntityType(it).toLowerCase() == "movie" | |
); | |
movieTiles.forEach((it) => tiles.splice(tiles.indexOf(it), 1)); | |
const seriesTiles = tiles.filter( | |
(it) => getEntityType(it).toLowerCase() == "tv show" | |
); | |
seriesTiles.forEach((it) => tiles.splice(tiles.indexOf(it), 1)); | |
const otherTiles = tiles; | |
const data = {}; | |
data.movies = movieTiles.map((it) => getTitle(it)); | |
data.series = seriesTiles.map((it) => getTitle(it)); | |
data.other = otherTiles.map((it) => getTitle(it)); | |
const json = JSON.stringify(data, null, 2); | |
const blob = new Blob([json], { type: "application/json" }); | |
const dl = document.createElement("a"); | |
dl.href = URL.createObjectURL(blob); | |
dl.download = "prime-video-library.json"; | |
document.body.appendChild(dl); | |
dl.click(); | |
document.body.removeChild(dl); | |
const total = movieTiles.length + seriesTiles.length + otherTiles.length; | |
console.info(json); | |
console.info( | |
`Found ${movieTiles.length} movies, ${seriesTiles.length} series and ${otherTiles.length} other. In total of ${total} videos` | |
); | |
data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment