Added helper functions to tmdb package
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"projectreshoot/logging"
|
"projectreshoot/logging"
|
||||||
|
"projectreshoot/tmdb"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ type Config struct {
|
|||||||
LogOutput string // "file", "console", or "both". Defaults to console
|
LogOutput string // "file", "console", or "both". Defaults to console
|
||||||
LogDir string // Path to create log files
|
LogDir string // Path to create log files
|
||||||
TMDBToken string // Read access token for TMDB API
|
TMDBToken string // Read access token for TMDB API
|
||||||
|
TMDBConfig *tmdb.Config // Config data for interfacing with TMDB
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the application configuration and get a pointer to the Config object
|
// Load the application configuration and get a pointer to the Config object
|
||||||
@@ -78,6 +80,10 @@ func GetConfig(args map[string]string) (*Config, error) {
|
|||||||
if logOutput != "both" && logOutput != "console" && logOutput != "file" {
|
if logOutput != "both" && logOutput != "console" && logOutput != "file" {
|
||||||
logOutput = "console"
|
logOutput = "console"
|
||||||
}
|
}
|
||||||
|
tmdbcfg, err := tmdb.GetConfig(os.Getenv("TMDB_API_TOKEN"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "tmdb.GetConfig")
|
||||||
|
}
|
||||||
|
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Host: host,
|
Host: host,
|
||||||
@@ -98,6 +104,7 @@ func GetConfig(args map[string]string) (*Config, error) {
|
|||||||
LogOutput: logOutput,
|
LogOutput: logOutput,
|
||||||
LogDir: GetEnvDefault("LOG_DIR", ""),
|
LogDir: GetEnvDefault("LOG_DIR", ""),
|
||||||
TMDBToken: os.Getenv("TMDB_API_TOKEN"),
|
TMDBToken: os.Getenv("TMDB_API_TOKEN"),
|
||||||
|
TMDBConfig: tmdbcfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SecretKey == "" && args["dbver"] != "true" {
|
if config.SecretKey == "" && args["dbver"] != "true" {
|
||||||
|
|||||||
23
tmdb/functions.go
Normal file
23
tmdb/functions.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package tmdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FormatRuntime(minutes int) string {
|
||||||
|
hours := minutes / 60
|
||||||
|
mins := minutes % 60
|
||||||
|
return fmt.Sprintf("%dh %02dm", hours, mins)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPoster(image *Image, size, imgpath string) string {
|
||||||
|
base, err := url.Parse(image.SecureBaseURL)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
fullPath := path.Join(base.Path, size, imgpath)
|
||||||
|
base.Path = fullPath
|
||||||
|
return base.String()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user