-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed being unable to extract video album and title
When there was no artist metadata on a video all other metadata was also ignored. This is fixed for new imports. For old imports please run the "Rescan video files for missing metadata" task. This will add missing metadata from the video files to the database. It will not clobber any existing metadata in the DB.
- Loading branch information
SimplyBoo
committed
Apr 22, 2021
1 parent
a74dcc0
commit d8d336b
Showing
4 changed files
with
123 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { execute } from 'proper-job'; | ||
|
||
import { Database, RouterTask, TaskRunnerCallback } from '../types'; | ||
import { ImportUtils } from '../cache/import-utils'; | ||
|
||
const BATCH_SIZE = 4; | ||
|
||
export function getTask(db: Database): RouterTask { | ||
return { | ||
id: 'RESCAN-VIDEO-METADATA', | ||
description: 'Rescan video files for missing metadata', | ||
runner: (updateStatus: TaskRunnerCallback) => { | ||
return execute( | ||
async () => { | ||
const videos = await db.subset({ | ||
corrupted: false, | ||
type: { equalsAll: ['video'] }, | ||
}); | ||
updateStatus(0, videos.length); | ||
|
||
return { | ||
iterable: videos, | ||
init: { | ||
current: 0, | ||
max: videos.length, | ||
}, | ||
}; | ||
}, | ||
async (hash, init) => { | ||
if (!init) { | ||
throw new Error('init not defined'); | ||
} | ||
|
||
try { | ||
const media = await db.getMedia(hash); | ||
if (!media) { | ||
throw new Error(`Couldn't find media to update metadata: ${hash}`); | ||
} | ||
if (media.metadata?.album && media.metadata?.artist && media.metadata?.title) { | ||
return; | ||
} | ||
const fileMetadata = await ImportUtils.getVideoMetadata(media.absolutePath); | ||
if (!fileMetadata.album && !fileMetadata.artist && !fileMetadata.title) { | ||
return; | ||
} | ||
|
||
try { | ||
await db.saveMedia(media.hash, { | ||
metadata: { | ||
...(media.metadata?.album ? {} : { album: fileMetadata.album }), | ||
...(media.metadata?.artist ? {} : { artist: fileMetadata.artist }), | ||
...(media.metadata?.title ? {} : { title: fileMetadata.title }), | ||
}, | ||
}); | ||
} catch (err) { | ||
console.log('Failed to save media preview state.', err, media); | ||
} | ||
} catch (err) { | ||
console.log(`Error getting metadata for ${hash}.`, err); | ||
await db.saveMedia(hash, { corrupted: true }); | ||
throw new Error(`Error getting metadata for ${hash}.`); | ||
} finally { | ||
updateStatus(init.current++, init.max); | ||
} | ||
}, | ||
{ parallel: BATCH_SIZE }, | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters