feat: option to enable adult content

This commit is contained in:
Simon Ding
2024-08-19 16:39:34 +08:00
parent 10e6e99990
commit 821d6859ff
7 changed files with 56 additions and 25 deletions

View File

@@ -3,16 +3,17 @@ package db
var Version = "undefined" var Version = "undefined"
const ( const (
SettingTmdbApiKey = "tmdb_api_key" SettingTmdbApiKey = "tmdb_api_key"
SettingLanguage = "language" SettingLanguage = "language"
SettingJacketUrl = "jacket_url" SettingJacketUrl = "jacket_url"
SettingJacketApiKey = "jacket_api_key" SettingJacketApiKey = "jacket_api_key"
SettingDownloadDir = "download_dir" SettingDownloadDir = "download_dir"
SettingLogLevel = "log_level" SettingLogLevel = "log_level"
SettingProxy = "proxy" SettingProxy = "proxy"
SettingPlexMatchEnabled = "plexmatch_enabled" SettingPlexMatchEnabled = "plexmatch_enabled"
SettingNfoSupportEnabled = "nfo_support_enabled" SettingNfoSupportEnabled = "nfo_support_enabled"
SettingAllowQiangban = "filter_qiangban" SettingAllowQiangban = "filter_qiangban"
SettingEnableTmdbAdultContent = "tmdb_adult_content"
) )
const ( const (

View File

@@ -15,9 +15,10 @@ import (
type Client struct { type Client struct {
apiKey string apiKey string
tmdbClient *tmdb.Client 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) tmdbClient, err := tmdb.Init(apiKey)
if err != nil { if err != nil {
@@ -44,6 +45,7 @@ func NewClient(apiKey, proxyUrl string) (*Client, error) {
return &Client{ return &Client{
apiKey: apiKey, apiKey: apiKey,
tmdbClient: tmdbClient, tmdbClient: tmdbClient,
enableAdultContent: enableAdultContent,
}, nil }, nil
} }
@@ -114,6 +116,9 @@ func (c *Client) SearchMedia(query string, lang string, page int) (*SearchResult
} }
options := withLangOption(lang) options := withLangOption(lang)
options["page"] = strconv.Itoa(page) options["page"] = strconv.Itoa(page)
if c.enableAdultContent {
options["include_adult"] = "true"
}
res, err := c.tmdbClient.GetSearchMulti(query, options) res, err := c.tmdbClient.GetSearchMulti(query, options)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "query imdb") return nil, errors.Wrap(err, "query imdb")

View File

@@ -67,7 +67,8 @@ func (c *Client) TMDB() (*tmdb.Client, error) {
return nil, errors.New("TMDB apiKey not set") return nil, errors.New("TMDB apiKey not set")
} }
proxy := c.db.GetSetting(db.SettingProxy) 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 { func (c *Client) MustTMDB() *tmdb.Client {

View File

@@ -131,7 +131,8 @@ func (s *Server) TMDB() (*tmdb.Client, error) {
return nil, errors.New("TMDB apiKey not set") return nil, errors.New("TMDB apiKey not set")
} }
proxy := s.db.GetSetting(db.SettingProxy) 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 { func (s *Server) MustTMDB() *tmdb.Client {

View File

@@ -14,13 +14,14 @@ import (
) )
type GeneralSettings struct { type GeneralSettings struct {
TmdbApiKey string `json:"tmdb_api_key"` TmdbApiKey string `json:"tmdb_api_key"`
DownloadDir string `json:"download_dir"` DownloadDir string `json:"download_dir"`
LogLevel string `json:"log_level"` LogLevel string `json:"log_level"`
Proxy string `json:"proxy"` Proxy string `json:"proxy"`
EnablePlexmatch bool `json:"enable_plexmatch"` EnablePlexmatch bool `json:"enable_plexmatch"`
EnableNfo bool `json:"enable_nfo"` EnableNfo bool `json:"enable_nfo"`
AllowQiangban bool `json:"allow_qiangban"` AllowQiangban bool `json:"allow_qiangban"`
EnableAdultContent bool `json:"enable_adult_content"`
} }
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) { func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
@@ -68,6 +69,11 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
} else { } else {
s.db.SetSetting(db.SettingNfoSupportEnabled, "false") 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 return nil, nil
} }
@@ -79,6 +85,7 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
plexmatchEnabled := s.db.GetSetting(db.SettingPlexMatchEnabled) plexmatchEnabled := s.db.GetSetting(db.SettingPlexMatchEnabled)
allowQiangban := s.db.GetSetting(db.SettingAllowQiangban) allowQiangban := s.db.GetSetting(db.SettingAllowQiangban)
enableNfo := s.db.GetSetting(db.SettingNfoSupportEnabled) enableNfo := s.db.GetSetting(db.SettingNfoSupportEnabled)
enableAdult := s.db.GetSetting(db.SettingEnableTmdbAdultContent)
return &GeneralSettings{ return &GeneralSettings{
TmdbApiKey: tmdb, TmdbApiKey: tmdb,
DownloadDir: downloadDir, DownloadDir: downloadDir,
@@ -87,6 +94,7 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
EnablePlexmatch: plexmatchEnabled == "true", EnablePlexmatch: plexmatchEnabled == "true",
AllowQiangban: allowQiangban == "true", AllowQiangban: allowQiangban == "true",
EnableNfo: enableNfo == "true", EnableNfo: enableNfo == "true",
EnableAdultContent: enableAdult == "true",
}, nil }, nil
} }

