|
1 | 1 | import {
|
2 | 2 | IpcId,
|
3 | 3 | TranscodeInfo,
|
4 |
| - TranscodeSourceType, |
| 4 | + TranscodeSource, |
5 | 5 | TranscodeState,
|
6 | 6 | } from '@freik/emp-shared';
|
7 | 7 | import { MakeLog } from '@freik/logger';
|
@@ -44,23 +44,22 @@ function reQuote(str: string): { [key: string]: string } {
|
44 | 44 | return JSON.parse(res) as { [key: string]: string };
|
45 | 45 | }
|
46 | 46 |
|
47 |
| -/// vvvv Hurray for a Typescript compiler bug |
48 |
| - |
49 |
| -enum XcodeResCode { |
50 |
| - alreadyExists, |
51 |
| - mediaInfoFailure, |
52 |
| - encodeFailure, |
53 |
| - unknownError, |
54 |
| - alreadyLowBitRate, |
55 |
| - success, |
56 |
| -} |
| 47 | +const XcodeResCode = Object.freeze({ |
| 48 | + alreadyExists: 0, |
| 49 | + mediaInfoFailure: 1, |
| 50 | + encodeFailure: 2, |
| 51 | + unknownError: 3, |
| 52 | + alreadyLowBitRate: 4, |
| 53 | + success: 5, |
| 54 | +} as const); |
| 55 | +type XcodeResCodeEnum = (typeof XcodeResCode)[keyof typeof XcodeResCode]; |
57 | 56 |
|
58 | 57 | type TranscodeResult = {
|
59 |
| - code: XcodeResCode; |
| 58 | + code: XcodeResCodeEnum; |
60 | 59 | message: string;
|
61 | 60 | };
|
62 | 61 |
|
63 |
| -const tr = (code: XcodeResCode, message: string) => ({ code, message }); |
| 62 | +const tr = (code: XcodeResCodeEnum, message: string) => ({ code, message }); |
64 | 63 | let bitrate = 163840;
|
65 | 64 |
|
66 | 65 | export async function toMp4Async(
|
@@ -246,7 +245,7 @@ async function getFullSongPathFromSettings(
|
246 | 245 | settings: TranscodeInfo,
|
247 | 246 | file: string,
|
248 | 247 | ): Promise<[string, string] | void> {
|
249 |
| - if (settings.source.type === TranscodeSourceType.Disk) { |
| 248 | + if (settings.source.type === TranscodeSource.Disk) { |
250 | 249 | const srcdir = settings.source.loc;
|
251 | 250 | if (!path.normalize(file).startsWith(srcdir)) {
|
252 | 251 | reportFailure(file, `${file} doesn't match ${srcdir}`);
|
@@ -505,29 +504,29 @@ export async function startTranscode(settings: TranscodeInfo): Promise<void> {
|
505 | 504 | startStatusReporting();
|
506 | 505 | try {
|
507 | 506 | const workQueue: string[] = [];
|
508 |
| - if (settings.source.type === TranscodeSourceType.Disk) { |
| 507 | + if (settings.source.type === TranscodeSource.Disk) { |
509 | 508 | await ScanSourceFromDisk(settings, workQueue);
|
510 | 509 | } else {
|
511 | 510 | // TODO: Handle artwork for this stuff
|
512 | 511 | const db = await GetAudioDB();
|
513 | 512 | switch (settings.source.type) {
|
514 |
| - case TranscodeSourceType.Album: { |
| 513 | + case TranscodeSource.Album: { |
515 | 514 | const album = db.getAlbum(settings.source.loc);
|
516 | 515 | if (album) {
|
517 | 516 | workQueue.push(...album.songs);
|
518 | 517 | }
|
519 | 518 | // TODO: Report no such album
|
520 | 519 | break;
|
521 | 520 | }
|
522 |
| - case TranscodeSourceType.Artist: { |
| 521 | + case TranscodeSource.Artist: { |
523 | 522 | const artist = db.getArtist(settings.source.loc);
|
524 | 523 | if (artist) {
|
525 | 524 | workQueue.push(...artist.songs);
|
526 | 525 | }
|
527 | 526 | // TODO: Report no such album
|
528 | 527 | break;
|
529 | 528 | }
|
530 |
| - case TranscodeSourceType.Playlist: |
| 529 | + case TranscodeSource.Playlist: |
531 | 530 | workQueue.push(...(await LoadPlaylist(settings.source.loc)));
|
532 | 531 | break;
|
533 | 532 | }
|
|
0 commit comments