Skip to content

Commit

Permalink
Merge pull request #43 from tphoney/tv_playlists
Browse files Browse the repository at this point in the history
(feat_ enable tv playlists
  • Loading branch information
tphoney authored Jun 7, 2024
2 parents 69babfa + 4367b86 commit 321429e
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 97 deletions.
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## features

- make language a pull down menu tv / movies page
- re-assess new filter for tv / movie page

## bugs

- mandalorian is not showing up on amazon tv search
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func initializeFlags() {

func initializePlexMovies() []types.PlexMovie {
var allMovies []types.PlexMovie
allMovies = append(allMovies, plex.GetPlexMovies(plexIP, plexMovieLibraryID, plexToken)...)
allMovies = append(allMovies, plex.AllMovies(plexIP, plexMovieLibraryID, plexToken)...)

fmt.Printf("\nThere are a total of %d movies in the library.\n\nMovies available:\n", len(allMovies))
return allMovies
Expand Down
2 changes: 1 addition & 1 deletion musicbrainz/musicbrainz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestSearchMusicBrainzArtist(t *testing.T) {
{
Name: "AC/DC",
ID: "66c662b6-6e2f-4930-8610-912e24c63ed1",
Albums: make([]types.MusicAlbumSearchResult, 17),
Albums: make([]types.MusicAlbumSearchResult, 18),
},
},
},
Expand Down
367 changes: 331 additions & 36 deletions plex/plex.go

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions plex/plex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestGetPlexMovies(t *testing.T) {
if plexIP == "" || plexMovieLibraryID == "" || plexToken == "" {
t.Skip("ACCEPTANCE TEST: PLEX environment variables not set")
}
result := GetPlexMovies(plexIP, plexMovieLibraryID, plexToken)
result := AllMovies(plexIP, plexMovieLibraryID, plexToken)

if len(result) == 0 {
t.Errorf("Expected at least one TV show, but got %d", len(result))
Expand All @@ -68,7 +68,7 @@ func TestGetPlexTV(t *testing.T) {
if plexIP == "" || plexTVLibraryID == "" || plexToken == "" {
t.Skip("ACCEPTANCE TEST: PLEX environment variables not set")
}
result := GetPlexTV(plexIP, plexTVLibraryID, plexToken)
result := AllTV(plexIP, plexTVLibraryID, plexToken)

if len(result) == 0 {
t.Errorf("Expected at least one TV show, but got %d", len(result))
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestGetPlexMusic(t *testing.T) {
if plexIP == "" || plexMusicLibraryID == "" || plexToken == "" {
t.Skip("ACCEPTANCE TEST: PLEX environment variables not set")
}
result := GetPlexMusicArtists(plexIP, plexToken, plexMusicLibraryID)
result := AllMusicArtists(plexIP, plexToken, plexMusicLibraryID)

if len(result) == 0 {
t.Errorf("Expected at least one album, but got %d", len(result))
Expand All @@ -121,7 +121,7 @@ func TestGetPlaylists(t *testing.T) {
if plexIP == "" || plexToken == "" {
t.Skip("ACCEPTANCE TEST: PLEX environment variables not set")
}
playlists, err := GetPlaylists(plexIP, plexToken, "3")
playlists, err := GetPlaylists(plexIP, plexToken, "2")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand Down Expand Up @@ -153,6 +153,16 @@ func TestGetMoviesFromPlaylist(t *testing.T) {
}
}

func TestGetTVFromPlaylist(t *testing.T) {
if plexIP == "" || plexToken == "" {
t.Skip("ACCEPTANCE TEST: PLEX environment variables not set")
}
items := GetTVFromPlaylist(plexIP, plexToken, "111908")
// Check the number of items
if len(items) == 0 {
t.Errorf("Expected at least one item, but got %d", len(items))
}
}
func Test_findLowestResolution(t *testing.T) {
tests := []struct {
name string
Expand Down
1 change: 0 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ type PlexTVShow struct {
}

type PlexTVSeason struct {
Title string
Number int
RatingKey string
LowestResolution string
Expand Down
44 changes: 21 additions & 23 deletions web/movies/movies.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ func MoviesHandler(w http.ResponseWriter, _ *http.Request) {
}
}

func (c MoviesConfig) PlaylistHTML(w http.ResponseWriter, _ *http.Request) {
playlistHTML := `<fieldset id="playlist">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist. (SLOW, only use for small libraries)
</label>`
playlists, _ := plex.GetPlaylists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMovieLibraryID)
fmt.Println("Playlists:", len(playlists))
for i := range playlists {
playlistHTML += fmt.Sprintf(
`<label for=%q>
<input type="radio" id="playlist" name="playlist" value=%q/>
%s</label>`,
playlists[i].Title, playlists[i].RatingKey, playlists[i].Title)
}

playlistHTML += `</fieldset>`
fmt.Fprint(w, playlistHTML)
}

func (c MoviesConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
playlist := r.FormValue("playlist")
lookup = r.FormValue("lookup")
Expand All @@ -47,9 +67,7 @@ func (c MoviesConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
lookupFilters.NewerVersion = r.FormValue("newerVersion") == types.StringTrue
// fetch from plex
if playlist == "all" {
if len(plexMovies) == 0 {
plexMovies = plex.GetPlexMovies(c.Config.PlexIP, c.Config.PlexMovieLibraryID, c.Config.PlexToken)
}
plexMovies = plex.AllMovies(c.Config.PlexIP, c.Config.PlexMovieLibraryID, c.Config.PlexToken)
} else {
plexMovies = plex.GetMoviesFromPlaylist(c.Config.PlexIP, c.Config.PlexToken, playlist)
}
Expand Down Expand Up @@ -83,26 +101,6 @@ func (c MoviesConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
}()
}

func (c MoviesConfig) PlaylistHTML(w http.ResponseWriter, _ *http.Request) {
playlistHTML := `<fieldset id="playlist">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist. (SLOW, only use for small libraries)
</label>`
playlists, _ := plex.GetPlaylists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMovieLibraryID)
fmt.Println("Playlists:", len(playlists))
for i := range playlists {
playlistHTML += fmt.Sprintf(
`<label for=%q>
<input type="radio" id="playlist" name="playlist" value=%q/>
%s</label>`,
playlists[i].Title, playlists[i].RatingKey, playlists[i].Title)
}

playlistHTML += `</fieldset>`
fmt.Fprint(w, playlistHTML)
}

func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) {
if lookup == "cinemaParadiso" {
// check job status
Expand Down
2 changes: 1 addition & 1 deletion web/movies/movies.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <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" hx-indicator="#indicator">
<legend><strong>Plex:</strong> filter by playlist</legend>
<fieldset id="playlist" hx-get="/moviesPlaylists" class="container" name="playlist" hx-trigger="load once"
<fieldset id="playlist" hx-get="/moviesplaylists" class="container" name="playlist" hx-trigger="load once"
hx-swap="outerHTML" hx-boost="true" hx-target="this">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
Expand Down
42 changes: 21 additions & 21 deletions web/music/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ func MusicHandler(w http.ResponseWriter, _ *http.Request) {
}
}

func (c MusicConfig) PlaylistHTML(w http.ResponseWriter, _ *http.Request) {
playlistHTML := `<fieldset id="playlist">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist. (SLOW, only use for small libraries)
</label>`
playlists, _ := plex.GetPlaylists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMusicLibraryID)
fmt.Println("Playlists:", len(playlists))
for i := range playlists {
playlistHTML += fmt.Sprintf(
`<label for=%q>
<input type="radio" id="playlist" name="playlist" value=%q/>
%s</label>`,
playlists[i].Title, playlists[i].RatingKey, playlists[i].Title)
}

playlistHTML += `</fieldset>`
fmt.Fprint(w, playlistHTML)
}

// nolint: lll, nolintlint
func (c MusicConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
playlist := r.FormValue("playlist")
Expand Down Expand Up @@ -77,7 +97,7 @@ func (c MusicConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
lookupType = r.FormValue("lookuptype")
// only get the artists from plex once
if playlist == "all" {
plexMusic = plex.GetPlexMusicArtists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMusicLibraryID)
plexMusic = plex.AllMusicArtists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMusicLibraryID)
} else {
plexMusic = plex.GetArtistsFromPlaylist(c.Config.PlexIP, c.Config.PlexToken, playlist)
}
Expand Down Expand Up @@ -134,26 +154,6 @@ func (c MusicConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Processed %d artists in %v\n", totalArtists, time.Since(startTime))
}

func (c MusicConfig) PlaylistHTML(w http.ResponseWriter, _ *http.Request) {
playlistHTML := `<fieldset id="playlist">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist. (SLOW, only use for small libraries)
</label>`
playlists, _ := plex.GetPlaylists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexMusicLibraryID)
fmt.Println("Playlists:", len(playlists))
for i := range playlists {
playlistHTML += fmt.Sprintf(
`<label for=%q>
<input type="radio" id="playlist" name="playlist" value=%q/>
%s</label>`,
playlists[i].Title, playlists[i].RatingKey, playlists[i].Title)
}

playlistHTML += `</fieldset>`
fmt.Fprint(w, playlistHTML)
}

func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) {
if lookup == spotifyString {
numberOfArtistsProcessed = spotify.GetJobProgress()
Expand Down
3 changes: 2 additions & 1 deletion web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ func StartServer(startingConfig *types.Configuration) {

mux.HandleFunc("/movies", movies.MoviesHandler)
mux.HandleFunc("/moviesprocess", movies.MoviesConfig{Config: config}.ProcessHTML)
mux.HandleFunc("/moviesPlaylists", movies.MoviesConfig{Config: config}.PlaylistHTML)
mux.HandleFunc("/moviesplaylists", movies.MoviesConfig{Config: config}.PlaylistHTML)
mux.HandleFunc("/moviesprogress", movies.ProgressBarHTML)

mux.HandleFunc("/tv", tv.TVHandler)
mux.HandleFunc("/tvprocess", tv.TVConfig{Config: config}.ProcessHTML)
mux.HandleFunc("/tvplaylists", tv.TVConfig{Config: config}.PlaylistHTML)
mux.HandleFunc("/tvprogress", tv.ProgressBarHTML)

mux.HandleFunc("/music", music.MusicHandler)
Expand Down
33 changes: 25 additions & 8 deletions web/tv/tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,38 @@ func TVHandler(w http.ResponseWriter, _ *http.Request) {
}
}

func (c TVConfig) PlaylistHTML(w http.ResponseWriter, _ *http.Request) {
playlistHTML := `<fieldset id="playlist">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist. (SLOW, only use for small libraries)
</label>`
playlists, _ := plex.GetPlaylists(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexTVLibraryID)
fmt.Println("Playlists:", len(playlists))
for i := range playlists {
playlistHTML += fmt.Sprintf(
`<label for=%q>
<input type="radio" id="playlist" name="playlist" value=%q/>
%s</label>`,
playlists[i].Title, playlists[i].RatingKey, playlists[i].Title)
}

playlistHTML += `</fieldset>`
fmt.Fprint(w, playlistHTML)
}

func (c TVConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
playlist := r.FormValue("playlist")
lookup = r.FormValue("lookup")
// lookup filters
newFilters := types.MovieLookupFilters{}
newFilters.AudioLanguage = r.FormValue("language")
newFilters.NewerVersion = r.FormValue("newerVersion") == types.StringTrue
if len(plexTV) == 0 || filters != newFilters {
plexTV = plex.GetPlexTV(c.Config.PlexIP, c.Config.PlexTVLibraryID, c.Config.PlexToken)
if playlist == "all" {
plexTV = plex.AllTV(c.Config.PlexIP, c.Config.PlexToken, c.Config.PlexTVLibraryID)
} else {
plexTV = plex.GetTVFromPlaylist(c.Config.PlexIP, c.Config.PlexToken, playlist)
}
filters = newFilters
//nolint: gocritic
// plexTV = plexTV[:20]
//lint: gocritic
Expand Down Expand Up @@ -95,7 +117,6 @@ func ProgressBarHTML(w http.ResponseWriter, _ *http.Request) {
}

func renderTVTable(searchResults []types.SearchResults) (tableRows string) {
searchResults = filterTVSearchResults(searchResults)
tableRows = `<thead><tr><th data-sort="string"><strong>Plex Title</strong></th><th data-sort="int"><strong>DVD</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 searchResults {
// build up plex season / resolution row
Expand Down Expand Up @@ -139,7 +160,3 @@ func renderTVTable(searchResults []types.SearchResults) (tableRows string) {
}
return tableRows // Return the generated HTML for table rows
}

func filterTVSearchResults(searchResults []types.SearchResults) []types.SearchResults {
return searchResults
}
8 changes: 8 additions & 0 deletions web/tv/tv.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
<h1 class="container">TV</h1>
<div hx-get="/settings/plexinfook" class="container" hx-trigger="load"></div>
<form hx-post="/tvprocess" class="container" hx-target="#progress" hx-boost="true" hx-indicator="#indicator">
<legend><strong>Plex:</strong> filter by playlist</legend>
<fieldset id="playlist" hx-get="/tvplaylists" class="container" name="playlist" hx-trigger="load once"
hx-swap="outerHTML" hx-boost="true" hx-target="this">
<label for="All">
<input type="radio" id="playlist" name="playlist" value="all" checked />
All: dont use a playlist.
</label>
</fieldset>
<fieldset>
<legend><strong>Lookup:</strong></legend>
<label for="amazon">
Expand Down

0 comments on commit 321429e

Please sign in to comment.