Merge pull request #145 from bnkai/scan_screens

Scan screens
This commit is contained in:
Leopere 2019-10-20 12:19:58 -04:00 committed by GitHub
commit a2e550063b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 5 deletions

View File

@ -81,7 +81,8 @@ func (t *ScanTask) scanScene() {
qb := models.NewSceneQueryBuilder()
scene, _ := qb.FindByPath(t.FilePath)
if scene != nil {
// We already have this item in the database, keep going
// We already have this item in the database, check for thumbnails,screenshots
t.makeScreenshots(nil, scene.Checksum)
return
}
@ -102,7 +103,7 @@ func (t *ScanTask) scanScene() {
return
}
t.makeScreenshots(*videoFile, checksum)
t.makeScreenshots(videoFile, checksum)
scene, _ = qb.FindByChecksum(checksum)
ctx := context.TODO()
@ -150,19 +151,38 @@ func (t *ScanTask) scanScene() {
}
}
func (t *ScanTask) makeScreenshots(probeResult ffmpeg.VideoFile, checksum string) {
func (t *ScanTask) makeScreenshots(probeResult *ffmpeg.VideoFile, checksum string) {
thumbPath := instance.Paths.Scene.GetThumbnailScreenshotPath(checksum)
normalPath := instance.Paths.Scene.GetScreenshotPath(checksum)
thumbExists, _ := utils.FileExists(thumbPath)
normalExists, _ := utils.FileExists(normalPath)
if thumbExists && normalExists {
logger.Debug("Screenshots already exist for this path... skipping")
return
}
t.makeScreenshot(probeResult, thumbPath, 5, 320)
t.makeScreenshot(probeResult, normalPath, 2, probeResult.Width)
if probeResult == nil {
var err error
probeResult, err = ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath)
if err != nil {
logger.Error(err.Error())
return
}
logger.Infof("Regenerating images for %s", t.FilePath)
}
if !thumbExists {
logger.Debugf("Creating thumbnail for %s", t.FilePath)
t.makeScreenshot(*probeResult, thumbPath, 5, 320)
}
if !normalExists {
logger.Debugf("Creating screenshot for %s", t.FilePath)
t.makeScreenshot(*probeResult, normalPath, 2, probeResult.Width)
}
}
func (t *ScanTask) makeScreenshot(probeResult ffmpeg.VideoFile, outputPath string, quality int, width int) {