diff --git a/server/content.go b/server/content.go index 4d81d75c..b0c7833b 100644 --- a/server/content.go +++ b/server/content.go @@ -257,11 +257,20 @@ func searchContent(query string, pageNum int) (TMDBSearchMultiResponse, error) { } func searchMovies(query string, pageNum int) (TMDBSearchMoviesResponse, error) { + return searchMoviesWithYear(query, pageNum, 0) +} + +func searchMoviesWithYear(query string, pageNum int, year int) (TMDBSearchMoviesResponse, error) { resp := new(TMDBSearchMoviesResponse) if pageNum == 0 { pageNum = 1 } - err := tmdbRequest("/search/movie", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp) + params := map[string]string{"query": query, "page": strconv.Itoa(pageNum)} + if year != 0 { + params["year"] = strconv.Itoa(year) + } + err := tmdbRequest("/search/movie", params, &resp) + if err != nil { slog.Error("Failed to complete movie search request!", "error", err.Error()) return TMDBSearchMoviesResponse{}, errors.New("failed to complete movie search request") @@ -273,11 +282,19 @@ func searchMovies(query string, pageNum int) (TMDBSearchMoviesResponse, error) { } func searchTv(query string, pageNum int) (TMDBSearchShowsResponse, error) { + return searchTvWithYear(query, pageNum, 0) +} + +func searchTvWithYear(query string, pageNum int, year int) (TMDBSearchShowsResponse, error) { resp := new(TMDBSearchShowsResponse) if pageNum == 0 { pageNum = 1 } - err := tmdbRequest("/search/tv", map[string]string{"query": query, "page": strconv.Itoa(pageNum)}, &resp) + params := map[string]string{"query": query, "page": strconv.Itoa(pageNum)} + if year != 0 { + params["year"] = strconv.Itoa(year) + } + err := tmdbRequest("/search/tv", params, &resp) if err != nil { slog.Error("Failed to complete tv search request!", "error", err.Error()) return TMDBSearchShowsResponse{}, errors.New("failed to complete tv search request") diff --git a/server/import.go b/server/import.go index 6de09a12..c8fe3278 100644 --- a/server/import.go +++ b/server/import.go @@ -39,6 +39,7 @@ type ImportRequest struct { WatchedEpisodes []WatchedEpisode `json:"watchedEpisodes"` WatchedSeason []WatchedSeason `json:"watchedSeasons"` Tags []TagAddRequest `json:"tags"` + Year int `json:"year"` } type ImportResponse struct { @@ -72,15 +73,75 @@ func importContent(db *gorm.DB, userId uint, ar ImportRequest) (ImportResponse, } } // tmdbId not passed.. search for the content by name. - sr, err := searchContent(ar.Name, 1) - if err != nil { - slog.Error("import: content search failed", "error", err) - return ImportResponse{}, errors.New("Content search failed") - } + // if a type is passed, use that type to filter the search results. pMatches := []TMDBSearchMultiResults{} - for _, r := range sr.Results { - if r.MediaType != "person" { - pMatches = append(pMatches, r) + if ar.Type == MOVIE { + movieRes, err := searchMoviesWithYear(ar.Name, 1, ar.Year) + if err != nil { + slog.Error("import: content search failed", "error", err) + return ImportResponse{}, errors.New("Content search failed") + } + for _, m := range movieRes.Results { + // Convert []int to []int64 + genreIds := make([]int64, len(m.GenreIds)) + for i, id := range m.GenreIds { + genreIds[i] = int64(id) + } + pMatches = append(pMatches, TMDBSearchMultiResults{ + Adult: m.Adult, + BackdropPath: m.BackdropPath, + GenreIds: genreIds, + ID: m.ID, + OriginalLanguage: m.OriginalLanguage, + Overview: m.Overview, + Popularity: float32(m.Popularity), + PosterPath: m.PosterPath, + Title: m.Title, + VoteAverage: float32(m.VoteAverage), + VoteCount: uint32(m.VoteCount), + MediaType: "movie", + }) + } + } else if ar.Type == SHOW { + tvRes, err := searchTvWithYear(ar.Name, 1, ar.Year) + if err != nil { + slog.Error("import: content search failed", "error", err) + return ImportResponse{}, errors.New("Content search failed") + } + for _, m := range tvRes.Results { + genreIds := make([]int64, len(m.GenreIds)) + for i, id := range m.GenreIds { + genreIds[i] = int64(id) + } + pMatches = append(pMatches, TMDBSearchMultiResults{ + Adult: m.Adult, + BackdropPath: m.BackdropPath, + GenreIds: genreIds, + ID: m.ID, + OriginalLanguage: m.OriginalLanguage, + OriginalName: m.OriginalName, + OriginCountry: m.OriginCountry, + Overview: m.Overview, + Popularity: float32(m.Popularity), + PosterPath: m.PosterPath, + FirstAirDate: m.FirstAirDate, + Name: m.Name, + VoteAverage: float32(m.VoteAverage), + VoteCount: uint32(m.VoteCount), + MediaType: "tv", + }) + } + } + if len(pMatches) == 0 { + sr, err := searchContent(ar.Name, 1) + if err != nil { + slog.Error("import: content search failed", "error", err) + return ImportResponse{}, errors.New("Content search failed") + } + for _, r := range sr.Results { + if r.MediaType != "person" { + pMatches = append(pMatches, r) + } } } resLen := len(pMatches) diff --git a/src/lib/Icon.svelte b/src/lib/Icon.svelte index de0169d3..0c351785 100644 --- a/src/lib/Icon.svelte +++ b/src/lib/Icon.svelte @@ -441,6 +441,17 @@ d="M490.18 181.4l-44.13-44.13a20 20 0 00-27-1 30.81 30.81 0 01-41.68-1.6 30.81 30.81 0 01-1.6-41.67 20 20 0 00-1-27L330.6 21.82a19.91 19.91 0 00-28.13 0l-70.35 70.34a39.87 39.87 0 00-9.57 15.5 7.71 7.71 0 01-4.83 4.83 39.78 39.78 0 00-15.5 9.58l-180.4 180.4a19.91 19.91 0 000 28.13L66 374.73a20 20 0 0027 1 30.69 30.69 0 0143.28 43.28 20 20 0 001 27l44.13 44.13a19.91 19.91 0 0028.13 0l180.4-180.4a39.82 39.82 0 009.58-15.49 7.69 7.69 0 014.84-4.84 39.84 39.84 0 0015.49-9.57l70.34-70.35a19.91 19.91 0 00-.01-28.09zm-228.37-29.65a16 16 0 01-22.63 0l-11.51-11.51a16 16 0 0122.63-22.62l11.51 11.5a16 16 0 010 22.63zm44 44a16 16 0 01-22.62 0l-11-11a16 16 0 1122.63-22.63l11 11a16 16 0 01.01 22.66zm44 44a16 16 0 01-22.63 0l-11-11a16 16 0 0122.63-22.62l11 11a16 16 0 01.05 22.67zm44.43 44.54a16 16 0 01-22.63 0l-11.44-11.5a16 16 0 1122.68-22.57l11.45 11.49a16 16 0 01-.01 22.63z" /> +{:else if i === "anilist"} + + + + {/if}