Skip to content

Commit

Permalink
Scanner: Get + POST Chaptet thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthi-chaud committed Apr 6, 2024
1 parent 10114e3 commit 45987b0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 13 additions & 4 deletions scanner/pkg/actions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func RegisterFile(path string, c *config.Config) error {
glg.Failf(err.Error())
return err
}
go func() {
for i, chapterId := range res.ChaptersId {
thumbnailBytes, err := pkg.GetFrame(path, int64(dto.Chapters[i].StartTimestamp)+int64(dto.Chapters[i].EndTimestamp-dto.Chapters[i].StartTimestamp)/2)
api.SaveChapterThumbnail(chapterId, thumbnailBytes, *c)
if err != nil {
glg.Fail(err)
}
}
}()
} else if parsedPath.Extra != nil {
dto, err := buildExtraDto(path, parsedPath.Extra, mediainfo)

Expand All @@ -53,14 +62,14 @@ func RegisterFile(path string, c *config.Config) error {
return err
}
}
thumbnailBytes, err := pkg.GetFrame(path, int64(mediainfo.Duration) / 2)
if (err != nil) {
thumbnailBytes, err := pkg.GetFrame(path, int64(mediainfo.Duration)/2)
if err != nil {
glg.Failf(err.Error())
return err
}
if (parsedPath.Extra != nil) {
if parsedPath.Extra != nil {
err = api.SaveExtraThumbnail(resourceUuid, thumbnailBytes, *c)
} else if (parsedPath.Movie != nil) {
} else if parsedPath.Movie != nil {
err = api.SaveMovieThumbnail(resourceUuid, thumbnailBytes, *c)
}
return err
Expand Down
9 changes: 7 additions & 2 deletions scanner/pkg/api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type NewExtraResponse struct {
ExtraId string `validate:"required" json:"extra_id"`
}

type NewChapterResponse struct {
ExtraId string `validate:"required" json:"extra_id"`
}

type NewMovieResponse struct {
MovieId string `validate:"required" json:"movie_id"`
}
MovieId string `validate:"required" json:"movie_id"`
ChaptersId []string `validate:"required,dive,required" json:"chapters_id"`
}
1 change: 0 additions & 1 deletion scanner/pkg/thumbnail.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ func GetFrame(filepath string, timestamp int64) (io.Reader, error) {
WithOutput(buf, os.Stdout).Run()
return buf, err
}

0 comments on commit 45987b0

Please sign in to comment.