some reformattings

remove test code from main
This commit is contained in:
lukas 2021-04-23 21:37:57 +02:00
parent d952538f0a
commit 8c44a931de
2 changed files with 37 additions and 41 deletions

View File

@ -9,15 +9,12 @@ import (
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"openmediacenter/apiGo/static" "openmediacenter/apiGo/static"
"openmediacenter/apiGo/videoparser" "openmediacenter/apiGo/videoparser"
"openmediacenter/apiGo/videoparser/tmdb"
) )
func main() { func main() {
fmt.Println("init OpenMediaCenter server") fmt.Println("init OpenMediaCenter server")
port := 8081 port := 8081
tmdb.SearchTVShow("Arrow")
db, verbose, pathPrefix := handleCommandLineArguments() db, verbose, pathPrefix := handleCommandLineArguments()
// todo some verbosity logger or sth // todo some verbosity logger or sth

View File

@ -28,20 +28,36 @@ type TVShowTMDB struct {
} }
type tmdbVidResult struct { type tmdbVidResult struct {
Poster_path string PosterPath string `json:"poster_path"`
Adult bool Adult bool `json:"adult"`
Overview string Overview string `json:"overview"`
Release_date string ReleaseDate string `json:"release_date"`
Genre_ids []int GenreIds []int `json:"genre_ids"`
Id int Id int `json:"id"`
Original_title string OriginalTitle string `json:"original_title"`
Original_language string OriginalLanguage string `json:"original_language"`
Title string Title string `json:"title"`
Backdrop_path string BackdropPath string `json:"backdrop_path"`
Popularity int Popularity int `json:"popularity"`
Vote_count int VoteCount int `json:"vote_count"`
Video bool Video bool `json:"video"`
Vote_average int 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 { type TMDBGenre struct {
@ -80,7 +96,7 @@ func SearchVideo(MovieName string, year int) *VideoTMDB {
if year != -1 { if year != -1 {
for _, result := range t.Results { for _, result := range t.Results {
r, _ := regexp.Compile(fmt.Sprintf(`^%d-[0-9]{2}?-[0-9]{2}?$`, year)) 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 tmdbVid = result
// continue parsing // continue parsing
goto cont goto cont
@ -95,34 +111,18 @@ func SearchVideo(MovieName string, year int) *VideoTMDB {
// continue label // continue label
cont: cont:
thumbnail := fetchPoster(tmdbVid.Poster_path) thumbnail := fetchPoster(tmdbVid.PosterPath)
result := VideoTMDB{ result := VideoTMDB{
Thumbnail: *thumbnail, Thumbnail: *thumbnail,
Overview: tmdbVid.Overview, Overview: tmdbVid.Overview,
Title: tmdbVid.Title, Title: tmdbVid.Title,
GenreIds: tmdbVid.Genre_ids, GenreIds: tmdbVid.GenreIds,
} }
return &result 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 { func SearchTVShow(Name string) *TVShowTMDB {
fmt.Printf("Searching TMDB for: TVShow: %s\n", Name) fmt.Printf("Searching TMDB for: TVShow: %s\n", Name)
queryURL := fmt.Sprintf("%ssearch/tv?api_key=%s&query=%s", baseUrl, apiKey, url.QueryEscape(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 { func fetchPoster(posterPath string) *string {
url := fmt.Sprintf("%s%s", pictureBase, posterPath) posterURL := fmt.Sprintf("%s%s", pictureBase, posterPath)
resp, err := http.Get(posterURL)
resp, err := http.Get(url)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return nil return nil
@ -185,8 +184,8 @@ func fetchPoster(posterPath string) *string {
var tmdbGenres *[]TMDBGenre var tmdbGenres *[]TMDBGenre
func fetchGenres() *[]TMDBGenre { func fetchGenres() *[]TMDBGenre {
url := fmt.Sprintf("%sgenre/movie/list?api_key=%s", baseUrl, apiKey) posterURL := fmt.Sprintf("%sgenre/movie/list?api_key=%s", baseUrl, apiKey)
resp, err := http.Get(url) resp, err := http.Get(posterURL)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return nil return nil