Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Movie URLs #4900

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions graphql/schema/types/movie.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type Movie {
studio: Studio
director: String
synopsis: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]!
created_at: Time!
updated_at: Time!

Expand All @@ -31,7 +32,8 @@ input MovieCreateInput {
studio_id: ID
director: String
synopsis: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
"This should be a URL or a base64 encoded data URL"
front_image: String
"This should be a URL or a base64 encoded data URL"
Expand All @@ -49,7 +51,8 @@ input MovieUpdateInput {
studio_id: ID
director: String
synopsis: String
url: String
url: String @deprecated(reason: "Use urls")
urls: [String!]
"This should be a URL or a base64 encoded data URL"
front_image: String
"This should be a URL or a base64 encoded data URL"
Expand All @@ -63,6 +66,7 @@ input BulkMovieUpdateInput {
rating100: Int
studio_id: ID
director: String
urls: BulkUpdateStrings
}

input MovieDestroyInput {
Expand Down
6 changes: 4 additions & 2 deletions graphql/schema/types/scraped-movie.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type ScrapedMovie {
date: String
rating: String
director: String
url: String
url: String @deprecated(reason: "use urls")
urls: [String!]
synopsis: String
studio: ScrapedStudio

Expand All @@ -24,6 +25,7 @@ input ScrapedMovieInput {
date: String
rating: String
director: String
url: String
url: String @deprecated(reason: "use urls")
urls: [String!]
synopsis: String
}
29 changes: 29 additions & 0 deletions internal/api/resolver_model_movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@ func (r *movieResolver) Rating100(ctx context.Context, obj *models.Movie) (*int,
return obj.Rating, nil
}

func (r *movieResolver) URL(ctx context.Context, obj *models.Movie) (*string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Movie)
}); err != nil {
return nil, err
}
}

urls := obj.URLs.List()
if len(urls) == 0 {
return nil, nil
}

return &urls[0], nil
}

func (r *movieResolver) Urls(ctx context.Context, obj *models.Movie) ([]string, error) {
if !obj.URLs.Loaded() {
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
return obj.LoadURLs(ctx, r.repository.Movie)
}); err != nil {
return nil, err
}
}

return obj.URLs.List(), nil
}

