fix random shit being added (i think)
build Details
--> Linted: DOCKERFILE_HADOLINT No errors were found in the linting process Details
--> Linted: EDITORCONFIG No errors were found in the linting process Details
--> Linted: GITHUB_ACTIONS No errors were found in the linting process Details
--> Linted: GITLEAKS No errors were found in the linting process Details
--> Linted: JSON No errors were found in the linting process Details
--> Linted: YAML No errors were found in the linting process Details
lint Details

This commit is contained in:
Chase 2023-08-21 19:14:34 -05:00
parent a206f506a0
commit 2537c509e5
Signed by: chase
GPG Key ID: 9EC29E797878008C
2 changed files with 24 additions and 20 deletions

View File

@ -1,2 +1,3 @@
NODE_ENV=development # development | production
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=

View File

@ -11,7 +11,7 @@ config();
const port = 43_019;
let scope = `user-follow-read user-library-modify`;
const includeGroups = `album,single,appears_on`;
const includeGroups = `album,single`; // `album,single,appears_on,compilation`
scope = encodeURIComponent(scope);
const app = express();
@ -68,7 +68,6 @@ app.get(`/token`, async (request, response) =>
let next = followingJson.artists.next;
while (next)
{
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
const nextResponse = await fetch(next, { headers: { Authorization: `Bearer ${ accessToken }` } });
const nextJson = await nextResponse.json();
next = nextJson.artists.next;
@ -85,35 +84,38 @@ app.get(`/token`, async (request, response) =>
if (artistJson.total > 0)
{
for (const album of artistJson.items)
{
{ // First set of albums
const releaseDate = new Date(album.release_date);
if (releaseDate > new Date(Number(lastRun)))
{
// console.log(`Found new release: ${ album.name } by ${ album.artists[0].name } (${ album.release_date })`);
if (process.env.NODE_ENV === `development`) console.log(`Found new release: ${ album.name } by ${ album.artists[0].name } (${ album.release_date })`);
const albumResponse = await fetch(`https://api.spotify.com/v1/albums/${ album.id }/tracks?limit=50`, { headers: { Authorization: `Bearer ${ accessToken }` } });
const albumJson = await albumResponse.json();
if (albumJson.total > 0 // only add if the artist is on the track.
&& albumJson.items.some((track) => track.artists.some((artist) => artist.id === artistId)))
if (albumJson.total > 0)
{
for (const track of albumJson.items)
newReleaseIds.push(track.id);
{
if (track.artists.some((artist) => artist.id === artistId))
newReleaseIds.push(track.id);
}
let next = albumJson.next;
while (next)
{
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
const nextResponse = await fetch(next, { headers: { Authorization: `Bearer ${ accessToken }` } });
const nextJson = await nextResponse.json();
next = nextJson.next;
for (const track of nextJson.items)
newReleaseIds.push(track.id);
{
if (track.artists.some((artist) => artist.id === artistId))
newReleaseIds.push(track.id);
}
}
}
}
}
let next = artistJson.next;
while (next)
{
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
{ // Rest of the albums
const nextResponse = await fetch(next, { headers: { Authorization: `Bearer ${ accessToken }` } });
const nextJson = await nextResponse.json();
next = nextJson.next;
@ -122,14 +124,16 @@ app.get(`/token`, async (request, response) =>
const releaseDate = new Date(album.release_date);
if (releaseDate > new Date(Number(lastRun)))
{
// console.log(`Found new release: ${ album.name } by ${ album.artists[0].name } (${ album.release_date })`);
if (process.env.NODE_ENV === `development`) console.log(`Found new release: ${ album.name } by ${ album.artists[0].name } (${ album.release_date })`);
const albumResponse = await fetch(`https://api.spotify.com/v1/albums/${ album.id }/tracks?limit=50`, { headers: { Authorization: `Bearer ${ accessToken }` } });
const albumJson = await albumResponse.json();
if (albumJson.total > 0 // only add if the artist is on the track.
&& albumJson.items.some((track) => track.artists.some((artist) => artist.id === artistId)))
if (albumJson.total > 0)
{
for (const track of albumJson.items)
newReleaseIds.push(track.id);
{
if (track.artists.some((artist) => artist.id === artistId))
newReleaseIds.push(track.id);
}
next = albumJson.next;
while (next)
{
@ -138,7 +142,10 @@ app.get(`/token`, async (request, response) =>
const nextJson = await nextResponse.json();
next = nextJson.next;
for (const track of nextJson.items)
newReleaseIds.push(track.id);
{
if (track.artists.some((artist) => artist.id === artistId))
newReleaseIds.push(track.id);
}
}
}
}
@ -155,7 +162,6 @@ app.get(`/token`, async (request, response) =>
while (offset < newReleaseIds.length)
{
const chunk = newReleaseIds.slice(offset, offset + 50);
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
const addResponse = await fetch(`https://api.spotify.com/v1/me/tracks?ids=${ chunk.join(`,`) }`, { method: `PUT`, headers: { Authorization: `Bearer ${ accessToken }` } });
if (addResponse.status !== 200)
{
@ -165,9 +171,6 @@ app.get(`/token`, async (request, response) =>
}
offset += 50;
}
console.log(`Done!`);
fs.writeFileSync(`doNotShareInfo.txt`, `${ refreshToken }\n${ Date.now() }\n`, `utf8`);
process.exit(0);
}
console.log(`Done!`);
fs.writeFileSync(`doNotShareInfo.txt`, `${ refreshToken }\n${ Date.now() }\n`, `utf8`);