diff --git a/Dockerfile b/Dockerfile index 40664a6..d2c989f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,16 @@ COPY plex/*.go plex/ COPY spotify/*.go spotify/ COPY types/*.go types/ COPY utils/*.go utils/ -COPY web/*.go web/ -COPY web/*.html web/ -COPY web/static/* web/static/ + +COPY web/movies/*.go web/movies/ +COPY web/movies/*.html web/movies/ +COPY web/music/*.go web/music/ +COPY web/music/*.html web/music/ +COPY web/tv/*.go web/tv/ +COPY web/tv/*.html web/tv/ +COPY web/settings/*.go web/settings/ +COPY web/settings/*.html web/settings/ +COPY web/server.go web/index.html web/static/ /web/ # Build RUN CGO_ENABLED=0 GOOS=linux go build -o /plex-lookup diff --git a/types/types.go b/types/types.go index 6e59e53..69fa540 100644 --- a/types/types.go +++ b/types/types.go @@ -15,6 +15,7 @@ const ( PlexResolution1080 = "1080" PlexResolution4K = "4k" ConcurrencyLimit = 10 + StringTrue = "true" ) type SearchResults struct { @@ -39,6 +40,11 @@ type Configuration struct { SpotifyClientSecret string } +type FilteringOptions struct { + AudioLanguage string + NewerVersion bool +} + // ============================================================================================================== type PlexMovie struct { Title string diff --git a/web/index.html b/web/index.html index e17f89b..cd10fe6 100644 --- a/web/index.html +++ b/web/index.html @@ -14,7 +14,7 @@

Plex lookup

Connect to your Plex library and scan your movies and TV shows. Then search for Higher quality versions of them (Blu-ray, 4k Blu-ray) on Amazon or CinemaParadiso.
- Plex configuration + Settings
Lookup Movies
diff --git a/web/movies.go b/web/movies/movies.go similarity index 82% rename from web/movies.go rename to web/movies/movies.go index 69876b4..4d01c19 100644 --- a/web/movies.go +++ b/web/movies/movies.go @@ -1,4 +1,4 @@ -package web +package movies import ( _ "embed" @@ -13,10 +13,6 @@ import ( "github.com/tphoney/plex-lookup/types" ) -const ( - stringTrue = "true" -) - var ( //go:embed movies.html moviesPage string @@ -25,9 +21,14 @@ var ( jobRunning bool = false totalMovies int = 0 searchResults []types.SearchResults + plexMovies []types.PlexMovie ) -func moviesHandler(w http.ResponseWriter, _ *http.Request) { +type MoviesConfig struct { + Config *types.Configuration +} + +func MoviesHandler(w http.ResponseWriter, _ *http.Request) { tmpl := template.Must(template.New("movies").Parse(moviesPage)) err := tmpl.Execute(w, nil) if err != nil { @@ -36,16 +37,16 @@ func moviesHandler(w http.ResponseWriter, _ *http.Request) { } } -func processMoviesHTML(w http.ResponseWriter, r *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("240p") - r480 := r.FormValue("480p") - r576 := r.FormValue("576p") - r720 := r.FormValue("720p") - r1080 := r.FormValue("1080p") - r4k := r.FormValue("4K") + 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 @@ -58,14 +59,16 @@ func processMoviesHTML(w http.ResponseWriter, r *http.Request) { german := r.FormValue("german") newerVersion := r.FormValue("newerVersion") // Prepare table plexMovies - plexMovies := fetchPlexMovies(config.PlexIP, config.PlexMovieLibraryID, config.PlexToken, filteredResolutions, german) + + plexMovies = fetchPlexMovies(c.Config.PlexIP, c.Config.PlexMovieLibraryID, c.Config.PlexToken, filteredResolutions, german) + var searchResult types.SearchResults jobRunning = true numberOfMoviesProcessed = 0 totalMovies = len(plexMovies) - 1 // write progress bar - fmt.Fprintf(w, `
+ fmt.Fprintf(w, `
`, numberOfMoviesProcessed, totalMovies) go func() { @@ -75,13 +78,13 @@ func processMoviesHTML(w http.ResponseWriter, r *http.Request) { if lookup == "cinemaParadiso" { searchResult, _ = cinemaparadiso.SearchCinemaParadisoMovie(movie) } else { - if german == stringTrue { + if german == types.StringTrue { searchResult, _ = amazon.SearchAmazonMovie(movie, "&audio=german") } else { searchResult, _ = amazon.SearchAmazonMovie(movie, "") } // if we are filtering by newer version, we need to search again - if newerVersion == stringTrue { + if newerVersion == types.StringTrue { scrapedResults := amazon.ScrapeTitles(&searchResult) searchResult.MovieSearchResults = scrapedResults } @@ -94,9 +97,9 @@ func processMoviesHTML(w http.ResponseWriter, r *http.Request) { }() } -func progressBarHTML(w http.ResponseWriter, _ *http.Request) { +func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) { if jobRunning { - fmt.Fprintf(w, `
+ fmt.Fprintf(w, `
`, numberOfMoviesProcessed, totalMovies) } if totalMovies == numberOfMoviesProcessed && totalMovies != 0 { @@ -143,7 +146,7 @@ func renderTable(movieCollection []types.SearchResults) (tableRows string) { func fetchPlexMovies(plexIP, plexMovieLibraryID, plexToken string, plexResolutions []string, german string) (allMovies []types.PlexMovie) { filter := []plex.Filter{} - if german == stringTrue { + if german == types.StringTrue { filter = []plex.Filter{ { Name: "audioLanguage", diff --git a/web/movies.html b/web/movies/movies.html similarity index 91% rename from web/movies.html rename to web/movies/movies.html index f6e88c2..d8fafc1 100644 --- a/web/movies.html +++ b/web/movies/movies.html @@ -25,12 +25,12 @@

Movies

-
-
+
+
Plex Filter: only compare movies that match the following criteria.
diff --git a/web/music.go b/web/music/music.go similarity index 86% rename from web/music.go rename to web/music/music.go index 705ac84..5fd0c43 100644 --- a/web/music.go +++ b/web/music/music.go @@ -1,4 +1,4 @@ -package web +package music import ( _ "embed" @@ -24,10 +24,14 @@ var ( totalArtists int = 0 plexMusic []types.PlexMusicArtist artistsSearchResults []types.SearchResults - albumReleaseYearCutoff int = 2 + albumReleaseYearCutoff int = 5 ) -func musicHandler(w http.ResponseWriter, _ *http.Request) { +type MusicConfig struct { + Config *types.Configuration +} + +func MusicHandler(w http.ResponseWriter, _ *http.Request) { tmpl := template.Must(template.New("music").Parse(musicPage)) err := tmpl.Execute(w, nil) if err != nil { @@ -37,19 +41,19 @@ func musicHandler(w http.ResponseWriter, _ *http.Request) { } // nolint: lll, nolintlint -func processArtistHTML(w http.ResponseWriter, r *http.Request) { +func (c MusicConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) { lookup := r.FormValue("lookup") lookupType := r.FormValue("lookuptype") // only get the artists from plex once if len(plexMusic) == 0 { - plexMusic = plex.GetPlexMusicArtists(config.PlexIP, config.PlexMusicLibraryID, config.PlexToken) + plexMusic = plex.GetPlexMusicArtists(c.Config.PlexIP, c.Config.PlexMusicLibraryID, c.Config.PlexToken) } var searchResult types.SearchResults artistsJobRunning = true numberOfArtistsProcessed = 0 totalArtists = len(plexMusic) - 1 - fmt.Fprintf(w, `
+ fmt.Fprintf(w, `
`, numberOfArtistsProcessed, totalArtists) if lookupType == "missingalbums" { @@ -72,7 +76,7 @@ func processArtistHTML(w http.ResponseWriter, r *http.Request) { startTime := time.Now() for i := range plexMusic { fmt.Print(".") - searchResult, _ = spotify.SearchSpotifyArtist(&plexMusic[i], config.SpotifyClientID, config.SpotifyClientSecret) + searchResult, _ = spotify.SearchSpotifyArtist(&plexMusic[i], c.Config.SpotifyClientID, c.Config.SpotifyClientSecret) artistsSearchResults = append(artistsSearchResults, searchResult) numberOfArtistsProcessed = i } @@ -89,9 +93,9 @@ func processArtistHTML(w http.ResponseWriter, r *http.Request) { } } -func artistProgressBarHTML(w http.ResponseWriter, _ *http.Request) { +func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) { if artistsJobRunning { - fmt.Fprintf(w, `
+ fmt.Fprintf(w, `
`, numberOfArtistsProcessed, totalArtists) } if totalArtists == numberOfArtistsProcessed && totalArtists != 0 { @@ -111,12 +115,12 @@ func renderArtistsTable(searchResults []types.SearchResults) (tableRows string) tableRows = `Plex ArtistAlbumsAlbum` //nolint: lll for i := range searchResults { if len(searchResults[i].MusicSearchResults) > 0 { - tableRows += fmt.Sprintf("%s%d