46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import {inject, service} from "../core/service";
|
|
import {CliService} from "./CliService";
|
|
|
|
@service('ffmpegService')
|
|
export default class FFMpegService {
|
|
@inject('cliService') protected accessor cliService!: CliService;
|
|
|
|
async checkFile(filename: string) {
|
|
const file = await this.cliService.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,
|
|
},
|
|
};
|
|
}
|
|
} |