mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Add oshash support (#667)
This commit is contained in:
@@ -10,10 +10,13 @@ import (
|
||||
|
||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/manager/config"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
// DestroyScene deletes a scene and its associated relationships from the
|
||||
// database.
|
||||
func DestroyScene(sceneID int, tx *sqlx.Tx) error {
|
||||
qb := models.NewSceneQueryBuilder()
|
||||
jqb := models.NewJoinsQueryBuilder()
|
||||
@@ -46,18 +49,25 @@ func DestroyScene(sceneID int, tx *sqlx.Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
markersFolder := filepath.Join(GetInstance().Paths.Generated.Markers, scene.Checksum)
|
||||
// DeleteGeneratedSceneFiles deletes generated files for the provided scene.
|
||||
func DeleteGeneratedSceneFiles(scene *models.Scene, fileNamingAlgo models.HashAlgorithm) {
|
||||
sceneHash := scene.GetHash(fileNamingAlgo)
|
||||
|
||||
if sceneHash == "" {
|
||||
return
|
||||
}
|
||||
|
||||
markersFolder := filepath.Join(GetInstance().Paths.Generated.Markers, sceneHash)
|
||||
|
||||
exists, _ := utils.FileExists(markersFolder)
|
||||
if exists {
|
||||
err := os.RemoveAll(markersFolder)
|
||||
if err != nil {
|
||||
logger.Warnf("Could not delete file %s: %s", scene.Path, err.Error())
|
||||
logger.Warnf("Could not delete folder %s: %s", markersFolder, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
thumbPath := GetInstance().Paths.Scene.GetThumbnailScreenshotPath(scene.Checksum)
|
||||
thumbPath := GetInstance().Paths.Scene.GetThumbnailScreenshotPath(sceneHash)
|
||||
exists, _ = utils.FileExists(thumbPath)
|
||||
if exists {
|
||||
err := os.Remove(thumbPath)
|
||||
@@ -66,7 +76,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
normalPath := GetInstance().Paths.Scene.GetScreenshotPath(scene.Checksum)
|
||||
normalPath := GetInstance().Paths.Scene.GetScreenshotPath(sceneHash)
|
||||
exists, _ = utils.FileExists(normalPath)
|
||||
if exists {
|
||||
err := os.Remove(normalPath)
|
||||
@@ -75,7 +85,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
streamPreviewPath := GetInstance().Paths.Scene.GetStreamPreviewPath(scene.Checksum)
|
||||
streamPreviewPath := GetInstance().Paths.Scene.GetStreamPreviewPath(sceneHash)
|
||||
exists, _ = utils.FileExists(streamPreviewPath)
|
||||
if exists {
|
||||
err := os.Remove(streamPreviewPath)
|
||||
@@ -84,7 +94,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
streamPreviewImagePath := GetInstance().Paths.Scene.GetStreamPreviewImagePath(scene.Checksum)
|
||||
streamPreviewImagePath := GetInstance().Paths.Scene.GetStreamPreviewImagePath(sceneHash)
|
||||
exists, _ = utils.FileExists(streamPreviewImagePath)
|
||||
if exists {
|
||||
err := os.Remove(streamPreviewImagePath)
|
||||
@@ -93,7 +103,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
transcodePath := GetInstance().Paths.Scene.GetTranscodePath(scene.Checksum)
|
||||
transcodePath := GetInstance().Paths.Scene.GetTranscodePath(sceneHash)
|
||||
exists, _ = utils.FileExists(transcodePath)
|
||||
if exists {
|
||||
// kill any running streams
|
||||
@@ -105,7 +115,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
spritePath := GetInstance().Paths.Scene.GetSpriteImageFilePath(scene.Checksum)
|
||||
spritePath := GetInstance().Paths.Scene.GetSpriteImageFilePath(sceneHash)
|
||||
exists, _ = utils.FileExists(spritePath)
|
||||
if exists {
|
||||
err := os.Remove(spritePath)
|
||||
@@ -114,7 +124,7 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
vttPath := GetInstance().Paths.Scene.GetSpriteVttFilePath(scene.Checksum)
|
||||
vttPath := GetInstance().Paths.Scene.GetSpriteVttFilePath(sceneHash)
|
||||
exists, _ = utils.FileExists(vttPath)
|
||||
if exists {
|
||||
err := os.Remove(vttPath)
|
||||
@@ -124,9 +134,11 @@ func DeleteGeneratedSceneFiles(scene *models.Scene) {
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteSceneMarkerFiles(scene *models.Scene, seconds int) {
|
||||
videoPath := GetInstance().Paths.SceneMarkers.GetStreamPath(scene.Checksum, seconds)
|
||||
imagePath := GetInstance().Paths.SceneMarkers.GetStreamPreviewImagePath(scene.Checksum, seconds)
|
||||
// DeleteSceneMarkerFiles deletes generated files for a scene marker with the
|
||||
// provided scene and timestamp.
|
||||
func DeleteSceneMarkerFiles(scene *models.Scene, seconds int, fileNamingAlgo models.HashAlgorithm) {
|
||||
videoPath := GetInstance().Paths.SceneMarkers.GetStreamPath(scene.GetHash(fileNamingAlgo), seconds)
|
||||
imagePath := GetInstance().Paths.SceneMarkers.GetStreamPreviewImagePath(scene.GetHash(fileNamingAlgo), seconds)
|
||||
|
||||
exists, _ := utils.FileExists(videoPath)
|
||||
if exists {
|
||||
@@ -145,6 +157,7 @@ func DeleteSceneMarkerFiles(scene *models.Scene, seconds int) {
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteSceneFile deletes the scene video file from the filesystem.
|
||||
func DeleteSceneFile(scene *models.Scene) {
|
||||
// kill any running encoders
|
||||
KillRunningStreams(scene.Path)
|
||||
@@ -195,8 +208,7 @@ func GetSceneStreamPaths(scene *models.Scene, directStreamURL string) ([]*models
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hasTranscode, _ := HasTranscode(scene)
|
||||
if hasTranscode || ffmpeg.IsValidAudioForContainer(audioCodec, container) {
|
||||
if HasTranscode(scene, config.GetVideoFileNamingAlgorithm()) || ffmpeg.IsValidAudioForContainer(audioCodec, container) {
|
||||
label := "Direct stream"
|
||||
ret = append(ret, &models.SceneStreamEndpoint{
|
||||
URL: directStreamURL,
|
||||
@@ -236,10 +248,20 @@ func GetSceneStreamPaths(scene *models.Scene, directStreamURL string) ([]*models
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func HasTranscode(scene *models.Scene) (bool, error) {
|
||||
// HasTranscode returns true if a transcoded video exists for the provided
|
||||
// scene. It will check using the OSHash of the scene first, then fall back
|
||||
// to the checksum.
|
||||
func HasTranscode(scene *models.Scene, fileNamingAlgo models.HashAlgorithm) bool {
|
||||
if scene == nil {
|
||||
return false, fmt.Errorf("nil scene")
|
||||
return false
|
||||
}
|
||||
transcodePath := instance.Paths.Scene.GetTranscodePath(scene.Checksum)
|
||||
return utils.FileExists(transcodePath)
|
||||
|
||||
sceneHash := scene.GetHash(fileNamingAlgo)
|
||||
if sceneHash == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
transcodePath := instance.Paths.Scene.GetTranscodePath(sceneHash)
|
||||
ret, _ := utils.FileExists(transcodePath)
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user