From 8c44a931def45a4d3a5639c34281e882aef90e5c Mon Sep 17 00:00:00 2001 From: lukas Date: Fri, 23 Apr 2021 21:37:57 +0200 Subject: [PATCH] some reformattings remove test code from main --- apiGo/main.go | 3 -- apiGo/videoparser/tmdb/TMDBApi.go | 75 +++++++++++++++---------------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/apiGo/main.go b/apiGo/main.go index 1c46361..0b52cb2 100644 --- a/apiGo/main.go +++ b/apiGo/main.go @@ -9,15 +9,12 @@ import ( "openmediacenter/apiGo/database" "openmediacenter/apiGo/static" "openmediacenter/apiGo/videoparser" - "openmediacenter/apiGo/videoparser/tmdb" ) func main() { fmt.Println("init OpenMediaCenter server") port := 8081 - tmdb.SearchTVShow("Arrow") - db, verbose, pathPrefix := handleCommandLineArguments() // todo some verbosity logger or sth diff --git a/apiGo/videoparser/tmdb/TMDBApi.go b/apiGo/videoparser/tmdb/TMDBApi.go index 659adc3..957ea80 100644 --- a/apiGo/videoparser/tmdb/TMDBApi.go +++ b/apiGo/videoparser/tmdb/TMDBApi.go @@ -28,20 +28,36 @@ type TVShowTMDB struct { } type tmdbVidResult struct { - Poster_path string - Adult bool - Overview string - Release_date string - Genre_ids []int - Id int - Original_title string - Original_language string - Title string - Backdrop_path string - Popularity int - Vote_count int - Video bool - Vote_average int + PosterPath string `json:"poster_path"` + Adult bool `json:"adult"` + Overview string `json:"overview"` + ReleaseDate string `json:"release_date"` + GenreIds []int `json:"genre_ids"` + Id int `json:"id"` + OriginalTitle string `json:"original_title"` + OriginalLanguage string `json:"original_language"` + Title string `json:"title"` + BackdropPath string `json:"backdrop_path"` + Popularity int `json:"popularity"` + VoteCount int `json:"vote_count"` + Video bool `json:"video"` + VoteAverage int `json:"vote_average"` +} + +type tmdbTvResult struct { + PosterPath string `json:"poster_path"` + Popularity int `json:"popularity"` + Id int `json:"id"` + BackdropPath string `json:"backdrop_path"` + VoteAverage int `json:"vote_average"` + Overview string `json:"overview"` + FirstAirDate string `json:"first_air_date"` + OriginCountry []string `json:"origin_country"` + GenreIds []int `json:"genre_ids"` + OriginalLanguage string `json:"original_language"` + VoteCount int `json:"vote_count"` + Name string `json:"name"` + OriginalName string `json:"original_name"` } type TMDBGenre struct { @@ -80,7 +96,7 @@ func SearchVideo(MovieName string, year int) *VideoTMDB { if year != -1 { for _, result := range t.Results { r, _ := regexp.Compile(fmt.Sprintf(`^%d-[0-9]{2}?-[0-9]{2}?$`, year)) - if r.MatchString(result.Release_date) { + if r.MatchString(result.ReleaseDate) { tmdbVid = result // continue parsing goto cont @@ -95,34 +111,18 @@ func SearchVideo(MovieName string, year int) *VideoTMDB { // continue label cont: - thumbnail := fetchPoster(tmdbVid.Poster_path) + thumbnail := fetchPoster(tmdbVid.PosterPath) result := VideoTMDB{ Thumbnail: *thumbnail, Overview: tmdbVid.Overview, Title: tmdbVid.Title, - GenreIds: tmdbVid.Genre_ids, + GenreIds: tmdbVid.GenreIds, } return &result } -type tmdbTvResult struct { - PosterPath string `json:"poster_path"` - Popularity int `json:"popularity"` - Id int `json:"id"` - BackdropPath string `json:"backdrop_path"` - VoteAverage int `json:"vote_average"` - Overview string `json:"overview"` - FirstAirDate string `json:"first_air_date"` - OriginCountry []string `json:"origin_country"` - GenreIds []int `json:"genre_ids"` - OriginalLanguage string `json:"original_language"` - VoteCount int `json:"vote_count"` - Name string `json:"name"` - OriginalName string `json:"original_name"` -} - func SearchTVShow(Name string) *TVShowTMDB { fmt.Printf("Searching TMDB for: TVShow: %s\n", Name) queryURL := fmt.Sprintf("%ssearch/tv?api_key=%s&query=%s", baseUrl, apiKey, url.QueryEscape(Name)) @@ -164,9 +164,8 @@ func SearchTVShow(Name string) *TVShowTMDB { } func fetchPoster(posterPath string) *string { - url := fmt.Sprintf("%s%s", pictureBase, posterPath) - - resp, err := http.Get(url) + posterURL := fmt.Sprintf("%s%s", pictureBase, posterPath) + resp, err := http.Get(posterURL) if err != nil { fmt.Println(err.Error()) return nil @@ -185,8 +184,8 @@ func fetchPoster(posterPath string) *string { var tmdbGenres *[]TMDBGenre func fetchGenres() *[]TMDBGenre { - url := fmt.Sprintf("%sgenre/movie/list?api_key=%s", baseUrl, apiKey) - resp, err := http.Get(url) + posterURL := fmt.Sprintf("%sgenre/movie/list?api_key=%s", baseUrl, apiKey) + resp, err := http.Get(posterURL) if err != nil { fmt.Println(err.Error()) return nil