mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-16 08:20:48 +08:00
feat: option to enable adult content
This commit is contained in:
21
db/const.go
21
db/const.go
@@ -3,16 +3,17 @@ package db
|
||||
var Version = "undefined"
|
||||
|
||||
const (
|
||||
SettingTmdbApiKey = "tmdb_api_key"
|
||||
SettingLanguage = "language"
|
||||
SettingJacketUrl = "jacket_url"
|
||||
SettingJacketApiKey = "jacket_api_key"
|
||||
SettingDownloadDir = "download_dir"
|
||||
SettingLogLevel = "log_level"
|
||||
SettingProxy = "proxy"
|
||||
SettingPlexMatchEnabled = "plexmatch_enabled"
|
||||
SettingNfoSupportEnabled = "nfo_support_enabled"
|
||||
SettingAllowQiangban = "filter_qiangban"
|
||||
SettingTmdbApiKey = "tmdb_api_key"
|
||||
SettingLanguage = "language"
|
||||
SettingJacketUrl = "jacket_url"
|
||||
SettingJacketApiKey = "jacket_api_key"
|
||||
SettingDownloadDir = "download_dir"
|
||||
SettingLogLevel = "log_level"
|
||||
SettingProxy = "proxy"
|
||||
SettingPlexMatchEnabled = "plexmatch_enabled"
|
||||
SettingNfoSupportEnabled = "nfo_support_enabled"
|
||||
SettingAllowQiangban = "filter_qiangban"
|
||||
SettingEnableTmdbAdultContent = "tmdb_adult_content"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -15,9 +15,10 @@ import (
|
||||
type Client struct {
|
||||
apiKey string
|
||||
tmdbClient *tmdb.Client
|
||||
enableAdultContent bool
|
||||
}
|
||||
|
||||
func NewClient(apiKey, proxyUrl string) (*Client, error) {
|
||||
func NewClient(apiKey, proxyUrl string, enableAdultContent bool) (*Client, error) {
|
||||
|
||||
tmdbClient, err := tmdb.Init(apiKey)
|
||||
if err != nil {
|
||||
@@ -44,6 +45,7 @@ func NewClient(apiKey, proxyUrl string) (*Client, error) {
|
||||
return &Client{
|
||||
apiKey: apiKey,
|
||||
tmdbClient: tmdbClient,
|
||||
enableAdultContent: enableAdultContent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -114,6 +116,9 @@ func (c *Client) SearchMedia(query string, lang string, page int) (*SearchResult
|
||||
}
|
||||
options := withLangOption(lang)
|
||||
options["page"] = strconv.Itoa(page)
|
||||
if c.enableAdultContent {
|
||||
options["include_adult"] = "true"
|
||||
}
|
||||
res, err := c.tmdbClient.GetSearchMulti(query, options)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "query imdb")
|
||||
|
||||
@@ -67,7 +67,8 @@ func (c *Client) TMDB() (*tmdb.Client, error) {
|
||||
return nil, errors.New("TMDB apiKey not set")
|
||||
}
|
||||
proxy := c.db.GetSetting(db.SettingProxy)
|
||||
return tmdb.NewClient(api, proxy)
|
||||
adult := c.db.GetSetting(db.SettingEnableTmdbAdultContent)
|
||||
return tmdb.NewClient(api, proxy, adult == "true")
|
||||
}
|
||||
|
||||
func (c *Client) MustTMDB() *tmdb.Client {
|
||||
|
||||
@@ -131,7 +131,8 @@ func (s *Server) TMDB() (*tmdb.Client, error) {
|
||||
return nil, errors.New("TMDB apiKey not set")
|
||||
}
|
||||
proxy := s.db.GetSetting(db.SettingProxy)
|
||||
return tmdb.NewClient(api, proxy)
|
||||
adult := s.db.GetSetting(db.SettingEnableTmdbAdultContent)
|
||||
return tmdb.NewClient(api, proxy, adult=="true")
|
||||
}
|
||||
|
||||
func (s *Server) MustTMDB() *tmdb.Client {
|
||||
|
||||
@@ -14,13 +14,14 @@ import (
|
||||
)
|
||||
|
||||
type GeneralSettings struct {
|
||||
TmdbApiKey string `json:"tmdb_api_key"`
|
||||
DownloadDir string `json:"download_dir"`
|
||||
LogLevel string `json:"log_level"`
|
||||
Proxy string `json:"proxy"`
|
||||
EnablePlexmatch bool `json:"enable_plexmatch"`
|
||||
EnableNfo bool `json:"enable_nfo"`
|
||||
AllowQiangban bool `json:"allow_qiangban"`
|
||||
TmdbApiKey string `json:"tmdb_api_key"`
|
||||
DownloadDir string `json:"download_dir"`
|
||||
LogLevel string `json:"log_level"`
|
||||
Proxy string `json:"proxy"`
|
||||
EnablePlexmatch bool `json:"enable_plexmatch"`
|
||||
EnableNfo bool `json:"enable_nfo"`
|
||||
AllowQiangban bool `json:"allow_qiangban"`
|
||||
EnableAdultContent bool `json:"enable_adult_content"`
|
||||
}
|
||||
|
||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
@@ -68,6 +69,11 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingNfoSupportEnabled, "false")
|
||||
}
|
||||
if in.EnableAdultContent {
|
||||
s.db.SetSetting(db.SettingEnableTmdbAdultContent, "true")
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingEnableTmdbAdultContent, "false")
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
@@ -79,6 +85,7 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
plexmatchEnabled := s.db.GetSetting(db.SettingPlexMatchEnabled)
|
||||
allowQiangban := s.db.GetSetting(db.SettingAllowQiangban)
|
||||
enableNfo := s.db.GetSetting(db.SettingNfoSupportEnabled)
|
||||
enableAdult := s.db.GetSetting(db.SettingEnableTmdbAdultContent)
|
||||
return &GeneralSettings{
|
||||
TmdbApiKey: tmdb,
|
||||
DownloadDir: downloadDir,
|
||||
@@ -87,6 +94,7 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
EnablePlexmatch: plexmatchEnabled == "true",
|
||||
AllowQiangban: allowQiangban == "true",
|
||||
EnableNfo: enableNfo == "true",
|
||||
EnableAdultContent: enableAdult == "true",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class GeneralSetting {
|
||||
bool? enablePlexmatch;
|
||||
bool? allowQiangban;
|
||||
bool? enableNfo;
|
||||
bool? enableAdult;
|
||||
|
||||
GeneralSetting(
|
||||
{this.tmdbApiKey,
|
||||
@@ -62,7 +63,8 @@ class GeneralSetting {
|
||||
this.proxy,
|
||||
this.enablePlexmatch,
|
||||
this.enableNfo,
|
||||
this.allowQiangban});
|
||||
this.allowQiangban,
|
||||
this.enableAdult});
|
||||
|
||||
factory GeneralSetting.fromJson(Map<String, dynamic> json) {
|
||||
return GeneralSetting(
|
||||
@@ -70,6 +72,7 @@ class GeneralSetting {
|
||||
downloadDIr: json["download_dir"],
|
||||
logLevel: json["log_level"],
|
||||
proxy: json["proxy"],
|
||||
enableAdult: json["enable_adult_content"]??false,
|
||||
allowQiangban: json["allow_qiangban"] ?? false,
|
||||
enableNfo: json["enable_nfo"] ?? false,
|
||||
enablePlexmatch: json["enable_plexmatch"] ?? false);
|
||||
@@ -84,6 +87,7 @@ class GeneralSetting {
|
||||
data["enable_plexmatch"] = enablePlexmatch;
|
||||
data["allow_qiangban"] = allowQiangban;
|
||||
data["enable_nfo"] = enableNfo;
|
||||
data["enable_adult_content"] = enableAdult;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
"enable_plexmatch": v.enablePlexmatch,
|
||||
"allow_qiangban": v.allowQiangban,
|
||||
"enable_nfo": v.enableNfo,
|
||||
"enable_adult": v.enableAdult,
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -81,6 +82,14 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
decoration:
|
||||
const InputDecoration(icon: Icon(Icons.back_hand)),
|
||||
name: "enable_adult",
|
||||
title: const Text("是否显示成人内容")),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
@@ -92,16 +101,17 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
decoration:
|
||||
const InputDecoration(icon: Icon(Icons.library_books), helperText: "emby/kodi等软件刮削需要"),
|
||||
decoration: const InputDecoration(
|
||||
icon: Icon(Icons.library_books),
|
||||
helperText: "emby/kodi等软件刮削需要"),
|
||||
name: "enable_nfo",
|
||||
title: const Text("nfo 文件支持")),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
decoration:
|
||||
const InputDecoration(icon: Icon(Icons.remove_circle)),
|
||||
decoration: const InputDecoration(
|
||||
icon: Icon(Icons.remove_circle)),
|
||||
name: "allow_qiangban",
|
||||
title: const Text("是否下载枪版资源")),
|
||||
),
|
||||
@@ -124,6 +134,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
logLevel: values["log_level"],
|
||||
proxy: values["proxy"],
|
||||
allowQiangban: values["allow_qiangban"],
|
||||
enableAdult: values["enable_adult"],
|
||||
enableNfo: values["enable_nfo"],
|
||||
enablePlexmatch:
|
||||
values["enable_plexmatch"]))
|
||||
|
||||
Reference in New Issue
Block a user