func (r *movieResolver) Studio(ctx context.Context, obj *models.Movie) (ret *models.Studio, err error) {
if obj.StudioID == nil {
return nil, nil
Expand Down
11 changes: 9 additions & 2 deletions internal/api/resolver_mutation_movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (r *mutationResolver) MovieCreate(ctx context.Context, input MovieCreateInp
newMovie.Rating = input.Rating100
newMovie.Director = translator.string(input.Director)
newMovie.Synopsis = translator.string(input.Synopsis)
newMovie.URL = translator.string(input.URL)

var err error

Expand All @@ -51,6 +50,12 @@ func (r *mutationResolver) MovieCreate(ctx context.Context, input MovieCreateInp
return nil, fmt.Errorf("converting studio id: %w", err)
}

if input.Urls != nil {
newMovie.URLs = models.NewRelatedStrings(input.Urls)
} else if input.URL != nil {
newMovie.URLs = models.NewRelatedStrings([]string{*input.URL})
}

// Process the base 64 encoded image string
var frontimageData []byte
if input.FrontImage != nil {
Expand Down Expand Up @@ -125,7 +130,6 @@ func (r *mutationResolver) MovieUpdate(ctx context.Context, input MovieUpdateInp
updatedMovie.Rating = translator.optionalInt(input.Rating100, "rating100")
updatedMovie.Director = translator.optionalString(input.Director, "director")
updatedMovie.Synopsis = translator.optionalString(input.Synopsis, "synopsis")
updatedMovie.URL = translator.optionalString(input.URL, "url")

updatedMovie.Date, err = translator.optionalDate(input.Date, "date")
if err != nil {
Expand All @@ -136,6 +140,8 @@ func (r *mutationResolver) MovieUpdate(ctx context.Context, input MovieUpdateInp
return nil, fmt.Errorf("converting studio id: %w", err)
}

updatedMovie.URLs = translator.optionalURLs(input.Urls, input.URL)

var frontimageData []byte
frontImageIncluded := translator.hasField("front_image")
if input.FrontImage != nil {
Expand Down Expand Up @@ -205,6 +211,7 @@ func (r *mutationResolver) BulkMovieUpdate(ctx context.Context, input BulkMovieU
if err != nil {
return nil, fmt.Errorf("converting studio id: %w", err)
}
updatedMovie.URLs = translator.optionalURLsBulk(input.Urls, nil)

ret := []*models.Movie{}

Expand Down
5 changes: 5 additions & 0 deletions internal/manager/task_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,11 @@ func (t *ExportTask) exportMovie(ctx context.Context, wg *sync.WaitGroup, jobCha
studioReader := r.Studio

for m := range jobChan {
if err := m.LoadURLs(ctx, r.Movie); err != nil {
logger.Errorf("[movies] <%s> error getting movie urls: %v", m.Name, err)
continue
}

newMovieJSON, err := movie.ToJSON(ctx, movieReader, studioReader, m)

if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/models/jsonschema/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ type Movie struct {
Synopsis string `json:"synopsis,omitempty"`
FrontImage string `json:"front_image,omitempty"`
BackImage string `json:"back_image,omitempty"`
URL string `json:"url,omitempty"`
URLs []string `json:"urls,omitempty"`
Studio string `json:"studio,omitempty"`
CreatedAt json.JSONTime `json:"created_at,omitempty"`
UpdatedAt json.JSONTime `json:"updated_at,omitempty"`

// deprecated - for import only
URL string `json:"url,omitempty"`
}

func (s Movie) Filename() string {
Expand Down
23 changes: 23 additions & 0 deletions pkg/models/mocks/MovieReaderWriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions pkg/models/model_movie.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"context"
"time"
)

Expand All @@ -15,9 +16,10 @@ type Movie struct {
StudioID *int `json:"studio_id"`
Director string `json:"director"`
Synopsis string `json:"synopsis"`
URL string `json:"url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`

URLs RelatedStrings `json:"urls"`
}

func NewMovie() Movie {
Expand All @@ -28,6 +30,12 @@ func NewMovie() Movie {
}
}

func (g *Movie) LoadURLs(ctx context.Context, l URLLoader) error {
return g.URLs.load(func() ([]string, error) {
return l.GetURLs(ctx, g.ID)
})
}

type MoviePartial struct {
Name OptionalString
Aliases OptionalString
Expand All @@ -38,7 +46,7 @@ type MoviePartial struct {
StudioID OptionalInt
Director OptionalString
Synopsis OptionalString
URL OptionalString
URLs *UpdateStrings
CreatedAt OptionalTime
UpdatedAt OptionalTime
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/models/model_scraped_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,16 @@ type ScrapedMovie struct {
Date *string `json:"date"`
Rating *string `json:"rating"`
Director *string `json:"director"`
URL *string `json:"url"`
URLs []string `json:"urls"`
Synopsis *string `json:"synopsis"`
Studio *ScrapedStudio `json:"studio"`
// This should be a base64 encoded data URL
FrontImage *string `json:"front_image"`
// This should be a base64 encoded data URL
BackImage *string `json:"back_image"`

// deprecated
URL *string `json:"url"`
}

func (ScrapedMovie) IsScrapedContent() {}
1 change: 1 addition & 0 deletions pkg/models/repository_movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type MovieReader interface {
MovieFinder
MovieQueryer
MovieCounter
URLLoader

All(ctx context.Context) ([]*Movie, error)
GetFrontImage(ctx context.Context, movieID int) ([]byte, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/movie/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ToJSON(ctx context.Context, reader ImageGetter, studioReader models.StudioG
Aliases: movie.Aliases,
Director: movie.Director,
Synopsis: movie.Synopsis,
URL: movie.URL,
URLs: movie.URLs.List(),
CreatedAt: json.JSONTime{Time: movie.CreatedAt},
UpdatedAt: json.JSONTime{Time: movie.UpdatedAt},
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/movie/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func createFullMovie(id int, studioID int) models.Movie {
Duration: &duration,
Director: director,
Synopsis: synopsis,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
StudioID: &studioID,
CreatedAt: createTime,
UpdatedAt: updateTime,
Expand All @@ -82,6 +82,7 @@ func createFullMovie(id int, studioID int) models.Movie {
func createEmptyMovie(id int) models.Movie {
return models.Movie{
ID: id,
URLs: models.NewRelatedStrings([]string{}),
CreatedAt: createTime,
UpdatedAt: updateTime,
}
Expand All @@ -96,7 +97,7 @@ func createFullJSONMovie(studio, frontImage, backImage string) *jsonschema.Movie
Duration: duration,
Director: director,
Synopsis: synopsis,
URL: url,
URLs: []string{url},
Studio: studio,
FrontImage: frontImage,
BackImage: backImage,
Expand All @@ -111,6 +112,7 @@ func createFullJSONMovie(studio, frontImage, backImage string) *jsonschema.Movie

func createEmptyJSONMovie() *jsonschema.Movie {
return &jsonschema.Movie{
URLs: []string{},
CreatedAt: json.JSONTime{
Time: createTime,
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/movie/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ func (i *Importer) movieJSONToMovie(movieJSON jsonschema.Movie) models.Movie {
Aliases: movieJSON.Aliases,
Director: movieJSON.Director,
Synopsis: movieJSON.Synopsis,
URL: movieJSON.URL,
CreatedAt: movieJSON.CreatedAt.GetTime(),
UpdatedAt: movieJSON.UpdatedAt.GetTime(),
}

if len(movieJSON.URLs) > 0 {
newMovie.URLs = models.NewRelatedStrings(movieJSON.URLs)
} else if movieJSON.URL != "" {
newMovie.URLs = models.NewRelatedStrings([]string{movieJSON.URL})
}
if movieJSON.Date != "" {
d, err := models.ParseDate(movieJSON.Date)
if err == nil {
Expand Down
19 changes: 11 additions & 8 deletions pkg/scraper/movie.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package scraper

type ScrapedMovieInput struct {
Name *string `json:"name"`
Aliases *string `json:"aliases"`
Duration *string `json:"duration"`
Date *string `json:"date"`
Rating *string `json:"rating"`
Director *string `json:"director"`
URL *string `json:"url"`
Synopsis *string `json:"synopsis"`
Name *string `json:"name"`
Aliases *string `json:"aliases"`
Duration *string `json:"duration"`
Date *string `json:"date"`
Rating *string `json:"rating"`
Director *string `json:"director"`
URLs []string `json:"urls"`
Synopsis *string `json:"synopsis"`

// deprecated
URL *string `json:"url"`
}
8 changes: 4 additions & 4 deletions pkg/sqlite/anonymise.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ func (db *Anonymiser) anonymiseMovies(ctx context.Context) error {
table.Col("name"),
table.Col("aliases"),
table.Col("synopsis"),
table.Col("url"),
table.Col("director"),
).Where(table.Col(idColumn).Gt(lastID)).Limit(1000)

Expand All @@ -860,7 +859,6 @@ func (db *Anonymiser) anonymiseMovies(ctx context.Context) error {
name sql.NullString
aliases sql.NullString
synopsis sql.NullString
url sql.NullString
director sql.NullString
)

Expand All @@ -869,7 +867,6 @@ func (db *Anonymiser) anonymiseMovies(ctx context.Context) error {
&name,
&aliases,
&synopsis,
&url,
&director,
); err != nil {
return err
Expand All @@ -879,7 +876,6 @@ func (db *Anonymiser) anonymiseMovies(ctx context.Context) error {
db.obfuscateNullString(set, "name", name)
db.obfuscateNullString(set, "aliases", aliases)
db.obfuscateNullString(set, "synopsis", synopsis)
db.obfuscateNullString(set, "url", url)
db.obfuscateNullString(set, "director", director)

if len(set) > 0 {
Expand All @@ -905,6 +901,10 @@ func (db *Anonymiser) anonymiseMovies(ctx context.Context) error {
}
}

if err := db.anonymiseURLs(ctx, goqu.T(movieURLsTable), "movie_id"); err != nil {
return err
}

return nil
}

Expand Down
Loading
Loading