mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Movies Section (#338)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,8 @@ models:
|
||||
model: github.com/stashapp/stash/pkg/models.ScrapedItem
|
||||
Studio:
|
||||
model: github.com/stashapp/stash/pkg/models.Studio
|
||||
Movie:
|
||||
model: github.com/stashapp/stash/pkg/models.Movie
|
||||
Tag:
|
||||
model: github.com/stashapp/stash/pkg/models.Tag
|
||||
ScrapedPerformer:
|
||||
@@ -36,6 +38,8 @@ models:
|
||||
model: github.com/stashapp/stash/pkg/models.ScrapedScenePerformer
|
||||
ScrapedSceneStudio:
|
||||
model: github.com/stashapp/stash/pkg/models.ScrapedSceneStudio
|
||||
ScrapedSceneMovie:
|
||||
model: github.com/stashapp/stash/pkg/models.ScrapedSceneMovie
|
||||
ScrapedSceneTag:
|
||||
model: github.com/stashapp/stash/pkg/models.ScrapedSceneTag
|
||||
SceneFileType:
|
||||
|
||||
5
graphql/documents/data/movie-slim.graphql
Normal file
5
graphql/documents/data/movie-slim.graphql
Normal file
@@ -0,0 +1,5 @@
|
||||
fragment SlimMovieData on Movie {
|
||||
id
|
||||
name
|
||||
front_image_path
|
||||
}
|
||||
15
graphql/documents/data/movie.graphql
Normal file
15
graphql/documents/data/movie.graphql
Normal file
@@ -0,0 +1,15 @@
|
||||
fragment MovieData on Movie {
|
||||
id
|
||||
checksum
|
||||
name
|
||||
aliases
|
||||
duration
|
||||
date
|
||||
rating
|
||||
director
|
||||
synopsis
|
||||
url
|
||||
front_image_path
|
||||
back_image_path
|
||||
scene_count
|
||||
}
|
||||
@@ -47,6 +47,15 @@ fragment SlimSceneData on Scene {
|
||||
image_path
|
||||
}
|
||||
|
||||
movies {
|
||||
movie {
|
||||
id
|
||||
name
|
||||
front_image_path
|
||||
}
|
||||
scene_index
|
||||
}
|
||||
|
||||
tags {
|
||||
id
|
||||
name
|
||||
|
||||
@@ -43,6 +43,13 @@ fragment SceneData on Scene {
|
||||
...StudioData
|
||||
}
|
||||
|
||||
movies {
|
||||
movie {
|
||||
...MovieData
|
||||
}
|
||||
scene_index
|
||||
}
|
||||
|
||||
tags {
|
||||
...TagData
|
||||
}
|
||||
|
||||
@@ -35,6 +35,30 @@ fragment ScrapedScenePerformerData on ScrapedScenePerformer {
|
||||
aliases
|
||||
}
|
||||
|
||||
fragment ScrapedMovieData on ScrapedMovie {
|
||||
name
|
||||
aliases
|
||||
duration
|
||||
date
|
||||
rating
|
||||
director
|
||||
url
|
||||
synopsis
|
||||
|
||||
}
|
||||
|
||||
fragment ScrapedSceneMovieData on ScrapedSceneMovie {
|
||||
id
|
||||
name
|
||||
aliases
|
||||
duration
|
||||
date
|
||||
rating
|
||||
director
|
||||
url
|
||||
synopsis
|
||||
}
|
||||
|
||||
fragment ScrapedSceneStudioData on ScrapedSceneStudio {
|
||||
id
|
||||
name
|
||||
@@ -74,4 +98,8 @@ fragment ScrapedSceneData on ScrapedScene {
|
||||
performers {
|
||||
...ScrapedScenePerformerData
|
||||
}
|
||||
|
||||
movies {
|
||||
...ScrapedSceneMovieData
|
||||
}
|
||||
}
|
||||
38
graphql/documents/mutations/movie.graphql
Normal file
38
graphql/documents/mutations/movie.graphql
Normal file
@@ -0,0 +1,38 @@
|
||||
mutation MovieCreate(
|
||||
$name: String!,
|
||||
$aliases: String,
|
||||
$duration: String,
|
||||
$date: String,
|
||||
$rating: String,
|
||||
$director: String,
|
||||
$synopsis: String,
|
||||
$url: String,
|
||||
$front_image: String,
|
||||
$back_image: String) {
|
||||
|
||||
movieCreate(input: { name: $name, aliases: $aliases, duration: $duration, date: $date, rating: $rating, director: $director, synopsis: $synopsis, url: $url, front_image: $front_image, back_image: $back_image }) {
|
||||
...MovieData
|
||||
}
|
||||
}
|
||||
|
||||
mutation MovieUpdate(
|
||||
$id: ID!
|
||||
$name: String,
|
||||
$aliases: String,
|
||||
$duration: String,
|
||||
$date: String,
|
||||
$rating: String,
|
||||
$director: String,
|
||||
$synopsis: String,
|
||||
$url: String,
|
||||
$front_image: String,
|
||||
$back_image: String) {
|
||||
|
||||
movieUpdate(input: { id: $id, name: $name, aliases: $aliases, duration: $duration, date: $date, rating: $rating, director: $director, synopsis: $synopsis, url: $url, front_image: $front_image, back_image: $back_image }) {
|
||||
...MovieData
|
||||
}
|
||||
}
|
||||
|
||||
mutation MovieDestroy($id: ID!) {
|
||||
movieDestroy(input: { id: $id })
|
||||
}
|
||||
@@ -8,6 +8,7 @@ mutation SceneUpdate(
|
||||
$studio_id: ID,
|
||||
$gallery_id: ID,
|
||||
$performer_ids: [ID!] = [],
|
||||
$movies: [SceneMovieInput!] = [],
|
||||
$tag_ids: [ID!] = [],
|
||||
$cover_image: String) {
|
||||
|
||||
@@ -21,6 +22,7 @@ mutation SceneUpdate(
|
||||
studio_id: $studio_id,
|
||||
gallery_id: $gallery_id,
|
||||
performer_ids: $performer_ids,
|
||||
movies: $movies,
|
||||
tag_ids: $tag_ids,
|
||||
cover_image: $cover_image
|
||||
}) {
|
||||
|
||||
@@ -29,6 +29,11 @@ query AllStudiosForFilter {
|
||||
...SlimStudioData
|
||||
}
|
||||
}
|
||||
query AllMoviesForFilter {
|
||||
allMovies {
|
||||
...SlimMovieData
|
||||
}
|
||||
}
|
||||
|
||||
query AllTagsForFilter {
|
||||
allTags {
|
||||
@@ -50,6 +55,7 @@ query Stats {
|
||||
gallery_count,
|
||||
performer_count,
|
||||
studio_count,
|
||||
movie_count,
|
||||
tag_count
|
||||
}
|
||||
}
|
||||
|
||||
14
graphql/documents/queries/movie.graphql
Normal file
14
graphql/documents/queries/movie.graphql
Normal file
@@ -0,0 +1,14 @@
|
||||
query FindMovies($filter: FindFilterType) {
|
||||
findMovies(filter: $filter) {
|
||||
count
|
||||
movies {
|
||||
...MovieData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query FindMovie($id: ID!) {
|
||||
findMovie(id: $id) {
|
||||
...MovieData
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,9 @@ query ParseSceneFilenames($filter: FindFilterType!, $config: SceneParserInput!)
|
||||
rating
|
||||
studio_id
|
||||
gallery_id
|
||||
movies {
|
||||
movie_id
|
||||
}
|
||||
performer_ids
|
||||
tag_ids
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@ type Query {
|
||||
"""A function which queries Studio objects"""
|
||||
findStudios(filter: FindFilterType): FindStudiosResultType!
|
||||
|
||||
"""Find a movie by ID"""
|
||||
findMovie(id: ID!): Movie
|
||||
"""A function which queries Movie objects"""
|
||||
findMovies(filter: FindFilterType): FindMoviesResultType!
|
||||
|
||||
findGallery(id: ID!): Gallery
|
||||
findGalleries(filter: FindFilterType): FindGalleriesResultType!
|
||||
|
||||
@@ -92,6 +97,7 @@ type Query {
|
||||
|
||||
allPerformers: [Performer!]!
|
||||
allStudios: [Studio!]!
|
||||
allMovies: [Movie!]!
|
||||
allTags: [Tag!]!
|
||||
|
||||
# Version
|
||||
@@ -126,6 +132,10 @@ type Mutation {
|
||||
studioUpdate(input: StudioUpdateInput!): Studio
|
||||
studioDestroy(input: StudioDestroyInput!): Boolean!
|
||||
|
||||
movieCreate(input: MovieCreateInput!): Movie
|
||||
movieUpdate(input: MovieUpdateInput!): Movie
|
||||
movieDestroy(input: MovieDestroyInput!): Boolean!
|
||||
|
||||
tagCreate(input: TagCreateInput!): Tag
|
||||
tagUpdate(input: TagUpdateInput!): Tag
|
||||
tagDestroy(input: TagDestroyInput!): Boolean!
|
||||
|
||||
@@ -74,6 +74,8 @@ input SceneFilterType {
|
||||
is_missing: String
|
||||
"""Filter to only include scenes with this studio"""
|
||||
studios: MultiCriterionInput
|
||||
"""Filter to only include scenes with this movie"""
|
||||
movies: MultiCriterionInput
|
||||
"""Filter to only include scenes with these tags"""
|
||||
tags: MultiCriterionInput
|
||||
"""Filter to only include scenes with these performers"""
|
||||
|
||||
54
graphql/schema/types/movie.graphql
Normal file
54
graphql/schema/types/movie.graphql
Normal file
@@ -0,0 +1,54 @@
|
||||
type Movie {
|
||||
id: ID!
|
||||
checksum: String!
|
||||
name: String
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
synopsis: String
|
||||
url: String
|
||||
|
||||
front_image_path: String # Resolver
|
||||
back_image_path: String # Resolver
|
||||
scene_count: Int # Resolver
|
||||
}
|
||||
|
||||
input MovieCreateInput {
|
||||
name: String!
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
synopsis: String
|
||||
url: String
|
||||
"""This should be base64 encoded"""
|
||||
front_image: String
|
||||
back_image: String
|
||||
}
|
||||
|
||||
input MovieUpdateInput {
|
||||
id: ID!
|
||||
name: String
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
synopsis: String
|
||||
url: String
|
||||
"""This should be base64 encoded"""
|
||||
front_image: String
|
||||
back_image: String
|
||||
}
|
||||
|
||||
input MovieDestroyInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
type FindMoviesResultType {
|
||||
count: Int!
|
||||
movies: [Movie!]!
|
||||
}
|
||||
@@ -18,6 +18,11 @@ type ScenePathsType {
|
||||
chapters_vtt: String # Resolver
|
||||
}
|
||||
|
||||
type SceneMovie {
|
||||
movie: Movie!
|
||||
scene_index: String
|
||||
}
|
||||
|
||||
type Scene {
|
||||
id: ID!
|
||||
checksum: String!
|
||||
@@ -36,10 +41,16 @@ type Scene {
|
||||
scene_markers: [SceneMarker!]!
|
||||
gallery: Gallery
|
||||
studio: Studio
|
||||
movies: [SceneMovie!]!
|
||||
tags: [Tag!]!
|
||||
performers: [Performer!]!
|
||||
}
|
||||
|
||||
input SceneMovieInput {
|
||||
movie_id: ID!
|
||||
scene_index: String
|
||||
}
|
||||
|
||||
input SceneUpdateInput {
|
||||
clientMutationId: String
|
||||
id: ID!
|
||||
@@ -51,6 +62,7 @@ input SceneUpdateInput {
|
||||
studio_id: ID
|
||||
gallery_id: ID
|
||||
performer_ids: [ID!]
|
||||
movies: [SceneMovieInput!]
|
||||
tag_ids: [ID!]
|
||||
"""This should be base64 encoded"""
|
||||
cover_image: String
|
||||
@@ -87,6 +99,11 @@ input SceneParserInput {
|
||||
capitalizeTitle: Boolean
|
||||
}
|
||||
|
||||
type SceneMovieID {
|
||||
movie_id: ID!
|
||||
scene_index: String
|
||||
}
|
||||
|
||||
type SceneParserResult {
|
||||
scene: Scene!
|
||||
title: String
|
||||
@@ -97,6 +114,7 @@ type SceneParserResult {
|
||||
studio_id: ID
|
||||
gallery_id: ID
|
||||
performer_ids: [ID!]
|
||||
movies: [SceneMovieID!]
|
||||
tag_ids: [ID!]
|
||||
}
|
||||
|
||||
|
||||
22
graphql/schema/types/scraped-movie.graphql
Normal file
22
graphql/schema/types/scraped-movie.graphql
Normal file
@@ -0,0 +1,22 @@
|
||||
"""A movie from a scraping operation..."""
|
||||
type ScrapedMovie {
|
||||
name: String
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
url: String
|
||||
synopsis: String
|
||||
}
|
||||
|
||||
input ScrapedMovieInput {
|
||||
name: String
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
url: String
|
||||
synopsis: String
|
||||
}
|
||||
@@ -43,6 +43,20 @@ type ScrapedScenePerformer {
|
||||
aliases: String
|
||||
}
|
||||
|
||||
type ScrapedSceneMovie {
|
||||
"""Set if movie matched"""
|
||||
id: ID
|
||||
name: String!
|
||||
aliases: String
|
||||
duration: String
|
||||
date: String
|
||||
rating: String
|
||||
director: String
|
||||
synopsis: String
|
||||
url: String
|
||||
|
||||
}
|
||||
|
||||
type ScrapedSceneStudio {
|
||||
"""Set if studio matched"""
|
||||
id: ID
|
||||
@@ -67,4 +81,5 @@ type ScrapedScene {
|
||||
studio: ScrapedSceneStudio
|
||||
tags: [ScrapedSceneTag!]
|
||||
performers: [ScrapedScenePerformer!]
|
||||
movies: [ScrapedSceneMovie!]
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ type StatsResultType {
|
||||
gallery_count: Int!
|
||||
performer_count: Int!
|
||||
studio_count: Int!
|
||||
movie_count: Int!
|
||||
tag_count: Int!
|
||||
}
|
||||
@@ -9,4 +9,5 @@ const (
|
||||
performerKey key = 1
|
||||
sceneKey key = 2
|
||||
studioKey key = 3
|
||||
movieKey key = 4
|
||||
)
|
||||
|
||||
@@ -33,6 +33,9 @@ func (r *Resolver) SceneMarker() models.SceneMarkerResolver {
|
||||
func (r *Resolver) Studio() models.StudioResolver {
|
||||
return &studioResolver{r}
|
||||
}
|
||||
func (r *Resolver) Movie() models.MovieResolver {
|
||||
return &movieResolver{r}
|
||||
}
|
||||
func (r *Resolver) Subscription() models.SubscriptionResolver {
|
||||
return &subscriptionResolver{r}
|
||||
}
|
||||
@@ -49,6 +52,7 @@ type performerResolver struct{ *Resolver }
|
||||
type sceneResolver struct{ *Resolver }
|
||||
type sceneMarkerResolver struct{ *Resolver }
|
||||
type studioResolver struct{ *Resolver }
|
||||
type movieResolver struct{ *Resolver }
|
||||
type tagResolver struct{ *Resolver }
|
||||
|
||||
func (r *queryResolver) MarkerWall(ctx context.Context, q *string) ([]*models.SceneMarker, error) {
|
||||
@@ -95,6 +99,8 @@ func (r *queryResolver) Stats(ctx context.Context) (*models.StatsResultType, err
|
||||
performersCount, _ := performersQB.Count()
|
||||
studiosQB := models.NewStudioQueryBuilder()
|
||||
studiosCount, _ := studiosQB.Count()
|
||||
moviesQB := models.NewMovieQueryBuilder()
|
||||
moviesCount, _ := moviesQB.Count()
|
||||
tagsQB := models.NewTagQueryBuilder()
|
||||
tagsCount, _ := tagsQB.Count()
|
||||
return &models.StatsResultType{
|
||||
@@ -102,6 +108,7 @@ func (r *queryResolver) Stats(ctx context.Context) (*models.StatsResultType, err
|
||||
GalleryCount: galleryCount,
|
||||
PerformerCount: performersCount,
|
||||
StudioCount: studiosCount,
|
||||
MovieCount: moviesCount,
|
||||
TagCount: tagsCount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
84
pkg/api/resolver_model_movie.go
Normal file
84
pkg/api/resolver_model_movie.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
func (r *movieResolver) Name(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Name.Valid {
|
||||
return &obj.Name.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) URL(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.URL.Valid {
|
||||
return &obj.URL.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Aliases(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Aliases.Valid {
|
||||
return &obj.Aliases.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Duration(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Duration.Valid {
|
||||
return &obj.Duration.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Date(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Date.Valid {
|
||||
result := utils.GetYMDFromDatabaseDate(obj.Date.String)
|
||||
return &result, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Rating(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Rating.Valid {
|
||||
return &obj.Rating.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Director(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Director.Valid {
|
||||
return &obj.Director.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) Synopsis(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
if obj.Synopsis.Valid {
|
||||
return &obj.Synopsis.String, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) FrontImagePath(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||
frontimagePath := urlbuilders.NewMovieURLBuilder(baseURL, obj.ID).GetMovieFrontImageURL()
|
||||
return &frontimagePath, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) BackImagePath(ctx context.Context, obj *models.Movie) (*string, error) {
|
||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||
backimagePath := urlbuilders.NewMovieURLBuilder(baseURL, obj.ID).GetMovieBackImageURL()
|
||||
return &backimagePath, nil
|
||||
}
|
||||
|
||||
func (r *movieResolver) SceneCount(ctx context.Context, obj *models.Movie) (*int, error) {
|
||||
qb := models.NewSceneQueryBuilder()
|
||||
res, err := qb.CountByMovieID(obj.ID)
|
||||
return &res, err
|
||||
}
|
||||
@@ -100,6 +100,31 @@ func (r *sceneResolver) Studio(ctx context.Context, obj *models.Scene) (*models.
|
||||
return qb.FindBySceneID(obj.ID)
|
||||
}
|
||||
|
||||
func (r *sceneResolver) Movies(ctx context.Context, obj *models.Scene) ([]*models.SceneMovie, error) {
|
||||
joinQB := models.NewJoinsQueryBuilder()
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
|
||||
sceneMovies, err := joinQB.GetSceneMovies(obj.ID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var ret []*models.SceneMovie
|
||||
for _, sm := range sceneMovies {
|
||||
movie, err := qb.Find(sm.MovieID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sceneIdx := sm.SceneIndex
|
||||
ret = append(ret, &models.SceneMovie{
|
||||
Movie: movie,
|
||||
SceneIndex: &sceneIdx,
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *sceneResolver) Tags(ctx context.Context, obj *models.Scene) ([]*models.Tag, error) {
|
||||
qb := models.NewTagQueryBuilder()
|
||||
return qb.FindBySceneID(obj.ID, nil)
|
||||
|
||||
178
pkg/api/resolver_mutation_movie.go
Normal file
178
pkg/api/resolver_mutation_movie.go
Normal file
@@ -0,0 +1,178 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) MovieCreate(ctx context.Context, input models.MovieCreateInput) (*models.Movie, error) {
|
||||
// generate checksum from movie name rather than image
|
||||
checksum := utils.MD5FromString(input.Name)
|
||||
|
||||
var frontimageData []byte
|
||||
var backimageData []byte
|
||||
var err error
|
||||
|
||||
if input.FrontImage == nil {
|
||||
input.FrontImage = &models.DefaultMovieImage
|
||||
}
|
||||
if input.BackImage == nil {
|
||||
input.BackImage = &models.DefaultMovieImage
|
||||
}
|
||||
// Process the base 64 encoded image string
|
||||
_, frontimageData, err = utils.ProcessBase64Image(*input.FrontImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Process the base 64 encoded image string
|
||||
_, backimageData, err = utils.ProcessBase64Image(*input.BackImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Populate a new movie from the input
|
||||
currentTime := time.Now()
|
||||
newMovie := models.Movie{
|
||||
BackImage: backimageData,
|
||||
FrontImage: frontimageData,
|
||||
Checksum: checksum,
|
||||
Name: sql.NullString{String: input.Name, Valid: true},
|
||||
CreatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: currentTime},
|
||||
}
|
||||
|
||||
if input.Aliases != nil {
|
||||
newMovie.Aliases = sql.NullString{String: *input.Aliases, Valid: true}
|
||||
}
|
||||
if input.Duration != nil {
|
||||
newMovie.Duration = sql.NullString{String: *input.Duration, Valid: true}
|
||||
}
|
||||
|
||||
if input.Date != nil {
|
||||
newMovie.Date = models.SQLiteDate{String: *input.Date, Valid: true}
|
||||
}
|
||||
|
||||
if input.Rating != nil {
|
||||
newMovie.Rating = sql.NullString{String: *input.Rating, Valid: true}
|
||||
}
|
||||
|
||||
if input.Director != nil {
|
||||
newMovie.Director = sql.NullString{String: *input.Director, Valid: true}
|
||||
}
|
||||
|
||||
if input.Synopsis != nil {
|
||||
newMovie.Synopsis = sql.NullString{String: *input.Synopsis, Valid: true}
|
||||
}
|
||||
|
||||
if input.URL != nil {
|
||||
newMovie.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||
}
|
||||
|
||||
// Start the transaction and save the movie
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
movie, err := qb.Create(newMovie, tx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Commit
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return movie, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) MovieUpdate(ctx context.Context, input models.MovieUpdateInput) (*models.Movie, error) {
|
||||
// Populate movie from the input
|
||||
movieID, _ := strconv.Atoi(input.ID)
|
||||
updatedMovie := models.Movie{
|
||||
ID: movieID,
|
||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: time.Now()},
|
||||
}
|
||||
if input.FrontImage != nil {
|
||||
_, frontimageData, err := utils.ProcessBase64Image(*input.FrontImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedMovie.FrontImage = frontimageData
|
||||
}
|
||||
if input.BackImage != nil {
|
||||
_, backimageData, err := utils.ProcessBase64Image(*input.BackImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedMovie.BackImage = backimageData
|
||||
}
|
||||
|
||||
if input.Name != nil {
|
||||
// generate checksum from movie name rather than image
|
||||
checksum := utils.MD5FromString(*input.Name)
|
||||
updatedMovie.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||
updatedMovie.Checksum = checksum
|
||||
}
|
||||
|
||||
if input.Aliases != nil {
|
||||
updatedMovie.Aliases = sql.NullString{String: *input.Aliases, Valid: true}
|
||||
}
|
||||
if input.Duration != nil {
|
||||
updatedMovie.Duration = sql.NullString{String: *input.Duration, Valid: true}
|
||||
}
|
||||
|
||||
if input.Date != nil {
|
||||
updatedMovie.Date = models.SQLiteDate{String: *input.Date, Valid: true}
|
||||
}
|
||||
|
||||
if input.Rating != nil {
|
||||
updatedMovie.Rating = sql.NullString{String: *input.Rating, Valid: true}
|
||||
}
|
||||
|
||||
if input.Director != nil {
|
||||
updatedMovie.Director = sql.NullString{String: *input.Director, Valid: true}
|
||||
}
|
||||
|
||||
if input.Synopsis != nil {
|
||||
updatedMovie.Synopsis = sql.NullString{String: *input.Synopsis, Valid: true}
|
||||
}
|
||||
|
||||
if input.URL != nil {
|
||||
updatedMovie.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||
}
|
||||
|
||||
// Start the transaction and save the movie
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
movie, err := qb.Update(updatedMovie, tx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Commit
|
||||
if err := tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return movie, nil
|
||||
}
|
||||
|
||||
func (r *mutationResolver) MovieDestroy(ctx context.Context, input models.MovieDestroyInput) (bool, error) {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
if err := qb.Destroy(input.ID, tx); err != nil {
|
||||
_ = tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
@@ -147,6 +147,28 @@ func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.T
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Save the movies
|
||||
var movieJoins []models.MoviesScenes
|
||||
|
||||
for _, movie := range input.Movies {
|
||||
|
||||
movieID, _ := strconv.Atoi(movie.MovieID)
|
||||
sceneIdx := ""
|
||||
if movie.SceneIndex != nil {
|
||||
sceneIdx = *movie.SceneIndex
|
||||
}
|
||||
|
||||
movieJoin := models.MoviesScenes{
|
||||
MovieID: movieID,
|
||||
SceneID: sceneID,
|
||||
SceneIndex: sceneIdx,
|
||||
}
|
||||
movieJoins = append(movieJoins, movieJoin)
|
||||
}
|
||||
if err := jqb.UpdateMoviesScenes(sceneID, movieJoins, tx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Save the tags
|
||||
var tagJoins []models.ScenesTags
|
||||
for _, tid := range input.TagIds {
|
||||
|
||||
28
pkg/api/resolver_query_find_movie.go
Normal file
28
pkg/api/resolver_query_find_movie.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
func (r *queryResolver) FindMovie(ctx context.Context, id string) (*models.Movie, error) {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
idInt, _ := strconv.Atoi(id)
|
||||
return qb.Find(idInt, nil)
|
||||
}
|
||||
|
||||
func (r *queryResolver) FindMovies(ctx context.Context, filter *models.FindFilterType) (*models.FindMoviesResultType, error) {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
movies, total := qb.Query(filter)
|
||||
return &models.FindMoviesResultType{
|
||||
Count: total,
|
||||
Movies: movies,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) AllMovies(ctx context.Context) ([]*models.Movie, error) {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
return qb.All()
|
||||
}
|
||||
54
pkg/api/routes_movie.go
Normal file
54
pkg/api/routes_movie.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type movieRoutes struct{}
|
||||
|
||||
func (rs movieRoutes) Routes() chi.Router {
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Route("/{movieId}", func(r chi.Router) {
|
||||
r.Use(MovieCtx)
|
||||
r.Get("/frontimage", rs.FrontImage)
|
||||
r.Get("/backimage", rs.BackImage)
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (rs movieRoutes) FrontImage(w http.ResponseWriter, r *http.Request) {
|
||||
movie := r.Context().Value(movieKey).(*models.Movie)
|
||||
_, _ = w.Write(movie.FrontImage)
|
||||
}
|
||||
|
||||
func (rs movieRoutes) BackImage(w http.ResponseWriter, r *http.Request) {
|
||||
movie := r.Context().Value(movieKey).(*models.Movie)
|
||||
_, _ = w.Write(movie.BackImage)
|
||||
}
|
||||
|
||||
func MovieCtx(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
movieID, err := strconv.Atoi(chi.URLParam(r, "movieId"))
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(404), 404)
|
||||
return
|
||||
}
|
||||
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
movie, err := qb.Find(movieID, nil)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(404), 404)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), movieKey, movie)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
@@ -109,6 +109,7 @@ func Start() {
|
||||
r.Mount("/performer", performerRoutes{}.Routes())
|
||||
r.Mount("/scene", sceneRoutes{}.Routes())
|
||||
r.Mount("/studio", studioRoutes{}.Routes())
|
||||
r.Mount("/movie", movieRoutes{}.Routes())
|
||||
|
||||
r.HandleFunc("/css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
|
||||
24
pkg/api/urlbuilders/movie.go
Normal file
24
pkg/api/urlbuilders/movie.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package urlbuilders
|
||||
|
||||
import "strconv"
|
||||
|
||||
type MovieURLBuilder struct {
|
||||
BaseURL string
|
||||
MovieID string
|
||||
}
|
||||
|
||||
func NewMovieURLBuilder(baseURL string, movieID int) MovieURLBuilder {
|
||||
return MovieURLBuilder{
|
||||
BaseURL: baseURL,
|
||||
MovieID: strconv.Itoa(movieID),
|
||||
}
|
||||
}
|
||||
|
||||
func (b MovieURLBuilder) GetMovieFrontImageURL() string {
|
||||
return b.BaseURL + "/movie/" + b.MovieID + "/frontimage"
|
||||
}
|
||||
|
||||
func (b MovieURLBuilder) GetMovieBackImageURL() string {
|
||||
return b.BaseURL + "/movie/" + b.MovieID + "/backimage"
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
var DB *sqlx.DB
|
||||
var appSchemaVersion uint = 3
|
||||
var appSchemaVersion uint = 4
|
||||
|
||||
const sqlite3Driver = "sqlite3_regexp"
|
||||
|
||||
|
||||
32
pkg/database/migrations/4_movie.up.sql
Normal file
32
pkg/database/migrations/4_movie.up.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
CREATE TABLE `movies` (
|
||||
`id` integer not null primary key autoincrement,
|
||||
`name` varchar(255),
|
||||
`aliases` varchar(255),
|
||||
`duration` varchar(6),
|
||||
`date` date,
|
||||
`rating` varchar(1),
|
||||
`director` varchar(255),
|
||||
`synopsis` text,
|
||||
`front_image` blob not null,
|
||||
`back_image` blob,
|
||||
`checksum` varchar(255) not null,
|
||||
`url` varchar(255),
|
||||
`created_at` datetime not null,
|
||||
`updated_at` datetime not null
|
||||
);
|
||||
CREATE TABLE `movies_scenes` (
|
||||
`movie_id` integer,
|
||||
`scene_id` integer,
|
||||
`scene_index` varchar(2),
|
||||
foreign key(`movie_id`) references `movies`(`id`),
|
||||
foreign key(`scene_id`) references `scenes`(`id`)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE `scraped_items` ADD COLUMN `movie_id` integer;
|
||||
CREATE UNIQUE INDEX `movies_checksum_unique` on `movies` (`checksum`);
|
||||
CREATE UNIQUE INDEX `index_movie_id_scene_index_unique` ON `movies_scenes` ( `movie_id`, `scene_index` );
|
||||
CREATE INDEX `index_movies_scenes_on_movie_id` on `movies_scenes` (`movie_id`);
|
||||
CREATE INDEX `index_movies_scenes_on_scene_id` on `movies_scenes` (`scene_id`);
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ func initParserFields() {
|
||||
ret["d"] = newParserField("d", `(?:\.|-|_)`, false)
|
||||
ret["performer"] = newParserField("performer", ".*", true)
|
||||
ret["studio"] = newParserField("studio", ".*", true)
|
||||
ret["movie"] = newParserField("movie", ".*", true)
|
||||
ret["tag"] = newParserField("tag", ".*", true)
|
||||
|
||||
// date fields
|
||||
@@ -204,6 +205,7 @@ type sceneHolder struct {
|
||||
mm string
|
||||
dd string
|
||||
performers []string
|
||||
movies []string
|
||||
studio string
|
||||
tags []string
|
||||
}
|
||||
@@ -307,6 +309,8 @@ func (h *sceneHolder) setField(field parserField, value interface{}) {
|
||||
h.performers = append(h.performers, value.(string))
|
||||
case "studio":
|
||||
h.studio = value.(string)
|
||||
case "movie":
|
||||
h.movies = append(h.movies, value.(string))
|
||||
case "tag":
|
||||
h.tags = append(h.tags, value.(string))
|
||||
case "yyyy":
|
||||
@@ -389,6 +393,10 @@ type studioQueryer interface {
|
||||
FindByName(name string, tx *sqlx.Tx) (*models.Studio, error)
|
||||
}
|
||||
|
||||
type movieQueryer interface {
|
||||
FindByName(name string, tx *sqlx.Tx) (*models.Movie, error)
|
||||
}
|
||||
|
||||
type SceneFilenameParser struct {
|
||||
Pattern string
|
||||
ParserInput models.SceneParserInput
|
||||
@@ -396,12 +404,14 @@ type SceneFilenameParser struct {
|
||||
whitespaceRE *regexp.Regexp
|
||||
performerCache map[string]*models.Performer
|
||||
studioCache map[string]*models.Studio
|
||||
movieCache map[string]*models.Movie
|
||||
tagCache map[string]*models.Tag
|
||||
|
||||
performerQuery performerQueryer
|
||||
sceneQuery sceneQueryer
|
||||
tagQuery tagQueryer
|
||||
studioQuery studioQueryer
|
||||
movieQuery movieQueryer
|
||||
}
|
||||
|
||||
func NewSceneFilenameParser(filter *models.FindFilterType, config models.SceneParserInput) *SceneFilenameParser {
|
||||
@@ -413,6 +423,7 @@ func NewSceneFilenameParser(filter *models.FindFilterType, config models.ScenePa
|
||||
|
||||
p.performerCache = make(map[string]*models.Performer)
|
||||
p.studioCache = make(map[string]*models.Studio)
|
||||
p.movieCache = make(map[string]*models.Movie)
|
||||
p.tagCache = make(map[string]*models.Tag)
|
||||
|
||||
p.initWhiteSpaceRegex()
|
||||
@@ -429,6 +440,9 @@ func NewSceneFilenameParser(filter *models.FindFilterType, config models.ScenePa
|
||||
studioQuery := models.NewStudioQueryBuilder()
|
||||
p.studioQuery = &studioQuery
|
||||
|
||||
movieQuery := models.NewMovieQueryBuilder()
|
||||
p.movieQuery = &movieQuery
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -535,6 +549,23 @@ func (p *SceneFilenameParser) queryStudio(studioName string) *models.Studio {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *SceneFilenameParser) queryMovie(movieName string) *models.Movie {
|
||||
// massage the movie name
|
||||
movieName = delimiterRE.ReplaceAllString(movieName, " ")
|
||||
|
||||
// check cache first
|
||||
if ret, found := p.movieCache[movieName]; found {
|
||||
return ret
|
||||
}
|
||||
|
||||
ret, _ := p.movieQuery.FindByName(movieName, nil)
|
||||
|
||||
// add result to cache
|
||||
p.movieCache[movieName] = ret
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *SceneFilenameParser) queryTag(tagName string) *models.Tag {
|
||||
// massage the performer name
|
||||
tagName = delimiterRE.ReplaceAllString(tagName, " ")
|
||||
@@ -596,6 +627,24 @@ func (p *SceneFilenameParser) setStudio(h sceneHolder, result *models.SceneParse
|
||||
}
|
||||
}
|
||||
|
||||
func (p *SceneFilenameParser) setMovies(h sceneHolder, result *models.SceneParserResult) {
|
||||
// query for each movie
|
||||
moviesSet := make(map[int]bool)
|
||||
for _, movieName := range h.movies {
|
||||
if movieName != "" {
|
||||
movie := p.queryMovie(movieName)
|
||||
if movie != nil {
|
||||
if _, found := moviesSet[movie.ID]; !found {
|
||||
result.Movies = append(result.Movies, &models.SceneMovieID{
|
||||
MovieID: strconv.Itoa(movie.ID),
|
||||
})
|
||||
moviesSet[movie.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *SceneFilenameParser) setParserResult(h sceneHolder, result *models.SceneParserResult) {
|
||||
if h.result.Title.Valid {
|
||||
title := h.result.Title.String
|
||||
@@ -619,4 +668,9 @@ func (p *SceneFilenameParser) setParserResult(h sceneHolder, result *models.Scen
|
||||
p.setTags(h, result)
|
||||
}
|
||||
p.setStudio(h, result)
|
||||
|
||||
if len(h.movies) > 0 {
|
||||
p.setMovies(h, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,14 @@ func (jp *jsonUtils) saveStudio(checksum string, studio *jsonschema.Studio) erro
|
||||
return jsonschema.SaveStudioFile(instance.Paths.JSON.StudioJSONPath(checksum), studio)
|
||||
}
|
||||
|
||||
func (jp *jsonUtils) getMovie(checksum string) (*jsonschema.Movie, error) {
|
||||
return jsonschema.LoadMovieFile(instance.Paths.JSON.MovieJSONPath(checksum))
|
||||
}
|
||||
|
||||
func (jp *jsonUtils) saveMovie(checksum string, movie *jsonschema.Movie) error {
|
||||
return jsonschema.SaveMovieFile(instance.Paths.JSON.MovieJSONPath(checksum), movie)
|
||||
}
|
||||
|
||||
func (jp *jsonUtils) getScene(checksum string) (*jsonschema.Scene, error) {
|
||||
return jsonschema.LoadSceneFile(instance.Paths.JSON.SceneJSONPath(checksum))
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type PathMapping struct {
|
||||
type Mappings struct {
|
||||
Performers []NameMapping `json:"performers"`
|
||||
Studios []NameMapping `json:"studios"`
|
||||
Movies []NameMapping `json:"movies"`
|
||||
Galleries []PathMapping `json:"galleries"`
|
||||
Scenes []PathMapping `json:"scenes"`
|
||||
}
|
||||
|
||||
46
pkg/manager/jsonschema/movie.go
Normal file
46
pkg/manager/jsonschema/movie.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package jsonschema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type Movie struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Aliases string `json:"aliases,omitempty"`
|
||||
Duration string `json:"duration,omitempty"`
|
||||
Date string `json:"date,omitempty"`
|
||||
Rating string `json:"rating,omitempty"`
|
||||
Director string `json:"director,omitempty"`
|
||||
Synopsis string `json:"sypnopsis,omitempty"`
|
||||
FrontImage string `json:"front_image,omitempty"`
|
||||
BackImage string `json:"back_image,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
||||
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
func LoadMovieFile(filePath string) (*Movie, error) {
|
||||
var movie Movie
|
||||
file, err := os.Open(filePath)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jsonParser := json.NewDecoder(file)
|
||||
err = jsonParser.Decode(&movie)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &movie, nil
|
||||
}
|
||||
|
||||
func SaveMovieFile(filePath string, movie *Movie) error {
|
||||
if movie == nil {
|
||||
return fmt.Errorf("movie must not be nil")
|
||||
}
|
||||
return marshalToFile(filePath, movie)
|
||||
}
|
||||
@@ -3,8 +3,9 @@ package jsonschema
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"os"
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type SceneMarker struct {
|
||||
@@ -27,6 +28,11 @@ type SceneFile struct {
|
||||
Bitrate int `json:"bitrate"`
|
||||
}
|
||||
|
||||
type SceneMovie struct {
|
||||
MovieName string `json:"movieName,omitempty"`
|
||||
SceneIndex string `json:"scene_index,omitempty"`
|
||||
}
|
||||
|
||||
type Scene struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Studio string `json:"studio,omitempty"`
|
||||
@@ -36,6 +42,7 @@ type Scene struct {
|
||||
Details string `json:"details,omitempty"`
|
||||
Gallery string `json:"gallery,omitempty"`
|
||||
Performers []string `json:"performers,omitempty"`
|
||||
Movies []SceneMovie `json:"movies,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Markers []SceneMarker `json:"markers,omitempty"`
|
||||
File *SceneFile `json:"file,omitempty"`
|
||||
|
||||
@@ -158,5 +158,6 @@ func (s *singleton) RefreshConfig() {
|
||||
_ = utils.EnsureDir(s.Paths.JSON.Scenes)
|
||||
_ = utils.EnsureDir(s.Paths.JSON.Galleries)
|
||||
_ = utils.EnsureDir(s.Paths.JSON.Studios)
|
||||
_ = utils.EnsureDir(s.Paths.JSON.Movies)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type jsonPaths struct {
|
||||
Scenes string
|
||||
Galleries string
|
||||
Studios string
|
||||
Movies string
|
||||
}
|
||||
|
||||
func newJSONPaths() *jsonPaths {
|
||||
@@ -23,6 +24,7 @@ func newJSONPaths() *jsonPaths {
|
||||
jp.Scenes = filepath.Join(config.GetMetadataPath(), "scenes")
|
||||
jp.Galleries = filepath.Join(config.GetMetadataPath(), "galleries")
|
||||
jp.Studios = filepath.Join(config.GetMetadataPath(), "studios")
|
||||
jp.Movies = filepath.Join(config.GetMetadataPath(), "movies")
|
||||
return &jp
|
||||
}
|
||||
|
||||
@@ -37,3 +39,7 @@ func (jp *jsonPaths) SceneJSONPath(checksum string) string {
|
||||
func (jp *jsonPaths) StudioJSONPath(checksum string) string {
|
||||
return filepath.Join(jp.Studios, checksum+".json")
|
||||
}
|
||||
|
||||
func (jp *jsonPaths) MovieJSONPath(checksum string) string {
|
||||
return filepath.Join(jp.Movies, checksum+".json")
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package manager
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/manager/jsonschema"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
"math"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ExportTask struct {
|
||||
@@ -20,7 +21,7 @@ type ExportTask struct {
|
||||
|
||||
func (t *ExportTask) Start(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
// @manager.total = Scene.count + Gallery.count + Performer.count + Studio.count
|
||||
// @manager.total = Scene.count + Gallery.count + Performer.count + Studio.count + Movie.count
|
||||
|
||||
t.Mappings = &jsonschema.Mappings{}
|
||||
t.Scraped = []jsonschema.ScrapedItem{}
|
||||
@@ -31,6 +32,7 @@ func (t *ExportTask) Start(wg *sync.WaitGroup) {
|
||||
t.ExportGalleries(ctx)
|
||||
t.ExportPerformers(ctx)
|
||||
t.ExportStudios(ctx)
|
||||
t.ExportMovies(ctx)
|
||||
|
||||
if err := instance.JSON.saveMappings(t.Mappings); err != nil {
|
||||
logger.Errorf("[mappings] failed to save json: %s", err.Error())
|
||||
@@ -44,10 +46,12 @@ func (t *ExportTask) ExportScenes(ctx context.Context) {
|
||||
defer tx.Commit()
|
||||
qb := models.NewSceneQueryBuilder()
|
||||
studioQB := models.NewStudioQueryBuilder()
|
||||
movieQB := models.NewMovieQueryBuilder()
|
||||
galleryQB := models.NewGalleryQueryBuilder()
|
||||
performerQB := models.NewPerformerQueryBuilder()
|
||||
tagQB := models.NewTagQueryBuilder()
|
||||
sceneMarkerQB := models.NewSceneMarkerQueryBuilder()
|
||||
joinQB := models.NewJoinsQueryBuilder()
|
||||
scenes, err := qb.All()
|
||||
if err != nil {
|
||||
logger.Errorf("[scenes] failed to fetch all scenes: %s", err.Error())
|
||||
@@ -80,6 +84,7 @@ func (t *ExportTask) ExportScenes(ctx context.Context) {
|
||||
}
|
||||
|
||||
performers, _ := performerQB.FindBySceneID(scene.ID, tx)
|
||||
sceneMovies, _ := joinQB.GetSceneMovies(scene.ID, tx)
|
||||
tags, _ := tagQB.FindBySceneID(scene.ID, tx)
|
||||
sceneMarkers, _ := sceneMarkerQB.FindBySceneID(scene.ID, tx)
|
||||
|
||||
@@ -135,6 +140,18 @@ func (t *ExportTask) ExportScenes(ctx context.Context) {
|
||||
newSceneJSON.Markers = append(newSceneJSON.Markers, sceneMarkerJSON)
|
||||
}
|
||||
|
||||
for _, sceneMovie := range sceneMovies {
|
||||
movie, _ := movieQB.Find(sceneMovie.MovieID, tx)
|
||||
|
||||
if movie.Name.Valid {
|
||||
sceneMovieJSON := jsonschema.SceneMovie{
|
||||
MovieName: movie.Name.String,
|
||||
SceneIndex: sceneMovie.SceneIndex,
|
||||
}
|
||||
newSceneJSON.Movies = append(newSceneJSON.Movies, sceneMovieJSON)
|
||||
}
|
||||
}
|
||||
|
||||
newSceneJSON.File = &jsonschema.SceneFile{}
|
||||
if scene.Size.Valid {
|
||||
newSceneJSON.File.Size = scene.Size.String
|
||||
@@ -328,6 +345,71 @@ func (t *ExportTask) ExportStudios(ctx context.Context) {
|
||||
logger.Infof("[studios] export complete")
|
||||
}
|
||||
|
||||
func (t *ExportTask) ExportMovies(ctx context.Context) {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
movies, err := qb.All()
|
||||
if err != nil {
|
||||
logger.Errorf("[movies] failed to fetch all movies: %s", err.Error())
|
||||
}
|
||||
|
||||
logger.Info("[movies] exporting")
|
||||
|
||||
for i, movie := range movies {
|
||||
index := i + 1
|
||||
logger.Progressf("[movies] %d of %d", index, len(movies))
|
||||
|
||||
t.Mappings.Movies = append(t.Mappings.Movies, jsonschema.NameMapping{Name: movie.Name.String, Checksum: movie.Checksum})
|
||||
|
||||
newMovieJSON := jsonschema.Movie{
|
||||
CreatedAt: models.JSONTime{Time: movie.CreatedAt.Timestamp},
|
||||
UpdatedAt: models.JSONTime{Time: movie.UpdatedAt.Timestamp},
|
||||
}
|
||||
|
||||
if movie.Name.Valid {
|
||||
newMovieJSON.Name = movie.Name.String
|
||||
}
|
||||
if movie.Aliases.Valid {
|
||||
newMovieJSON.Aliases = movie.Aliases.String
|
||||
}
|
||||
if movie.Date.Valid {
|
||||
newMovieJSON.Date = utils.GetYMDFromDatabaseDate(movie.Date.String)
|
||||
}
|
||||
if movie.Rating.Valid {
|
||||
newMovieJSON.Rating = movie.Rating.String
|
||||
}
|
||||
if movie.Duration.Valid {
|
||||
newMovieJSON.Duration = movie.Duration.String
|
||||
}
|
||||
|
||||
if movie.Director.Valid {
|
||||
newMovieJSON.Director = movie.Director.String
|
||||
}
|
||||
|
||||
if movie.Synopsis.Valid {
|
||||
newMovieJSON.Synopsis = movie.Synopsis.String
|
||||
}
|
||||
|
||||
if movie.URL.Valid {
|
||||
newMovieJSON.URL = movie.URL.String
|
||||
}
|
||||
|
||||
newMovieJSON.FrontImage = utils.GetBase64StringFromData(movie.FrontImage)
|
||||
newMovieJSON.BackImage = utils.GetBase64StringFromData(movie.BackImage)
|
||||
movieJSON, err := instance.JSON.getMovie(movie.Checksum)
|
||||
if err != nil {
|
||||
logger.Debugf("[movies] error reading movie json: %s", err.Error())
|
||||
} else if jsonschema.CompareJSON(*movieJSON, newMovieJSON) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := instance.JSON.saveMovie(movie.Checksum, &newMovieJSON); err != nil {
|
||||
logger.Errorf("[movies] <%s> failed to save json: %s", movie.Checksum, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof("[movies] export complete")
|
||||
}
|
||||
|
||||
func (t *ExportTask) ExportScrapedItems(ctx context.Context) {
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
defer tx.Commit()
|
||||
|
||||
@@ -46,6 +46,7 @@ func (t *ImportTask) Start(wg *sync.WaitGroup) {
|
||||
|
||||
t.ImportPerformers(ctx)
|
||||
t.ImportStudios(ctx)
|
||||
t.ImportMovies(ctx)
|
||||
t.ImportGalleries(ctx)
|
||||
t.ImportTags(ctx)
|
||||
|
||||
@@ -204,6 +205,72 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
|
||||
logger.Info("[studios] import complete")
|
||||
}
|
||||
|
||||
func (t *ImportTask) ImportMovies(ctx context.Context) {
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
|
||||
for i, mappingJSON := range t.Mappings.Movies {
|
||||
index := i + 1
|
||||
movieJSON, err := instance.JSON.getMovie(mappingJSON.Checksum)
|
||||
if err != nil {
|
||||
logger.Errorf("[movies] failed to read json: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
if mappingJSON.Checksum == "" || mappingJSON.Name == "" || movieJSON == nil {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Progressf("[movies] %d of %d", index, len(t.Mappings.Movies))
|
||||
|
||||
// generate checksum from movie name rather than image
|
||||
checksum := utils.MD5FromString(movieJSON.Name)
|
||||
|
||||
// Process the base 64 encoded image string
|
||||
_, frontimageData, err := utils.ProcessBase64Image(movieJSON.FrontImage)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
logger.Errorf("[movies] <%s> invalid front_image: %s", mappingJSON.Checksum, err.Error())
|
||||
return
|
||||
}
|
||||
_, backimageData, err := utils.ProcessBase64Image(movieJSON.BackImage)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
logger.Errorf("[movies] <%s> invalid back_image: %s", mappingJSON.Checksum, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Populate a new movie from the input
|
||||
newMovie := models.Movie{
|
||||
FrontImage: frontimageData,
|
||||
BackImage: backimageData,
|
||||
Checksum: checksum,
|
||||
Name: sql.NullString{String: movieJSON.Name, Valid: true},
|
||||
Aliases: sql.NullString{String: movieJSON.Aliases, Valid: true},
|
||||
Date: models.SQLiteDate{String: movieJSON.Date, Valid: true},
|
||||
Duration: sql.NullString{String: movieJSON.Duration, Valid: true},
|
||||
Rating: sql.NullString{String: movieJSON.Rating, Valid: true},
|
||||
Director: sql.NullString{String: movieJSON.Director, Valid: true},
|
||||
Synopsis: sql.NullString{String: movieJSON.Synopsis, Valid: true},
|
||||
URL: sql.NullString{String: movieJSON.URL, Valid: true},
|
||||
CreatedAt: models.SQLiteTimestamp{Timestamp: t.getTimeFromJSONTime(movieJSON.CreatedAt)},
|
||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: t.getTimeFromJSONTime(movieJSON.UpdatedAt)},
|
||||
}
|
||||
|
||||
_, err = qb.Create(newMovie, tx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
logger.Errorf("[movies] <%s> failed to create: %s", mappingJSON.Checksum, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("[movies] importing")
|
||||
if err := tx.Commit(); err != nil {
|
||||
logger.Errorf("[movies] import failed to commit: %s", err.Error())
|
||||
}
|
||||
logger.Info("[movies] import complete")
|
||||
}
|
||||
|
||||
func (t *ImportTask) ImportGalleries(ctx context.Context) {
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
qb := models.NewGalleryQueryBuilder()
|
||||
@@ -508,6 +575,18 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Relate the scene to the movies
|
||||
if len(sceneJSON.Movies) > 0 {
|
||||
moviesScenes, err := t.getMoviesScenes(sceneJSON.Movies, scene.ID, tx)
|
||||
if err != nil {
|
||||
logger.Warnf("[scenes] <%s> failed to fetch movies: %s", scene.Checksum, err.Error())
|
||||
} else {
|
||||
if err := jqb.CreateMoviesScenes(moviesScenes, tx); err != nil {
|
||||
logger.Errorf("[scenes] <%s> failed to associate movies: %s", scene.Checksum, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Relate the scene to the tags
|
||||
if len(sceneJSON.Tags) > 0 {
|
||||
tags, err := t.getTags(scene.Checksum, sceneJSON.Tags, tx)
|
||||
@@ -614,6 +693,30 @@ func (t *ImportTask) getPerformers(names []string, tx *sqlx.Tx) ([]*models.Perfo
|
||||
return performers, nil
|
||||
}
|
||||
|
||||
func (t *ImportTask) getMoviesScenes(input []jsonschema.SceneMovie, sceneID int, tx *sqlx.Tx) ([]models.MoviesScenes, error) {
|
||||
mqb := models.NewMovieQueryBuilder()
|
||||
|
||||
var movies []models.MoviesScenes
|
||||
for _, inputMovie := range input {
|
||||
movie, err := mqb.FindByName(inputMovie.MovieName, tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if movie == nil {
|
||||
logger.Warnf("[scenes] movie %s does not exist", inputMovie.MovieName)
|
||||
} else {
|
||||
movies = append(movies, models.MoviesScenes{
|
||||
MovieID: movie.ID,
|
||||
SceneID: sceneID,
|
||||
SceneIndex: inputMovie.SceneIndex,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return movies, nil
|
||||
}
|
||||
|
||||
func (t *ImportTask) getTags(sceneChecksum string, names []string, tx *sqlx.Tx) ([]*models.Tag, error) {
|
||||
tqb := models.NewTagQueryBuilder()
|
||||
tags, err := tqb.FindByNames(names, tx)
|
||||
|
||||
@@ -5,6 +5,12 @@ type PerformersScenes struct {
|
||||
SceneID int `db:"scene_id" json:"scene_id"`
|
||||
}
|
||||
|
||||
type MoviesScenes struct {
|
||||
MovieID int `db:"movie_id" json:"movie_id"`
|
||||
SceneID int `db:"scene_id" json:"scene_id"`
|
||||
SceneIndex string `db:"scene_index" json:"scene_index"`
|
||||
}
|
||||
|
||||
type ScenesTags struct {
|
||||
SceneID int `db:"scene_id" json:"scene_id"`
|
||||
TagID int `db:"tag_id" json:"tag_id"`
|
||||
|
||||
24
pkg/models/model_movie.go
Normal file
24
pkg/models/model_movie.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Movie struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
FrontImage []byte `db:"front_image" json:"front_image"`
|
||||
BackImage []byte `db:"back_image" json:"back_image"`
|
||||
Checksum string `db:"checksum" json:"checksum"`
|
||||
Name sql.NullString `db:"name" json:"name"`
|
||||
Aliases sql.NullString `db:"aliases" json:"aliases"`
|
||||
Duration sql.NullString `db:"duration" json:"duration"`
|
||||
Date SQLiteDate `db:"date" json:"date"`
|
||||
Rating sql.NullString `db:"rating" json:"rating"`
|
||||
Director sql.NullString `db:"director" json:"director"`
|
||||
Synopsis sql.NullString `db:"synopsis" json:"synopsis"`
|
||||
URL sql.NullString `db:"url" json:"url"`
|
||||
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
||||
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
var DefaultMovieImage string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4wgVBQsJl1CMZAAAASJJREFUeNrt3N0JwyAYhlEj3cj9R3Cm5rbkqtAP+qrnGaCYHPwJpLlaa++mmLpbAERAgAgIEAEBIiBABERAgAgIEAEBIiBABERAgAgIEAHZuVflj40x4i94zhk9vqsVvEq6AsQqMP1EjORx20OACAgQRRx7T+zzcFBxcjNDfoB4ntQqTm5Awo7MlqywZxcgYQ+RlqywJ3ozJAQCSBiEJSsQA0gYBpDAgAARECACAkRAgAgIEAERECACAmSjUv6eAOSB8m8YIGGzBUjYbAESBgMkbBkDEjZbgITBAClcxiqQvEoatreYIWEBASIgJ4Gkf11ntXH3nS9uxfGWfJ5J9hAgAgJEQAQEiIAAERAgAgJEQAQEiIAAERAgAgJEQAQEiL7qBuc6RKLHxr0CAAAAAElFTkSuQmCC"
|
||||
@@ -48,6 +48,7 @@ type ScenePartial struct {
|
||||
Framerate *sql.NullFloat64 `db:"framerate" json:"framerate"`
|
||||
Bitrate *sql.NullInt64 `db:"bitrate" json:"bitrate"`
|
||||
StudioID *sql.NullInt64 `db:"studio_id,omitempty" json:"studio_id"`
|
||||
MovieID *sql.NullInt64 `db:"movie_id,omitempty" json:"movie_id"`
|
||||
CreatedAt *SQLiteTimestamp `db:"created_at" json:"created_at"`
|
||||
UpdatedAt *SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ type ScrapedScene struct {
|
||||
Date *string `graphql:"date" json:"date"`
|
||||
File *SceneFileType `graphql:"file" json:"file"`
|
||||
Studio *ScrapedSceneStudio `graphql:"studio" json:"studio"`
|
||||
Movies []*ScrapedSceneMovie `graphql:"movies" json:"movies"`
|
||||
Tags []*ScrapedSceneTag `graphql:"tags" json:"tags"`
|
||||
Performers []*ScrapedScenePerformer `graphql:"performers" json:"performers"`
|
||||
}
|
||||
@@ -79,6 +80,19 @@ type ScrapedSceneStudio struct {
|
||||
URL *string `graphql:"url" json:"url"`
|
||||
}
|
||||
|
||||
type ScrapedSceneMovie struct {
|
||||
// Set if movie matched
|
||||
ID *string `graphql:"id" json:"id"`
|
||||
Name string `graphql:"name" json:"name"`
|
||||
Aliases string `graphql:"aliases" json:"aliases"`
|
||||
Duration string `graphql:"duration" json:"duration"`
|
||||
Date string `graphql:"date" json:"date"`
|
||||
Rating string `graphql:"rating" json:"rating"`
|
||||
Director string `graphql:"director" json:"director"`
|
||||
Synopsis string `graphql:"synopsis" json:"synopsis"`
|
||||
URL *string `graphql:"url" json:"url"`
|
||||
}
|
||||
|
||||
type ScrapedSceneTag struct {
|
||||
// Set if tag matched
|
||||
ID *string `graphql:"id" json:"id"`
|
||||
|
||||
@@ -111,6 +111,103 @@ func (qb *JoinsQueryBuilder) DestroyPerformersScenes(sceneID int, tx *sqlx.Tx) e
|
||||
return err
|
||||
}
|
||||
|
||||
func (qb *JoinsQueryBuilder) GetSceneMovies(sceneID int, tx *sqlx.Tx) ([]MoviesScenes, error) {
|
||||
query := `SELECT * from movies_scenes WHERE scene_id = ?`
|
||||
|
||||
var rows *sqlx.Rows
|
||||
var err error
|
||||
if tx != nil {
|
||||
rows, err = tx.Queryx(query, sceneID)
|
||||
} else {
|
||||
rows, err = database.DB.Queryx(query, sceneID)
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
movieScenes := make([]MoviesScenes, 0)
|
||||
for rows.Next() {
|
||||
movieScene := MoviesScenes{}
|
||||
if err := rows.StructScan(&movieScene); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
movieScenes = append(movieScenes, movieScene)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return movieScenes, nil
|
||||
}
|
||||
|
||||
func (qb *JoinsQueryBuilder) CreateMoviesScenes(newJoins []MoviesScenes, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
for _, join := range newJoins {
|
||||
_, err := tx.NamedExec(
|
||||
`INSERT INTO movies_scenes (movie_id, scene_id, scene_index) VALUES (:movie_id, :scene_id, :scene_index)`,
|
||||
join,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddMovieScene adds a movie to a scene. It does not make any change
|
||||
// if the movie already exists on the scene. It returns true if scene
|
||||
// movie was added.
|
||||
|
||||
func (qb *JoinsQueryBuilder) AddMoviesScene(sceneID int, movieID int, sceneIdx string, tx *sqlx.Tx) (bool, error) {
|
||||
ensureTx(tx)
|
||||
|
||||
existingMovies, err := qb.GetSceneMovies(sceneID, tx)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// ensure not already present
|
||||
for _, p := range existingMovies {
|
||||
if p.MovieID == movieID && p.SceneID == sceneID {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
movieJoin := MoviesScenes{
|
||||
MovieID: movieID,
|
||||
SceneID: sceneID,
|
||||
SceneIndex: sceneIdx,
|
||||
}
|
||||
movieJoins := append(existingMovies, movieJoin)
|
||||
|
||||
err = qb.UpdateMoviesScenes(sceneID, movieJoins, tx)
|
||||
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
func (qb *JoinsQueryBuilder) UpdateMoviesScenes(sceneID int, updatedJoins []MoviesScenes, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
|
||||
// Delete the existing joins and then create new ones
|
||||
_, err := tx.Exec("DELETE FROM movies_scenes WHERE scene_id = ?", sceneID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return qb.CreateMoviesScenes(updatedJoins, tx)
|
||||
}
|
||||
|
||||
func (qb *JoinsQueryBuilder) DestroyMoviesScenes(sceneID int, tx *sqlx.Tx) error {
|
||||
ensureTx(tx)
|
||||
|
||||
// Delete the existing joins
|
||||
_, err := tx.Exec("DELETE FROM movies_scenes WHERE scene_id = ?", sceneID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (qb *JoinsQueryBuilder) GetSceneTags(sceneID int, tx *sqlx.Tx) ([]ScenesTags, error) {
|
||||
ensureTx(tx)
|
||||
|
||||
|
||||
194
pkg/models/querybuilder_movies.go
Normal file
194
pkg/models/querybuilder_movies.go
Normal file
@@ -0,0 +1,194 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
)
|
||||
|
||||
type MovieQueryBuilder struct{}
|
||||
|
||||
func NewMovieQueryBuilder() MovieQueryBuilder {
|
||||
return MovieQueryBuilder{}
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Create(newMovie Movie, tx *sqlx.Tx) (*Movie, error) {
|
||||
ensureTx(tx)
|
||||
result, err := tx.NamedExec(
|
||||
`INSERT INTO movies (front_image, back_image, checksum, name, aliases, duration, date, rating, director, synopsis, url, created_at, updated_at)
|
||||
VALUES (:front_image, :back_image, :checksum, :name, :aliases, :duration, :date, :rating, :director, :synopsis, :url, :created_at, :updated_at)
|
||||
`,
|
||||
newMovie,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
movieID, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := tx.Get(&newMovie, `SELECT * FROM movies WHERE id = ? LIMIT 1`, movieID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &newMovie, nil
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Update(updatedMovie Movie, tx *sqlx.Tx) (*Movie, error) {
|
||||
ensureTx(tx)
|
||||
_, err := tx.NamedExec(
|
||||
`UPDATE movies SET `+SQLGenKeys(updatedMovie)+` WHERE movies.id = :id`,
|
||||
updatedMovie,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := tx.Get(&updatedMovie, `SELECT * FROM movies WHERE id = ? LIMIT 1`, updatedMovie.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &updatedMovie, nil
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Destroy(id string, tx *sqlx.Tx) error {
|
||||
// delete movie from movies_scenes
|
||||
|
||||
_, err := tx.Exec("DELETE FROM movies_scenes WHERE movie_id = ?", id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// // remove movie from scraped items
|
||||
// _, err = tx.Exec("UPDATE scraped_items SET movie_id = null WHERE movie_id = ?", id)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
return executeDeleteQuery("movies", id, tx)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Find(id int, tx *sqlx.Tx) (*Movie, error) {
|
||||
query := "SELECT * FROM movies WHERE id = ? LIMIT 1"
|
||||
args := []interface{}{id}
|
||||
return qb.queryMovie(query, args, tx)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) FindBySceneID(sceneID int, tx *sqlx.Tx) ([]*Movie, error) {
|
||||
query := `
|
||||
SELECT movies.* FROM movies
|
||||
LEFT JOIN movies_scenes as scenes_join on scenes_join.movie_id = movies.id
|
||||
LEFT JOIN scenes on scenes_join.scene_id = scenes.id
|
||||
WHERE scenes.id = ?
|
||||
GROUP BY movies.id
|
||||
`
|
||||
args := []interface{}{sceneID}
|
||||
return qb.queryMovies(query, args, tx)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Movie, error) {
|
||||
query := "SELECT * FROM movies WHERE name = ? LIMIT 1"
|
||||
args := []interface{}{name}
|
||||
return qb.queryMovie(query, args, tx)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]*Movie, error) {
|
||||
query := "SELECT * FROM movies WHERE name IN " + getInBinding(len(names))
|
||||
var args []interface{}
|
||||
for _, name := range names {
|
||||
args = append(args, name)
|
||||
}
|
||||
return qb.queryMovies(query, args, tx)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Count() (int, error) {
|
||||
return runCountQuery(buildCountQuery("SELECT movies.id FROM movies"), nil)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) All() ([]*Movie, error) {
|
||||
return qb.queryMovies(selectAll("movies")+qb.getMovieSort(nil), nil, nil)
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) Query(findFilter *FindFilterType) ([]*Movie, int) {
|
||||
if findFilter == nil {
|
||||
findFilter = &FindFilterType{}
|
||||
}
|
||||
|
||||
var whereClauses []string
|
||||
var havingClauses []string
|
||||
var args []interface{}
|
||||
body := selectDistinctIDs("movies")
|
||||
body += `
|
||||
left join movies_scenes as scenes_join on scenes_join.movie_id = movies.id
|
||||
left join scenes on scenes_join.scene_id = scenes.id
|
||||
`
|
||||
|
||||
if q := findFilter.Q; q != nil && *q != "" {
|
||||
searchColumns := []string{"movies.name"}
|
||||
clause, thisArgs := getSearchBinding(searchColumns, *q, false)
|
||||
whereClauses = append(whereClauses, clause)
|
||||
args = append(args, thisArgs...)
|
||||
}
|
||||
|
||||
sortAndPagination := qb.getMovieSort(findFilter) + getPagination(findFilter)
|
||||
idsResult, countResult := executeFindQuery("movies", body, args, sortAndPagination, whereClauses, havingClauses)
|
||||
|
||||
var movies []*Movie
|
||||
for _, id := range idsResult {
|
||||
movie, _ := qb.Find(id, nil)
|
||||
movies = append(movies, movie)
|
||||
}
|
||||
|
||||
return movies, countResult
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) getMovieSort(findFilter *FindFilterType) string {
|
||||
var sort string
|
||||
var direction string
|
||||
if findFilter == nil {
|
||||
sort = "name"
|
||||
direction = "ASC"
|
||||
} else {
|
||||
sort = findFilter.GetSort("name")
|
||||
direction = findFilter.GetDirection()
|
||||
}
|
||||
return getSort(sort, direction, "movies")
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) queryMovie(query string, args []interface{}, tx *sqlx.Tx) (*Movie, error) {
|
||||
results, err := qb.queryMovies(query, args, tx)
|
||||
if err != nil || len(results) < 1 {
|
||||
return nil, err
|
||||
}
|
||||
return results[0], nil
|
||||
}
|
||||
|
||||
func (qb *MovieQueryBuilder) queryMovies(query string, args []interface{}, tx *sqlx.Tx) ([]*Movie, error) {
|
||||
var rows *sqlx.Rows
|
||||
var err error
|
||||
if tx != nil {
|
||||
rows, err = tx.Queryx(query, args...)
|
||||
} else {
|
||||
rows, err = database.DB.Queryx(query, args...)
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
movies := make([]*Movie, 0)
|
||||
for rows.Next() {
|
||||
movie := Movie{}
|
||||
if err := rows.StructScan(&movie); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
movies = append(movies, &movie)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return movies, nil
|
||||
}
|
||||
@@ -23,6 +23,13 @@ JOIN studios ON studios.id = scenes.studio_id
|
||||
WHERE studios.id = ?
|
||||
GROUP BY scenes.id
|
||||
`
|
||||
const scenesForMovieQuery = `
|
||||
SELECT scenes.* FROM scenes
|
||||
LEFT JOIN movies_scenes as movies_join on movies_join.scene_id = scenes.id
|
||||
LEFT JOIN movies on movies_join.movie_id = movies.id
|
||||
WHERE movies.id = ?
|
||||
GROUP BY scenes.id
|
||||
`
|
||||
|
||||
const scenesForTagQuery = `
|
||||
SELECT scenes.* FROM scenes
|
||||
@@ -170,6 +177,16 @@ func (qb *SceneQueryBuilder) FindByStudioID(studioID int) ([]*Scene, error) {
|
||||
return qb.queryScenes(scenesForStudioQuery, args, nil)
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) FindByMovieID(movieID int) ([]*Scene, error) {
|
||||
args := []interface{}{movieID}
|
||||
return qb.queryScenes(scenesForMovieQuery, args, nil)
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) CountByMovieID(movieID int) (int, error) {
|
||||
args := []interface{}{movieID}
|
||||
return runCountQuery(buildCountQuery(scenesForMovieQuery), args)
|
||||
}
|
||||
|
||||
func (qb *SceneQueryBuilder) Count() (int, error) {
|
||||
return runCountQuery(buildCountQuery("SELECT scenes.id FROM scenes"), nil)
|
||||
}
|
||||
@@ -212,7 +229,9 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
||||
body = body + `
|
||||
left join scene_markers on scene_markers.scene_id = scenes.id
|
||||
left join performers_scenes as performers_join on performers_join.scene_id = scenes.id
|
||||
left join movies_scenes as movies_join on movies_join.scene_id = scenes.id
|
||||
left join performers on performers_join.performer_id = performers.id
|
||||
left join movies on movies_join.movie_id = movies.id
|
||||
left join studios as studio on studio.id = scenes.studio_id
|
||||
left join galleries as gallery on gallery.scene_id = scenes.id
|
||||
left join scenes_tags as tags_join on tags_join.scene_id = scenes.id
|
||||
@@ -281,6 +300,8 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
||||
whereClauses = append(whereClauses, "gallery.scene_id IS NULL")
|
||||
case "studio":
|
||||
whereClauses = append(whereClauses, "scenes.studio_id IS NULL")
|
||||
case "movie":
|
||||
whereClauses = append(whereClauses, "movies_join.scene_id IS NULL")
|
||||
case "performers":
|
||||
whereClauses = append(whereClauses, "performers_join.scene_id IS NULL")
|
||||
case "date":
|
||||
@@ -320,6 +341,16 @@ func (qb *SceneQueryBuilder) Query(sceneFilter *SceneFilterType, findFilter *Fin
|
||||
havingClauses = appendClause(havingClauses, havingClause)
|
||||
}
|
||||
|
||||
if moviesFilter := sceneFilter.Movies; moviesFilter != nil && len(moviesFilter.Value) > 0 {
|
||||
for _, movieID := range moviesFilter.Value {
|
||||
args = append(args, movieID)
|
||||
}
|
||||
|
||||
whereClause, havingClause := getMultiCriterionClause("movies", "movies_scenes", "movie_id", moviesFilter)
|
||||
whereClauses = appendClause(whereClauses, whereClause)
|
||||
havingClauses = appendClause(havingClauses, havingClause)
|
||||
}
|
||||
|
||||
sortAndPagination := qb.getSceneSort(findFilter) + getPagination(findFilter)
|
||||
idsResult, countResult := executeFindQuery("scenes", body, args, sortAndPagination, whereClauses, havingClauses)
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ func getSort(sort string, direction string, tableName string) string {
|
||||
colName := getColumn(tableName, sort)
|
||||
var additional string
|
||||
if tableName == "scenes" {
|
||||
additional = ", bitrate DESC, framerate DESC, rating DESC, duration DESC"
|
||||
additional = ", bitrate DESC, framerate DESC, scenes.rating DESC, scenes.duration DESC"
|
||||
} else if tableName == "scene_markers" {
|
||||
additional = ", scene_markers.scene_id ASC, scene_markers.seconds ASC"
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ func (qb *TagQueryBuilder) Create(newTag Tag, tx *sqlx.Tx) (*Tag, error) {
|
||||
if err := tx.Get(&newTag, `SELECT * FROM tags WHERE id = ? LIMIT 1`, studioID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &newTag, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,24 @@ func matchStudio(s *models.ScrapedSceneStudio) error {
|
||||
s.ID = &id
|
||||
return nil
|
||||
}
|
||||
func matchMovie(m *models.ScrapedSceneMovie) error {
|
||||
qb := models.NewMovieQueryBuilder()
|
||||
|
||||
movies, err := qb.FindByNames([]string{m.Name}, nil)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(movies) !=1 {
|
||||
// ignore - cannot match
|
||||
return nil
|
||||
}
|
||||
|
||||
id := strconv.Itoa(movies[0].ID)
|
||||
m.ID = &id
|
||||
return nil
|
||||
}
|
||||
|
||||
func matchTag(s *models.ScrapedSceneTag) error {
|
||||
qb := models.NewTagQueryBuilder()
|
||||
@@ -189,6 +207,13 @@ func postScrapeScene(ret *models.ScrapedScene) error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range ret.Movies {
|
||||
err := matchMovie(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, t := range ret.Tags {
|
||||
err := matchTag(t)
|
||||
if err != nil {
|
||||
|
||||
@@ -265,6 +265,7 @@ const (
|
||||
XPathScraperConfigSceneTags = "Tags"
|
||||
XPathScraperConfigScenePerformers = "Performers"
|
||||
XPathScraperConfigSceneStudio = "Studio"
|
||||
XPathScraperConfigSceneMovies = "Movies"
|
||||
)
|
||||
|
||||
func (s xpathScraper) GetSceneSimple() xpathScraperConfig {
|
||||
@@ -274,7 +275,7 @@ func (s xpathScraper) GetSceneSimple() xpathScraperConfig {
|
||||
|
||||
if mapped != nil {
|
||||
for k, v := range mapped {
|
||||
if k != XPathScraperConfigSceneTags && k != XPathScraperConfigScenePerformers && k != XPathScraperConfigSceneStudio {
|
||||
if k != XPathScraperConfigSceneTags && k != XPathScraperConfigScenePerformers && k != XPathScraperConfigSceneStudio && k != XPathScraperConfigSceneMovies {
|
||||
ret[k] = v
|
||||
}
|
||||
}
|
||||
@@ -313,6 +314,10 @@ func (s xpathScraper) GetSceneStudio() xpathScraperConfig {
|
||||
return s.getSceneSubMap(XPathScraperConfigSceneStudio)
|
||||
}
|
||||
|
||||
func (s xpathScraper) GetSceneMovies() xpathScraperConfig {
|
||||
return s.getSceneSubMap(XPathScraperConfigSceneMovies)
|
||||
}
|
||||
|
||||
func (s xpathScraper) scrapePerformer(doc *html.Node) (*models.ScrapedPerformer, error) {
|
||||
var ret models.ScrapedPerformer
|
||||
|
||||
@@ -358,6 +363,7 @@ func (s xpathScraper) scrapeScene(doc *html.Node) (*models.ScrapedScene, error)
|
||||
scenePerformersMap := s.GetScenePerformers()
|
||||
sceneTagsMap := s.GetSceneTags()
|
||||
sceneStudioMap := s.GetSceneStudio()
|
||||
sceneMoviesMap := s.GetSceneMovies()
|
||||
|
||||
results := sceneMap.process(doc, s.Common)
|
||||
if len(results) > 0 {
|
||||
@@ -393,6 +399,17 @@ func (s xpathScraper) scrapeScene(doc *html.Node) (*models.ScrapedScene, error)
|
||||
ret.Studio = studio
|
||||
}
|
||||
}
|
||||
|
||||
if sceneMoviesMap != nil {
|
||||
movieResults := sceneMoviesMap.process(doc, s.Common)
|
||||
|
||||
for _, p := range movieResults {
|
||||
movie := &models.ScrapedSceneMovie{}
|
||||
p.apply(movie)
|
||||
ret.Movies = append(ret.Movies, movie)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
|
||||
@@ -9,6 +9,7 @@ import Scenes from "./components/scenes/scenes";
|
||||
import { Settings } from "./components/Settings/Settings";
|
||||
import { Stats } from "./components/Stats";
|
||||
import Studios from "./components/Studios/Studios";
|
||||
import Movies from "./components/Movies/Movies";
|
||||
import Tags from "./components/Tags/Tags";
|
||||
import { SceneFilenameParser } from "./components/scenes/SceneFilenameParser";
|
||||
import { Sidebar } from "./components/Sidebar";
|
||||
@@ -39,6 +40,11 @@ export const App: FunctionComponent<IProps> = (props: IProps) => {
|
||||
text: "Scenes",
|
||||
href: "/scenes"
|
||||
},
|
||||
{
|
||||
href: "/movies",
|
||||
icon: "film",
|
||||
text: "Movies"
|
||||
},
|
||||
{
|
||||
href: "/scenes/markers",
|
||||
icon: "map-marker",
|
||||
@@ -80,6 +86,7 @@ export const App: FunctionComponent<IProps> = (props: IProps) => {
|
||||
<Route path="/performers" component={Performers} />
|
||||
<Route path="/tags" component={Tags} />
|
||||
<Route path="/studios" component={Studios} />
|
||||
<Route path="/movies" component={Movies} />
|
||||
<Route path="/settings" component={Settings} />
|
||||
<Route path="/sceneFilenameParser" component={SceneFilenameParser} />
|
||||
<Route component={PageNotFound} />
|
||||
|
||||
@@ -29,6 +29,10 @@ export const MainNavbar: FunctionComponent<IProps> = (props) => {
|
||||
setNewButtonPath("/studios/new");
|
||||
break;
|
||||
}
|
||||
case "/movies": {
|
||||
setNewButtonPath("/movies/new");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
setNewButtonPath(undefined);
|
||||
}
|
||||
|
||||
67
ui/v2/src/components/Movies/MovieCard.tsx
Normal file
67
ui/v2/src/components/Movies/MovieCard.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
Card,
|
||||
Elevation,
|
||||
H4,
|
||||
} from "@blueprintjs/core";
|
||||
import React, { FunctionComponent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import * as GQL from "../../core/generated-graphql";
|
||||
import { ColorUtils } from "../../utils/color";
|
||||
|
||||
interface IProps {
|
||||
movie: GQL.MovieDataFragment;
|
||||
sceneIndex?: string;
|
||||
// scene: GQL.SceneDataFragment;
|
||||
}
|
||||
|
||||
|
||||
export const MovieCard: FunctionComponent<IProps> = (props: IProps) => {
|
||||
function maybeRenderRatingBanner() {
|
||||
if (!props.movie.rating) { return; }
|
||||
return (
|
||||
<div className={`rating-banner ${ColorUtils.classForRating(parseInt(props.movie.rating,10))}`}>
|
||||
RATING: {props.movie.rating}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function maybeRenderSceneNumber() {
|
||||
if (!props.sceneIndex) {
|
||||
return (
|
||||
<div className="card-section">
|
||||
<H4 style={{textOverflow: "ellipsis", overflow: "hidden"}}>
|
||||
{props.movie.name}
|
||||
</H4>
|
||||
<span className="bp3-text-muted block">{props.movie.scene_count} scenes.</span>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div className="card-section">
|
||||
<H4 style={{textOverflow: "ellipsis", overflow: "hidden"}}>
|
||||
{props.movie.name}
|
||||
</H4>
|
||||
<span className="bp3-text-muted block">Scene number: {props.sceneIndex}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card
|
||||
className="grid-item"
|
||||
elevation={Elevation.ONE}
|
||||
>
|
||||
|
||||
<Link
|
||||
to={`/movies/${props.movie.id}`}
|
||||
className="movie previewable image"
|
||||
style={{backgroundImage: `url(${props.movie.front_image_path})`}}
|
||||
>
|
||||
{maybeRenderRatingBanner()}
|
||||
</Link>
|
||||
{maybeRenderSceneNumber()}
|
||||
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
205
ui/v2/src/components/Movies/MovieDetails/Movie.tsx
Normal file
205
ui/v2/src/components/Movies/MovieDetails/Movie.tsx
Normal file
@@ -0,0 +1,205 @@
|
||||
import {
|
||||
EditableText,
|
||||
HTMLTable,
|
||||
Spinner,
|
||||
} from "@blueprintjs/core";
|
||||
import React, { FunctionComponent, useEffect, useState } from "react";
|
||||
import * as GQL from "../../../core/generated-graphql";
|
||||
import { StashService } from "../../../core/StashService";
|
||||
import { IBaseProps } from "../../../models";
|
||||
import { ErrorUtils } from "../../../utils/errors";
|
||||
import { TableUtils } from "../../../utils/table";
|
||||
import { DetailsEditNavbar } from "../../Shared/DetailsEditNavbar";
|
||||
import { ImageUtils } from "../../../utils/image";
|
||||
|
||||
interface IProps extends IBaseProps {}
|
||||
|
||||
export const Movie: FunctionComponent<IProps> = (props: IProps) => {
|
||||
const isNew = props.match.params.id === "new";
|
||||
|
||||
// Editing state
|
||||
const [isEditing, setIsEditing] = useState<boolean>(isNew);
|
||||
|
||||
// Editing movie state
|
||||
const [front_image, setFrontImage] = useState<string | undefined>(undefined);
|
||||
const [back_image, setBackImage] = useState<string | undefined>(undefined);
|
||||
const [name, setName] = useState<string | undefined>(undefined);
|
||||
const [aliases, setAliases] = useState<string | undefined>(undefined);
|
||||
const [duration, setDuration] = useState<string | undefined>(undefined);
|
||||
const [date, setDate] = useState<string | undefined>(undefined);
|
||||
const [rating, setRating] = useState<string | undefined>(undefined);
|
||||
const [director, setDirector] = useState<string | undefined>(undefined);
|
||||
const [synopsis, setSynopsis] = useState<string | undefined>(undefined);
|
||||
const [url, setUrl] = useState<string | undefined>(undefined);
|
||||
|
||||
// Movie state
|
||||
const [movie, setMovie] = useState<Partial<GQL.MovieDataFragment>>({});
|
||||
const [imagePreview, setImagePreview] = useState<string | undefined>(undefined);
|
||||
const [backimagePreview, setBackImagePreview] = useState<string | undefined>(undefined);
|
||||
|
||||
// Network state
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const { data, error, loading } = StashService.useFindMovie(props.match.params.id);
|
||||
const updateMovie = StashService.useMovieUpdate(getMovieInput() as GQL.MovieUpdateInput);
|
||||
const createMovie = StashService.useMovieCreate(getMovieInput() as GQL.MovieCreateInput);
|
||||
const deleteMovie = StashService.useMovieDestroy(getMovieInput() as GQL.MovieDestroyInput);
|
||||
|
||||
function updateMovieEditState(state: Partial<GQL.MovieDataFragment>) {
|
||||
setName(state.name);
|
||||
setAliases(state.aliases);
|
||||
setDuration(state.duration);
|
||||
setDate(state.date);
|
||||
setRating(state.rating);
|
||||
setDirector(state.director);
|
||||
setSynopsis(state.synopsis);
|
||||
setUrl(state.url);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(loading);
|
||||
if (!data || !data.findMovie || !!error) { return; }
|
||||
setMovie(data.findMovie);
|
||||
}, [data, loading, error]);
|
||||
|
||||
useEffect(() => {
|
||||
setImagePreview(movie.front_image_path);
|
||||
setBackImagePreview(movie.back_image_path);
|
||||
setFrontImage(undefined);
|
||||
setBackImage(undefined);
|
||||
updateMovieEditState(movie);
|
||||
if (!isNew) {
|
||||
setIsEditing(false);
|
||||
}
|
||||
}, [movie, isNew]);
|
||||
|
||||
function onImageLoad(this: FileReader) {
|
||||
setImagePreview(this.result as string);
|
||||
setFrontImage(this.result as string);
|
||||
|
||||
}
|
||||
|
||||
function onBackImageLoad(this: FileReader) {
|
||||
setBackImagePreview(this.result as string);
|
||||
setBackImage(this.result as string);
|
||||
}
|
||||
|
||||
|
||||
ImageUtils.addPasteImageHook(onImageLoad);
|
||||
ImageUtils.addPasteImageHook(onBackImageLoad);
|
||||
|
||||
if (!isNew && !isEditing) {
|
||||
if (!data || !data.findMovie || isLoading) { return <Spinner size={Spinner.SIZE_LARGE} />; }
|
||||
if (!!error) { return <>error...</>; }
|
||||
}
|
||||
|
||||
function getMovieInput() {
|
||||
const input: Partial<GQL.MovieCreateInput | GQL.MovieUpdateInput> = {
|
||||
name,
|
||||
aliases,
|
||||
duration,
|
||||
date,
|
||||
rating,
|
||||
director,
|
||||
synopsis,
|
||||
url,
|
||||
front_image,
|
||||
back_image
|
||||
|
||||
};
|
||||
|
||||
if (!isNew) {
|
||||
(input as GQL.MovieUpdateInput).id = props.match.params.id;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
async function onSave() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
if (!isNew) {
|
||||
const result = await updateMovie();
|
||||
setMovie(result.data.movieUpdate);
|
||||
} else {
|
||||
const result = await createMovie();
|
||||
setMovie(result.data.movieCreate);
|
||||
props.history.push(`/movies/${result.data.movieCreate.id}`);
|
||||
}
|
||||
} catch (e) {
|
||||
ErrorUtils.handle(e);
|
||||
}
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function onDelete() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
await deleteMovie();
|
||||
} catch (e) {
|
||||
ErrorUtils.handle(e);
|
||||
}
|
||||
setIsLoading(false);
|
||||
|
||||
// redirect to movies page
|
||||
props.history.push(`/movies`);
|
||||
}
|
||||
|
||||
function onImageChange(event: React.FormEvent<HTMLInputElement>) {
|
||||
ImageUtils.onImageChange(event, onImageLoad);
|
||||
}
|
||||
|
||||
function onBackImageChange(event: React.FormEvent<HTMLInputElement>) {
|
||||
ImageUtils.onImageChange(event, onBackImageLoad);
|
||||
}
|
||||
|
||||
// TODO: CSS class
|
||||
return (
|
||||
<>
|
||||
<div className="columns is-multiline no-spacing">
|
||||
<div className="column is-half details-image-container">
|
||||
<img alt={name} className="movie" src={imagePreview} />
|
||||
<img alt={name} className="movie" src={backimagePreview} />
|
||||
</div>
|
||||
<div className="column is-half details-detail-container">
|
||||
<DetailsEditNavbar
|
||||
movie={movie}
|
||||
isNew={isNew}
|
||||
isEditing={isEditing}
|
||||
onToggleEdit={() => { setIsEditing(!isEditing); updateMovieEditState(movie); }}
|
||||
onSave={onSave}
|
||||
onDelete={onDelete}
|
||||
onImageChange={onImageChange}
|
||||
onBackImageChange={onBackImageChange}
|
||||
/>
|
||||
<h1 className="bp3-heading">
|
||||
<EditableText
|
||||
disabled={!isEditing}
|
||||
value={name}
|
||||
placeholder="Name"
|
||||
onChange={(value) => setName(value)}
|
||||
/>
|
||||
</h1>
|
||||
|
||||
<HTMLTable style={{width: "100%"}}>
|
||||
<tbody>
|
||||
{TableUtils.renderInputGroup({title: "Aliases", value: aliases, isEditing, onChange: setAliases})}
|
||||
{TableUtils.renderInputGroup({title: "Duration", value: duration, isEditing, onChange: setDuration})}
|
||||
{TableUtils.renderInputGroup({title: "Date (YYYY-MM-DD)", value: date, isEditing, onChange: setDate})}
|
||||
{TableUtils.renderInputGroup({title: "Director", value: director, isEditing, onChange: setDirector})}
|
||||
{TableUtils.renderHtmlSelect({
|
||||
title: "Rating",
|
||||
value: rating,
|
||||
isEditing,
|
||||
onChange: (value: string) => setRating(value),
|
||||
selectOptions: ["","1","2","3","4","5"]
|
||||
})}
|
||||
{TableUtils.renderInputGroup({title: "URL", value: url, isEditing, onChange: setUrl})}
|
||||
{TableUtils.renderTextArea({title: "Synopsis", value: synopsis, isEditing, onChange: setSynopsis})}
|
||||
|
||||
</tbody>
|
||||
</HTMLTable>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
33
ui/v2/src/components/Movies/MovieList.tsx
Normal file
33
ui/v2/src/components/Movies/MovieList.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React, { FunctionComponent } from "react";
|
||||
import { QueryHookResult } from "react-apollo-hooks";
|
||||
import { FindMoviesQuery, FindMoviesVariables } from "../../core/generated-graphql";
|
||||
import { ListHook } from "../../hooks/ListHook";
|
||||
import { IBaseProps } from "../../models/base-props";
|
||||
import { ListFilterModel } from "../../models/list-filter/filter";
|
||||
import { DisplayMode, FilterMode } from "../../models/list-filter/types";
|
||||
import { MovieCard } from "./MovieCard";
|
||||
|
||||
interface IProps extends IBaseProps {}
|
||||
|
||||
export const MovieList: FunctionComponent<IProps> = (props: IProps) => {
|
||||
const listData = ListHook.useList({
|
||||
filterMode: FilterMode.Movies,
|
||||
props,
|
||||
renderContent,
|
||||
});
|
||||
|
||||
function renderContent(result: QueryHookResult<FindMoviesQuery, FindMoviesVariables>, filter: ListFilterModel) {
|
||||
if (!result.data || !result.data.findMovies) { return; }
|
||||
if (filter.displayMode === DisplayMode.Grid) {
|
||||
return (
|
||||
<div className="grid">
|
||||
{result.data.findMovies.movies.map((movie) => (<MovieCard key={movie.id} movie={movie}/>))}
|
||||
</div>
|
||||
);
|
||||
} else if (filter.displayMode === DisplayMode.List) {
|
||||
return <h1>TODO</h1>;
|
||||
}
|
||||
}
|
||||
|
||||
return listData.template;
|
||||
};
|
||||
13
ui/v2/src/components/Movies/Movies.tsx
Normal file
13
ui/v2/src/components/Movies/Movies.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from "react";
|
||||
import { Route, Switch } from "react-router-dom";
|
||||
import { Movie } from "./MovieDetails/Movie";
|
||||
import { MovieList } from "./MovieList";
|
||||
|
||||
const Movies = () => (
|
||||
<Switch>
|
||||
<Route exact={true} path="/movies" component={MovieList} />
|
||||
<Route path="/movies/:id" component={Movie} />
|
||||
</Switch>
|
||||
);
|
||||
|
||||
export default Movies;
|
||||
@@ -16,6 +16,7 @@ import { NavigationUtils } from "../../utils/navigation";
|
||||
interface IProps {
|
||||
performer?: Partial<GQL.PerformerDataFragment>;
|
||||
studio?: Partial<GQL.StudioDataFragment>;
|
||||
movie?: Partial<GQL.MovieDataFragment>;
|
||||
isNew: boolean;
|
||||
isEditing: boolean;
|
||||
onToggleEdit: () => void;
|
||||
@@ -23,6 +24,7 @@ interface IProps {
|
||||
onDelete: () => void;
|
||||
onAutoTag?: () => void;
|
||||
onImageChange: (event: React.FormEvent<HTMLInputElement>) => void;
|
||||
onBackImageChange?: (event: React.FormEvent<HTMLInputElement>) => void;
|
||||
|
||||
// TODO: only for performers. make generic
|
||||
scrapers?: GQL.ListPerformerScrapersListPerformerScrapers[];
|
||||
@@ -58,6 +60,12 @@ export const DetailsEditNavbar: FunctionComponent<IProps> = (props: IProps) => {
|
||||
return <FileInput text="Choose image..." onInputChange={props.onImageChange} inputProps={{accept: ".jpg,.jpeg"}} />;
|
||||
}
|
||||
|
||||
function renderBackImageInput() {
|
||||
if (!props.movie) { return; }
|
||||
if (!props.isEditing) { return; }
|
||||
return <FileInput text="Choose back image..." onInputChange={props.onBackImageChange} inputProps={{accept: ".jpg,.jpeg"}} />;
|
||||
}
|
||||
|
||||
function renderScraperMenuItem(scraper : GQL.ListPerformerScrapersListPerformerScrapers) {
|
||||
return (
|
||||
<MenuItem
|
||||
@@ -98,6 +106,8 @@ export const DetailsEditNavbar: FunctionComponent<IProps> = (props: IProps) => {
|
||||
linkSrc = NavigationUtils.makePerformerScenesUrl(props.performer);
|
||||
} else if (!!props.studio) {
|
||||
linkSrc = NavigationUtils.makeStudioScenesUrl(props.studio);
|
||||
} else if (!!props.movie) {
|
||||
linkSrc = NavigationUtils.makeMovieScenesUrl(props.movie);
|
||||
}
|
||||
return (
|
||||
<Link className="bp3-button" to={linkSrc}>
|
||||
@@ -115,6 +125,9 @@ export const DetailsEditNavbar: FunctionComponent<IProps> = (props: IProps) => {
|
||||
if (props.studio) {
|
||||
name = props.studio.name;
|
||||
}
|
||||
if (props.movie) {
|
||||
name = props.movie.name;
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert
|
||||
@@ -143,6 +156,7 @@ export const DetailsEditNavbar: FunctionComponent<IProps> = (props: IProps) => {
|
||||
{props.isEditing && !props.isNew ? <NavbarDivider /> : undefined}
|
||||
{renderScraperMenu()}
|
||||
{renderImageInput()}
|
||||
{renderBackImageInput()}
|
||||
{renderSaveButton()}
|
||||
|
||||
{renderAutoTagButton()}
|
||||
|
||||
@@ -4,13 +4,14 @@ import {
|
||||
} from "@blueprintjs/core";
|
||||
import React, { FunctionComponent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { PerformerDataFragment, SceneMarkerDataFragment, TagDataFragment } from "../../core/generated-graphql";
|
||||
import { MovieDataFragment,PerformerDataFragment, SceneMarkerDataFragment, TagDataFragment } from "../../core/generated-graphql";
|
||||
import { NavigationUtils } from "../../utils/navigation";
|
||||
import { TextUtils } from "../../utils/text";
|
||||
|
||||
interface IProps extends ITagProps {
|
||||
tag?: Partial<TagDataFragment>;
|
||||
performer?: Partial<PerformerDataFragment>;
|
||||
movie?: Partial<MovieDataFragment>;
|
||||
marker?: Partial<SceneMarkerDataFragment>;
|
||||
}
|
||||
|
||||
@@ -23,6 +24,9 @@ export const TagLink: FunctionComponent<IProps> = (props: IProps) => {
|
||||
} else if (!!props.performer) {
|
||||
link = NavigationUtils.makePerformerScenesUrl(props.performer);
|
||||
title = props.performer.name || "";
|
||||
} else if (!!props.movie) {
|
||||
link = NavigationUtils.makeMovieScenesUrl(props.movie);
|
||||
title = props.movie.name || "";
|
||||
} else if (!!props.marker) {
|
||||
link = NavigationUtils.makeSceneMarkerUrl(props.marker);
|
||||
title = `${props.marker.title} - ${TextUtils.secondsToTimestamp(props.marker.seconds || 0)}`;
|
||||
|
||||
@@ -15,6 +15,12 @@ export const Stats: FunctionComponent = () => {
|
||||
<p className="heading">Scenes</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="level-item has-text-centered">
|
||||
<div>
|
||||
<p className="title">{data.stats.movie_count}</p>
|
||||
<p className="heading">Movies</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="level-item has-text-centered">
|
||||
<div>
|
||||
<p className="title">{data.stats.gallery_count}</p>
|
||||
|
||||
@@ -15,6 +15,7 @@ import { Criterion, CriterionType, DurationCriterion } from "../../models/list-f
|
||||
import { NoneCriterion } from "../../models/list-filter/criteria/none";
|
||||
import { PerformersCriterion } from "../../models/list-filter/criteria/performers";
|
||||
import { StudiosCriterion } from "../../models/list-filter/criteria/studios";
|
||||
import { MoviesCriterion } from "../../models/list-filter/criteria/movies";
|
||||
import { TagsCriterion } from "../../models/list-filter/criteria/tags";
|
||||
import { makeCriteria } from "../../models/list-filter/criteria/utils";
|
||||
import { ListFilterModel } from "../../models/list-filter/filter";
|
||||
@@ -123,11 +124,13 @@ export const AddFilter: FunctionComponent<IAddFilterProps> = (props: IAddFilterP
|
||||
}
|
||||
|
||||
if (isArray(criterion.value)) {
|
||||
let type: "performers" | "studios" | "tags" | "" = "";
|
||||
let type: "performers" | "studios" | "movies" | "tags" | "" = "";
|
||||
if (criterion instanceof PerformersCriterion) {
|
||||
type = "performers";
|
||||
} else if (criterion instanceof StudiosCriterion) {
|
||||
type = "studios";
|
||||
} else if (criterion instanceof MoviesCriterion) {
|
||||
type = "movies";
|
||||
} else if (criterion instanceof TagsCriterion) {
|
||||
type = "tags";
|
||||
}
|
||||
|
||||
@@ -124,6 +124,36 @@ export const SceneCard: FunctionComponent<ISceneCardProps> = (props: ISceneCardP
|
||||
);
|
||||
}
|
||||
|
||||
function maybeRenderMoviePopoverButton() {
|
||||
if (props.scene.movies.length <= 0) { return; }
|
||||
|
||||
const movies = props.scene.movies.map((sceneMovie) => {
|
||||
let movie = sceneMovie.movie;
|
||||
return (
|
||||
<>
|
||||
<div className="movie-tag-container">
|
||||
<Link
|
||||
to={`/movies/${movie.id}`}
|
||||
className="movie-tag previewable image"
|
||||
style={{backgroundImage: `url(${movie.front_image_path})`}}
|
||||
></Link>
|
||||
<TagLink key={movie.id} movie={movie} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<Popover interactionKind={"hover"} position="bottom">
|
||||
<Button
|
||||
icon="film"
|
||||
text={props.scene.movies.length}
|
||||
/>
|
||||
<>{movies}</>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
||||
function maybeRenderSceneMarkerPopoverButton() {
|
||||
if (props.scene.scene_markers.length <= 0) { return; }
|
||||
|
||||
@@ -157,14 +187,17 @@ export const SceneCard: FunctionComponent<ISceneCardProps> = (props: ISceneCardP
|
||||
function maybeRenderPopoverButtonGroup() {
|
||||
if (props.scene.tags.length > 0 ||
|
||||
props.scene.performers.length > 0 ||
|
||||
props.scene.movies.length > 0 ||
|
||||
props.scene.scene_markers.length > 0 ||
|
||||
props.scene.o_counter) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Divider />
|
||||
<ButtonGroup minimal={true} className="card-section centered">
|
||||
{maybeRenderTagPopoverButton()}
|
||||
{maybeRenderPerformerPopoverButton()}
|
||||
{maybeRenderMoviePopoverButton()}
|
||||
{maybeRenderSceneMarkerPopoverButton()}
|
||||
{maybeRenderOCounter()}
|
||||
</ButtonGroup>
|
||||
|
||||
@@ -16,6 +16,7 @@ import { SceneEditPanel } from "./SceneEditPanel";
|
||||
import { SceneFileInfoPanel } from "./SceneFileInfoPanel";
|
||||
import { SceneMarkersPanel } from "./SceneMarkersPanel";
|
||||
import { ScenePerformerPanel } from "./ScenePerformerPanel";
|
||||
import { SceneMoviePanel } from "./SceneMoviePanel";
|
||||
import { ErrorUtils } from "../../../utils/errors";
|
||||
import { IOCounterButtonProps, OCounterButton } from "../OCounterButton";
|
||||
|
||||
@@ -133,6 +134,14 @@ export const Scene: FunctionComponent<ISceneProps> = (props: ISceneProps) => {
|
||||
panel={<ScenePerformerPanel scene={modifiedScene} />}
|
||||
/> : undefined
|
||||
}
|
||||
{modifiedScene.movies.length > 0 ?
|
||||
<Tab
|
||||
id="scene-movie-panel"
|
||||
title="Movies"
|
||||
panel={<SceneMoviePanel scene={modifiedScene} />}
|
||||
/> : undefined
|
||||
}
|
||||
|
||||
{!!modifiedScene.gallery ?
|
||||
<Tab
|
||||
id="scene-gallery-panel"
|
||||
|
||||
@@ -24,6 +24,7 @@ import { FilterMultiSelect } from "../../select/FilterMultiSelect";
|
||||
import { FilterSelect } from "../../select/FilterSelect";
|
||||
import { ValidGalleriesSelect } from "../../select/ValidGalleriesSelect";
|
||||
import { ImageUtils } from "../../../utils/image";
|
||||
import { SceneMovieTable } from "./SceneMovieTable";
|
||||
|
||||
interface IProps {
|
||||
scene: GQL.SceneDataFragment;
|
||||
@@ -41,6 +42,8 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
const [galleryId, setGalleryId] = useState<string | undefined>(undefined);
|
||||
const [studioId, setStudioId] = useState<string | undefined>(undefined);
|
||||
const [performerIds, setPerformerIds] = useState<string[] | undefined>(undefined);
|
||||
const [movieIds, setMovieIds] = useState<string[] | undefined>(undefined);
|
||||
const [sceneIdx, setSceneIdx] = useState<string[] | undefined>(undefined);
|
||||
const [tagIds, setTagIds] = useState<string[] | undefined>(undefined);
|
||||
const [coverImage, setCoverImage] = useState<string | undefined>(undefined);
|
||||
|
||||
@@ -75,6 +78,9 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
|
||||
function updateSceneEditState(state: Partial<GQL.SceneDataFragment>) {
|
||||
const perfIds = !!state.performers ? state.performers.map((performer) => performer.id) : undefined;
|
||||
const moviIds = !!state.movies ? state.movies.map((sceneMovie) => sceneMovie.movie.id) : undefined;
|
||||
const scenIdx = !!state.movies ? state.movies.map((movie) => movie.scene_index!) : undefined;
|
||||
|
||||
const tIds = !!state.tags ? state.tags.map((tag) => tag.id) : undefined;
|
||||
|
||||
setTitle(state.title);
|
||||
@@ -84,7 +90,9 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
setRating(state.rating == null ? NaN : state.rating);
|
||||
setGalleryId(state.gallery ? state.gallery.id : undefined);
|
||||
setStudioId(state.studio ? state.studio.id : undefined);
|
||||
setMovieIds(moviIds);
|
||||
setPerformerIds(perfIds);
|
||||
setSceneIdx(scenIdx);
|
||||
setTagIds(tIds);
|
||||
}
|
||||
|
||||
@@ -111,11 +119,35 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
gallery_id: galleryId,
|
||||
studio_id: studioId,
|
||||
performer_ids: performerIds,
|
||||
movies: makeMovieInputs(),
|
||||
tag_ids: tagIds,
|
||||
cover_image: coverImage,
|
||||
};
|
||||
}
|
||||
|
||||
function makeMovieInputs(): GQL.SceneMovieInput[] | undefined {
|
||||
if (!movieIds) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let ret = movieIds.map((id) => {
|
||||
let r : GQL.SceneMovieInput = {
|
||||
movie_id: id
|
||||
};
|
||||
return r;
|
||||
});
|
||||
|
||||
if (sceneIdx) {
|
||||
sceneIdx.forEach((idx, i) => {
|
||||
if (!!idx && ret.length > i) {
|
||||
ret[i].scene_index = idx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
async function onSave() {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
@@ -150,7 +182,7 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
props.onDelete();
|
||||
}
|
||||
|
||||
function renderMultiSelect(type: "performers" | "tags", initialIds: string[] | undefined) {
|
||||
function renderMultiSelect(type: "performers" | "movies" | "tags", initialIds: string[] | undefined) {
|
||||
return (
|
||||
<FilterMultiSelect
|
||||
type={type}
|
||||
@@ -158,6 +190,7 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
const ids = items.map((i) => i.id);
|
||||
switch (type) {
|
||||
case "performers": setPerformerIds(ids); break;
|
||||
case "movies": setMovieIds(ids); break;
|
||||
case "tags": setTagIds(ids); break;
|
||||
}
|
||||
}}
|
||||
@@ -166,6 +199,19 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
function renderTableMovies( initialIds: string[] | undefined, initialIdx: string[] | undefined ) {
|
||||
return (
|
||||
<SceneMovieTable
|
||||
initialIds={initialIds}
|
||||
initialIdx={initialIdx}
|
||||
onUpdate={(items) => {
|
||||
const idx = items.map((i) => i);
|
||||
setSceneIdx(idx);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function renderDeleteAlert() {
|
||||
return (
|
||||
<>
|
||||
@@ -282,6 +328,28 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
}
|
||||
}
|
||||
|
||||
if ((!movieIds || movieIds.length === 0) && scene.movies && scene.movies.length > 0) {
|
||||
let idMovis = scene.movies.filter((p) => {
|
||||
return p.id !== undefined && p.id !== null;
|
||||
});
|
||||
|
||||
if (idMovis.length > 0) {
|
||||
let newIds = idMovis.map((p) => p.id);
|
||||
setMovieIds(newIds as string[]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((!sceneIdx || sceneIdx.length === 0) && scene.movies && scene.movies.length > 0) {
|
||||
let idxScen= scene.movies.filter((p) => {
|
||||
return p.id !== undefined && p.id !== null;
|
||||
});
|
||||
|
||||
if (idxScen.length > 0) {
|
||||
let newIds = idxScen.map((p) => p.id);
|
||||
setSceneIdx(newIds as string[]);
|
||||
}
|
||||
}
|
||||
|
||||
if ((!tagIds || tagIds.length === 0) && scene.tags && scene.tags.length > 0) {
|
||||
let idTags = scene.tags.filter((p) => {
|
||||
return p.id !== undefined && p.id !== null;
|
||||
@@ -384,6 +452,11 @@ export const SceneEditPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
{renderMultiSelect("performers", performerIds)}
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup label="Movies/Scenes">
|
||||
{renderMultiSelect("movies", movieIds)}
|
||||
{renderTableMovies(movieIds, sceneIdx)}
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup label="Tags">
|
||||
{renderMultiSelect("tags", tagIds)}
|
||||
</FormGroup>
|
||||
|
||||
21
ui/v2/src/components/scenes/SceneDetails/SceneMoviePanel.tsx
Normal file
21
ui/v2/src/components/scenes/SceneDetails/SceneMoviePanel.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React, { FunctionComponent } from "react";
|
||||
import * as GQL from "../../../core/generated-graphql";
|
||||
import { MovieCard } from "../../Movies/MovieCard";
|
||||
|
||||
interface ISceneMoviePanelProps {
|
||||
scene: GQL.SceneDataFragment;
|
||||
}
|
||||
|
||||
export const SceneMoviePanel: FunctionComponent<ISceneMoviePanelProps> = (props: ISceneMoviePanelProps) => {
|
||||
const cards = props.scene.movies.map((sceneMovie) => (
|
||||
<MovieCard key={sceneMovie.movie.id} movie={sceneMovie.movie} sceneIndex={sceneMovie.scene_index} />
|
||||
));
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="grid">
|
||||
{cards}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
117
ui/v2/src/components/scenes/SceneDetails/SceneMovieTable.tsx
Normal file
117
ui/v2/src/components/scenes/SceneDetails/SceneMovieTable.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
import * as React from "react";
|
||||
import { HTMLSelect, Divider} from "@blueprintjs/core";
|
||||
import * as GQL from "../../../core/generated-graphql";
|
||||
import { StashService } from "../../../core/StashService";
|
||||
|
||||
type ValidTypes = GQL.SlimMovieDataFragment;
|
||||
|
||||
export interface IProps {
|
||||
initialIds: string[] | undefined;
|
||||
initialIdx: string[] | undefined;
|
||||
onUpdate: (itemsNumber: string[]) => void;
|
||||
}
|
||||
let items: ValidTypes[];
|
||||
let itemsFilter: ValidTypes[];
|
||||
let storeIdx: string[];
|
||||
|
||||
export const SceneMovieTable: React.FunctionComponent<IProps> = (props: IProps) => {
|
||||
const [itemsNumber, setItemsNumber] = React.useState<string[]>([]);
|
||||
const [initialIdsprev, setinitialIdsprev] = React.useState(props.initialIds);
|
||||
const { data } = StashService.useAllMoviesForFilter();
|
||||
|
||||
items = !!data && !!data.allMovies ? data.allMovies : [];
|
||||
itemsFilter=[];
|
||||
storeIdx=[];
|
||||
|
||||
|
||||
if (!!props.initialIds && !!items && !!props.initialIdx)
|
||||
{
|
||||
for(var i=0; i< props.initialIds!.length; i++)
|
||||
{
|
||||
itemsFilter=itemsFilter.concat(items.filter((x) => x.id ===props.initialIds![i]));
|
||||
}
|
||||
|
||||
}
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
React.useEffect(() => {
|
||||
if (!!props.initialIdx)
|
||||
{
|
||||
setItemsNumber(props.initialIdx);
|
||||
}
|
||||
}, [props.initialIdx]);
|
||||
/* eslint-enable */
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!!props.initialIds) {
|
||||
setinitialIdsprev(props.initialIds);
|
||||
UpdateIndex();
|
||||
}
|
||||
}, [props.initialIds]);
|
||||
|
||||
const updateFieldChanged = (index : any) => (e : any) => {
|
||||
let newArr = [...itemsNumber];
|
||||
newArr[index] = e.target.value;
|
||||
setItemsNumber(newArr);
|
||||
props.onUpdate(newArr);
|
||||
}
|
||||
|
||||
const updateIdsChanged = (index : any, value: string) => {
|
||||
storeIdx.push(value);
|
||||
setItemsNumber(storeIdx);
|
||||
props.onUpdate(storeIdx);
|
||||
}
|
||||
|
||||
|
||||
function UpdateIndex(){
|
||||
|
||||
if (!!props.initialIds && !!initialIdsprev ){
|
||||
loop1:
|
||||
for(var i=0; i< props.initialIds!.length; i++) {
|
||||
for(var j=0; j< initialIdsprev!.length; j++) {
|
||||
|
||||
if (props.initialIds[i]===initialIdsprev[j])
|
||||
{
|
||||
updateIdsChanged(i, props.initialIdx![j]);
|
||||
continue loop1;
|
||||
}
|
||||
}
|
||||
updateIdsChanged(i, "0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function renderTableData() {
|
||||
|
||||
return(
|
||||
<tbody>
|
||||
{ itemsFilter!.map((item, index : any) => (
|
||||
<tr>
|
||||
<td>{item.name} </td>
|
||||
<td><Divider /> </td>
|
||||
<td key={item.toString()}> Scene number: <HTMLSelect
|
||||
options={["","1", "2", "3", "4", "5","6","7","8","9","10"]}
|
||||
onChange={updateFieldChanged(index)}
|
||||
value={itemsNumber[index]}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
<div>
|
||||
<table id='movies'>
|
||||
{renderTableData()}
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,14 @@ export const SceneListTable: FunctionComponent<ISceneListTableProps> = (props: I
|
||||
}
|
||||
}
|
||||
|
||||
function renderMovies(movies : GQL.SlimSceneDataMovies[]) {
|
||||
return movies.map((sceneMovie) => (
|
||||
<Link to={NavigationUtils.makeMovieScenesUrl(sceneMovie.movie)}>
|
||||
<H6>{sceneMovie.movie.name}</H6>
|
||||
</Link>
|
||||
));
|
||||
}
|
||||
|
||||
function renderSceneRow(scene : GQL.SlimSceneDataFragment) {
|
||||
return (
|
||||
<>
|
||||
@@ -93,6 +101,9 @@ export const SceneListTable: FunctionComponent<ISceneListTableProps> = (props: I
|
||||
<td>
|
||||
{renderStudio(scene.studio)}
|
||||
</td>
|
||||
<td>
|
||||
{renderMovies(scene.movies)}
|
||||
</td>
|
||||
</tr>
|
||||
</>
|
||||
)
|
||||
@@ -111,6 +122,7 @@ export const SceneListTable: FunctionComponent<ISceneListTableProps> = (props: I
|
||||
<th>Tags</th>
|
||||
<th>Performers</th>
|
||||
<th>Studio</th>
|
||||
<th>Movies</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -11,14 +11,16 @@ import { ToastUtils } from "../../utils/toasts";
|
||||
const InternalPerformerMultiSelect = MultiSelect.ofType<GQL.AllPerformersForFilterAllPerformers>();
|
||||
const InternalTagMultiSelect = MultiSelect.ofType<GQL.AllTagsForFilterAllTags>();
|
||||
const InternalStudioMultiSelect = MultiSelect.ofType<GQL.AllStudiosForFilterAllStudios>();
|
||||
const InternalMovieMultiSelect = MultiSelect.ofType<GQL.AllMoviesForFilterAllMovies>();
|
||||
|
||||
type ValidTypes =
|
||||
GQL.AllPerformersForFilterAllPerformers |
|
||||
GQL.AllTagsForFilterAllTags |
|
||||
GQL.AllMoviesForFilterAllMovies |
|
||||
GQL.AllStudiosForFilterAllStudios;
|
||||
|
||||
interface IProps extends HTMLInputProps, Partial<IMultiSelectProps<ValidTypes>> {
|
||||
type: "performers" | "studios" | "tags";
|
||||
type: "performers" | "studios" | "movies" | "tags";
|
||||
initialIds?: string[];
|
||||
onUpdate: (items: ValidTypes[]) => void;
|
||||
}
|
||||
@@ -95,7 +97,7 @@ export const FilterMultiSelect: React.FunctionComponent<IProps> = (props: IProps
|
||||
|
||||
function getMultiSelectImpl() {
|
||||
let getInternalMultiSelect: () => new (props: IMultiSelectProps<any>) => MultiSelect<any>;
|
||||
let getData: () => GQL.AllPerformersForFilterQuery | GQL.AllStudiosForFilterQuery | GQL.AllTagsForFilterQuery | undefined;
|
||||
let getData: () => GQL.AllPerformersForFilterQuery | GQL.AllStudiosForFilterQuery | GQL.AllMoviesForFilterQuery | GQL.AllTagsForFilterQuery | undefined;
|
||||
let translateData: () => void;
|
||||
let createNewObject: ((query : string) => void) | undefined = undefined;
|
||||
|
||||
@@ -112,6 +114,13 @@ export const FilterMultiSelect: React.FunctionComponent<IProps> = (props: IProps
|
||||
translateData = () => { let studioData = data as GQL.AllStudiosForFilterQuery; setItems(!!studioData && !!studioData.allStudios ? studioData.allStudios : []); };
|
||||
break;
|
||||
}
|
||||
case "movies": {
|
||||
getInternalMultiSelect = () => { return InternalMovieMultiSelect; };
|
||||
getData = () => { const { data } = StashService.useAllMoviesForFilter(); return data; }
|
||||
translateData = () => { let moviData = data as GQL.AllMoviesForFilterQuery; setItems(!!moviData && !!moviData.allMovies ? moviData.allMovies : []); };
|
||||
break;
|
||||
}
|
||||
|
||||
case "tags": {
|
||||
getInternalMultiSelect = () => { return InternalTagMultiSelect; };
|
||||
getData = () => { const { data } = StashService.useAllTagsForFilter(); return data; }
|
||||
|
||||
@@ -9,14 +9,16 @@ import { HTMLInputProps } from "../../models";
|
||||
const InternalPerformerSelect = Select.ofType<GQL.AllPerformersForFilterAllPerformers>();
|
||||
const InternalTagSelect = Select.ofType<GQL.AllTagsForFilterAllTags>();
|
||||
const InternalStudioSelect = Select.ofType<GQL.AllStudiosForFilterAllStudios>();
|
||||
const InternalMovieSelect = Select.ofType<GQL.AllMoviesForFilterAllMovies>();
|
||||
|
||||
type ValidTypes =
|
||||
GQL.AllPerformersForFilterAllPerformers |
|
||||
GQL.AllTagsForFilterAllTags |
|
||||
GQL.AllStudiosForFilterAllStudios;
|
||||
GQL.AllStudiosForFilterAllStudios |
|
||||
GQL.AllMoviesForFilterAllMovies;
|
||||
|
||||
interface IProps extends HTMLInputProps {
|
||||
type: "performers" | "studios" | "tags";
|
||||
type: "performers" | "studios" | "movies" | "tags";
|
||||
initialId?: string;
|
||||
noSelectionString?: string;
|
||||
onSelectItem: (item: ValidTypes | undefined) => void;
|
||||
@@ -45,6 +47,14 @@ export const FilterSelect: React.FunctionComponent<IProps> = (props: IProps) =>
|
||||
InternalSelect = InternalStudioSelect;
|
||||
break;
|
||||
}
|
||||
case "movies": {
|
||||
const { data } = StashService.useAllMoviesForFilter();
|
||||
items = !!data && !!data.allMovies ? data.allMovies : [];
|
||||
addNoneOption(items);
|
||||
InternalSelect = InternalMovieSelect;
|
||||
break;
|
||||
}
|
||||
|
||||
case "tags": {
|
||||
const { data } = StashService.useAllTagsForFilter();
|
||||
items = !!data && !!data.allTags ? data.allTags : [];
|
||||
|
||||
@@ -163,6 +163,14 @@ export class StashService {
|
||||
});
|
||||
}
|
||||
|
||||
public static useFindMovies(filter: ListFilterModel) {
|
||||
return GQL.useFindMovies({
|
||||
variables: {
|
||||
filter: filter.makeFindFilter(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public static useFindPerformers(filter: ListFilterModel) {
|
||||
let performerFilter = {};
|
||||
// if (!!filter && filter.criteriaFilterOpen) {
|
||||
@@ -205,6 +213,10 @@ export class StashService {
|
||||
const skip = id === "new" ? true : false;
|
||||
return GQL.useFindStudio({ variables: { id }, skip });
|
||||
}
|
||||
public static useFindMovie(id: string) {
|
||||
const skip = id === "new" ? true : false;
|
||||
return GQL.useFindMovie({ variables: { id }, skip });
|
||||
}
|
||||
|
||||
// TODO - scene marker manipulation functions are handled differently
|
||||
private static sceneMarkerMutationImpactedQueries = [
|
||||
@@ -244,6 +256,7 @@ export class StashService {
|
||||
public static useAllTagsForFilter() { return GQL.useAllTagsForFilter(); }
|
||||
public static useAllPerformersForFilter() { return GQL.useAllPerformersForFilter(); }
|
||||
public static useAllStudiosForFilter() { return GQL.useAllStudiosForFilter(); }
|
||||
public static useAllMoviesForFilter() { return GQL.useAllMoviesForFilter(); }
|
||||
public static useValidGalleriesForScene(sceneId: string) {
|
||||
return GQL.useValidGalleriesForScene({ variables: { scene_id: sceneId } });
|
||||
}
|
||||
@@ -283,6 +296,7 @@ export class StashService {
|
||||
"findScenes",
|
||||
"findSceneMarkers",
|
||||
"findStudios",
|
||||
"findMovies",
|
||||
"allTags"
|
||||
// TODO - add "findTags" when it is implemented
|
||||
];
|
||||
@@ -301,6 +315,7 @@ export class StashService {
|
||||
"findPerformers",
|
||||
"findSceneMarkers",
|
||||
"findStudios",
|
||||
"findMovies",
|
||||
"allTags"
|
||||
];
|
||||
|
||||
@@ -367,6 +382,34 @@ export class StashService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static movieMutationImpactedQueries = [
|
||||
"findMovies",
|
||||
"findScenes",
|
||||
"allMovies"
|
||||
];
|
||||
|
||||
public static useMovieCreate(input: GQL.MovieCreateInput) {
|
||||
return GQL.useMovieCreate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.movieMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
public static useMovieUpdate(input: GQL.MovieUpdateInput) {
|
||||
return GQL.useMovieUpdate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.movieMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
public static useMovieDestroy(input: GQL.MovieDestroyInput) {
|
||||
return GQL.useMovieDestroy({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.movieMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
private static tagMutationImpactedQueries = [
|
||||
"findScenes",
|
||||
"findSceneMarkers",
|
||||
|
||||
@@ -60,6 +60,13 @@ const PerformerFilterListImpl: IFilterListImpl = {
|
||||
getCount: (data: any) => { return !!data && !!data.findPerformers ? data.findPerformers.count : 0; }
|
||||
}
|
||||
|
||||
const MoviesFilterListImpl: IFilterListImpl = {
|
||||
getData: (filter : ListFilterModel) => { return StashService.useFindMovies(filter); },
|
||||
getItems: (data: any) => { return !!data && !!data.findMovies ? data.findMovies.movies : []; },
|
||||
getCount: (data: any) => { return !!data && !!data.findMovies ? data.findMovies.count : 0; }
|
||||
}
|
||||
|
||||
|
||||
function getFilterListImpl(filterMode: FilterMode) {
|
||||
switch (filterMode) {
|
||||
case FilterMode.Scenes: {
|
||||
@@ -77,6 +84,9 @@ function getFilterListImpl(filterMode: FilterMode) {
|
||||
case FilterMode.Performers: {
|
||||
return PerformerFilterListImpl;
|
||||
}
|
||||
case FilterMode.Movies: {
|
||||
return MoviesFilterListImpl;
|
||||
}
|
||||
default: {
|
||||
console.error("REMOVE DEFAULT IN LIST HOOK");
|
||||
return SceneFilterListImpl;
|
||||
|
||||
@@ -256,6 +256,32 @@ video.preview.portrait {
|
||||
color: #f5f8fa;
|
||||
}
|
||||
|
||||
.scene-movie-overlay {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: .7em;
|
||||
right: .7em;
|
||||
font-weight: 900;
|
||||
width: 40%;
|
||||
height: 20%;
|
||||
opacity: 0.75;
|
||||
z-index: 9;
|
||||
}
|
||||
|
||||
.scene-movie-overlay a {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-size: contain;
|
||||
display: inline-block;
|
||||
background-position: right top;
|
||||
background-repeat: no-repeat;
|
||||
letter-spacing: -.03em;
|
||||
text-shadow: 0 0 3px #000;
|
||||
text-align: right;
|
||||
text-decoration: none;
|
||||
color: #f5f8fa;
|
||||
}
|
||||
|
||||
.overlay-resolution {
|
||||
font-weight: 900;
|
||||
text-transform: uppercase;
|
||||
@@ -263,13 +289,13 @@ video.preview.portrait {
|
||||
}
|
||||
|
||||
.scene-card {
|
||||
& .scene-specs-overlay, .rating-banner, .scene-studio-overlay {
|
||||
& .scene-specs-overlay, .rating-banner, .scene-studio-overlay, .scene-movie-overlay {
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
}
|
||||
|
||||
.scene-card:hover {
|
||||
& .scene-specs-overlay, .rating-banner, .scene-studio-overlay {
|
||||
& .scene-specs-overlay, .rating-banner, .scene-studio-overlay, .scene-movie-overlay {
|
||||
opacity: 0;
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
@@ -278,6 +304,10 @@ video.preview.portrait {
|
||||
opacity: 0.75;
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
.scene-movie-overlay:hover {
|
||||
opacity: 0.75;
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
}
|
||||
|
||||
.button-link {
|
||||
@@ -377,6 +407,20 @@ span.block {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.movie-tag-container {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.movie-tag.image {
|
||||
height: 150px;
|
||||
width: 100%;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
|
||||
.studio.image {
|
||||
height: 100px;
|
||||
background-size: contain !important;
|
||||
@@ -384,6 +428,14 @@ span.block {
|
||||
background-repeat: no-repeat !important;
|
||||
}
|
||||
|
||||
.movie.image {
|
||||
height: 300px;
|
||||
background-size: contain !important;
|
||||
background-position: center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
}
|
||||
|
||||
|
||||
.no-spacing {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
@@ -455,6 +507,11 @@ span.block {
|
||||
width: 15ch;
|
||||
}
|
||||
|
||||
& .scene-parser-row .parser-field-movie input {
|
||||
width: 15ch;
|
||||
}
|
||||
|
||||
|
||||
& .scene-parser-row input {
|
||||
min-width: 10ch;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export type CriterionType =
|
||||
"sceneTags" |
|
||||
"performers" |
|
||||
"studios" |
|
||||
"movies" |
|
||||
"birth_year" |
|
||||
"age" |
|
||||
"ethnicity" |
|
||||
@@ -44,6 +45,7 @@ export abstract class Criterion<Option = any, Value = any> {
|
||||
case "sceneTags": return "Scene Tags";
|
||||
case "performers": return "Performers";
|
||||
case "studios": return "Studios";
|
||||
case "movies": return "Movies";
|
||||
case "birth_year": return "Birth Year";
|
||||
case "age": return "Age";
|
||||
case "ethnicity": return "Ethnicity";
|
||||
|
||||
@@ -10,7 +10,7 @@ export class IsMissingCriterion extends Criterion<string, string> {
|
||||
public parameterName: string = "is_missing";
|
||||
public modifier = CriterionModifier.Equals;
|
||||
public modifierOptions = [];
|
||||
public options: string[] = ["title", "url", "date", "gallery", "studio", "performers"];
|
||||
public options: string[] = ["title", "url", "date", "gallery", "studio", "movie", "performers"];
|
||||
public value: string = "";
|
||||
}
|
||||
|
||||
|
||||
30
ui/v2/src/models/list-filter/criteria/movies.ts
Normal file
30
ui/v2/src/models/list-filter/criteria/movies.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { CriterionModifier } from "../../../core/generated-graphql";
|
||||
import { ILabeledId } from "../types";
|
||||
import {
|
||||
Criterion,
|
||||
CriterionType,
|
||||
ICriterionOption,
|
||||
} from "./criterion";
|
||||
|
||||
interface IOptionType {
|
||||
id: string;
|
||||
name?: string;
|
||||
image_path?: string;
|
||||
}
|
||||
|
||||
export class MoviesCriterion extends Criterion<IOptionType, ILabeledId[]> {
|
||||
public type: CriterionType = "movies";
|
||||
public parameterName: string = "movies";
|
||||
public modifier = CriterionModifier.Includes;
|
||||
public modifierOptions = [
|
||||
Criterion.getModifierOption(CriterionModifier.Includes),
|
||||
Criterion.getModifierOption(CriterionModifier.Excludes),
|
||||
];
|
||||
public options: IOptionType[] = [];
|
||||
public value: ILabeledId[] = [];
|
||||
}
|
||||
|
||||
export class MoviesCriterionOption implements ICriterionOption {
|
||||
public label: string = Criterion.getLabel("movies");
|
||||
public value: CriterionType = "movies";
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { PerformersCriterion } from "./performers";
|
||||
import { RatingCriterion } from "./rating";
|
||||
import { ResolutionCriterion } from "./resolution";
|
||||
import { StudiosCriterion } from "./studios";
|
||||
import { MoviesCriterion } from "./movies";
|
||||
import { TagsCriterion } from "./tags";
|
||||
|
||||
export function makeCriteria(type: CriterionType = "none") {
|
||||
@@ -26,6 +27,7 @@ export function makeCriteria(type: CriterionType = "none") {
|
||||
case "sceneTags": return new TagsCriterion("sceneTags");
|
||||
case "performers": return new PerformersCriterion();
|
||||
case "studios": return new StudiosCriterion();
|
||||
case "movies": return new MoviesCriterion();
|
||||
|
||||
case "birth_year": return new NumberCriterion(type, type);
|
||||
case "age":
|
||||
|
||||
@@ -16,6 +16,7 @@ import { PerformersCriterion, PerformersCriterionOption } from "./criteria/perfo
|
||||
import { RatingCriterion, RatingCriterionOption } from "./criteria/rating";
|
||||
import { ResolutionCriterion, ResolutionCriterionOption } from "./criteria/resolution";
|
||||
import { StudiosCriterion, StudiosCriterionOption } from "./criteria/studios";
|
||||
import { MoviesCriterion, MoviesCriterionOption } from "./criteria/movies";
|
||||
import { SceneTagsCriterionOption, TagsCriterion, TagsCriterionOption } from "./criteria/tags";
|
||||
import { makeCriteria } from "./criteria/utils";
|
||||
import {
|
||||
@@ -67,12 +68,12 @@ export class ListFilterModel {
|
||||
new RatingCriterionOption(),
|
||||
ListFilterModel.createCriterionOption("o_counter"),
|
||||
new ResolutionCriterionOption(),
|
||||
ListFilterModel.createCriterionOption("duration"),
|
||||
new HasMarkersCriterionOption(),
|
||||
new IsMissingCriterionOption(),
|
||||
new TagsCriterionOption(),
|
||||
new PerformersCriterionOption(),
|
||||
new StudiosCriterionOption(),
|
||||
new MoviesCriterionOption(),
|
||||
];
|
||||
break;
|
||||
case FilterMode.Performers:
|
||||
@@ -116,6 +117,19 @@ export class ListFilterModel {
|
||||
new NoneCriterionOption(),
|
||||
];
|
||||
break;
|
||||
|
||||
case FilterMode.Movies:
|
||||
if (!!this.sortBy === false) { this.sortBy = "name"; }
|
||||
this.sortByOptions = ["name", "scenes_count"];
|
||||
this.displayModeOptions = [
|
||||
DisplayMode.Grid,
|
||||
];
|
||||
this.criterionOptions = [
|
||||
new NoneCriterionOption(),
|
||||
];
|
||||
break;
|
||||
|
||||
|
||||
case FilterMode.Galleries:
|
||||
if (!!this.sortBy === false) { this.sortBy = "path"; }
|
||||
this.sortByOptions = ["path"];
|
||||
@@ -230,9 +244,9 @@ export class ListFilterModel {
|
||||
}
|
||||
|
||||
private setRandomSeed() {
|
||||
if (this.sortBy == "random") {
|
||||
if (this.sortBy === "random") {
|
||||
// #321 - set the random seed if it is not set
|
||||
if (this.randomSeed == -1) {
|
||||
if (this.randomSeed === -1) {
|
||||
// generate 8-digit seed
|
||||
this.randomSeed = Math.floor(Math.random() * Math.pow(10, 8));
|
||||
}
|
||||
@@ -244,7 +258,7 @@ export class ListFilterModel {
|
||||
private getSortBy(): string | undefined {
|
||||
this.setRandomSeed();
|
||||
|
||||
if (this.sortBy == "random") {
|
||||
if (this.sortBy === "random") {
|
||||
return this.sortBy + "_" + this.randomSeed.toString();
|
||||
}
|
||||
|
||||
@@ -335,6 +349,11 @@ export class ListFilterModel {
|
||||
const studCrit = criterion as StudiosCriterion;
|
||||
result.studios = { value: studCrit.value.map((studio) => studio.id), modifier: studCrit.modifier };
|
||||
break;
|
||||
case "movies":
|
||||
const movieCrit = criterion as MoviesCriterion;
|
||||
result.movies = { value: movieCrit.value.map((movie) => movie.id), modifier: movieCrit.modifier };
|
||||
break;
|
||||
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// NOTE: add new enum values to the end, to ensure existing data
|
||||
// is not impacted
|
||||
export enum DisplayMode {
|
||||
Grid,
|
||||
List,
|
||||
@@ -10,6 +12,7 @@ export enum FilterMode {
|
||||
Studios,
|
||||
Galleries,
|
||||
SceneMarkers,
|
||||
Movies,
|
||||
}
|
||||
|
||||
export interface ILabeledId {
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
object-fit: contain;
|
||||
box-shadow: 0px 0px 10px black;
|
||||
}
|
||||
|
||||
& img.movie {
|
||||
height: 50%;
|
||||
max-width: 50%;
|
||||
object-fit: contain;
|
||||
box-shadow: 0px 0px 10px black;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.details-detail-container {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as GQL from "../core/generated-graphql";
|
||||
import { PerformersCriterion } from "../models/list-filter/criteria/performers";
|
||||
import { StudiosCriterion } from "../models/list-filter/criteria/studios";
|
||||
import { MoviesCriterion } from "../models/list-filter/criteria/movies";
|
||||
import { TagsCriterion } from "../models/list-filter/criteria/tags";
|
||||
import { ListFilterModel } from "../models/list-filter/filter";
|
||||
import { FilterMode } from "../models/list-filter/types";
|
||||
@@ -24,6 +25,15 @@ export class NavigationUtils {
|
||||
return `/scenes?${filter.makeQueryParameters()}`;
|
||||
}
|
||||
|
||||
public static makeMovieScenesUrl(movie: Partial<GQL.MovieDataFragment>): string {
|
||||
if (movie.id === undefined) { return "#"; }
|
||||
const filter = new ListFilterModel(FilterMode.Scenes);
|
||||
const criterion = new MoviesCriterion();
|
||||
criterion.value = [{ id: movie.id, label: movie.name || `Movie ${movie.id}` }];
|
||||
filter.criteria.push(criterion);
|
||||
return `/scenes?${filter.makeQueryParameters()}`;
|
||||
}
|
||||
|
||||
public static makeTagScenesUrl(tag: Partial<GQL.TagDataFragment>): string {
|
||||
if (tag.id === undefined) { return "#"; }
|
||||
const filter = new ListFilterModel(FilterMode.Scenes);
|
||||
|
||||
Reference in New Issue
Block a user