mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Add oshash support (#667)
This commit is contained in:
@@ -13,9 +13,10 @@ import (
|
||||
)
|
||||
|
||||
type GenerateMarkersTask struct {
|
||||
Scene *models.Scene
|
||||
Marker *models.SceneMarker
|
||||
Overwrite bool
|
||||
Scene *models.Scene
|
||||
Marker *models.SceneMarker
|
||||
Overwrite bool
|
||||
fileNamingAlgorithm models.HashAlgorithm
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) Start(wg *sync.WaitGroup) {
|
||||
@@ -56,27 +57,28 @@ func (t *GenerateMarkersTask) generateSceneMarkers() {
|
||||
return
|
||||
}
|
||||
|
||||
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
||||
|
||||
// Make the folder for the scenes markers
|
||||
markersFolder := filepath.Join(instance.Paths.Generated.Markers, t.Scene.Checksum)
|
||||
_ = utils.EnsureDir(markersFolder)
|
||||
markersFolder := filepath.Join(instance.Paths.Generated.Markers, sceneHash)
|
||||
utils.EnsureDir(markersFolder)
|
||||
|
||||
for i, sceneMarker := range sceneMarkers {
|
||||
index := i + 1
|
||||
logger.Progressf("[generator] <%s> scene marker %d of %d", t.Scene.Checksum, index, len(sceneMarkers))
|
||||
logger.Progressf("[generator] <%s> scene marker %d of %d", sceneHash, index, len(sceneMarkers))
|
||||
|
||||
t.generateMarker(videoFile, t.Scene, sceneMarker)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) generateMarker(videoFile *ffmpeg.VideoFile, scene *models.Scene, sceneMarker *models.SceneMarker) {
|
||||
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
||||
seconds := int(sceneMarker.Seconds)
|
||||
|
||||
videoExists := t.videoExists(sceneHash, seconds)
|
||||
imageExists := t.imageExists(sceneHash, seconds)
|
||||
|
||||
baseFilename := strconv.Itoa(seconds)
|
||||
videoFilename := baseFilename + ".mp4"
|
||||
imageFilename := baseFilename + ".webp"
|
||||
videoPath := instance.Paths.SceneMarkers.GetStreamPath(scene.Checksum, seconds)
|
||||
imagePath := instance.Paths.SceneMarkers.GetStreamPreviewImagePath(scene.Checksum, seconds)
|
||||
videoExists, _ := utils.FileExists(videoPath)
|
||||
imageExists, _ := utils.FileExists(imagePath)
|
||||
|
||||
options := ffmpeg.SceneMarkerOptions{
|
||||
ScenePath: scene.Path,
|
||||
@@ -87,6 +89,9 @@ func (t *GenerateMarkersTask) generateMarker(videoFile *ffmpeg.VideoFile, scene
|
||||
encoder := ffmpeg.NewEncoder(instance.FFMPEGPath)
|
||||
|
||||
if t.Overwrite || !videoExists {
|
||||
videoFilename := baseFilename + ".mp4"
|
||||
videoPath := instance.Paths.SceneMarkers.GetStreamPath(sceneHash, seconds)
|
||||
|
||||
options.OutputPath = instance.Paths.Generated.GetTmpPath(videoFilename) // tmp output in case the process ends abruptly
|
||||
if err := encoder.SceneMarkerVideo(*videoFile, options); err != nil {
|
||||
logger.Errorf("[generator] failed to generate marker video: %s", err)
|
||||
@@ -97,18 +102,20 @@ func (t *GenerateMarkersTask) generateMarker(videoFile *ffmpeg.VideoFile, scene
|
||||
}
|
||||
|
||||
if t.Overwrite || !imageExists {
|
||||
imageFilename := baseFilename + ".webp"
|
||||
imagePath := instance.Paths.SceneMarkers.GetStreamPreviewImagePath(sceneHash, seconds)
|
||||
|
||||
options.OutputPath = instance.Paths.Generated.GetTmpPath(imageFilename) // tmp output in case the process ends abruptly
|
||||
if err := encoder.SceneMarkerImage(*videoFile, options); err != nil {
|
||||
logger.Errorf("[generator] failed to generate marker image: %s", err)
|
||||
} else {
|
||||
_ = os.Rename(options.OutputPath, imagePath)
|
||||
logger.Debug("created marker image: ", videoPath)
|
||||
logger.Debug("created marker image: ", imagePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) isMarkerNeeded() int {
|
||||
|
||||
markers := 0
|
||||
qb := models.NewSceneMarkerQueryBuilder()
|
||||
sceneMarkers, _ := qb.FindBySceneID(t.Scene.ID, nil)
|
||||
@@ -116,18 +123,49 @@ func (t *GenerateMarkersTask) isMarkerNeeded() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
||||
for _, sceneMarker := range sceneMarkers {
|
||||
seconds := int(sceneMarker.Seconds)
|
||||
videoPath := instance.Paths.SceneMarkers.GetStreamPath(t.Scene.Checksum, seconds)
|
||||
imagePath := instance.Paths.SceneMarkers.GetStreamPreviewImagePath(t.Scene.Checksum, seconds)
|
||||
videoExists, _ := utils.FileExists(videoPath)
|
||||
imageExists, _ := utils.FileExists(imagePath)
|
||||
|
||||
if t.Overwrite || !videoExists || !imageExists {
|
||||
if t.Overwrite || !t.markerExists(sceneHash, seconds) {
|
||||
markers++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return markers
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) markerExists(sceneChecksum string, seconds int) bool {
|
||||
if sceneChecksum == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
videoPath := instance.Paths.SceneMarkers.GetStreamPath(sceneChecksum, seconds)
|
||||
imagePath := instance.Paths.SceneMarkers.GetStreamPreviewImagePath(sceneChecksum, seconds)
|
||||
videoExists, _ := utils.FileExists(videoPath)
|
||||
imageExists, _ := utils.FileExists(imagePath)
|
||||
|
||||
return videoExists && imageExists
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) videoExists(sceneChecksum string, seconds int) bool {
|
||||
if sceneChecksum == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
videoPath := instance.Paths.SceneMarkers.GetStreamPath(sceneChecksum, seconds)
|
||||
videoExists, _ := utils.FileExists(videoPath)
|
||||
|
||||
return videoExists
|
||||
}
|
||||
|
||||
func (t *GenerateMarkersTask) imageExists(sceneChecksum string, seconds int) bool {
|
||||
if sceneChecksum == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
imagePath := instance.Paths.SceneMarkers.GetStreamPreviewImagePath(sceneChecksum, seconds)
|
||||
imageExists, _ := utils.FileExists(imagePath)
|
||||
|
||||
return imageExists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user