-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata-to-db.ts
34 lines (27 loc) · 1.21 KB
/
metadata-to-db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { setupDb, dbRun, stmtRun } from './src/db';
import { getTrackMetadata } from './src/itunes';
const FOLDER = 'music';
const DB_PATH = './metadata.db';
const MUSIC_DIR = 'Z:\\Music\\Music';
const ALT_MUSIC_DIR = 'C:\\Users\\tim\\Music\\iTunes\\iTunes Media\\Music';
const ITUNES_DB_PATH = 'C:\\Users\\tim\\Music\\iTunes\\iTunes Music Library.xml';
insertMetadataIntoDb();
async function insertMetadataIntoDb() {
const db = await setupDb(DB_PATH);
await dbRun(db, `
CREATE TABLE IF NOT EXISTS ratings (
path STRING PRIMARY KEY,
localPath STRING,
rating TINYINT,
playCount SMALLINT,
dateModified STRING,
dateAdded STRING,
datePlayed STRING
)
`);
const insert = db.prepare('INSERT OR REPLACE INTO ratings (path, localPath, rating, playCount, dateModified, dateAdded, datePlayed) VALUES (?, ?, ?, ?, ?, ?, ?)');
const metadata = await getTrackMetadata(ITUNES_DB_PATH, FOLDER, [MUSIC_DIR, ALT_MUSIC_DIR]);
for (const { s3Path, filePath, rating, playCount, dateModified, dateAdded, playDate } of metadata) {
stmtRun(insert, s3Path, filePath, rating, playCount, dateModified, dateAdded, playDate);
}
}