Skip to content

Commit

Permalink
(feat) tv playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
tphoney committed Jun 7, 2024
1 parent aee072c commit e293326
Show file tree
Hide file tree
Showing 10 changed files with 394 additions and 78 deletions.
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
332 changes: 305 additions & 27 deletions plex/plex.go

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion plex/plex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.AllMovies(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
40 changes: 20 additions & 20 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 @@ -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
28 changes: 25 additions & 3 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.AllTV(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
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="/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 />
All: dont use a playlist.
</label>
</fieldset>
<fieldset>
<legend><strong>Lookup:</strong></legend>
<label for="amazon">
Expand Down

0 comments on commit e293326

Please sign in to comment.