diff --git a/cmd/root.go b/cmd/root.go index e42302e..0e5f5c4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -62,10 +62,7 @@ func initializeFlags() { func initializePlexMovies() []types.PlexMovie { var allMovies []types.PlexMovie - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, types.PlexResolution240, nil)...) - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, types.PlexResolution480, nil)...) - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, types.PlexResolution576, nil)...) - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, types.PlexResolution720, nil)...) + allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, nil)...) fmt.Printf("\nThere are a total of %d movies in the library.\n\nMovies available:\n", len(allMovies)) return allMovies diff --git a/plex/plex.go b/plex/plex.go index 54a46bd..6c6c10d 100644 --- a/plex/plex.go +++ b/plex/plex.go @@ -473,13 +473,8 @@ type Filter struct { Modifier string } -func GetPlexMovies(ipAddress, libraryID, plexToken, resolution string, filters []Filter) (movieList []types.PlexMovie) { - url := fmt.Sprintf("http://%s:32400/library/sections/%s", ipAddress, libraryID) - if resolution == "" { - url += "/all" - } else { - url += fmt.Sprintf("/resolution/%s", resolution) - } +func GetPlexMovies(ipAddress, libraryID, plexToken string, filters []Filter) (movieList []types.PlexMovie) { + url := fmt.Sprintf("http://%s:32400/library/sections/%s/all", ipAddress, libraryID) for i := range filters { if i == 0 { @@ -514,7 +509,7 @@ func GetPlexMovies(ipAddress, libraryID, plexToken, resolution string, filters [ } movieList = extractMovies(string(body)) - fmt.Printf("Movies at resolution %s: %v\n", resolution, movieList) + fmt.Printf("Movies: %v\n", movieList) return movieList } @@ -528,9 +523,10 @@ func extractMovies(xmlString string) (movieList []types.PlexMovie) { for i := range container.Video { movieList = append(movieList, types.PlexMovie{ - Title: container.Video[i].Title, - Year: container.Video[i].Year, - DateAdded: parsePlexDate(container.Video[i].AddedAt)}) + Title: container.Video[i].Title, + Year: container.Video[i].Year, + Resolution: container.Video[i].Media.VideoResolution, + DateAdded: parsePlexDate(container.Video[i].AddedAt)}) } return movieList } diff --git a/plex/plex_test.go b/plex/plex_test.go index 823523f..a23374e 100644 --- a/plex/plex_test.go +++ b/plex/plex_test.go @@ -25,9 +25,10 @@ func TestFindMovieDetails(t *testing.T) { processed := extractMovies(string(rawdata)) expected := []types.PlexMovie{ { - Title: "Chaos Theory", - Year: "2007", - DateAdded: time.Date(2023, time.January, 21, 15, 03, 10, 0, time.FixedZone("GMT", 0)), + Title: "Chaos Theory", + Year: "2007", + Resolution: "sd", + DateAdded: time.Date(2023, time.January, 21, 15, 03, 10, 0, time.FixedZone("GMT", 0)), }, } @@ -46,13 +47,17 @@ func TestFindMovieDetails(t *testing.T) { if processed[0].DateAdded.Compare(expected[0].DateAdded) != 0 { t.Errorf("Expected date %s, but got %s", expected[0].DateAdded, processed[0].DateAdded) } + + if processed[0].Resolution != expected[0].Resolution { + t.Errorf("Expected resolution %s, but got %s", expected[0].Resolution, processed[0].Resolution) + } } func TestGetPlexMovies(t *testing.T) { if plexIP == "" || plexMovieLibraryID == "" || plexToken == "" { t.Skip("ACCEPTANCE TEST: PLEX environment variables not set") } - result := GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, "", nil) + result := GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, nil) if len(result) == 0 { t.Errorf("Expected at least one TV show, but got %d", len(result)) diff --git a/types/types.go b/types/types.go index b8b2306..f38f180 100644 --- a/types/types.go +++ b/types/types.go @@ -47,9 +47,10 @@ type FilteringOptions struct { // ============================================================================================================== type PlexMovie struct { - Title string - Year string - DateAdded time.Time + Title string + Year string + Resolution string + DateAdded time.Time } type MovieSearchResult struct { diff --git a/web/movies/movies.go b/web/movies/movies.go index 4d01c19..0ad5f84 100644 --- a/web/movies/movies.go +++ b/web/movies/movies.go @@ -39,29 +39,14 @@ func MoviesHandler(w http.ResponseWriter, _ *http.Request) { func (c MoviesConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) { lookup := r.FormValue("lookup") - // plex resolutions - sd := r.FormValue("sd") - r240 := r.FormValue("240") - r480 := r.FormValue("480") - r576 := r.FormValue("576") - r720 := r.FormValue("720") - r1080 := r.FormValue("1080") - r4k := r.FormValue("4k") - plexResolutions := []string{sd, r240, r480, r576, r720, r1080, r4k} - // remove empty resolutions - var filteredResolutions []string - for _, resolution := range plexResolutions { - if resolution != "" { - filteredResolutions = append(filteredResolutions, resolution) - } - } // lookup filters german := r.FormValue("german") newerVersion := r.FormValue("newerVersion") - // Prepare table plexMovies - - plexMovies = fetchPlexMovies(c.Config.PlexIP, c.Config.PlexMovieLibraryID, c.Config.PlexToken, filteredResolutions, german) - + // fetch from plex + plexMovies = fetchPlexMovies(c.Config.PlexIP, c.Config.PlexMovieLibraryID, c.Config.PlexToken, german) + //nolint: gocritic + // plexMovies = plexMovies[:10] + //nolint: gocritic var searchResult types.SearchResults jobRunning = true numberOfMoviesProcessed = 0 @@ -116,12 +101,12 @@ func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) { } func renderTable(movieCollection []types.SearchResults) (tableRows string) { - tableRows = `<thead><tr><th data-sort="string"><strong>Plex Title</strong></th><th data-sort="int"><strong>Blu-ray</strong></th><th data-sort="int"><strong>4K-ray</strong></th><th><strong>Disc</strong></th></tr></thead><tbody>` //nolint: lll + tableRows = `<thead><tr><th data-sort="string"><strong>Plex Title</strong></th><th data-sort="string"><strong>Plex Resolution</strong></th><th data-sort="int"><strong>Blu-ray</strong></th><th data-sort="int"><strong>4K-ray</strong></th><th><strong>Disc</strong></th></tr></thead><tbody>` //nolint: lll for i := range movieCollection { tableRows += fmt.Sprintf( - `<tr><td><a href=%q target="_blank">%s [%v]</a></td><td>%d</td><td>%d</td>`, + `<tr><td><a href=%q target="_blank">%s [%v]</a></td><td>%s</td><td>%d</td><td>%d</td>`, movieCollection[i].SearchURL, movieCollection[i].PlexMovie.Title, movieCollection[i].PlexMovie.Year, - movieCollection[i].MatchesBluray, movieCollection[i].Matches4k) + movieCollection[i].PlexMovie.Resolution, movieCollection[i].MatchesBluray, movieCollection[i].Matches4k) if movieCollection[i].MatchesBluray+movieCollection[i].Matches4k > 0 { tableRows += "<td>" for _, result := range movieCollection[i].MovieSearchResults { @@ -144,7 +129,7 @@ func renderTable(movieCollection []types.SearchResults) (tableRows string) { return tableRows // Return the generated HTML for table rows } -func fetchPlexMovies(plexIP, plexMovieLibraryID, plexToken string, plexResolutions []string, german string) (allMovies []types.PlexMovie) { +func fetchPlexMovies(plexIP, plexMovieLibraryID, plexToken, german string) (allMovies []types.PlexMovie) { filter := []plex.Filter{} if german == types.StringTrue { filter = []plex.Filter{ @@ -160,12 +145,6 @@ func fetchPlexMovies(plexIP, plexMovieLibraryID, plexToken string, plexResolutio // }, } } - if len(plexResolutions) == 0 { - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, "", filter)...) - } else { - for _, resolution := range plexResolutions { - allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, resolution, filter)...) - } - } + allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken, filter)...) return allMovies } diff --git a/web/movies/movies.html b/web/movies/movies.html index d8fafc1..0eb782d 100644 --- a/web/movies/movies.html +++ b/web/movies/movies.html @@ -27,33 +27,6 @@ <h1 class="container">Movies</h1> <div hx-get="/settings/plexinfook" class="container" hx-trigger="load"></div> <form hx-post="/moviesprocess" class="container" hx-target="#progress" hx-boost="true"> - <fieldset> - <legend><strong>Plex Filter:</strong> only compare movies that match the following criteria.</legend> - <label for="title" data-sort="title"> - <input type="checkbox" id="sd" name="sd" value="sd"> - SD - </label> - <label for="title" data-sort="title"> - <input type="checkbox" id="480" name="480" value="480"> - 480p - </label> - <label for="title" data-sort="title"> - <input type="checkbox" id="576" name="576" value="576"> - 576p - </label> - <label for="title" data-sort="title"> - <input type="checkbox" id="720" name="720" value="720"> - 720p - </label> - <label for="title" data-sort="title"> - <input type="checkbox" id="1080" name="1080" value="1080"> - 1080p - </label> - <label for="title" data-sort="title"> - <input type="checkbox" id="4k" name="4k" value="4k"> - 4K - </label> - </fieldset> <fieldset> <legend><strong>Lookup:</strong></legend> <label for="amazon">