19 lines
636 B
TypeScript
19 lines
636 B
TypeScript
|
import { writeFile } from 'node:fs/promises';
|
||
|
import nodePath from 'node:path';
|
||
|
import m3u from 'm3u';
|
||
|
import type { SongMeta } from './services/jellyfin.ts';
|
||
|
|
||
|
const createM3U = (name: string, songlist: SongMeta[]) => {
|
||
|
const m3uWriter = m3u.writer();
|
||
|
for (const song of songlist) {
|
||
|
const extension = song.Path.split('.').pop();
|
||
|
m3uWriter.file(`${song.Id}.${extension}`);
|
||
|
}
|
||
|
return m3uWriter.toString();
|
||
|
};
|
||
|
|
||
|
export const writeM3UFile = async (path: string, name: string, songlist: SongMeta[]) => {
|
||
|
const contents = createM3U(name, songlist);
|
||
|
return writeFile(nodePath.join(path, `${name}.m3u`), contents, 'utf8');
|
||
|
};
|