Skip to content

Commit

Permalink
(maint) clean up plex function names
Browse files Browse the repository at this point in the history
  • Loading branch information
tphoney committed Jun 3, 2024
1 parent 69babfa commit aee072c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 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
18 changes: 9 additions & 9 deletions plex/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ type Filter struct {
Modifier string
}

func GetPlexMovies(ipAddress, libraryID, plexToken string) (movieList []types.PlexMovie) {
func AllMovies(ipAddress, libraryID, plexToken string) (movieList []types.PlexMovie) {
url := fmt.Sprintf("http://%s:32400/library/sections/%s/all", ipAddress, libraryID)

response, err := makePlexAPIRequest(url, plexToken)
Expand All @@ -845,7 +845,7 @@ func GetPlexMovies(ipAddress, libraryID, plexToken string) (movieList []types.Pl
semaphore <- struct{}{}
go func(i int) {
defer func() { <-semaphore }()
getPlexMovieDetails(ipAddress, plexToken, &movieList[i], ch)
getMovieDetails(ipAddress, plexToken, &movieList[i], ch)
}(i)
}
detailedMovies := make([]types.PlexMovie, len(movieList))
Expand Down Expand Up @@ -876,7 +876,7 @@ func extractMovies(xmlString string) (movieList []types.PlexMovie) {
return movieList
}

func getPlexMovieDetails(ipAddress, plexToken string, movie *types.PlexMovie, ch chan<- types.PlexMovie) {
func getMovieDetails(ipAddress, plexToken string, movie *types.PlexMovie, ch chan<- types.PlexMovie) {
url := fmt.Sprintf("http://%s:32400/library/metadata/%s", ipAddress, movie.RatingKey)

response, err := makePlexAPIRequest(url, plexToken)
Expand Down Expand Up @@ -908,7 +908,7 @@ func getPlexMovieDetails(ipAddress, plexToken string, movie *types.PlexMovie, ch
}

// =================================================================================================
func GetPlexTV(ipAddress, libraryID, plexToken string) (tvShowList []types.PlexTVShow) {
func AllTV(ipAddress, libraryID, plexToken string) (tvShowList []types.PlexTVShow) {
url := fmt.Sprintf("http://%s:32400/library/sections/%s/all", ipAddress, libraryID)

response, err := makePlexAPIRequest(url, plexToken)
Expand Down Expand Up @@ -954,7 +954,7 @@ func getPlexTVSeasons(ipAddress, plexToken, ratingKey string) (seasonList []type
semaphore <- struct{}{}
go func(i int) {
defer func() { <-semaphore }()
getPlexTVEpisodes(ipAddress, plexToken, &seasonList[i], ch)
getTVEpisodes(ipAddress, plexToken, &seasonList[i], ch)
}(i)
}

Expand Down Expand Up @@ -988,7 +988,7 @@ func getPlexTVSeasons(ipAddress, plexToken, ratingKey string) (seasonList []type
return filteredSeasons
}

func getPlexTVEpisodes(ipAddress, plexToken string, season *types.PlexTVSeason, ch chan<- types.PlexTVSeason) {
func getTVEpisodes(ipAddress, plexToken string, season *types.PlexTVSeason, ch chan<- types.PlexTVSeason) {
url := fmt.Sprintf("http://%s:32400/library/metadata/%s/children?", ipAddress, season.RatingKey)

response, err := makePlexAPIRequest(url, plexToken)
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func extractTVEpisodes(xmlString string) (episodeList []types.PlexTVEpisode) {
}

// =================================================================================================
func GetPlexMusicArtists(ipAddress, plexToken, libraryID string) (artists []types.PlexMusicArtist) {
func AllMusicArtists(ipAddress, plexToken, libraryID string) (artists []types.PlexMusicArtist) {
url := fmt.Sprintf("http://%s:32400/library/sections/%s/all", ipAddress, libraryID)

response, err := makePlexAPIRequest(url, plexToken)
Expand All @@ -1079,14 +1079,14 @@ func GetPlexMusicArtists(ipAddress, plexToken, libraryID string) (artists []type
}
// now we need to get the albums for each artist
for i := range artists {
artists[i].Albums = GetPlexMusicAlbums(ipAddress, plexToken, libraryID, artists[i].RatingKey)
artists[i].Albums = GetArtistMusicAlbums(ipAddress, plexToken, libraryID, artists[i].RatingKey)
}

fmt.Printf("Plex music artists: %d.\n", len(artists))
return artists
}

func GetPlexMusicAlbums(ipAddress, plexToken, libraryID, ratingKey string) (albums []types.PlexMusicAlbum) {
func GetArtistMusicAlbums(ipAddress, plexToken, libraryID, ratingKey string) (albums []types.PlexMusicAlbum) {
url := fmt.Sprintf("http://%s:32400/library/sections/%s/all?artist.id=%s&type=9", ipAddress, libraryID, ratingKey)

response, err := makePlexAPIRequest(url, plexToken)
Expand Down
6 changes: 3 additions & 3 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 Down
2 changes: 1 addition & 1 deletion web/movies/movies.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c MoviesConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
// 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
2 changes: 1 addition & 1 deletion web/music/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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
2 changes: 1 addition & 1 deletion web/tv/tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c TVConfig) ProcessHTML(w http.ResponseWriter, r *http.Request) {
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)
plexTV = plex.AllTV(c.Config.PlexIP, c.Config.PlexTVLibraryID, c.Config.PlexToken)
}
filters = newFilters
//nolint: gocritic
Expand Down

0 comments on commit aee072c

Please sign in to comment.