Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caption support #2462

Merged
merged 63 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
5598f91
support for english caption
cj12312021 Mar 31, 2022
040a677
support other languages
cj12312021 Apr 1, 2022
8ee6fed
changed manualCleanup to true
cj12312021 Apr 1, 2022
5b6a133
Merge branch 'develop' into caption_support
cj12312021 Apr 1, 2022
1e793a5
added captions to manual
cj12312021 Apr 1, 2022
25b64f9
added captioned to sortByList
cj12312021 Apr 1, 2022
590693a
created entry for captioned in en-GB.json file
cj12312021 Apr 1, 2022
bc636d6
updated formatting
cj12312021 Apr 1, 2022
cf6cebc
Translated caption labels
cj12312021 Apr 1, 2022
fb43459
Removed unused GetCaptionPath method
cj12312021 Apr 1, 2022
feeeb1c
Updated caption background to be semi transparent
cj12312021 Apr 1, 2022
9e3424f
Removed edge styling on caption text
cj12312021 Apr 1, 2022
2d8c5c5
convert srt files
cj12312021 Apr 3, 2022
6152119
Merge branch 'develop' into caption_support
cj12312021 Apr 3, 2022
861a1b7
import vtt-live-edit
cj12312021 Apr 4, 2022
09182b1
linter fix
cj12312021 Apr 4, 2022
81d031b
Merge branch 'develop' into caption_support
cj12312021 Apr 4, 2022
188e141
updated schema version after merge and applied bnkai's change
cj12312021 Apr 4, 2022
0c8f5dc
created our own subtitle offseting implementation
cj12312021 Apr 5, 2022
7ddf865
handle captions when transcoding
cj12312021 Apr 5, 2022
e503bbd
updated inner for loop var name. and other linter flags
cj12312021 Apr 5, 2022
41bf0b3
this might be the cause of the bug
cj12312021 Apr 5, 2022
657b2ae
format update
cj12312021 Apr 5, 2022
6074053
added ability to detect what subs were provided
cj12312021 Apr 5, 2022
b177119
linter update
cj12312021 Apr 5, 2022
a30ff42
generically load captions and show user lang by default
cj12312021 Apr 8, 2022
dfcbdee
updated css attribute order
cj12312021 Apr 8, 2022
4fc85e7
simpler caption settings text fix
cj12312021 Apr 8, 2022
2777509
generically detect caption files and includes some clean up
cj12312021 Apr 9, 2022
9298311
linter update
cj12312021 Apr 9, 2022
c3e9593
update to caption detect method
cj12312021 Apr 10, 2022
ffeb5f0
update to caption filter, and md file
cj12312021 Apr 10, 2022
322b3b8
Merge branch 'develop' into caption_support
cj12312021 Apr 11, 2022
482b967
moved change to v0150.md
cj12312021 Apr 11, 2022
fdaa1cf
added tests for caption work and updated md file
cj12312021 Apr 12, 2022
fe702bd
updated captions to string array
cj12312021 Apr 17, 2022
3afdd80
Merge branch 'develop' into caption_support
cj12312021 Apr 17, 2022
83ba144
merge update
cj12312021 Apr 17, 2022
85a982e
removed unused variable
cj12312021 Apr 17, 2022
08e733a
Updated CleanCaptions
cj12312021 Apr 17, 2022
af85da3
Update task_scan_scene.go
cj12312021 Apr 17, 2022
2fdcf9b
expanded caption table
cj12312021 Apr 18, 2022
917c4ce
prettier on ScenePlayer.tsx
cj12312021 Apr 18, 2022
422a214
merge
cj12312021 Apr 18, 2022
69075b3
fix merge issue
cj12312021 Apr 18, 2022
f7f0772
ensure one caption can be active
cj12312021 Apr 18, 2022
38dbce4
Update ScenePlayer.tsx
cj12312021 Apr 18, 2022
5b2f4d8
moved hasDefault declaration
cj12312021 Apr 18, 2022
0ec3e78
dumbed down caption filter
cj12312021 Apr 23, 2022
d1dedca
removed caption index
cj12312021 Apr 23, 2022
7be9076
ran prettier
cj12312021 Apr 23, 2022
75e8bfb
detect captions by default, updated filter, and database
cj12312021 May 4, 2022
10d29c6
Merge branch 'develop' into caption_support
cj12312021 May 4, 2022
7d0eb25
fixes conflicts
cj12312021 May 4, 2022
ea6d415
Merge remote-tracking branch 'upstream/develop' into prs/2462
WithoutPants May 5, 2022
8da00f2
Fix spelling error
WithoutPants May 5, 2022
852183f
Re-add filename to database
WithoutPants May 5, 2022
a79cf2d
Fix caption filtering
WithoutPants May 5, 2022
fdea166
Remove superfluous code
WithoutPants May 5, 2022
a3bce53
Adjust changelog entry
WithoutPants May 5, 2022
92dbf25
Ensure one caption per scene/language
WithoutPants May 5, 2022
013031b
Remove superfluous field
WithoutPants May 5, 2022
2a4f8e6
Fix primary key to support multiple caption types
WithoutPants May 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (

require (
github.com/apenwarr/fixconsole v0.0.0-20191012055117-5a9f6489cc29
github.com/asticode/go-astisub v0.20.0
github.com/go-chi/httplog v0.2.1
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4
github.com/hashicorp/golang-lru v0.5.4
Expand All @@ -61,6 +62,8 @@ require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab // indirect
github.com/asticode/go-astikit v0.20.0 // indirect
github.com/asticode/go-astits v1.8.0 // indirect
github.com/chromedp/sysutil v1.0.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=
github.com/asticode/go-astikit v0.20.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astisub v0.20.0 h1:mKuLwgGkQj35RRHFiTcq+2hgR7g1mHiYiIkr9UNTmXw=
github.com/asticode/go-astisub v0.20.0/go.mod h1:WTkuSzFB+Bp7wezuSf2Oxulj5A8zu2zLRVFf6bIFQK8=
github.com/asticode/go-astits v1.8.0 h1:rf6aiiGn/QhlFjNON1n5plqF3Fs025XLUwiQ0NB6oZg=
github.com/asticode/go-astits v1.8.0/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ=
github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go-v2 v1.3.2/go.mod h1:7OaACgj2SX3XGWnrIjGlJM22h6yD6MEWKvm7levnnM8=
github.com/aws/aws-sdk-go-v2 v1.6.0/go.mod h1:tI4KhsR5VkzlUa2DZAdwx7wCAYGwkZZ1H31PYrBFx1w=
Expand Down Expand Up @@ -629,6 +635,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
1 change: 1 addition & 0 deletions graphql/documents/data/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fragment ConfigDefaultSettingsData on ConfigDefaultSettingsResult {
scan {
useFileMetadata
stripFileExtension
scanDetectCaptions
scanGeneratePreviews
scanGenerateImagePreviews
scanGenerateSprites
Expand Down
6 changes: 6 additions & 0 deletions graphql/documents/data/scene-slim.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ fragment SlimSceneData on Scene {
phash
interactive
interactive_speed
captions {
language_code
path
caption_type
}

file {
size
Expand All @@ -35,6 +40,7 @@ fragment SlimSceneData on Scene {
sprite
funscript
interactive_heatmap
caption
}

scene_markers {
Expand Down
6 changes: 6 additions & 0 deletions graphql/documents/data/scene.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ fragment SceneData on Scene {
phash
interactive
interactive_speed
captions {
language_code
path
caption_type
}
created_at
updated_at

Expand All @@ -37,6 +42,7 @@ fragment SceneData on Scene {
sprite
funscript
interactive_heatmap
caption
}

scene_markers {
Expand Down
2 changes: 2 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ input SceneFilterType {
interactive: Boolean
"""Filter by InteractiveSpeed"""
interactive_speed: IntCriterionInput
"""Filter to only include scenes which have captions. `true` or `false`"""
captioned: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the values are only true or false, then it should be a boolean. I think however, that the filtering should probably be a StringCriterionInput or something so that one can filter on caption language etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a StringCriterionInput initially similar to the studio alias filter. However, we noticed that approach inherited some issues the studio alias filter has. The current implementation was copied from the has markers filter, which also uses strings to define a Boolean, but I can look into updating this to use a Boolean.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having had a quick look, I think the StringCriterionInput is probably better. I'd prefer to use that and fix the issues arising out of that than have to change the graphql schema later when we figure it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll revert the change to continue using the StringCriterionInput.

}

input MovieFilterType {
Expand Down
4 changes: 4 additions & 0 deletions graphql/schema/types/metadata.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ input ScanMetadataInput {
scanGeneratePhashes: Boolean
"""Generate image thumbnails during scan"""
scanGenerateThumbnails: Boolean
"""Detect scene captions"""
scanDetectCaptions: Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the benefit of making this optional?

Copy link
Collaborator Author

@cj12312021 cj12312021 May 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was this intentional. I can update it to be required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I mean is - is there any reason not to have the scan task always detect captions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detect captions toggle was introduced when the code was still looking for captions by trying various name combinations to see if we could get a match. That approach was expensive, which led to this toggle being added so users without captions wouldn't be impacted by that search when it didn't benefit them. The toggle could probably be removed now that the search code is more intelligent.


"Filter options for the scan"
filter: ScanMetaDataFilterInput
Expand All @@ -105,6 +107,8 @@ type ScanMetadataOptions {
scanGeneratePhashes: Boolean!
"""Generate image thumbnails during scan"""
scanGenerateThumbnails: Boolean!
"""Detect scene captions"""
scanDetectCaptions: Boolean!
}

input CleanMetadataInput {
Expand Down
8 changes: 8 additions & 0 deletions graphql/schema/types/scene.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ type ScenePathsType {
sprite: String # Resolver
funscript: String # Resolver
interactive_heatmap: String # Resolver
caption: String # Resolver
}

type SceneMovie {
movie: Movie!
scene_index: Int
}

type SceneCaption {
language_code: String!
path: String!
caption_type: String!
}

type Scene {
id: ID!
checksum: String
Expand All @@ -41,6 +48,7 @@ type Scene {
phash: String
interactive: Boolean!
interactive_speed: Int
captions: [SceneCaption!]
created_at: Time!
updated_at: Time!
file_mod_time: Time
Expand Down
13 changes: 13 additions & 0 deletions internal/api/resolver_model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.S
spritePath := builder.GetSpriteURL()
chaptersVttPath := builder.GetChaptersVTTURL()
funscriptPath := builder.GetFunscriptURL()
captionBasePath := builder.GetCaptionURL()
interactiveHeatmap := builder.GetInteractiveHeatmapURL()

return &models.ScenePathsType{
Expand All @@ -110,6 +111,7 @@ func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.S
Sprite: &spritePath,
Funscript: &funscriptPath,
InteractiveHeatmap: &interactiveHeatmap,
Caption: &captionBasePath,
}, nil
}

Expand All @@ -124,6 +126,17 @@ func (r *sceneResolver) SceneMarkers(ctx context.Context, obj *models.Scene) (re
return ret, nil
}

func (r *sceneResolver) Captions(ctx context.Context, obj *models.Scene) (ret []*models.SceneCaption, err error) {
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
ret, err = repo.Scene().GetCaptions(obj.ID)
return err
}); err != nil {
return nil, err
}

return ret, err
}

func (r *sceneResolver) Galleries(ctx context.Context, obj *models.Scene) (ret []*models.Gallery, err error) {
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
ret, err = repo.Gallery().FindBySceneID(obj.ID)
Expand Down
45 changes: 45 additions & 0 deletions internal/api/routes_scene.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"bytes"
"context"
"net/http"
"strconv"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (rs sceneRoutes) Routes() chi.Router {
r.Get("/vtt/chapter", rs.ChapterVtt)
r.Get("/funscript", rs.Funscript)
r.Get("/interactive_heatmap", rs.InteractiveHeatmap)
r.Get("/caption", rs.CaptionLang)

r.Get("/scene_marker/{sceneMarkerId}/stream", rs.SceneMarkerStream)
r.Get("/scene_marker/{sceneMarkerId}/preview", rs.SceneMarkerPreview)
Expand Down Expand Up @@ -283,6 +285,49 @@ func (rs sceneRoutes) InteractiveHeatmap(w http.ResponseWriter, r *http.Request)
http.ServeFile(w, r, filepath)
}

func (rs sceneRoutes) Caption(w http.ResponseWriter, r *http.Request, lang string, ext string) {
s := r.Context().Value(sceneKey).(*models.Scene)

path := ""
if err := rs.txnManager.WithReadTxn(r.Context(), func(repo models.ReaderRepository) error {
var err error
captions, err := repo.Scene().GetCaptions(s.ID)
for _, caption := range captions {
if lang == caption.LanguageCode && ext == caption.CaptionType {
path = caption.Path

sub, err := scene.ReadSubs(path)
if err == nil {
var b bytes.Buffer
err = sub.WriteToWebVTT(&b)
if err == nil {
w.Header().Set("Content-Type", "text/vtt")
w.Header().Add("Cache-Control", "no-cache")
_, _ = b.WriteTo(w)
}
return err
}
logger.Debugf("Error while reading subs: %v", err)
}
}
return err
}); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

func (rs sceneRoutes) CaptionLang(w http.ResponseWriter, r *http.Request) {
// serve caption based on lang query param, if provided
if err := r.ParseForm(); err != nil {
logger.Warnf("[caption] error parsing query form: %v", err)
}

l := r.Form.Get("lang")
ext := r.Form.Get("type")
rs.Caption(w, r, l, ext)
}

func (rs sceneRoutes) VttThumbs(w http.ResponseWriter, r *http.Request) {
scene := r.Context().Value(sceneKey).(*models.Scene)
w.Header().Set("Content-Type", "text/vtt")
Expand Down
4 changes: 4 additions & 0 deletions internal/api/urlbuilders/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (b SceneURLBuilder) GetFunscriptURL() string {
return b.BaseURL + "/scene/" + b.SceneID + "/funscript"
}

func (b SceneURLBuilder) GetCaptionURL() string {
return b.BaseURL + "/scene/" + b.SceneID + "/caption"
}

func (b SceneURLBuilder) GetInteractiveHeatmapURL() string {
return b.BaseURL + "/scene/" + b.SceneID + "/interactive_heatmap"
}
5 changes: 5 additions & 0 deletions internal/manager/manager_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import (
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
)

func isGallery(pathname string) bool {
gExt := config.GetInstance().GetGalleryExtensions()
return fsutil.MatchExtension(pathname, gExt)
}

func isCaptions(pathname string) bool {
return fsutil.MatchExtension(pathname, scene.CaptionExts)
}

func isVideo(pathname string) bool {
vidExt := config.GetInstance().GetVideoExtensions()
return fsutil.MatchExtension(pathname, vidExt)
Expand Down
10 changes: 10 additions & 0 deletions internal/manager/task_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/scene/generate"
"github.com/stashapp/stash/pkg/utils"
)
Expand Down Expand Up @@ -89,6 +90,7 @@ func (j *ScanJob) Execute(ctx context.Context, progress *job.Progress) {
file: file.FSFile(f.path, f.info),
UseFileMetadata: utils.IsTrue(input.UseFileMetadata),
StripFileExtension: utils.IsTrue(input.StripFileExtension),
DetectCaptions: utils.IsTrue(input.ScanDetectCaptions),
fileNamingAlgorithm: fileNamingAlgo,
calculateMD5: calculateMD5,
GeneratePreview: utils.IsTrue(input.ScanGeneratePreviews),
Expand Down Expand Up @@ -252,6 +254,7 @@ type ScanTask struct {
file file.SourceFile
UseFileMetadata bool
StripFileExtension bool
DetectCaptions bool
calculateMD5 bool
fileNamingAlgorithm models.HashAlgorithm
GenerateSprite bool
Expand All @@ -277,6 +280,8 @@ func (t *ScanTask) Start(ctx context.Context) {
s = t.scanScene(ctx)
case isImage(path):
t.scanImage(ctx)
case t.DetectCaptions && isCaptions(path):
t.associateCaptions(ctx)
}
})

Expand Down Expand Up @@ -351,6 +356,7 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
vidExt := config.GetVideoExtensions()
imgExt := config.GetImageExtensions()
gExt := config.GetGalleryExtensions()
capExt := scene.CaptionExts
excludeVidRegex := generateRegexps(config.GetExcludes())
excludeImgRegex := generateRegexps(config.GetImageExcludes())

Expand Down Expand Up @@ -394,6 +400,10 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
}
}

if fsutil.MatchExtension(path, capExt) {
return f(path, info, err)
}

return nil
})
}
48 changes: 48 additions & 0 deletions internal/manager/task_scan_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package manager

import (
"context"
"path/filepath"

"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/logger"
Expand Down Expand Up @@ -60,6 +62,7 @@ func (t *ScanTask) scanScene(ctx context.Context) *models.Scene {
PluginCache: instance.PluginCache,
MutexManager: t.mutexManager,
UseFileMetadata: t.UseFileMetadata,
DetectCaptions: t.DetectCaptions,
}

if s != nil {
Expand All @@ -78,3 +81,48 @@ func (t *ScanTask) scanScene(ctx context.Context) *models.Scene {

return retScene
}

// associates captions to scene/s with the same basename
func (t *ScanTask) associateCaptions(ctx context.Context) {
vExt := config.GetInstance().GetVideoExtensions()
captionPath := t.file.Path()
captionLang := scene.GetCaptionsLangFromPath(captionPath)

relatedFiles := scene.GenerateCaptionCandidates(captionPath, vExt)
if err := t.TxnManager.WithTxn(ctx, func(r models.Repository) error {
var err error
sqb := r.Scene()

for _, scenePath := range relatedFiles {
s, er := sqb.FindByPath(scenePath)

if er != nil {
logger.Errorf("Error searching for scene %s: %v", scenePath, er)
continue
}
if s != nil { // found related Scene
logger.Debugf("Matched captions to scene %s", s.Path)
captions, er := sqb.GetCaptions(s.ID)
if er == nil {
fileExt := filepath.Ext(captionPath)
ext := fileExt[1:]
if !scene.IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
newCaption := &models.SceneCaption{
LanguageCode: captionLang,
Path: captionPath,
CaptionType: ext,
}
captions = append(captions, newCaption)
er = sqb.UpdateCaptions(s.ID, captions)
if er == nil {
logger.Debugf("Updated captions for scene %s. Added %s", s.Path, captionLang)
}
}
}
}
}
return err
}); err != nil {
logger.Error(err.Error())
}
}
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
var DB *sqlx.DB
var WriteMu sync.Mutex
var dbPath string
var appSchemaVersion uint = 30
var appSchemaVersion uint = 31
var databaseSchemaVersion uint

//go:embed migrations/*.sql
Expand Down
Loading