chore: update public repo

This commit is contained in:
desu-bot 2025-05-14 09:48:24 +00:00
parent 8c04afc6d2
commit 3057b2a78c
No known key found for this signature in database

View file

@ -0,0 +1,60 @@
import { createReadStream } from 'node:fs'
import { nodeReadableToFuman } from '@fuman/node'
import Database from 'better-sqlite3'
import { question } from 'zx'
import { CsvReader } from '../../utils/csv.ts'
const csvPath = process.argv[2] ?? await question('path to csv > ')
// convert csv generated by https://mainstream.ghan.nl/export.html to an sqlite database
const db = new Database('assets/lastfm-import.db')
db.exec(`
CREATE TABLE IF NOT EXISTS scrobbles (
date_uts TEXT,
artist_mbid TEXT,
artist_name TEXT,
album_mbid TEXT,
album_name TEXT,
track_mbid TEXT,
track_name TEXT
);
`)
const insertQuery = db.prepare(`
INSERT INTO scrobbles (
date_uts,
artist_mbid,
artist_name,
album_mbid,
album_name,
track_mbid,
track_name
) VALUES (?, ?, ?, ?, ?, ?, ?)
`)
const file = nodeReadableToFuman(createReadStream(csvPath))
const csv = new CsvReader(file, {
schema: ['uts', 'utc_time', 'artist', 'artist_mbid', 'album', 'album_mbid', 'track', 'track_mbid'],
})
let i = 0
while (true) {
const obj = await csv.read()
if (!obj) break
i += 1
if (i % 1000 === 0) {
console.log('inserted', i)
}
insertQuery.run(
obj.uts,
obj.artist_mbid,
obj.artist,
obj.album_mbid,
obj.album,
obj.track_mbid,
obj.track,
)
}