Skip to content

Instantly share code, notes, and snippets.

@muekoeff
Created March 23, 2024 17:48
Show Gist options
  • Save muekoeff/221baf06ee1083cdd0bbfb558a5dcb89 to your computer and use it in GitHub Desktop.
Save muekoeff/221baf06ee1083cdd0bbfb558a5dcb89 to your computer and use it in GitHub Desktop.
Scrapes a list of tracks marked as favourite from a Navidrome instance
// 1. Navigate to: https://your.navidrome.instance/app/#/song?displayedFilters=%7B%22starred%22%3Atrue%7D&filter=%7B%22starred%22%3Atrue%7D&perPage=500&sort=title
// 2. Call `await collectAll();`
const section
async function collectAll() {
let acc = [];
let hasNavigated = false;
do {
acc = [...acc, ...collectList()];
const hasNavigated = navigateToNextPage();
if (hasNavigated) {
await (new Promise((resolve) => setTimeout(resolve, 3000)));
}
} while(hasNavigated);
return acc;
}
function collectList() {
const rows = document.querySelectorAll('.MuiTable-root tbody tr');
return [...rows].map(collectRow);
}
function collectRow(row) {
const title = row.querySelector('td:nth-of-type(2)').textContent;
const album = row.querySelector('td:nth-of-type(3)').textContent;
const artist = row.querySelector('td:nth-of-type(4)').textContent;
const track = row.querySelector('td:nth-of-type(5)').textContent;
const plays = row.querySelector('td:nth-of-type(6)').textContent;
const year = row.querySelector('td:nth-of-type(7)').textContent;
const time = row.querySelector('td:nth-of-type(9)').textContent;
return {
title: title,
album: album,
artist: artist,
track: track,
plays: plays,
year: year,
time: time
};
}
function hasNextPage() {
return document.querySelector('.next-page') !== null;
}
function navigateToNextPage() {
if (hasNextPage()) {
document.querySelector('.next-page')?.click();
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment