tangled
alpha
login
or
join now
rocksky.app
/
rocksky
96
fork
atom
A decentralized music tracking and discovery platform built on AT Protocol 🎵
rocksky.app
spotify
atproto
lastfm
musicbrainz
scrobbling
listenbrainz
96
fork
atom
overview
issues
7
pulls
pipelines
[api] add sync library script
tsiry-sandratraina.com
8 months ago
e26e734f
8ceb99ef
+24
-1
1 changed file
expand all
collapse all
unified
split
apps
api
src
scripts
sync-library.ts
+24
-1
apps/api/src/scripts/sync-library.ts
···
1
1
import chalk from "chalk";
2
2
import { ctx } from "context";
3
3
-
import { and, count, eq } from "drizzle-orm";
3
3
+
import { and, count, eq, not } from "drizzle-orm";
4
4
import tables from "schema";
5
5
import { InsertArtistAlbum } from "schema/artist-albums";
6
6
···
8
8
const total = await ctx.db
9
9
.select({ value: count() })
10
10
.from(tables.tracks)
11
11
+
.where(
12
12
+
and(
13
13
+
not(eq(tables.tracks.albumUri, null)),
14
14
+
not(eq(tables.tracks.artistUri, null))
15
15
+
)
16
16
+
)
11
17
.execute()
12
18
.then(([row]) => row.value);
13
19
20
20
+
console.log(`Total tracks to process: ${chalk.magentaBright(total)}`);
21
21
+
14
22
for (let i = 0; i < total; i += size) {
15
23
const skip = i;
16
24
console.log(
···
19
27
const results = await ctx.db
20
28
.select()
21
29
.from(tables.tracks)
30
30
+
.where(
31
31
+
and(
32
32
+
not(eq(tables.tracks.albumUri, null)),
33
33
+
not(eq(tables.tracks.artistUri, null))
34
34
+
)
35
35
+
)
22
36
.limit(size)
23
37
.offset(skip)
24
38
.execute();
···
63
77
.execute()
64
78
.then((rows) => rows[0]),
65
79
]);
80
80
+
81
81
+
if (!artist || !album) {
82
82
+
console.error(
83
83
+
`Artist or album not found for track: ${track.uri}. Skipping...`
84
84
+
);
85
85
+
console.log("artist", artist);
86
86
+
console.log("album", album);
87
87
+
continue;
88
88
+
}
66
89
67
90
await ctx.db
68
91
.insert(tables.artistAlbums)