View File

@@ -54,6 +54,7 @@ class GeneralSetting {
bool? enablePlexmatch; bool? enablePlexmatch;
bool? allowQiangban; bool? allowQiangban;
bool? enableNfo; bool? enableNfo;
bool? enableAdult;
GeneralSetting( GeneralSetting(
{this.tmdbApiKey, {this.tmdbApiKey,
@@ -62,7 +63,8 @@ class GeneralSetting {
this.proxy, this.proxy,
this.enablePlexmatch, this.enablePlexmatch,
this.enableNfo, this.enableNfo,
this.allowQiangban}); this.allowQiangban,
this.enableAdult});
factory GeneralSetting.fromJson(Map<String, dynamic> json) { factory GeneralSetting.fromJson(Map<String, dynamic> json) {
return GeneralSetting( return GeneralSetting(
@@ -70,6 +72,7 @@ class GeneralSetting {
downloadDIr: json["download_dir"], downloadDIr: json["download_dir"],
logLevel: json["log_level"], logLevel: json["log_level"],
proxy: json["proxy"], proxy: json["proxy"],
enableAdult: json["enable_adult_content"]??false,
allowQiangban: json["allow_qiangban"] ?? false, allowQiangban: json["allow_qiangban"] ?? false,
enableNfo: json["enable_nfo"] ?? false, enableNfo: json["enable_nfo"] ?? false,
enablePlexmatch: json["enable_plexmatch"] ?? false); enablePlexmatch: json["enable_plexmatch"] ?? false);
@@ -84,6 +87,7 @@ class GeneralSetting {
data["enable_plexmatch"] = enablePlexmatch; data["enable_plexmatch"] = enablePlexmatch;
data["allow_qiangban"] = allowQiangban; data["allow_qiangban"] = allowQiangban;
data["enable_nfo"] = enableNfo; data["enable_nfo"] = enableNfo;
data["enable_adult_content"] = enableAdult;
return data; return data;
} }
} }

View File

@@ -37,6 +37,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
"enable_plexmatch": v.enablePlexmatch, "enable_plexmatch": v.enablePlexmatch,
"allow_qiangban": v.allowQiangban, "allow_qiangban": v.allowQiangban,
"enable_nfo": v.enableNfo, "enable_nfo": v.enableNfo,
"enable_adult": v.enableAdult,
}, },
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -81,6 +82,14 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
validator: FormBuilderValidators.required(), validator: FormBuilderValidators.required(),
), ),
), ),
SizedBox(
width: 300,
child: FormBuilderSwitch(
decoration:
const InputDecoration(icon: Icon(Icons.back_hand)),
name: "enable_adult",
title: const Text("是否显示成人内容")),
),
SizedBox( SizedBox(
width: 300, width: 300,
child: FormBuilderSwitch( child: FormBuilderSwitch(
@@ -92,16 +101,17 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
SizedBox( SizedBox(
width: 300, width: 300,
child: FormBuilderSwitch( child: FormBuilderSwitch(
decoration: decoration: const InputDecoration(
const InputDecoration(icon: Icon(Icons.library_books), helperText: "emby/kodi等软件刮削需要"), icon: Icon(Icons.library_books),
helperText: "emby/kodi等软件刮削需要"),
name: "enable_nfo", name: "enable_nfo",
title: const Text("nfo 文件支持")), title: const Text("nfo 文件支持")),
), ),
SizedBox( SizedBox(
width: 300, width: 300,
child: FormBuilderSwitch( child: FormBuilderSwitch(
decoration: decoration: const InputDecoration(
const InputDecoration(icon: Icon(Icons.remove_circle)), icon: Icon(Icons.remove_circle)),
name: "allow_qiangban", name: "allow_qiangban",
title: const Text("是否下载枪版资源")), title: const Text("是否下载枪版资源")),
), ),
@@ -124,6 +134,7 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
logLevel: values["log_level"], logLevel: values["log_level"],
proxy: values["proxy"], proxy: values["proxy"],
allowQiangban: values["allow_qiangban"], allowQiangban: values["allow_qiangban"],
enableAdult: values["enable_adult"],
enableNfo: values["enable_nfo"], enableNfo: values["enable_nfo"],
enablePlexmatch: enablePlexmatch:
values["enable_plexmatch"])) values["enable_plexmatch"]))