Added helper functions to tmdb package
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"projectreshoot/logging"
|
||||
"projectreshoot/tmdb"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
@@ -31,6 +32,7 @@ type Config struct {
|
||||
LogOutput string // "file", "console", or "both". Defaults to console
|
||||
LogDir string // Path to create log files
|
||||
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
|
||||
@@ -78,6 +80,10 @@ func GetConfig(args map[string]string) (*Config, error) {
|
||||
if logOutput != "both" && logOutput != "console" && logOutput != "file" {
|
||||
logOutput = "console"
|
||||
}
|
||||
tmdbcfg, err := tmdb.GetConfig(os.Getenv("TMDB_API_TOKEN"))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "tmdb.GetConfig")
|
||||
}
|
||||
|
||||
config := &Config{
|
||||
Host: host,
|
||||
@@ -98,6 +104,7 @@ func GetConfig(args map[string]string) (*Config, error) {
|
||||
LogOutput: logOutput,
|
||||
LogDir: GetEnvDefault("LOG_DIR", ""),
|
||||
TMDBToken: os.Getenv("TMDB_API_TOKEN"),
|
||||
TMDBConfig: tmdbcfg,
|
||||
}
|
||||
|
||||
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