Service decorators - oh the evil I have wraught....
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import {runCommand} from "./CliService";
|
||||
import {service} from "../core/service";
|
||||
|
||||
@service('ffmpegService')
|
||||
export default class FFMpegService {
|
||||
static async checkFile(filename: string) {
|
||||
const file = await runCommand('ffprobe', [
|
||||
'-v',
|
||||
'quiet',
|
||||
'-print_format',
|
||||
'json',
|
||||
'-show_format',
|
||||
filename
|
||||
]);
|
||||
|
||||
if (file.stderr !== '') {
|
||||
throw new Error('FFMpeg returned error: ' + file.stderr);
|
||||
}
|
||||
|
||||
const json = JSON.parse(file.stdout);
|
||||
|
||||
if (!json || !json.format) {
|
||||
throw new Error('FFMpeg did not return format block: ' + file.stdout);
|
||||
}
|
||||
|
||||
return {
|
||||
type: json.format.format_name,
|
||||
duration: parseFloat(json.format.duration),
|
||||
size: parseFloat(json.format.size),
|
||||
tags: {
|
||||
title: json.format.tags?.title || json.format.tags?.TITLE || null,
|
||||
album: json.format.tags?.album || json.format.tags?.ALBUM || null,
|
||||
artist: json.format.tags?.artist || json.format.tags?.ARTIST || null,
|
||||
comment: json.format.tags?.comment || json.format.tags?.COMMENT || null,
|
||||
track: json.format.tags?.track || json.format.tags?.TRACK || null,
|
||||
genre: json.format.tags?.genre || json.format.tags?.GENRE || null,
|
||||
publisher: json.format.tags?.publisher || json.format.tags?.PUBLISHER || null,
|
||||
album_artist: json.format.tags?.album_artist || json.format.tags?.ALBUM_ARTIST || null,
|
||||
composer: json.format.tags?.composer || json.format.tags?.COMPOSER || null,
|
||||
year: json.format.tags?.year || json.format.tags?.YEAR || null,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user