From 40b270eb499ab3b7da46eda8f1801702ad100073 Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Wed, 16 Oct 2019 04:17:04 +0300 Subject: [PATCH 1/5] fix issue #144 --- pkg/manager/task_scan.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index 4309cbbd7..ea39b345f 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -81,7 +81,31 @@ 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 + + thumbPath := instance.Paths.Scene.GetThumbnailScreenshotPath(scene.Checksum) + normalPath := instance.Paths.Scene.GetScreenshotPath(scene.Checksum) + + thumbExists, _ := utils.FileExists(thumbPath) + normalExists, _ := utils.FileExists(normalPath) + + if !thumbExists || !normalExists { + checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) + + if err != nil { + logger.Error(err.Error()) + return + } + if !thumbExists { + logger.Infof("Recreating thumbnail for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) + } + + if !normalExists { + logger.Infof("Recreating screeenshot for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) + } + } return } From 02f485e40ea90f8d33e4f743cb6ea7913256d3eb Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Wed, 16 Oct 2019 18:27:38 +0300 Subject: [PATCH 2/5] refactoring --- pkg/manager/task_scan.go | 55 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index ea39b345f..648a6d1e9 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -82,30 +82,7 @@ func (t *ScanTask) scanScene() { scene, _ := qb.FindByPath(t.FilePath) if scene != nil { // We already have this item in the database, check for thumbnails,screenshots - - thumbPath := instance.Paths.Scene.GetThumbnailScreenshotPath(scene.Checksum) - normalPath := instance.Paths.Scene.GetScreenshotPath(scene.Checksum) - - thumbExists, _ := utils.FileExists(thumbPath) - normalExists, _ := utils.FileExists(normalPath) - - if !thumbExists || !normalExists { - checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) - - if err != nil { - logger.Error(err.Error()) - return - } - if !thumbExists { - logger.Infof("Recreating thumbnail for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) - } - - if !normalExists { - logger.Infof("Recreating screeenshot for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) - } - } + t.checkScreenshots(scene.Checksum) return } @@ -209,3 +186,33 @@ func (t *ScanTask) calculateChecksum() (string, error) { logger.Debugf("Checksum calculated: %s", checksum) return checksum, nil } + +func (t *ScanTask) checkScreenshots(checksum string) { + //check for existance of screenshot or thumbnail and create them if needed + + thumbPath := instance.Paths.Scene.GetThumbnailScreenshotPath(checksum) + normalPath := instance.Paths.Scene.GetScreenshotPath(checksum) + + thumbExists, _ := utils.FileExists(thumbPath) + normalExists, _ := utils.FileExists(normalPath) + + if !thumbExists || !normalExists { + checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) + + if err != nil { + logger.Error(err.Error()) + return + } + if !thumbExists { + logger.Infof("Recreating thumbnail for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) + } + + if !normalExists { + logger.Infof("Recreating screenshot for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) + } + } + return + +} From ab1690d5b18e4be88f4a156a35d5d45b0101adcb Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Thu, 17 Oct 2019 16:50:30 +0300 Subject: [PATCH 3/5] makeScreenshots can be called for a new or already existing file --- pkg/manager/task_scan.go | 64 ++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index 648a6d1e9..d35e75b6f 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -82,7 +82,7 @@ func (t *ScanTask) scanScene() { scene, _ := qb.FindByPath(t.FilePath) if scene != nil { // We already have this item in the database, check for thumbnails,screenshots - t.checkScreenshots(scene.Checksum) + t.makeScreenshots(nil, scene.Checksum) return } @@ -103,7 +103,7 @@ func (t *ScanTask) scanScene() { return } - t.makeScreenshots(*videoFile, checksum) + t.makeScreenshots(videoFile, checksum) scene, _ = qb.FindByChecksum(checksum) ctx := context.TODO() @@ -151,19 +151,43 @@ 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 { + // makescreenshots is called for a new file + t.makeScreenshot(*probeResult, thumbPath, 5, 320) + t.makeScreenshot(*probeResult, normalPath, 2, probeResult.Width) + } else { + // makescreenshots is called for an already existing file + if !thumbExists || !normalExists { + checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) + + if err != nil { + logger.Error(err.Error()) + return + } + if !thumbExists { + logger.Infof("Recreating thumbnail for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) + } + + if !normalExists { + logger.Infof("Recreating screenshot for %s", t.FilePath) + t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) + } + } + } + } func (t *ScanTask) makeScreenshot(probeResult ffmpeg.VideoFile, outputPath string, quality int, width int) { @@ -186,33 +210,3 @@ func (t *ScanTask) calculateChecksum() (string, error) { logger.Debugf("Checksum calculated: %s", checksum) return checksum, nil } - -func (t *ScanTask) checkScreenshots(checksum string) { - //check for existance of screenshot or thumbnail and create them if needed - - thumbPath := instance.Paths.Scene.GetThumbnailScreenshotPath(checksum) - normalPath := instance.Paths.Scene.GetScreenshotPath(checksum) - - thumbExists, _ := utils.FileExists(thumbPath) - normalExists, _ := utils.FileExists(normalPath) - - if !thumbExists || !normalExists { - checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) - - if err != nil { - logger.Error(err.Error()) - return - } - if !thumbExists { - logger.Infof("Recreating thumbnail for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) - } - - if !normalExists { - logger.Infof("Recreating screenshot for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) - } - } - return - -} From 8d2df527b746a71af28c000d9dc2822980d9dc87 Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Fri, 18 Oct 2019 02:17:51 +0300 Subject: [PATCH 4/5] makeScreenshots cleanup --- pkg/manager/task_scan.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index d35e75b6f..3d394f37e 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -163,31 +163,25 @@ func (t *ScanTask) makeScreenshots(probeResult *ffmpeg.VideoFile, checksum strin return } - if probeResult != nil { - // makescreenshots is called for a new file - t.makeScreenshot(*probeResult, thumbPath, 5, 320) - t.makeScreenshot(*probeResult, normalPath, 2, probeResult.Width) - } else { - // makescreenshots is called for an already existing file - if !thumbExists || !normalExists { - checkvideoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) + if probeResult == nil { + var err error + probeResult, err = ffmpeg.NewVideoFile(instance.FFProbePath, t.FilePath) - if err != nil { - logger.Error(err.Error()) - return - } - if !thumbExists { - logger.Infof("Recreating thumbnail for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, thumbPath, 5, 320) - } - - if !normalExists { - logger.Infof("Recreating screenshot for %s", t.FilePath) - t.makeScreenshot(*checkvideoFile, normalPath, 2, checkvideoFile.Width) - } + if err != nil { + logger.Error(err.Error()) + return } } + 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) { From 2693a2b22f8e0434e7e62a3bb93caed2076be309 Mon Sep 17 00:00:00 2001 From: bill <48220860+bnkai@users.noreply.github.com> Date: Fri, 18 Oct 2019 20:35:53 +0300 Subject: [PATCH 5/5] print message when recreating images for the scan process --- pkg/manager/task_scan.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/manager/task_scan.go b/pkg/manager/task_scan.go index 3d394f37e..0fde3371a 100644 --- a/pkg/manager/task_scan.go +++ b/pkg/manager/task_scan.go @@ -164,13 +164,14 @@ func (t *ScanTask) makeScreenshots(probeResult *ffmpeg.VideoFile, checksum strin } if probeResult == nil { - var err error + 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 {