diff --git a/db/const.go b/db/const.go index d704240..607fda2 100644 --- a/db/const.go +++ b/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 ( diff --git a/pkg/tmdb/tmdb.go b/pkg/tmdb/tmdb.go index 2b4c162..ef78538 100644 --- a/pkg/tmdb/tmdb.go +++ b/pkg/tmdb/tmdb.go @@ -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") diff --git a/server/core/client.go b/server/core/client.go index 7359693..5a8e780 100644 --- a/server/core/client.go +++ b/server/core/client.go @@ -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 { diff --git a/server/server.go b/server/server.go index c950be8..d9816d7 100644 --- a/server/server.go +++ b/server/server.go @@ -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 { diff --git a/server/setting.go b/server/setting.go index 9aec41c..9ef3e22 100644 --- a/server/setting.go +++ b/server/setting.go @@ -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 } diff --git a/ui/lib/providers/settings.dart b/ui/lib/providers/settings.dart index 85efa97..087bddf 100644 --- a/ui/lib/providers/settings.dart +++ b/ui/lib/providers/settings.dart @@ -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 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; } } diff --git a/ui/lib/settings/general.dart b/ui/lib/settings/general.dart index 44efa19..9576538 100644 --- a/ui/lib/settings/general.dart +++ b/ui/lib/settings/general.dart @@ -37,6 +37,7 @@ class _GeneralState extends ConsumerState { "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 { 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 { 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 { logLevel: values["log_level"], proxy: values["proxy"], allowQiangban: values["allow_qiangban"], + enableAdult: values["enable_adult"], enableNfo: values["enable_nfo"], enablePlexmatch: values["enable_plexmatch"]))