Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60110f4ca6 | ||
|
|
b7ca02429c | ||
|
|
ff63084014 | ||
|
|
821d6859ff | ||
|
|
10e6e99990 | ||
|
|
23a5997814 | ||
|
|
b487c81865 | ||
|
|
32914344d1 | ||
|
|
644c9ed228 | ||
|
|
d3ad80380f | ||
|
|
19c6308a81 | ||
|
|
7017f32fe3 | ||
|
|
02a23f13f9 | ||
|
|
cc211a89a4 | ||
|
|
4800e6c79d | ||
|
|
b5f0b28c61 | ||
|
|
081338df24 | ||
|
|
9632ca45b3 | ||
|
|
b948bff497 | ||
|
|
29383cf75c | ||
|
|
57ec0b9eb9 | ||
|
|
0cce4ffee0 | ||
|
|
5c01c45068 | ||
|
|
712bf84c90 | ||
|
|
fdb63a8459 | ||
|
|
990d9dab08 | ||
|
|
da863588e4 | ||
|
|
09ff67fef7 | ||
|
|
3c37948798 | ||
|
|
6fd39d818c | ||
|
|
a0e211c328 | ||
|
|
27d8b1672a | ||
|
|
349e394e8e | ||
|
|
620f085ca5 | ||
|
|
5b70badb50 | ||
|
|
5c6ac2c430 | ||
|
|
365cfddf8f | ||
|
|
6c26812b92 | ||
|
|
0057a75a95 | ||
|
|
f110f257d4 |
18
README.md
@@ -14,7 +14,11 @@ Polaris 是一个电视剧和电影的追踪软件。配置好了之后,当剧
|
||||
|
||||
交流群: https://t.me/+8R2nzrlSs2JhMDgx
|
||||
|
||||
## 功能
|
||||
## 快速开始
|
||||
|
||||
使用此程序参考 [【快速开始】](https://simonding.gitbook.io/polaris/quick_start)
|
||||
|
||||
## Features
|
||||
|
||||
- [x] 电视剧自动追踪下载
|
||||
- [x] 电影自动追踪下载
|
||||
@@ -23,17 +27,17 @@ Polaris 是一个电视剧和电影的追踪软件。配置好了之后,当剧
|
||||
- [x] 后台代理支持
|
||||
- [x] 用户认证
|
||||
- [x] plex 刮削支持
|
||||
- [x] NFO 刮削文件支持
|
||||
- [x] BT/PT 支持
|
||||
- [x] and more...
|
||||
|
||||
## Todos
|
||||
|
||||
- [] qbittorrent客户端支持
|
||||
- [] 更多通知客户端支持
|
||||
- [] 第三方watchlist导入支持
|
||||
- [ ] qbittorrent客户端支持
|
||||
- [ ] 更多通知客户端支持
|
||||
- [ ] 第三方watchlist导入支持
|
||||
- [ ] 手机客户端
|
||||
|
||||
## 使用
|
||||
|
||||
使用此程序参考 [【快速开始】](./doc/quick_start.md)
|
||||
|
||||
## 原理
|
||||
|
||||
|
||||
31
db/const.go
@@ -3,27 +3,30 @@ 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"
|
||||
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 (
|
||||
SettingAuthEnabled = "auth_enbled"
|
||||
SettingUsername = "auth_username"
|
||||
SettingPassword = "auth_password"
|
||||
SettingUsername = "auth_username"
|
||||
SettingPassword = "auth_password"
|
||||
)
|
||||
|
||||
const (
|
||||
IndexerTorznabImpl = "torznab"
|
||||
DataPath = "./data"
|
||||
ImgPath = DataPath + "/img"
|
||||
LogPath = DataPath + "/logs"
|
||||
DataPath = "./data"
|
||||
ImgPath = DataPath + "/img"
|
||||
LogPath = DataPath + "/logs"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,4 +36,4 @@ const (
|
||||
|
||||
type ResolutionType string
|
||||
|
||||
const JwtSerectKey = "jwt_secrect_key"
|
||||
const JwtSerectKey = "jwt_secrect_key"
|
||||
|
||||
11
db/db.go
@@ -150,6 +150,7 @@ func (c *Client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, er
|
||||
SetTargetDir(m.TargetDir).
|
||||
SetDownloadHistoryEpisodes(m.DownloadHistoryEpisodes).
|
||||
SetLimiter(m.Limiter).
|
||||
SetExtras(m.Extras).
|
||||
AddEpisodeIDs(episodes...).
|
||||
Save(context.TODO())
|
||||
return r, err
|
||||
@@ -491,7 +492,7 @@ func (c *Client) GetHistories() ent.Histories {
|
||||
|
||||
func (c *Client) GetRunningHistories() ent.Histories {
|
||||
h, err := c.ent.History.Query().Where(history.Or(history.StatusEQ(history.StatusRunning),
|
||||
history.StatusEQ(history.StatusUploading))).All(context.TODO())
|
||||
history.StatusEQ(history.StatusUploading), history.StatusEQ(history.StatusSeeding))).All(context.TODO())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -571,3 +572,11 @@ func (c *Client) EditMediaMetadata(in EditMediaData) error {
|
||||
return c.ent.Media.Update().Where(media.ID(in.ID)).SetResolution(in.Resolution).SetTargetDir(in.TargetDir).SetLimiter(in.Limiter).
|
||||
Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) UpdateEpisodeTargetFile(id int, filename string) error {
|
||||
return c.ent.Episode.Update().Where(episode.ID(id)).SetTargetFile(filename).Exec(context.Background())
|
||||
}
|
||||
|
||||
func (c *Client) GetSeasonEpisodes(mediaId, seasonNum int) ([]*ent.Episode, error) {
|
||||
return c.ent.Episode.Query().Where(episode.MediaID(mediaId), episode.SeasonNumber(seasonNum)).All(context.Background())
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.6 MiB |
@@ -33,6 +33,8 @@ type Episode struct {
|
||||
Status episode.Status `json:"status,omitempty"`
|
||||
// Monitored holds the value of the "monitored" field.
|
||||
Monitored bool `json:"monitored"`
|
||||
// TargetFile holds the value of the "target_file" field.
|
||||
TargetFile string `json:"target_file,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the EpisodeQuery when eager-loading is set.
|
||||
Edges EpisodeEdges `json:"edges"`
|
||||
@@ -68,7 +70,7 @@ func (*Episode) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullBool)
|
||||
case episode.FieldID, episode.FieldMediaID, episode.FieldSeasonNumber, episode.FieldEpisodeNumber:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate, episode.FieldStatus:
|
||||
case episode.FieldTitle, episode.FieldOverview, episode.FieldAirDate, episode.FieldStatus, episode.FieldTargetFile:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -139,6 +141,12 @@ func (e *Episode) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
e.Monitored = value.Bool
|
||||
}
|
||||
case episode.FieldTargetFile:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field target_file", values[i])
|
||||
} else if value.Valid {
|
||||
e.TargetFile = value.String
|
||||
}
|
||||
default:
|
||||
e.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -203,6 +211,9 @@ func (e *Episode) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("monitored=")
|
||||
builder.WriteString(fmt.Sprintf("%v", e.Monitored))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("target_file=")
|
||||
builder.WriteString(e.TargetFile)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ const (
|
||||
FieldStatus = "status"
|
||||
// FieldMonitored holds the string denoting the monitored field in the database.
|
||||
FieldMonitored = "monitored"
|
||||
// FieldTargetFile holds the string denoting the target_file field in the database.
|
||||
FieldTargetFile = "target_file"
|
||||
// EdgeMedia holds the string denoting the media edge name in mutations.
|
||||
EdgeMedia = "media"
|
||||
// Table holds the table name of the episode in the database.
|
||||
@@ -54,6 +56,7 @@ var Columns = []string{
|
||||
FieldAirDate,
|
||||
FieldStatus,
|
||||
FieldMonitored,
|
||||
FieldTargetFile,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -146,6 +149,11 @@ func ByMonitored(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMonitored, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTargetFile orders the results by the target_file field.
|
||||
func ByTargetFile(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTargetFile, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMediaField orders the results by media field.
|
||||
func ByMediaField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
|
||||
@@ -89,6 +89,11 @@ func Monitored(v bool) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldMonitored, v))
|
||||
}
|
||||
|
||||
// TargetFile applies equality check predicate on the "target_file" field. It's identical to TargetFileEQ.
|
||||
func TargetFile(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// MediaIDEQ applies the EQ predicate on the "media_id" field.
|
||||
func MediaIDEQ(v int) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldMediaID, v))
|
||||
@@ -424,6 +429,81 @@ func MonitoredNEQ(v bool) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNEQ(FieldMonitored, v))
|
||||
}
|
||||
|
||||
// TargetFileEQ applies the EQ predicate on the "target_file" field.
|
||||
func TargetFileEQ(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEQ(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileNEQ applies the NEQ predicate on the "target_file" field.
|
||||
func TargetFileNEQ(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNEQ(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileIn applies the In predicate on the "target_file" field.
|
||||
func TargetFileIn(vs ...string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldIn(FieldTargetFile, vs...))
|
||||
}
|
||||
|
||||
// TargetFileNotIn applies the NotIn predicate on the "target_file" field.
|
||||
func TargetFileNotIn(vs ...string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNotIn(FieldTargetFile, vs...))
|
||||
}
|
||||
|
||||
// TargetFileGT applies the GT predicate on the "target_file" field.
|
||||
func TargetFileGT(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldGT(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileGTE applies the GTE predicate on the "target_file" field.
|
||||
func TargetFileGTE(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldGTE(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileLT applies the LT predicate on the "target_file" field.
|
||||
func TargetFileLT(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldLT(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileLTE applies the LTE predicate on the "target_file" field.
|
||||
func TargetFileLTE(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldLTE(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileContains applies the Contains predicate on the "target_file" field.
|
||||
func TargetFileContains(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldContains(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileHasPrefix applies the HasPrefix predicate on the "target_file" field.
|
||||
func TargetFileHasPrefix(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldHasPrefix(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileHasSuffix applies the HasSuffix predicate on the "target_file" field.
|
||||
func TargetFileHasSuffix(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldHasSuffix(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileIsNil applies the IsNil predicate on the "target_file" field.
|
||||
func TargetFileIsNil() predicate.Episode {
|
||||
return predicate.Episode(sql.FieldIsNull(FieldTargetFile))
|
||||
}
|
||||
|
||||
// TargetFileNotNil applies the NotNil predicate on the "target_file" field.
|
||||
func TargetFileNotNil() predicate.Episode {
|
||||
return predicate.Episode(sql.FieldNotNull(FieldTargetFile))
|
||||
}
|
||||
|
||||
// TargetFileEqualFold applies the EqualFold predicate on the "target_file" field.
|
||||
func TargetFileEqualFold(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldEqualFold(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// TargetFileContainsFold applies the ContainsFold predicate on the "target_file" field.
|
||||
func TargetFileContainsFold(v string) predicate.Episode {
|
||||
return predicate.Episode(sql.FieldContainsFold(FieldTargetFile, v))
|
||||
}
|
||||
|
||||
// HasMedia applies the HasEdge predicate on the "media" edge.
|
||||
func HasMedia() predicate.Episode {
|
||||
return predicate.Episode(func(s *sql.Selector) {
|
||||
|
||||
@@ -92,6 +92,20 @@ func (ec *EpisodeCreate) SetNillableMonitored(b *bool) *EpisodeCreate {
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetTargetFile sets the "target_file" field.
|
||||
func (ec *EpisodeCreate) SetTargetFile(s string) *EpisodeCreate {
|
||||
ec.mutation.SetTargetFile(s)
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetNillableTargetFile sets the "target_file" field if the given value is not nil.
|
||||
func (ec *EpisodeCreate) SetNillableTargetFile(s *string) *EpisodeCreate {
|
||||
if s != nil {
|
||||
ec.SetTargetFile(*s)
|
||||
}
|
||||
return ec
|
||||
}
|
||||
|
||||
// SetMedia sets the "media" edge to the Media entity.
|
||||
func (ec *EpisodeCreate) SetMedia(m *Media) *EpisodeCreate {
|
||||
return ec.SetMediaID(m.ID)
|
||||
@@ -224,6 +238,10 @@ func (ec *EpisodeCreate) createSpec() (*Episode, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
|
||||
_node.Monitored = value
|
||||
}
|
||||
if value, ok := ec.mutation.TargetFile(); ok {
|
||||
_spec.SetField(episode.FieldTargetFile, field.TypeString, value)
|
||||
_node.TargetFile = value
|
||||
}
|
||||
if nodes := ec.mutation.MediaIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
||||
@@ -160,6 +160,26 @@ func (eu *EpisodeUpdate) SetNillableMonitored(b *bool) *EpisodeUpdate {
|
||||
return eu
|
||||
}
|
||||
|
||||
// SetTargetFile sets the "target_file" field.
|
||||
func (eu *EpisodeUpdate) SetTargetFile(s string) *EpisodeUpdate {
|
||||
eu.mutation.SetTargetFile(s)
|
||||
return eu
|
||||
}
|
||||
|
||||
// SetNillableTargetFile sets the "target_file" field if the given value is not nil.
|
||||
func (eu *EpisodeUpdate) SetNillableTargetFile(s *string) *EpisodeUpdate {
|
||||
if s != nil {
|
||||
eu.SetTargetFile(*s)
|
||||
}
|
||||
return eu
|
||||
}
|
||||
|
||||
// ClearTargetFile clears the value of the "target_file" field.
|
||||
func (eu *EpisodeUpdate) ClearTargetFile() *EpisodeUpdate {
|
||||
eu.mutation.ClearTargetFile()
|
||||
return eu
|
||||
}
|
||||
|
||||
// SetMedia sets the "media" edge to the Media entity.
|
||||
func (eu *EpisodeUpdate) SetMedia(m *Media) *EpisodeUpdate {
|
||||
return eu.SetMediaID(m.ID)
|
||||
@@ -252,6 +272,12 @@ func (eu *EpisodeUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := eu.mutation.Monitored(); ok {
|
||||
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := eu.mutation.TargetFile(); ok {
|
||||
_spec.SetField(episode.FieldTargetFile, field.TypeString, value)
|
||||
}
|
||||
if eu.mutation.TargetFileCleared() {
|
||||
_spec.ClearField(episode.FieldTargetFile, field.TypeString)
|
||||
}
|
||||
if eu.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -433,6 +459,26 @@ func (euo *EpisodeUpdateOne) SetNillableMonitored(b *bool) *EpisodeUpdateOne {
|
||||
return euo
|
||||
}
|
||||
|
||||
// SetTargetFile sets the "target_file" field.
|
||||
func (euo *EpisodeUpdateOne) SetTargetFile(s string) *EpisodeUpdateOne {
|
||||
euo.mutation.SetTargetFile(s)
|
||||
return euo
|
||||
}
|
||||
|
||||
// SetNillableTargetFile sets the "target_file" field if the given value is not nil.
|
||||
func (euo *EpisodeUpdateOne) SetNillableTargetFile(s *string) *EpisodeUpdateOne {
|
||||
if s != nil {
|
||||
euo.SetTargetFile(*s)
|
||||
}
|
||||
return euo
|
||||
}
|
||||
|
||||
// ClearTargetFile clears the value of the "target_file" field.
|
||||
func (euo *EpisodeUpdateOne) ClearTargetFile() *EpisodeUpdateOne {
|
||||
euo.mutation.ClearTargetFile()
|
||||
return euo
|
||||
}
|
||||
|
||||
// SetMedia sets the "media" edge to the Media entity.
|
||||
func (euo *EpisodeUpdateOne) SetMedia(m *Media) *EpisodeUpdateOne {
|
||||
return euo.SetMediaID(m.ID)
|
||||
@@ -555,6 +601,12 @@ func (euo *EpisodeUpdateOne) sqlSave(ctx context.Context) (_node *Episode, err e
|
||||
if value, ok := euo.mutation.Monitored(); ok {
|
||||
_spec.SetField(episode.FieldMonitored, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := euo.mutation.TargetFile(); ok {
|
||||
_spec.SetField(episode.FieldTargetFile, field.TypeString, value)
|
||||
}
|
||||
if euo.mutation.TargetFileCleared() {
|
||||
_spec.ClearField(episode.FieldTargetFile, field.TypeString)
|
||||
}
|
||||
if euo.mutation.MediaCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
||||
@@ -76,6 +76,7 @@ const (
|
||||
StatusSuccess Status = "success"
|
||||
StatusFail Status = "fail"
|
||||
StatusUploading Status = "uploading"
|
||||
StatusSeeding Status = "seeding"
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
@@ -85,7 +86,7 @@ func (s Status) String() string {
|
||||
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(s Status) error {
|
||||
switch s {
|
||||
case StatusRunning, StatusSuccess, StatusFail, StatusUploading:
|
||||
case StatusRunning, StatusSuccess, StatusFail, StatusUploading, StatusSeeding:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("history: invalid enum value for status field: %q", s)
|
||||
|
||||
15
ent/media.go
@@ -47,6 +47,8 @@ type Media struct {
|
||||
DownloadHistoryEpisodes bool `json:"download_history_episodes,omitempty"`
|
||||
// Limiter holds the value of the "limiter" field.
|
||||
Limiter schema.MediaLimiter `json:"limiter,omitempty"`
|
||||
// Extras holds the value of the "extras" field.
|
||||
Extras schema.MediaExtras `json:"extras,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the MediaQuery when eager-loading is set.
|
||||
Edges MediaEdges `json:"edges"`
|
||||
@@ -76,7 +78,7 @@ func (*Media) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case media.FieldLimiter:
|
||||
case media.FieldLimiter, media.FieldExtras:
|
||||
values[i] = new([]byte)
|
||||
case media.FieldDownloadHistoryEpisodes:
|
||||
values[i] = new(sql.NullBool)
|
||||
@@ -193,6 +195,14 @@ func (m *Media) assignValues(columns []string, values []any) error {
|
||||
return fmt.Errorf("unmarshal field limiter: %w", err)
|
||||
}
|
||||
}
|
||||
case media.FieldExtras:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field extras", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &m.Extras); err != nil {
|
||||
return fmt.Errorf("unmarshal field extras: %w", err)
|
||||
}
|
||||
}
|
||||
default:
|
||||
m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -275,6 +285,9 @@ func (m *Media) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("limiter=")
|
||||
builder.WriteString(fmt.Sprintf("%v", m.Limiter))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("extras=")
|
||||
builder.WriteString(fmt.Sprintf("%v", m.Extras))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ const (
|
||||
FieldDownloadHistoryEpisodes = "download_history_episodes"
|
||||
// FieldLimiter holds the string denoting the limiter field in the database.
|
||||
FieldLimiter = "limiter"
|
||||
// FieldExtras holds the string denoting the extras field in the database.
|
||||
FieldExtras = "extras"
|
||||
// EdgeEpisodes holds the string denoting the episodes edge name in mutations.
|
||||
EdgeEpisodes = "episodes"
|
||||
// Table holds the table name of the media in the database.
|
||||
@@ -73,6 +75,7 @@ var Columns = []string{
|
||||
FieldTargetDir,
|
||||
FieldDownloadHistoryEpisodes,
|
||||
FieldLimiter,
|
||||
FieldExtras,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
|
||||
@@ -785,6 +785,16 @@ func LimiterNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldLimiter))
|
||||
}
|
||||
|
||||
// ExtrasIsNil applies the IsNil predicate on the "extras" field.
|
||||
func ExtrasIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldExtras))
|
||||
}
|
||||
|
||||
// ExtrasNotNil applies the NotNil predicate on the "extras" field.
|
||||
func ExtrasNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldExtras))
|
||||
}
|
||||
|
||||
// HasEpisodes applies the HasEdge predicate on the "episodes" edge.
|
||||
func HasEpisodes() predicate.Media {
|
||||
return predicate.Media(func(s *sql.Selector) {
|
||||
|
||||
@@ -170,6 +170,20 @@ func (mc *MediaCreate) SetNillableLimiter(sl *schema.MediaLimiter) *MediaCreate
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (mc *MediaCreate) SetExtras(se schema.MediaExtras) *MediaCreate {
|
||||
mc.mutation.SetExtras(se)
|
||||
return mc
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (mc *MediaCreate) SetNillableExtras(se *schema.MediaExtras) *MediaCreate {
|
||||
if se != nil {
|
||||
mc.SetExtras(*se)
|
||||
}
|
||||
return mc
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (mc *MediaCreate) AddEpisodeIDs(ids ...int) *MediaCreate {
|
||||
mc.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -359,6 +373,10 @@ func (mc *MediaCreate) createSpec() (*Media, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(media.FieldLimiter, field.TypeJSON, value)
|
||||
_node.Limiter = value
|
||||
}
|
||||
if value, ok := mc.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
_node.Extras = value
|
||||
}
|
||||
if nodes := mc.mutation.EpisodesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -270,6 +270,26 @@ func (mu *MediaUpdate) ClearLimiter() *MediaUpdate {
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (mu *MediaUpdate) SetExtras(se schema.MediaExtras) *MediaUpdate {
|
||||
mu.mutation.SetExtras(se)
|
||||
return mu
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (mu *MediaUpdate) SetNillableExtras(se *schema.MediaExtras) *MediaUpdate {
|
||||
if se != nil {
|
||||
mu.SetExtras(*se)
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (mu *MediaUpdate) ClearExtras() *MediaUpdate {
|
||||
mu.mutation.ClearExtras()
|
||||
return mu
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (mu *MediaUpdate) AddEpisodeIDs(ids ...int) *MediaUpdate {
|
||||
mu.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -428,6 +448,12 @@ func (mu *MediaUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if mu.mutation.LimiterCleared() {
|
||||
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
||||
}
|
||||
if value, ok := mu.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
}
|
||||
if mu.mutation.ExtrasCleared() {
|
||||
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
||||
}
|
||||
if mu.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -733,6 +759,26 @@ func (muo *MediaUpdateOne) ClearLimiter() *MediaUpdateOne {
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (muo *MediaUpdateOne) SetExtras(se schema.MediaExtras) *MediaUpdateOne {
|
||||
muo.mutation.SetExtras(se)
|
||||
return muo
|
||||
}
|
||||
|
||||
// SetNillableExtras sets the "extras" field if the given value is not nil.
|
||||
func (muo *MediaUpdateOne) SetNillableExtras(se *schema.MediaExtras) *MediaUpdateOne {
|
||||
if se != nil {
|
||||
muo.SetExtras(*se)
|
||||
}
|
||||
return muo
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (muo *MediaUpdateOne) ClearExtras() *MediaUpdateOne {
|
||||
muo.mutation.ClearExtras()
|
||||
return muo
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by IDs.
|
||||
func (muo *MediaUpdateOne) AddEpisodeIDs(ids ...int) *MediaUpdateOne {
|
||||
muo.mutation.AddEpisodeIDs(ids...)
|
||||
@@ -921,6 +967,12 @@ func (muo *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error
|
||||
if muo.mutation.LimiterCleared() {
|
||||
_spec.ClearField(media.FieldLimiter, field.TypeJSON)
|
||||
}
|
||||
if value, ok := muo.mutation.Extras(); ok {
|
||||
_spec.SetField(media.FieldExtras, field.TypeJSON, value)
|
||||
}
|
||||
if muo.mutation.ExtrasCleared() {
|
||||
_spec.ClearField(media.FieldExtras, field.TypeJSON)
|
||||
}
|
||||
if muo.mutation.EpisodesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -39,6 +39,7 @@ var (
|
||||
{Name: "air_date", Type: field.TypeString},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"missing", "downloading", "downloaded"}, Default: "missing"},
|
||||
{Name: "monitored", Type: field.TypeBool, Default: false},
|
||||
{Name: "target_file", Type: field.TypeString, Nullable: true},
|
||||
{Name: "media_id", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// EpisodesTable holds the schema information for the "episodes" table.
|
||||
@@ -49,7 +50,7 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "episodes_media_episodes",
|
||||
Columns: []*schema.Column{EpisodesColumns[8]},
|
||||
Columns: []*schema.Column{EpisodesColumns[9]},
|
||||
RefColumns: []*schema.Column{MediaColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -66,7 +67,7 @@ var (
|
||||
{Name: "size", Type: field.TypeInt, Default: 0},
|
||||
{Name: "download_client_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "indexer_id", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading"}},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"running", "success", "fail", "uploading", "seeding"}},
|
||||
{Name: "saved", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
// HistoriesTable holds the schema information for the "histories" table.
|
||||
@@ -109,6 +110,7 @@ var (
|
||||
{Name: "target_dir", Type: field.TypeString, Nullable: true},
|
||||
{Name: "download_history_episodes", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "limiter", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "extras", Type: field.TypeJSON, Nullable: true},
|
||||
}
|
||||
// MediaTable holds the schema information for the "media" table.
|
||||
MediaTable = &schema.Table{
|
||||
|
||||
150
ent/mutation.go
@@ -923,6 +923,7 @@ type EpisodeMutation struct {
|
||||
air_date *string
|
||||
status *episode.Status
|
||||
monitored *bool
|
||||
target_file *string
|
||||
clearedFields map[string]struct{}
|
||||
media *int
|
||||
clearedmedia bool
|
||||
@@ -1370,6 +1371,55 @@ func (m *EpisodeMutation) ResetMonitored() {
|
||||
m.monitored = nil
|
||||
}
|
||||
|
||||
// SetTargetFile sets the "target_file" field.
|
||||
func (m *EpisodeMutation) SetTargetFile(s string) {
|
||||
m.target_file = &s
|
||||
}
|
||||
|
||||
// TargetFile returns the value of the "target_file" field in the mutation.
|
||||
func (m *EpisodeMutation) TargetFile() (r string, exists bool) {
|
||||
v := m.target_file
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldTargetFile returns the old "target_file" field's value of the Episode entity.
|
||||
// If the Episode object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *EpisodeMutation) OldTargetFile(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldTargetFile is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldTargetFile requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldTargetFile: %w", err)
|
||||
}
|
||||
return oldValue.TargetFile, nil
|
||||
}
|
||||
|
||||
// ClearTargetFile clears the value of the "target_file" field.
|
||||
func (m *EpisodeMutation) ClearTargetFile() {
|
||||
m.target_file = nil
|
||||
m.clearedFields[episode.FieldTargetFile] = struct{}{}
|
||||
}
|
||||
|
||||
// TargetFileCleared returns if the "target_file" field was cleared in this mutation.
|
||||
func (m *EpisodeMutation) TargetFileCleared() bool {
|
||||
_, ok := m.clearedFields[episode.FieldTargetFile]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTargetFile resets all changes to the "target_file" field.
|
||||
func (m *EpisodeMutation) ResetTargetFile() {
|
||||
m.target_file = nil
|
||||
delete(m.clearedFields, episode.FieldTargetFile)
|
||||
}
|
||||
|
||||
// ClearMedia clears the "media" edge to the Media entity.
|
||||
func (m *EpisodeMutation) ClearMedia() {
|
||||
m.clearedmedia = true
|
||||
@@ -1431,7 +1481,7 @@ func (m *EpisodeMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *EpisodeMutation) Fields() []string {
|
||||
fields := make([]string, 0, 8)
|
||||
fields := make([]string, 0, 9)
|
||||
if m.media != nil {
|
||||
fields = append(fields, episode.FieldMediaID)
|
||||
}
|
||||
@@ -1456,6 +1506,9 @@ func (m *EpisodeMutation) Fields() []string {
|
||||
if m.monitored != nil {
|
||||
fields = append(fields, episode.FieldMonitored)
|
||||
}
|
||||
if m.target_file != nil {
|
||||
fields = append(fields, episode.FieldTargetFile)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -1480,6 +1533,8 @@ func (m *EpisodeMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.Status()
|
||||
case episode.FieldMonitored:
|
||||
return m.Monitored()
|
||||
case episode.FieldTargetFile:
|
||||
return m.TargetFile()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -1505,6 +1560,8 @@ func (m *EpisodeMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
return m.OldStatus(ctx)
|
||||
case episode.FieldMonitored:
|
||||
return m.OldMonitored(ctx)
|
||||
case episode.FieldTargetFile:
|
||||
return m.OldTargetFile(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Episode field %s", name)
|
||||
}
|
||||
@@ -1570,6 +1627,13 @@ func (m *EpisodeMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetMonitored(v)
|
||||
return nil
|
||||
case episode.FieldTargetFile:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTargetFile(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Episode field %s", name)
|
||||
}
|
||||
@@ -1630,6 +1694,9 @@ func (m *EpisodeMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(episode.FieldMediaID) {
|
||||
fields = append(fields, episode.FieldMediaID)
|
||||
}
|
||||
if m.FieldCleared(episode.FieldTargetFile) {
|
||||
fields = append(fields, episode.FieldTargetFile)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -1647,6 +1714,9 @@ func (m *EpisodeMutation) ClearField(name string) error {
|
||||
case episode.FieldMediaID:
|
||||
m.ClearMediaID()
|
||||
return nil
|
||||
case episode.FieldTargetFile:
|
||||
m.ClearTargetFile()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Episode nullable field %s", name)
|
||||
}
|
||||
@@ -1679,6 +1749,9 @@ func (m *EpisodeMutation) ResetField(name string) error {
|
||||
case episode.FieldMonitored:
|
||||
m.ResetMonitored()
|
||||
return nil
|
||||
case episode.FieldTargetFile:
|
||||
m.ResetTargetFile()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Episode field %s", name)
|
||||
}
|
||||
@@ -3602,6 +3675,7 @@ type MediaMutation struct {
|
||||
target_dir *string
|
||||
download_history_episodes *bool
|
||||
limiter *schema.MediaLimiter
|
||||
extras *schema.MediaExtras
|
||||
clearedFields map[string]struct{}
|
||||
episodes map[int]struct{}
|
||||
removedepisodes map[int]struct{}
|
||||
@@ -4319,6 +4393,55 @@ func (m *MediaMutation) ResetLimiter() {
|
||||
delete(m.clearedFields, media.FieldLimiter)
|
||||
}
|
||||
|
||||
// SetExtras sets the "extras" field.
|
||||
func (m *MediaMutation) SetExtras(se schema.MediaExtras) {
|
||||
m.extras = &se
|
||||
}
|
||||
|
||||
// Extras returns the value of the "extras" field in the mutation.
|
||||
func (m *MediaMutation) Extras() (r schema.MediaExtras, exists bool) {
|
||||
v := m.extras
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldExtras returns the old "extras" field's value of the Media entity.
|
||||
// If the Media object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *MediaMutation) OldExtras(ctx context.Context) (v schema.MediaExtras, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExtras is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldExtras requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldExtras: %w", err)
|
||||
}
|
||||
return oldValue.Extras, nil
|
||||
}
|
||||
|
||||
// ClearExtras clears the value of the "extras" field.
|
||||
func (m *MediaMutation) ClearExtras() {
|
||||
m.extras = nil
|
||||
m.clearedFields[media.FieldExtras] = struct{}{}
|
||||
}
|
||||
|
||||
// ExtrasCleared returns if the "extras" field was cleared in this mutation.
|
||||
func (m *MediaMutation) ExtrasCleared() bool {
|
||||
_, ok := m.clearedFields[media.FieldExtras]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetExtras resets all changes to the "extras" field.
|
||||
func (m *MediaMutation) ResetExtras() {
|
||||
m.extras = nil
|
||||
delete(m.clearedFields, media.FieldExtras)
|
||||
}
|
||||
|
||||
// AddEpisodeIDs adds the "episodes" edge to the Episode entity by ids.
|
||||
func (m *MediaMutation) AddEpisodeIDs(ids ...int) {
|
||||
if m.episodes == nil {
|
||||
@@ -4407,7 +4530,7 @@ func (m *MediaMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *MediaMutation) Fields() []string {
|
||||
fields := make([]string, 0, 14)
|
||||
fields := make([]string, 0, 15)
|
||||
if m.tmdb_id != nil {
|
||||
fields = append(fields, media.FieldTmdbID)
|
||||
}
|
||||
@@ -4450,6 +4573,9 @@ func (m *MediaMutation) Fields() []string {
|
||||
if m.limiter != nil {
|
||||
fields = append(fields, media.FieldLimiter)
|
||||
}
|
||||
if m.extras != nil {
|
||||
fields = append(fields, media.FieldExtras)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -4486,6 +4612,8 @@ func (m *MediaMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.DownloadHistoryEpisodes()
|
||||
case media.FieldLimiter:
|
||||
return m.Limiter()
|
||||
case media.FieldExtras:
|
||||
return m.Extras()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -4523,6 +4651,8 @@ func (m *MediaMutation) OldField(ctx context.Context, name string) (ent.Value, e
|
||||
return m.OldDownloadHistoryEpisodes(ctx)
|
||||
case media.FieldLimiter:
|
||||
return m.OldLimiter(ctx)
|
||||
case media.FieldExtras:
|
||||
return m.OldExtras(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
@@ -4630,6 +4760,13 @@ func (m *MediaMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetLimiter(v)
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
v, ok := value.(schema.MediaExtras)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetExtras(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
@@ -4702,6 +4839,9 @@ func (m *MediaMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(media.FieldLimiter) {
|
||||
fields = append(fields, media.FieldLimiter)
|
||||
}
|
||||
if m.FieldCleared(media.FieldExtras) {
|
||||
fields = append(fields, media.FieldExtras)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -4731,6 +4871,9 @@ func (m *MediaMutation) ClearField(name string) error {
|
||||
case media.FieldLimiter:
|
||||
m.ClearLimiter()
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
m.ClearExtras()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media nullable field %s", name)
|
||||
}
|
||||
@@ -4781,6 +4924,9 @@ func (m *MediaMutation) ResetField(name string) error {
|
||||
case media.FieldLimiter:
|
||||
m.ResetLimiter()
|
||||
return nil
|
||||
case media.FieldExtras:
|
||||
m.ResetExtras()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
|
||||
@@ -22,16 +22,17 @@ func (Episode) Fields() []ent.Field {
|
||||
field.String("air_date"),
|
||||
field.Enum("status").Values("missing", "downloading", "downloaded").Default("missing"),
|
||||
field.Bool("monitored").Default(false).StructTag("json:\"monitored\""), //whether this episode is monitored
|
||||
field.String("target_file").Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Episode.
|
||||
func (Episode) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("media", Media.Type).
|
||||
Ref("episodes").
|
||||
Unique().
|
||||
edge.From("media", Media.Type).
|
||||
Ref("episodes").
|
||||
Unique().
|
||||
Field("media_id"),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func (History) Fields() []ent.Field {
|
||||
field.Int("size").Default(0),
|
||||
field.Int("download_client_id").Optional(),
|
||||
field.Int("indexer_id").Optional(),
|
||||
field.Enum("status").Values("running", "success", "fail", "uploading"),
|
||||
field.Enum("status").Values("running", "success", "fail", "uploading", "seeding"),
|
||||
field.String("saved").Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func (Media) Fields() []ent.Field {
|
||||
field.String("target_dir").Optional(),
|
||||
field.Bool("download_history_episodes").Optional().Default(false).Comment("tv series only"),
|
||||
field.JSON("limiter", MediaLimiter{}).Optional(),
|
||||
field.JSON("extras", MediaExtras{}).Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +45,18 @@ type MediaLimiter struct {
|
||||
SizeMin int `json:"size_min"` //in B
|
||||
SizeMax int `json:"size_max"` //in B
|
||||
}
|
||||
|
||||
type MediaExtras struct {
|
||||
IsAdultMovie bool `json:"is_adult_movie"`
|
||||
JavId string `json:"javid"`
|
||||
//OriginCountry []string `json:"origin_country"`
|
||||
OriginalLanguage string `json:"original_language"`
|
||||
Genres []struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"genres"`
|
||||
}
|
||||
|
||||
func (m *MediaExtras) IsJav() bool {
|
||||
return m.IsAdultMovie && m.JavId != ""
|
||||
}
|
||||
|
||||
8
go.sum
@@ -101,6 +101,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||
@@ -116,6 +118,8 @@ github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/nikoksr/notify v1.0.0 h1:qe9/6FRsWdxBgQgWcpvQ0sv8LRGJZDpRB4TkL2uNdO8=
|
||||
github.com/nikoksr/notify v1.0.0/go.mod h1:hPaaDt30d6LAA7/5nb0e48Bp/MctDfycCSs8VEgN29I=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
@@ -139,6 +143,8 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
|
||||
@@ -201,6 +207,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
|
||||
@@ -11,6 +11,7 @@ type MovieMetadata struct {
|
||||
Name string
|
||||
Year int
|
||||
Resolution string
|
||||
IsQingban bool
|
||||
}
|
||||
|
||||
func ParseMovie(name string) *MovieMetadata {
|
||||
@@ -50,5 +51,22 @@ func ParseMovie(name string) *MovieMetadata {
|
||||
if len(resMatches) > 0 {
|
||||
meta.Resolution = resMatches[0]
|
||||
}
|
||||
meta.IsQingban = isQiangban(name)
|
||||
return meta
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Pirated_movie_release_types
|
||||
func isQiangban(name string) bool {
|
||||
qiangbanFilter := []string{"CAMRip","CAM-Rip", "CAM", "HDCAM", "TS","TSRip", "HDTS", "TELESYNC", "PDVD", "PreDVDRip", "TC", "HDTC", "TELECINE", "WP", "WORKPRINT"}
|
||||
re := regexp.MustCompile(`\W`)
|
||||
name = re.ReplaceAllString(strings.ToLower(name), " ")
|
||||
fields := strings.Fields(name)
|
||||
for _, q := range qiangbanFilter {
|
||||
for _, f := range fields {
|
||||
if strings.EqualFold(q, f) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -99,5 +99,7 @@ func (l *LocalStorage) ReadFile(name string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (l *LocalStorage) WriteFile(name string, data []byte) error {
|
||||
return os.WriteFile(filepath.Join(l.dir, name), data, os.ModePerm)
|
||||
path := filepath.Join(l.dir, name)
|
||||
os.MkdirAll(filepath.Dir(path), os.ModePerm)
|
||||
return os.WriteFile(path, data, os.ModePerm)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
@@ -204,6 +209,11 @@ func (c *Client) GetTVAlternativeTitles(id int, language string) (*tmdb.TVAltern
|
||||
return c.tmdbClient.GetTVAlternativeTitles(id, withLangOption(language))
|
||||
}
|
||||
|
||||
func (c *Client) GetMovieAlternativeTitles(id int, language string) (*tmdb.MovieAlternativeTitles, error) {
|
||||
return c.tmdbClient.GetMovieAlternativeTitles(id, withLangOption(language))
|
||||
}
|
||||
|
||||
|
||||
func wrapLanguage(lang string) string {
|
||||
if lang == "" {
|
||||
lang = "zh-CN"
|
||||
|
||||
@@ -5,4 +5,4 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var cc = cache.NewCache[string, Response](time.Minute * 30)
|
||||
var cc = cache.NewCache[string, *Response](time.Minute * 30)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -76,6 +77,9 @@ func (i *Item) GetAttr(key string) string {
|
||||
func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
|
||||
var res []Result
|
||||
for _, item := range r.Channel.Item {
|
||||
if slices.Contains(item.Category, "3000") { //exclude audio files
|
||||
continue
|
||||
}
|
||||
r := Result{
|
||||
Name: item.Title,
|
||||
Link: item.Link,
|
||||
@@ -83,6 +87,7 @@ func (r *Response) ToResults(indexer *db.TorznabInfo) []Result {
|
||||
Seeders: mustAtoI(item.GetAttr("seeders")),
|
||||
Peers: mustAtoI(item.GetAttr("peers")),
|
||||
Category: mustAtoI(item.GetAttr("category")),
|
||||
ImdbId: item.GetAttr("imdbid"),
|
||||
DownloadVolumeFactor: tryParseFloat(item.GetAttr("downloadvolumefactor")),
|
||||
UploadVolumeFactor: tryParseFloat(item.GetAttr("uploadvolumefactor")),
|
||||
Source: indexer.Name,
|
||||
@@ -130,19 +135,10 @@ func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
|
||||
cacheRes, ok := cc.Get(key)
|
||||
if !ok {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
res, err := doRequest(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "do http")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "read http body")
|
||||
}
|
||||
var res Response
|
||||
err = xml.Unmarshal(data, &res)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "json unmarshal")
|
||||
cc.Set(key, &Response{})
|
||||
return nil, errors.Wrap(err, "do http request")
|
||||
}
|
||||
cacheRes = res
|
||||
cc.Set(key, cacheRes)
|
||||
@@ -150,6 +146,24 @@ func Search(indexer *db.TorznabInfo, keyWord string) ([]Result, error) {
|
||||
return cacheRes.ToResults(indexer), nil
|
||||
}
|
||||
|
||||
func doRequest(req *http.Request) (*Response, error) {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "do http")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "read http body")
|
||||
}
|
||||
var res Response
|
||||
err = xml.Unmarshal(data, &res)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "xml unmarshal data: %v", string(data))
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Name string `json:"name"`
|
||||
Link string `json:"link"`
|
||||
@@ -163,4 +177,5 @@ type Result struct {
|
||||
IndexerId int `json:"indexer_id"`
|
||||
Priority int `json:"priority"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
ImdbId string `json:"imdb_id"`
|
||||
}
|
||||
|
||||
@@ -15,31 +15,41 @@ import (
|
||||
|
||||
type Activity struct {
|
||||
*ent.History
|
||||
Progress int `json:"progress"`
|
||||
Progress int `json:"progress"`
|
||||
SeedRatio float32 `json:"seed_ratio"`
|
||||
}
|
||||
|
||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
q := c.Query("status")
|
||||
his := s.db.GetHistories()
|
||||
var activities = make([]Activity, 0, len(his))
|
||||
for _, h := range his {
|
||||
if q == "active" && (h.Status != history.StatusRunning && h.Status != history.StatusUploading) {
|
||||
continue //active downloads
|
||||
} else if q == "archive" && (h.Status == history.StatusRunning || h.Status == history.StatusUploading) {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
for id, task := range s.core.GetTasks() {
|
||||
if h.ID == id && task.Exists() {
|
||||
a.Progress = task.Progress()
|
||||
var activities = make([]Activity, 0)
|
||||
if q == "active" {
|
||||
his := s.db.GetRunningHistories()
|
||||
for _, h := range his {
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
for id, task := range s.core.GetTasks() {
|
||||
if h.ID == id && task.Exists() {
|
||||
a.Progress = task.Progress()
|
||||
a.SeedRatio = float32(*task.SeedRatio())
|
||||
}
|
||||
}
|
||||
activities = append(activities, a)
|
||||
}
|
||||
activities = append(activities, a)
|
||||
}
|
||||
} else {
|
||||
his := s.db.GetHistories()
|
||||
for _, h := range his {
|
||||
if h.Status == history.StatusRunning || h.Status == history.StatusUploading || h.Status == history.StatusSeeding {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
activities = append(activities, a)
|
||||
}
|
||||
|
||||
}
|
||||
return activities, nil
|
||||
}
|
||||
|
||||
@@ -60,7 +70,9 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
|
||||
if his.EpisodeID != 0 {
|
||||
s.db.SetEpisodeStatus(his.EpisodeID, episode.StatusMissing)
|
||||
if his.Status == history.StatusRunning || his.Status == history.StatusUploading {
|
||||
s.db.SetEpisodeStatus(his.EpisodeID, episode.StatusMissing)
|
||||
}
|
||||
|
||||
} else {
|
||||
seasonNum, err := utils.SeasonId(his.TargetDir)
|
||||
@@ -68,8 +80,9 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
|
||||
log.Errorf("no season id: %v", his.TargetDir)
|
||||
seasonNum = -1
|
||||
}
|
||||
s.db.SetSeasonAllEpisodeStatus(his.MediaID, seasonNum, episode.StatusMissing)
|
||||
|
||||
if his.Status == history.StatusRunning || his.Status == history.StatusUploading {
|
||||
s.db.SetSeasonAllEpisodeStatus(his.MediaID, seasonNum, episode.StatusMissing)
|
||||
}
|
||||
}
|
||||
|
||||
err = s.db.DeleteHistory(id)
|
||||
|
||||
@@ -33,7 +33,7 @@ func (c *Client) Init() {
|
||||
}
|
||||
|
||||
func (c *Client) reloadTasks() {
|
||||
allTasks := c.db.GetHistories()
|
||||
allTasks := c.db.GetRunningHistories()
|
||||
for _, t := range allTasks {
|
||||
torrent, err := transmission.ReloadTorrent(t.Saved)
|
||||
if err != nil {
|
||||
@@ -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 {
|
||||
@@ -78,8 +79,7 @@ func (c *Client) MustTMDB() *tmdb.Client {
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
func (c *Client) RemoveTaskAndTorrent(id int)error {
|
||||
func (c *Client) RemoveTaskAndTorrent(id int) error {
|
||||
torrent := c.tasks[id]
|
||||
if torrent != nil {
|
||||
if err := torrent.Remove(); err != nil {
|
||||
@@ -92,4 +92,4 @@ func (c *Client) RemoveTaskAndTorrent(id int)error {
|
||||
|
||||
func (c *Client) GetTasks() map[int]*Task {
|
||||
return c.tasks
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,122 @@ package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"polaris/db"
|
||||
"polaris/ent/media"
|
||||
storage1 "polaris/ent/storage"
|
||||
"polaris/log"
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/notifier"
|
||||
"polaris/pkg/storage"
|
||||
"polaris/pkg/utils"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) writePlexmatch(seriesId int, episodeId int, targetDir, name string) error {
|
||||
func (c *Client) writeNfoFile(historyId int) error {
|
||||
if !c.nfoSupportEnabled() {
|
||||
return nil
|
||||
}
|
||||
|
||||
his := c.db.GetHistory(historyId)
|
||||
|
||||
md, err := c.db.GetMedia(his.MediaID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if md.MediaType == media.MediaTypeTv { //tvshow.nfo
|
||||
st, err := c.getStorage(md.StorageID, media.MediaTypeTv)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get storage")
|
||||
}
|
||||
|
||||
nfoPath := filepath.Join(md.TargetDir, "tvshow.nfo")
|
||||
_, err = st.ReadFile(nfoPath)
|
||||
if err != nil {
|
||||
log.Infof("tvshow.nfo file missing, create new one, tv series name: %s", md.NameEn)
|
||||
show := Tvshow{
|
||||
Title: md.NameCn,
|
||||
Originaltitle: md.OriginalName,
|
||||
Showtitle: md.NameCn,
|
||||
Plot: md.Overview,
|
||||
ID: strconv.Itoa(md.TmdbID),
|
||||
Uniqueid: []UniqueId{
|
||||
{
|
||||
Text: strconv.Itoa(md.TmdbID),
|
||||
Type: "tmdb",
|
||||
Default: "true",
|
||||
},
|
||||
{
|
||||
Text: md.ImdbID,
|
||||
Type: "imdb",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := xml.MarshalIndent(&show, " ", " ")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "xml marshal")
|
||||
}
|
||||
return st.WriteFile(nfoPath, data)
|
||||
}
|
||||
|
||||
} else if md.MediaType == media.MediaTypeMovie { //movie.nfo
|
||||
st, err := c.getStorage(md.StorageID, media.MediaTypeMovie)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get storage")
|
||||
}
|
||||
|
||||
nfoPath := filepath.Join(md.TargetDir, "movie.nfo")
|
||||
_, err = st.ReadFile(nfoPath)
|
||||
if err != nil {
|
||||
log.Infof("movie.nfo file missing, create new one, tv series name: %s", md.NameEn)
|
||||
nfoData := Movie{
|
||||
Title: md.NameCn,
|
||||
Originaltitle: md.OriginalName,
|
||||
Sorttitle: md.NameCn,
|
||||
Plot: md.Overview,
|
||||
ID: strconv.Itoa(md.TmdbID),
|
||||
Uniqueid: []UniqueId{
|
||||
{
|
||||
Text: strconv.Itoa(md.TmdbID),
|
||||
Type: "tmdb",
|
||||
Default: "true",
|
||||
},
|
||||
{
|
||||
Text: md.ImdbID,
|
||||
Type: "imdb",
|
||||
},
|
||||
},
|
||||
}
|
||||
data, err := xml.MarshalIndent(&nfoData, " ", " ")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "xml marshal")
|
||||
}
|
||||
return st.WriteFile(nfoPath, data)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) writePlexmatch(historyId int) error {
|
||||
|
||||
if !c.plexmatchEnabled() {
|
||||
return nil
|
||||
}
|
||||
series, err := c.db.GetMedia(seriesId)
|
||||
|
||||
his := c.db.GetHistory(historyId)
|
||||
|
||||
series, err := c.db.GetMedia(his.MediaID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if series.MediaType != media.MediaTypeTv {
|
||||
if series.MediaType != media.MediaTypeTv { //.plexmatch only support tv series
|
||||
return nil
|
||||
}
|
||||
st, err := c.getStorage(series.StorageID, media.MediaTypeTv)
|
||||
@@ -47,24 +140,49 @@ func (c *Client) writePlexmatch(seriesId int, episodeId int, targetDir, name str
|
||||
}
|
||||
}
|
||||
|
||||
//season plexmatch file
|
||||
ep, err := c.db.GetEpisodeByID(episodeId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "query episode")
|
||||
}
|
||||
buff := bytes.Buffer{}
|
||||
seasonPlex := filepath.Join(targetDir, ".plexmatch")
|
||||
seasonPlex := filepath.Join(his.TargetDir, ".plexmatch")
|
||||
data, err := st.ReadFile(seasonPlex)
|
||||
if err != nil {
|
||||
log.Infof("read season plexmatch: %v", err)
|
||||
} else {
|
||||
buff.Write(data)
|
||||
}
|
||||
if strings.Contains(buff.String(), name) {
|
||||
log.Debugf("already write plex episode line: %v", name)
|
||||
return nil
|
||||
|
||||
if his.EpisodeID > 0 {
|
||||
//single episode download
|
||||
ep, err := c.db.GetEpisodeByID(his.EpisodeID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "query episode")
|
||||
}
|
||||
if strings.Contains(buff.String(), ep.TargetFile) {
|
||||
log.Debugf("already write plex episode line: %v", ep.TargetFile)
|
||||
return nil
|
||||
}
|
||||
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, ep.TargetFile))
|
||||
} else {
|
||||
seasonNum, err := utils.SeasonId(his.TargetDir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "no season id")
|
||||
}
|
||||
allEpisodes, err := c.db.GetSeasonEpisodes(his.MediaID, seasonNum)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "query season episode")
|
||||
}
|
||||
for _, ep := range allEpisodes {
|
||||
if ep.TargetFile == "" {
|
||||
log.Errorf("no episode file of episode %d, season %d", ep.EpisodeNumber, ep.SeasonNumber)
|
||||
//TODO update db
|
||||
continue
|
||||
}
|
||||
if strings.Contains(buff.String(), ep.TargetFile) {
|
||||
log.Debugf("already write plex episode line: %v", ep.TargetFile)
|
||||
continue
|
||||
}
|
||||
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, ep.TargetFile))
|
||||
}
|
||||
|
||||
}
|
||||
buff.WriteString(fmt.Sprintf("\nep: %d: %s\n", ep.EpisodeNumber, name))
|
||||
log.Infof("write season plexmatch file content: %s", buff.String())
|
||||
return st.WriteFile(seasonPlex, buff.Bytes())
|
||||
}
|
||||
@@ -73,6 +191,10 @@ func (c *Client) plexmatchEnabled() bool {
|
||||
return c.db.GetSetting(db.SettingPlexMatchEnabled) == "true"
|
||||
}
|
||||
|
||||
func (c *Client) nfoSupportEnabled() bool {
|
||||
return c.db.GetSetting(db.SettingNfoSupportEnabled) == "true"
|
||||
}
|
||||
|
||||
func (c *Client) getStorage(storageId int, mediaType media.MediaType) (storage.Storage, error) {
|
||||
st := c.db.GetStorage(storageId)
|
||||
targetPath := st.TvPath
|
||||
@@ -128,3 +250,63 @@ func (c *Client) sendMsg(msg string) {
|
||||
log.Debugf("send message to %s success, msg is %s", cl.Name, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) findEpisodeFilesPreMoving(historyId int) error {
|
||||
his := c.db.GetHistory(historyId)
|
||||
|
||||
isSingleEpisode := his.EpisodeID > 0
|
||||
downloadDir := c.db.GetDownloadDir()
|
||||
task := c.tasks[historyId]
|
||||
target := filepath.Join(downloadDir, task.Name())
|
||||
fi, err := os.Stat(target)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "read dir %v", target)
|
||||
}
|
||||
if isSingleEpisode {
|
||||
if fi.IsDir() {
|
||||
//download single episode in dir
|
||||
//TODO
|
||||
} else {
|
||||
//is file
|
||||
if err := c.db.UpdateEpisodeTargetFile(his.EpisodeID, fi.Name()); err != nil {
|
||||
log.Errorf("writing downloaded file name to db error: %v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if !fi.IsDir() {
|
||||
return fmt.Errorf("not season pack downloaded")
|
||||
}
|
||||
seasonNum, err := utils.SeasonId(his.TargetDir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "no season id")
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
if f.IsDir() { //want media file
|
||||
continue
|
||||
}
|
||||
excludedExt := []string{".txt", ".srt", ".ass", ".sub"}
|
||||
ext := filepath.Ext(f.Name())
|
||||
if slices.Contains(excludedExt, strings.ToLower(ext)) {
|
||||
continue
|
||||
}
|
||||
|
||||
meta := metadata.ParseTv(f.Name())
|
||||
if meta.Episode > 0 {
|
||||
//episode exists
|
||||
ep, err := c.db.GetEpisode(his.MediaID, seasonNum, meta.Episode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.db.UpdateEpisodeTargetFile(ep.ID, f.Name()); err != nil {
|
||||
return errors.Wrap(err, "update episode file")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
253
server/core/nfo.go
Normal file
@@ -0,0 +1,253 @@
|
||||
package core
|
||||
|
||||
import "encoding/xml"
|
||||
|
||||
type Tvshow struct {
|
||||
XMLName xml.Name `xml:"tvshow"`
|
||||
Text string `xml:",chardata"`
|
||||
Title string `xml:"title"`
|
||||
Originaltitle string `xml:"originaltitle"`
|
||||
Showtitle string `xml:"showtitle"`
|
||||
Ratings struct {
|
||||
Text string `xml:",chardata"`
|
||||
Rating []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name,attr"`
|
||||
Max string `xml:"max,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
Value string `xml:"value"`
|
||||
Votes string `xml:"votes"`
|
||||
} `xml:"rating"`
|
||||
} `xml:"ratings"`
|
||||
Userrating string `xml:"userrating"`
|
||||
Top250 string `xml:"top250"`
|
||||
Season string `xml:"season"`
|
||||
Episode string `xml:"episode"`
|
||||
Displayseason string `xml:"displayseason"`
|
||||
Displayepisode string `xml:"displayepisode"`
|
||||
Outline string `xml:"outline"`
|
||||
Plot string `xml:"plot"`
|
||||
Tagline string `xml:"tagline"`
|
||||
Runtime string `xml:"runtime"`
|
||||
Thumb []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Spoof string `xml:"spoof,attr"`
|
||||
Cache string `xml:"cache,attr"`
|
||||
Aspect string `xml:"aspect,attr"`
|
||||
Preview string `xml:"preview,attr"`
|
||||
Season string `xml:"season,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
} `xml:"thumb"`
|
||||
Fanart struct {
|
||||
Text string `xml:",chardata"`
|
||||
Thumb []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Colors string `xml:"colors,attr"`
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
} `xml:"fanart"`
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Premiered string `xml:"premiered"`
|
||||
Year string `xml:"year"`
|
||||
Status string `xml:"status"`
|
||||
Code string `xml:"code"`
|
||||
Aired string `xml:"aired"`
|
||||
Studio string `xml:"studio"`
|
||||
Trailer string `xml:"trailer"`
|
||||
Actor []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Role string `xml:"role"`
|
||||
Order string `xml:"order"`
|
||||
Thumb string `xml:"thumb"`
|
||||
} `xml:"actor"`
|
||||
Namedseason []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Number string `xml:"number,attr"`
|
||||
} `xml:"namedseason"`
|
||||
Resume struct {
|
||||
Text string `xml:",chardata"`
|
||||
Position string `xml:"position"`
|
||||
Total string `xml:"total"`
|
||||
} `xml:"resume"`
|
||||
Dateadded string `xml:"dateadded"`
|
||||
}
|
||||
|
||||
type UniqueId struct {
|
||||
Text string `xml:",chardata"`
|
||||
Type string `xml:"type,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
}
|
||||
|
||||
type Episodedetails struct {
|
||||
XMLName xml.Name `xml:"episodedetails"`
|
||||
Text string `xml:",chardata"`
|
||||
Title string `xml:"title"`
|
||||
Showtitle string `xml:"showtitle"`
|
||||
Ratings struct {
|
||||
Text string `xml:",chardata"`
|
||||
Rating []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name,attr"`
|
||||
Max string `xml:"max,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
Value string `xml:"value"`
|
||||
Votes string `xml:"votes"`
|
||||
} `xml:"rating"`
|
||||
} `xml:"ratings"`
|
||||
Userrating string `xml:"userrating"`
|
||||
Top250 string `xml:"top250"`
|
||||
Season string `xml:"season"`
|
||||
Episode string `xml:"episode"`
|
||||
Displayseason string `xml:"displayseason"`
|
||||
Displayepisode string `xml:"displayepisode"`
|
||||
Outline string `xml:"outline"`
|
||||
Plot string `xml:"plot"`
|
||||
Tagline string `xml:"tagline"`
|
||||
Runtime string `xml:"runtime"`
|
||||
Thumb []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Spoof string `xml:"spoof,attr"`
|
||||
Cache string `xml:"cache,attr"`
|
||||
Aspect string `xml:"aspect,attr"`
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Type string `xml:"type,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
} `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Credits []string `xml:"credits"`
|
||||
Director string `xml:"director"`
|
||||
Premiered string `xml:"premiered"`
|
||||
Year string `xml:"year"`
|
||||
Status string `xml:"status"`
|
||||
Code string `xml:"code"`
|
||||
Aired string `xml:"aired"`
|
||||
Studio string `xml:"studio"`
|
||||
Trailer string `xml:"trailer"`
|
||||
Actor []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Role string `xml:"role"`
|
||||
Order string `xml:"order"`
|
||||
Thumb string `xml:"thumb"`
|
||||
} `xml:"actor"`
|
||||
Resume struct {
|
||||
Text string `xml:",chardata"`
|
||||
Position string `xml:"position"`
|
||||
Total string `xml:"total"`
|
||||
} `xml:"resume"`
|
||||
Dateadded string `xml:"dateadded"`
|
||||
}
|
||||
|
||||
type Movie struct {
|
||||
XMLName xml.Name `xml:"movie"`
|
||||
Text string `xml:",chardata"`
|
||||
Title string `xml:"title"`
|
||||
Originaltitle string `xml:"originaltitle"`
|
||||
Sorttitle string `xml:"sorttitle"`
|
||||
Ratings struct {
|
||||
Text string `xml:",chardata"`
|
||||
Rating []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name,attr"`
|
||||
Max string `xml:"max,attr"`
|
||||
Default string `xml:"default,attr"`
|
||||
Value string `xml:"value"`
|
||||
Votes string `xml:"votes"`
|
||||
} `xml:"rating"`
|
||||
} `xml:"ratings"`
|
||||
Userrating string `xml:"userrating"`
|
||||
Top250 string `xml:"top250"`
|
||||
Outline string `xml:"outline"`
|
||||
Plot string `xml:"plot"`
|
||||
Tagline string `xml:"tagline"`
|
||||
Runtime string `xml:"runtime"`
|
||||
Thumb []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Spoof string `xml:"spoof,attr"`
|
||||
Cache string `xml:"cache,attr"`
|
||||
Aspect string `xml:"aspect,attr"`
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
Fanart struct {
|
||||
Text string `xml:",chardata"`
|
||||
Thumb struct {
|
||||
Text string `xml:",chardata"`
|
||||
Colors string `xml:"colors,attr"`
|
||||
Preview string `xml:"preview,attr"`
|
||||
} `xml:"thumb"`
|
||||
} `xml:"fanart"`
|
||||
Mpaa string `xml:"mpaa"`
|
||||
Playcount string `xml:"playcount"`
|
||||
Lastplayed string `xml:"lastplayed"`
|
||||
ID string `xml:"id"`
|
||||
Uniqueid []UniqueId `xml:"uniqueid"`
|
||||
Genre string `xml:"genre"`
|
||||
Country []string `xml:"country"`
|
||||
Set struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Overview string `xml:"overview"`
|
||||
} `xml:"set"`
|
||||
Tag []string `xml:"tag"`
|
||||
Videoassettitle string `xml:"videoassettitle"`
|
||||
Videoassetid string `xml:"videoassetid"`
|
||||
Videoassettype string `xml:"videoassettype"`
|
||||
Hasvideoversions string `xml:"hasvideoversions"`
|
||||
Hasvideoextras string `xml:"hasvideoextras"`
|
||||
Isdefaultvideoversion string `xml:"isdefaultvideoversion"`
|
||||
Credits []string `xml:"credits"`
|
||||
Director string `xml:"director"`
|
||||
Premiered string `xml:"premiered"`
|
||||
Year string `xml:"year"`
|
||||
Status string `xml:"status"`
|
||||
Code string `xml:"code"`
|
||||
Aired string `xml:"aired"`
|
||||
Studio string `xml:"studio"`
|
||||
Trailer string `xml:"trailer"`
|
||||
Fileinfo struct {
|
||||
Text string `xml:",chardata"`
|
||||
Streamdetails struct {
|
||||
Text string `xml:",chardata"`
|
||||
Video struct {
|
||||
Text string `xml:",chardata"`
|
||||
Codec string `xml:"codec"`
|
||||
Aspect string `xml:"aspect"`
|
||||
Width string `xml:"width"`
|
||||
Height string `xml:"height"`
|
||||
Durationinseconds string `xml:"durationinseconds"`
|
||||
Stereomode string `xml:"stereomode"`
|
||||
Hdrtype string `xml:"hdrtype"`
|
||||
} `xml:"video"`
|
||||
Audio struct {
|
||||
Text string `xml:",chardata"`
|
||||
Codec string `xml:"codec"`
|
||||
Language string `xml:"language"`
|
||||
Channels string `xml:"channels"`
|
||||
} `xml:"audio"`
|
||||
Subtitle struct {
|
||||
Text string `xml:",chardata"`
|
||||
Language string `xml:"language"`
|
||||
} `xml:"subtitle"`
|
||||
} `xml:"streamdetails"`
|
||||
} `xml:"fileinfo"`
|
||||
Actor []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Name string `xml:"name"`
|
||||
Role string `xml:"role"`
|
||||
Order string `xml:"order"`
|
||||
Thumb string `xml:"thumb"`
|
||||
} `xml:"actor"`
|
||||
}
|
||||
@@ -67,7 +67,9 @@ func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum,
|
||||
return nil, errors.Wrap(err, "save record")
|
||||
}
|
||||
if episodeNum > 0 {
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
if ep.Status == episode.StatusMissing {
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
}
|
||||
} else {
|
||||
c.db.SetSeasonAllEpisodeStatus(seriesId, seasonNum, episode.StatusDownloading)
|
||||
}
|
||||
@@ -80,8 +82,17 @@ func (c *Client) DownloadEpisodeTorrent(r1 torznab.Result, seriesId, seasonNum,
|
||||
|
||||
}
|
||||
func (c *Client) SearchAndDownload(seriesId, seasonNum, episodeNum int) (*string, error) {
|
||||
|
||||
res, err := SearchTvSeries(c.db, seriesId, seasonNum, []int{episodeNum}, true, true)
|
||||
var episodes []int
|
||||
if episodeNum > 0 {
|
||||
episodes = append(episodes, episodeNum)
|
||||
}
|
||||
res, err := SearchTvSeries(c.db, &SearchParam{
|
||||
MediaId: seriesId,
|
||||
SeasonNum: seasonNum,
|
||||
Episodes: episodes,
|
||||
CheckFileSize: true,
|
||||
CheckResolution: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -124,7 +135,10 @@ func (c *Client) DownloadMovie(m *ent.Media, link, name string, size int, indexe
|
||||
|
||||
c.tasks[history.ID] = &Task{Torrent: torrent}
|
||||
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
if ep.Status == episode.StatusMissing {
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
c.sendMsg(fmt.Sprintf(message.BeginDownload, name))
|
||||
|
||||
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"polaris/db"
|
||||
"polaris/ent"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -18,8 +19,8 @@ import (
|
||||
func (c *Client) addSysCron() {
|
||||
c.mustAddCron("@every 1m", c.checkTasks)
|
||||
c.mustAddCron("0 0 * * * *", func() {
|
||||
c.downloadTvSeries()
|
||||
c.downloadMovie()
|
||||
c.downloadAllTvSeries()
|
||||
c.downloadAllMovies()
|
||||
})
|
||||
c.mustAddCron("0 0 */12 * * *", c.checkAllSeriesNewSeason)
|
||||
c.cron.Start()
|
||||
@@ -35,38 +36,53 @@ func (c *Client) mustAddCron(spec string, cmd func()) {
|
||||
func (c *Client) checkTasks() {
|
||||
log.Debug("begin check tasks...")
|
||||
for id, t := range c.tasks {
|
||||
r := c.db.GetHistory(id)
|
||||
if !t.Exists() {
|
||||
log.Infof("task no longer exists: %v", id)
|
||||
|
||||
delete(c.tasks, id)
|
||||
continue
|
||||
}
|
||||
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
|
||||
if t.Progress() == 100 {
|
||||
r := c.db.GetHistory(id)
|
||||
if r.Status == history.StatusSuccess {
|
||||
|
||||
if r.Status == history.StatusSeeding {
|
||||
//task already success, check seed ratio
|
||||
torrent := c.tasks[id]
|
||||
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if ok {
|
||||
log.Infof("torrent file seed ratio reached, remove: %v", torrent.Name())
|
||||
log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", torrent.Name(), *torrent.SeedRatio())
|
||||
torrent.Remove()
|
||||
delete(c.tasks, id)
|
||||
} else {
|
||||
log.Infof("torrent file still sedding: %v", torrent.Name())
|
||||
log.Infof("torrent file still sedding: %v, current seed ratio: %v", torrent.Name(), *torrent.SeedRatio())
|
||||
}
|
||||
continue
|
||||
}
|
||||
log.Infof("task is done: %v", t.Name())
|
||||
c.sendMsg(fmt.Sprintf(message.DownloadComplete, t.Name()))
|
||||
go func() {
|
||||
if err := c.moveCompletedTask(id); err != nil {
|
||||
log.Infof("post tasks for id %v fail: %v", id, err)
|
||||
}
|
||||
}()
|
||||
|
||||
go c.postTaskProcessing(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) postTaskProcessing(id int) {
|
||||
if err := c.findEpisodeFilesPreMoving(id); err != nil {
|
||||
log.Errorf("finding all episode file error: %v", err)
|
||||
} else {
|
||||
if err := c.writePlexmatch(id); err != nil {
|
||||
log.Errorf("write plexmatch file error: %v", err)
|
||||
}
|
||||
if err := c.writeNfoFile(id); err != nil {
|
||||
log.Errorf("write nfo file error: %v", err)
|
||||
}
|
||||
}
|
||||
if err := c.moveCompletedTask(id); err != nil {
|
||||
log.Infof("post tasks for id %v fail: %v", id, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
torrent := c.tasks[id]
|
||||
r := c.db.GetHistory(id)
|
||||
@@ -96,7 +112,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
} else {
|
||||
c.db.SetSeasonAllEpisodeStatus(r.MediaID, seasonNum, episode.StatusMissing)
|
||||
}
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingFailed, err))
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingFailed, err1))
|
||||
if downloadclient.RemoveFailedDownloads {
|
||||
log.Debugf("task failed, remove failed torrent and files related")
|
||||
delete(c.tasks, r.ID)
|
||||
@@ -116,17 +132,12 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// .plexmatch file
|
||||
if err := c.writePlexmatch(r.MediaID, r.EpisodeID, r.TargetDir, torrentName); err != nil {
|
||||
log.Errorf("create .plexmatch file error: %v", err)
|
||||
}
|
||||
|
||||
//如果种子是路径,则会把路径展开,只移动文件,类似 move dir/* dir2/, 如果种子是文件,则会直接移动文件,类似 move file dir/
|
||||
if err := stImpl.Copy(filepath.Join(c.db.GetDownloadDir(), torrentName), r.TargetDir); err != nil {
|
||||
return errors.Wrap(err, "move file")
|
||||
}
|
||||
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSeeding)
|
||||
if r.EpisodeID != 0 {
|
||||
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusDownloaded)
|
||||
} else {
|
||||
@@ -137,7 +148,8 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
//判断是否需要删除本地文件
|
||||
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if downloadclient.RemoveCompletedDownloads && ok {
|
||||
log.Debugf("download complete,remove torrent and files related")
|
||||
log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, *torrent.SeedRatio())
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
delete(c.tasks, r.ID)
|
||||
torrent.Remove()
|
||||
}
|
||||
@@ -202,68 +214,123 @@ type Task struct {
|
||||
pkg.Torrent
|
||||
}
|
||||
|
||||
func (c *Client) downloadTvSeries() {
|
||||
log.Infof("begin check all tv series resources")
|
||||
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||
for _, series := range allSeries {
|
||||
tvDetail := c.db.GetMediaDetails(series.ID)
|
||||
for _, ep := range tvDetail.Episodes {
|
||||
if !ep.Monitored { //未监控的剧集不去下载
|
||||
continue
|
||||
func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
|
||||
tvDetail := c.db.GetMediaDetails(id)
|
||||
m := make(map[int][]*ent.Episode)
|
||||
for _, ep := range tvDetail.Episodes {
|
||||
m[ep.SeasonNumber] = append(m[ep.SeasonNumber], ep)
|
||||
}
|
||||
var allNames []string
|
||||
for seasonNum, epsides := range m {
|
||||
if seasonNum == 0 {
|
||||
continue
|
||||
}
|
||||
wantedSeasonPack := true
|
||||
for _, ep := range epsides {
|
||||
if !ep.Monitored {
|
||||
wantedSeasonPack = false
|
||||
}
|
||||
if ep.Status != episode.StatusMissing {
|
||||
wantedSeasonPack = false
|
||||
}
|
||||
}
|
||||
if wantedSeasonPack {
|
||||
name, err := c.SearchAndDownload(id, seasonNum, -1)
|
||||
if err == nil {
|
||||
allNames = append(allNames, *name)
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
} else {
|
||||
log.Warnf("finding season pack error: %v", err)
|
||||
wantedSeasonPack = false
|
||||
}
|
||||
|
||||
if ep.Status != episode.StatusMissing { //已经下载的不去下载
|
||||
continue
|
||||
}
|
||||
name, err := c.SearchAndDownload(series.ID, ep.SeasonNumber, ep.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Infof("cannot find resource to download for %s: %v", ep.Title, err)
|
||||
} else {
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
}
|
||||
if !wantedSeasonPack {
|
||||
for _, ep := range epsides {
|
||||
if !ep.Monitored {
|
||||
continue
|
||||
}
|
||||
if ep.Status != episode.StatusMissing {
|
||||
continue
|
||||
}
|
||||
name, err := c.SearchAndDownload(id, ep.SeasonNumber, ep.EpisodeNumber)
|
||||
if err != nil {
|
||||
log.Warnf("finding resoruces of season %d episode %d error: %v", ep.SeasonNumber, ep.EpisodeNumber, err)
|
||||
continue
|
||||
} else {
|
||||
allNames = append(allNames, *name)
|
||||
log.Infof("begin download torrent resource: %v", name)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return allNames
|
||||
}
|
||||
|
||||
func (c *Client) downloadMovie() {
|
||||
func (c *Client) downloadAllTvSeries() {
|
||||
log.Infof("begin check all tv series resources")
|
||||
allSeries := c.db.GetMediaWatchlist(media.MediaTypeTv)
|
||||
for _, series := range allSeries {
|
||||
c.DownloadSeriesAllEpisodes(series.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) downloadAllMovies() {
|
||||
log.Infof("begin check all movie resources")
|
||||
allSeries := c.db.GetMediaWatchlist(media.MediaTypeMovie)
|
||||
|
||||
for _, series := range allSeries {
|
||||
detail := c.db.GetMediaDetails(series.ID)
|
||||
if len(detail.Episodes) == 0 {
|
||||
log.Errorf("no related dummy episode: %v", detail.NameEn)
|
||||
continue
|
||||
}
|
||||
ep := detail.Episodes[0]
|
||||
if ep.Status == episode.StatusDownloaded {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := c.downloadMovieSingleEpisode(ep); err != nil {
|
||||
if _, err := c.DownloadMovieByID(series.ID); err != nil {
|
||||
log.Errorf("download movie error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) downloadMovieSingleEpisode(ep *ent.Episode) error {
|
||||
trc, dlc, err := c.getDownloadClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "connect transmission")
|
||||
func (c *Client) DownloadMovieByID(id int) (string, error) {
|
||||
detail := c.db.GetMediaDetails(id)
|
||||
if len(detail.Episodes) == 0 {
|
||||
return "", fmt.Errorf("no related dummy episode: %v", detail.NameEn)
|
||||
}
|
||||
ep := detail.Episodes[0]
|
||||
if ep.Status != episode.StatusMissing {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
res, err := SearchMovie(c.db, ep.MediaID, true, true)
|
||||
if name, err := c.downloadMovieSingleEpisode(ep, detail.TargetDir); err != nil {
|
||||
return "", errors.Wrap(err, "download movie")
|
||||
} else {
|
||||
return name, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) downloadMovieSingleEpisode(ep *ent.Episode, targetDir string) (string, error) {
|
||||
trc, dlc, err := c.getDownloadClient()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "connect transmission")
|
||||
}
|
||||
qiangban := c.db.GetSetting(db.SettingAllowQiangban)
|
||||
allowQiangban := false
|
||||
if qiangban == "true" {
|
||||
allowQiangban = false
|
||||
}
|
||||
|
||||
res, err := SearchMovie(c.db, &SearchParam{
|
||||
MediaId: ep.MediaID,
|
||||
CheckFileSize: true,
|
||||
CheckResolution: true,
|
||||
FilterQiangban: !allowQiangban,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
return errors.Wrap(err, "search movie")
|
||||
return "", errors.Wrap(err, "search movie")
|
||||
}
|
||||
r1 := res[0]
|
||||
log.Infof("begin download torrent resource: %v", r1.Name)
|
||||
torrent, err := trc.Download(r1.Link, c.db.GetDownloadDir())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "downloading")
|
||||
return "", errors.Wrap(err, "downloading")
|
||||
}
|
||||
torrent.Start()
|
||||
|
||||
@@ -271,7 +338,7 @@ func (c *Client) downloadMovieSingleEpisode(ep *ent.Episode) error {
|
||||
MediaID: ep.MediaID,
|
||||
EpisodeID: ep.ID,
|
||||
SourceTitle: r1.Name,
|
||||
TargetDir: "./",
|
||||
TargetDir: targetDir,
|
||||
Status: history.StatusRunning,
|
||||
Size: r1.Size,
|
||||
Saved: torrent.Save(),
|
||||
@@ -285,7 +352,7 @@ func (c *Client) downloadMovieSingleEpisode(ep *ent.Episode) error {
|
||||
c.tasks[history.ID] = &Task{Torrent: torrent}
|
||||
|
||||
c.db.SetEpisodeStatus(ep.ID, episode.StatusDownloading)
|
||||
return nil
|
||||
return r1.Name, nil
|
||||
}
|
||||
|
||||
func (c *Client) checkAllSeriesNewSeason() {
|
||||
|
||||
@@ -3,10 +3,11 @@ package core
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"polaris/pkg/metadata"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/pkg/utils"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -16,12 +17,21 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, checkResolution bool, checkFileSize bool) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(seriesId)
|
||||
type SearchParam struct {
|
||||
MediaId int
|
||||
SeasonNum int //for tv
|
||||
Episodes []int //for tv
|
||||
CheckResolution bool
|
||||
CheckFileSize bool
|
||||
FilterQiangban bool //for movie, 是否过滤枪版电影
|
||||
}
|
||||
|
||||
func SearchTvSeries(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
series := db1.GetMediaDetails(param.MediaId)
|
||||
if series == nil {
|
||||
return nil, fmt.Errorf("no tv series of id %v", seriesId)
|
||||
return nil, fmt.Errorf("no tv series of id %v", param.MediaId)
|
||||
}
|
||||
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, seasonNum, episodes)
|
||||
log.Debugf("check tv series %s, season %d, episode %v", series.NameEn, param.SeasonNum, param.Episodes)
|
||||
|
||||
res := searchWithTorznab(db1, series.NameEn, series.NameCn, series.OriginalName)
|
||||
|
||||
@@ -32,39 +42,39 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
|
||||
if meta == nil { //cannot parse name
|
||||
continue
|
||||
}
|
||||
if !isNumberedSeries(series) && meta.Season != seasonNum { //do not check season on series that only rely on episode number
|
||||
if isImdbidNotMatch(series.ImdbID, r.ImdbId) { //has imdb id and not match
|
||||
continue
|
||||
}
|
||||
|
||||
if !imdbIDMatchExact(series.ImdbID, r.ImdbId) { //imdb id not exact match, check file name
|
||||
if !torrentNameOk(series, r.Name) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if !isNoSeasonSeries(series) && meta.Season != param.SeasonNum { //do not check season on series that only rely on episode number
|
||||
continue
|
||||
|
||||
}
|
||||
if isNumberedSeries(series) && len(episodes) == 0 {
|
||||
if isNoSeasonSeries(series) && len(param.Episodes) == 0 {
|
||||
//should not want season
|
||||
continue
|
||||
}
|
||||
|
||||
if len(episodes) > 0 && !slices.Contains(episodes, meta.Episode) { //not season pack, but episode number not equal
|
||||
if len(param.Episodes) > 0 && !slices.Contains(param.Episodes, meta.Episode) { //not season pack, but episode number not equal
|
||||
continue
|
||||
|
||||
} else if len(episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
|
||||
} else if len(param.Episodes) == 0 && !meta.IsSeasonPack { //want season pack, but not season pack
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != series.Resolution.String() {
|
||||
continue
|
||||
}
|
||||
if !utils.IsNameAcceptable(meta.NameEn, series.NameEn) && !utils.IsNameAcceptable(meta.NameCn, series.NameCn) &&
|
||||
!utils.IsNameAcceptable(meta.NameCn, series.OriginalName) {
|
||||
if param.CheckResolution && meta.Resolution != series.Resolution.String() {
|
||||
continue
|
||||
}
|
||||
|
||||
if checkFileSize {
|
||||
if series.Limiter.SizeMin > 0 && r.Size < series.Limiter.SizeMin {
|
||||
//min size not satified
|
||||
continue
|
||||
}
|
||||
if series.Limiter.SizeMax > 0 && r.Size > series.Limiter.SizeMax {
|
||||
//max size not satified
|
||||
continue
|
||||
}
|
||||
if !torrentSizeOk(series, r.Size, param) {
|
||||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
if len(filtered) == 0 {
|
||||
@@ -75,7 +85,60 @@ func SearchTvSeries(db1 *db.Client, seriesId, seasonNum int, episodes []int, che
|
||||
|
||||
}
|
||||
|
||||
func isNumberedSeries(detail *db.MediaDetails) bool {
|
||||
// imdbid not exist consider match
|
||||
func isImdbidNotMatch(id1, id2 string) bool {
|
||||
if id1 == "" || id2 == "" {
|
||||
return false
|
||||
}
|
||||
id1 = strings.TrimPrefix(id1, "tt")
|
||||
id2 = strings.TrimPrefix(id2, "tt")
|
||||
return id1 != id2
|
||||
}
|
||||
|
||||
// imdbid not exist consider not match
|
||||
func imdbIDMatchExact(id1, id2 string) bool {
|
||||
if id1 == "" || id2 == "" {
|
||||
return false
|
||||
}
|
||||
id1 = strings.TrimPrefix(id1, "tt")
|
||||
id2 = strings.TrimPrefix(id2, "tt")
|
||||
return id1 == id2
|
||||
}
|
||||
|
||||
func torrentSizeOk(detail *db.MediaDetails, torrentSize int, param *SearchParam) bool {
|
||||
if param.CheckFileSize {
|
||||
multiplier := 1 //大小倍数,正常为1,如果是季包则为季内集数
|
||||
if detail.MediaType == media.MediaTypeTv && len(param.Episodes) == 0 { //tv season pack
|
||||
multiplier = seasonEpisodeCount(detail, param.SeasonNum)
|
||||
}
|
||||
|
||||
if detail.Limiter.SizeMin > 0 { //min size
|
||||
sizeMin := detail.Limiter.SizeMin * multiplier
|
||||
if torrentSize < sizeMin { //比最小要求的大小还要小
|
||||
return false
|
||||
}
|
||||
}
|
||||
if detail.Limiter.SizeMax > 0 { //max size
|
||||
sizeMax := detail.Limiter.SizeMax * multiplier
|
||||
if torrentSize > sizeMax { //larger than max size wanted
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func seasonEpisodeCount(detail *db.MediaDetails, seasonNum int) int {
|
||||
count := 0
|
||||
for _, ep := range detail.Episodes {
|
||||
if ep.SeasonNumber == seasonNum {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func isNoSeasonSeries(detail *db.MediaDetails) bool {
|
||||
hasSeason2 := false
|
||||
season2HasEpisode1 := false
|
||||
for _, ep := range detail.Episodes {
|
||||
@@ -90,13 +153,17 @@ func isNumberedSeries(detail *db.MediaDetails) bool {
|
||||
return hasSeason2 && !season2HasEpisode1 //only one 1st episode
|
||||
}
|
||||
|
||||
func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSize bool) ([]torznab.Result, error) {
|
||||
movieDetail := db1.GetMediaDetails(movieId)
|
||||
func SearchMovie(db1 *db.Client, param *SearchParam) ([]torznab.Result, error) {
|
||||
movieDetail := db1.GetMediaDetails(param.MediaId)
|
||||
if movieDetail == nil {
|
||||
return nil, errors.New("no media found of id")
|
||||
}
|
||||
|
||||
res := searchWithTorznab(db1, movieDetail.NameEn, movieDetail.NameCn, movieDetail.OriginalName)
|
||||
if movieDetail.Extras.IsJav(){
|
||||
res1 := searchWithTorznab(db1, movieDetail.Extras.JavId)
|
||||
res = append(res, res1...)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
return nil, fmt.Errorf("no resource found")
|
||||
@@ -104,28 +171,33 @@ func SearchMovie(db1 *db.Client, movieId int, checkResolution bool, checkFileSiz
|
||||
var filtered []torznab.Result
|
||||
for _, r := range res {
|
||||
meta := metadata.ParseMovie(r.Name)
|
||||
if !utils.IsNameAcceptable(meta.Name, movieDetail.NameEn) && !utils.IsNameAcceptable(meta.Name, movieDetail.NameCn) &&
|
||||
!utils.IsNameAcceptable(meta.Name, movieDetail.OriginalName) {
|
||||
continue
|
||||
}
|
||||
if checkResolution && meta.Resolution != movieDetail.Resolution.String() {
|
||||
|
||||
if isImdbidNotMatch(movieDetail.ImdbID, r.ImdbId) { //imdb id not match
|
||||
continue
|
||||
}
|
||||
|
||||
if checkFileSize {
|
||||
if movieDetail.Limiter.SizeMin > 0 && r.Size < movieDetail.Limiter.SizeMin {
|
||||
//min size not satified
|
||||
if !imdbIDMatchExact(movieDetail.ImdbID, r.ImdbId) {
|
||||
if !torrentNameOk(movieDetail, r.Name) {
|
||||
continue
|
||||
}
|
||||
if movieDetail.Limiter.SizeMax > 0 && r.Size > movieDetail.Limiter.SizeMax {
|
||||
//max size not satified
|
||||
continue
|
||||
if !movieDetail.Extras.IsJav() {
|
||||
ss := strings.Split(movieDetail.AirDate, "-")[0]
|
||||
year, _ := strconv.Atoi(ss)
|
||||
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ss := strings.Split(movieDetail.AirDate, "-")[0]
|
||||
year, _ := strconv.Atoi(ss)
|
||||
if meta.Year != year && meta.Year != year-1 && meta.Year != year+1 { //year not match
|
||||
if param.CheckResolution && meta.Resolution != movieDetail.Resolution.String() {
|
||||
continue
|
||||
}
|
||||
|
||||
if param.FilterQiangban && meta.IsQingban { //过滤枪版电影
|
||||
continue
|
||||
}
|
||||
|
||||
if !torrentSizeOk(movieDetail, r.Size, param) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -152,20 +224,21 @@ func searchWithTorznab(db *db.Client, queries ...string) []torznab.Result {
|
||||
if tor.Disabled {
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
log.Debugf("search torznab %v with %v", tor.Name, queries)
|
||||
defer wg.Done()
|
||||
for _, q := range queries {
|
||||
for _, q := range queries {
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
log.Debugf("search torznab %v with %v", tor.Name, queries)
|
||||
defer wg.Done()
|
||||
|
||||
resp, err := torznab.Search(tor, q)
|
||||
if err != nil {
|
||||
log.Errorf("search %s error: %v", tor.Name, err)
|
||||
log.Warnf("search %s with query %s error: %v", tor.Name, q, err)
|
||||
return
|
||||
}
|
||||
resChan <- resp
|
||||
}
|
||||
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
wg.Wait()
|
||||
@@ -176,7 +249,7 @@ func searchWithTorznab(db *db.Client, queries ...string) []torznab.Result {
|
||||
res = append(res, result...)
|
||||
}
|
||||
|
||||
//res = dedup(res)
|
||||
res = dedup(res)
|
||||
|
||||
sort.SliceStable(res, func(i, j int) bool { //先按做种人数排序
|
||||
var s1 = res[i]
|
||||
@@ -226,3 +299,20 @@ func dedup(list []torznab.Result) []torznab.Result {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func torrentNameOk(detail *db.MediaDetails, torrentName string) bool {
|
||||
if detail.Extras.IsJav() && isNameAcceptable(torrentName, detail.Extras.JavId) {
|
||||
return true
|
||||
}
|
||||
return isNameAcceptable(torrentName, detail.NameCn) || isNameAcceptable(torrentName, detail.NameEn) ||
|
||||
isNameAcceptable(torrentName, detail.OriginalName)
|
||||
}
|
||||
|
||||
func isNameAcceptable(torrentName, wantedName string) bool {
|
||||
re := regexp.MustCompile(`[^\p{L}\w\s]`)
|
||||
torrentName = re.ReplaceAllString(strings.ToLower(torrentName), " ")
|
||||
wantedName = re.ReplaceAllString(strings.ToLower(wantedName), " ")
|
||||
torrentName = strings.Join(strings.Fields(torrentName), " ")
|
||||
wantedName = strings.Join(strings.Fields(wantedName), " ")
|
||||
return strings.Contains(torrentName, wantedName)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/db"
|
||||
"polaris/ent/media"
|
||||
"polaris/log"
|
||||
"polaris/pkg/torznab"
|
||||
"polaris/server/core"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,7 +15,13 @@ import (
|
||||
|
||||
func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*string, error) {
|
||||
|
||||
res, err := core.SearchTvSeries(s.db, seriesId, seasonNum, nil, true, true)
|
||||
res, err := core.SearchTvSeries(s.db, &core.SearchParam{
|
||||
MediaId: seriesId,
|
||||
SeasonNum: seasonNum,
|
||||
Episodes: nil,
|
||||
CheckResolution: true,
|
||||
CheckFileSize: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -46,13 +54,21 @@ func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) {
|
||||
if in.Episode == 0 {
|
||||
//search season package
|
||||
log.Infof("search series season package S%02d", in.Season)
|
||||
res, err = core.SearchTvSeries(s.db, in.ID, in.Season, nil, false, false)
|
||||
res, err = core.SearchTvSeries(s.db, &core.SearchParam{
|
||||
MediaId: in.ID,
|
||||
SeasonNum: in.Season,
|
||||
Episodes: nil,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "search season package")
|
||||
}
|
||||
} else {
|
||||
log.Infof("search series episode S%02dE%02d", in.Season, in.Episode)
|
||||
res, err = core.SearchTvSeries(s.db, in.ID, in.Season, []int{in.Episode}, false, false)
|
||||
res, err = core.SearchTvSeries(s.db, &core.SearchParam{
|
||||
MediaId: in.ID,
|
||||
SeasonNum: in.Season,
|
||||
Episodes: []int{in.Episode},
|
||||
})
|
||||
if err != nil {
|
||||
if err.Error() == "no resource found" {
|
||||
return []string{}, nil
|
||||
@@ -63,7 +79,16 @@ func (s *Server) SearchAvailableTorrents(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
} else {
|
||||
log.Info("search movie %d", in.ID)
|
||||
res, err = core.SearchMovie(s.db, in.ID, false, false)
|
||||
qiangban := s.db.GetSetting(db.SettingAllowQiangban)
|
||||
allowQiangban := false
|
||||
if qiangban == "true" {
|
||||
allowQiangban = true
|
||||
}
|
||||
|
||||
res, err = core.SearchMovie(s.db, &core.SearchParam{
|
||||
MediaId: in.ID,
|
||||
FilterQiangban: !allowQiangban,
|
||||
})
|
||||
if err != nil {
|
||||
if err.Error() == "no resource found" {
|
||||
return []string{}, nil
|
||||
@@ -143,3 +168,21 @@ func (s *Server) DownloadTorrent(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) DownloadAll(c *gin.Context) (interface{}, error) {
|
||||
ids := c.Param("id")
|
||||
id, err := strconv.Atoi(ids)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "convert")
|
||||
}
|
||||
m, err := s.db.GetMedia(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get media")
|
||||
}
|
||||
if m.MediaType == media.MediaTypeTv {
|
||||
return s.core.DownloadSeriesAllEpisodes(m.ID), nil
|
||||
}
|
||||
name, err := s.core.DownloadMovieByID(m.ID)
|
||||
|
||||
return []string{name}, err
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ func (s *Server) Serve() error {
|
||||
tv.DELETE("/record/:id", HttpHandler(s.DeleteFromWatchlist))
|
||||
tv.GET("/suggest/tv/:tmdb_id", HttpHandler(s.SuggestedSeriesFolderName))
|
||||
tv.GET("/suggest/movie/:tmdb_id", HttpHandler(s.SuggestedMovieFolderName))
|
||||
tv.GET("/downloadall/:id", HttpHandler(s.DownloadAll))
|
||||
}
|
||||
indexer := api.Group("/indexer")
|
||||
{
|
||||
@@ -130,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,11 +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"`
|
||||
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) {
|
||||
@@ -54,6 +57,24 @@ func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
|
||||
s.db.SetSetting(db.SettingProxy, in.Proxy)
|
||||
|
||||
if in.AllowQiangban {
|
||||
s.db.SetSetting(db.SettingAllowQiangban, "true")
|
||||
} else {
|
||||
s.db.SetSetting(db.SettingAllowQiangban, "false")
|
||||
}
|
||||
|
||||
if in.EnableNfo {
|
||||
s.db.SetSetting(db.SettingNfoSupportEnabled, "true")
|
||||
} 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
|
||||
}
|
||||
|
||||
@@ -62,12 +83,18 @@ func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
downloadDir := s.db.GetSetting(db.SettingDownloadDir)
|
||||
logLevel := s.db.GetSetting(db.SettingLogLevel)
|
||||
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,
|
||||
LogLevel: logLevel,
|
||||
Proxy: s.db.GetSetting(db.SettingProxy),
|
||||
EnablePlexmatch: plexmatchEnabled == "true",
|
||||
AllowQiangban: allowQiangban == "true",
|
||||
EnableNfo: enableNfo == "true",
|
||||
EnableAdultContent: enableAdult == "true",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -218,4 +245,4 @@ func (s *Server) EditMediaMetadata(c *gin.Context) (interface{}, error) {
|
||||
return nil, errors.Wrap(err, "save db")
|
||||
}
|
||||
return "success", nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,13 @@ func (s *Server) SuggestedMovieFolderName(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
name := d1.Title
|
||||
|
||||
if isJav(d1) {
|
||||
javid := s.getJavid(id)
|
||||
if javid != "" {
|
||||
return gin.H{"name": javid}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if s.language == db.LanguageCN {
|
||||
en, err := s.MustTMDB().GetMovieDetails(id, db.LanguageEN)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"polaris/ent/schema"
|
||||
"polaris/log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tmdb "github.com/cyruzin/golang-tmdb"
|
||||
@@ -151,6 +152,10 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
TargetDir: in.Folder,
|
||||
DownloadHistoryEpisodes: in.DownloadHistoryEpisodes,
|
||||
Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax},
|
||||
Extras: schema.MediaExtras{
|
||||
OriginalLanguage: detail.OriginalLanguage,
|
||||
Genres: detail.Genres,
|
||||
},
|
||||
}
|
||||
|
||||
r, err := s.db.AddMediaWatchlist(m, epIds)
|
||||
@@ -174,6 +179,26 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func isJav(detail *tmdb.MovieDetails) bool {
|
||||
if detail.Adult && len(detail.ProductionCountries) > 0 && strings.ToUpper(detail.ProductionCountries[0].Iso3166_1) == "JP" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *Server) getJavid(id int) string {
|
||||
alters, err := s.MustTMDB().GetMovieAlternativeTitles(id, s.language)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, t := range alters.Titles {
|
||||
if t.Iso3166_1 == "JP" && t.Type == "" {
|
||||
return t.Title
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
var in addWatchlistIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
@@ -209,7 +234,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
log.Infof("added dummy episode for movie: %v", nameEn)
|
||||
|
||||
r, err := s.db.AddMediaWatchlist(&ent.Media{
|
||||
movie := ent.Media{
|
||||
TmdbID: int(detail.ID),
|
||||
ImdbID: detail.IMDbID,
|
||||
MediaType: media.MediaTypeMovie,
|
||||
@@ -222,7 +247,20 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
StorageID: in.StorageID,
|
||||
TargetDir: in.Folder,
|
||||
Limiter: schema.MediaLimiter{SizeMin: in.SizeMin, SizeMax: in.SizeMax},
|
||||
}, []int{epid})
|
||||
}
|
||||
|
||||
extras := schema.MediaExtras{
|
||||
IsAdultMovie: detail.Adult,
|
||||
OriginalLanguage: detail.OriginalLanguage,
|
||||
Genres: detail.Genres,
|
||||
}
|
||||
if isJav(detail) {
|
||||
javid := s.getJavid(in.TmdbID)
|
||||
extras.JavId = javid
|
||||
}
|
||||
|
||||
movie.Extras = extras
|
||||
r, err := s.db.AddMediaWatchlist(&movie, []int{epid})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "add to list")
|
||||
}
|
||||
|
||||
@@ -54,12 +54,15 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
],
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
var activitiesWatcher = ref.watch(activitiesDataProvider("active"));
|
||||
AsyncValue<List<Activity>>? activitiesWatcher;
|
||||
|
||||
if (selectedTab == 1) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider("archive"));
|
||||
} else if (selectedTab == 0) {
|
||||
activitiesWatcher = ref.watch(activitiesDataProvider("active"));
|
||||
}
|
||||
|
||||
return activitiesWatcher.when(
|
||||
return activitiesWatcher!.when(
|
||||
data: (activities) {
|
||||
return Flexible(
|
||||
child: ListView.builder(
|
||||
@@ -86,6 +89,17 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
Icons.close,
|
||||
color: Colors.red,
|
||||
));
|
||||
} else if (ac.status == "seeding") {
|
||||
//seeding
|
||||
return Tooltip(
|
||||
message: "做种中",
|
||||
child: Icon(
|
||||
Icons.keyboard_double_arrow_up,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.inversePrimary,
|
||||
),
|
||||
);
|
||||
} else if (ac.status == "success") {
|
||||
return const Tooltip(
|
||||
message: "下载成功",
|
||||
@@ -107,15 +121,17 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
),
|
||||
);
|
||||
}(),
|
||||
title:
|
||||
Text( (ac.sourceTitle ?? "")),
|
||||
title: Text((ac.sourceTitle ?? "")),
|
||||
subtitle: Opacity(
|
||||
opacity: 0.7,
|
||||
child: Wrap(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Text("开始时间:${timeago.format(ac.date!)}"),
|
||||
Text("大小:${(ac.size ?? 0).readableFileSize()}")
|
||||
Text("大小:${(ac.size ?? 0).readableFileSize()}"),
|
||||
ac.seedRatio > 0
|
||||
? Text("分享率:${ac.seedRatio}")
|
||||
: SizedBox()
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -186,8 +186,15 @@ class _MainSkeletonState extends State<MainSkeleton> {
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text("Polaris"),
|
||||
|
||||
title: TextButton(
|
||||
onPressed: () => context.go(WelcomePage.routeTv),
|
||||
child: Text(
|
||||
"Polaris",
|
||||
overflow: TextOverflow.clip,
|
||||
style: TextStyle(fontSize: 28),
|
||||
),
|
||||
),
|
||||
|
||||
actions: [
|
||||
SearchAnchor(
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
|
||||
@@ -8,6 +8,7 @@ class APIs {
|
||||
static final _baseUrl = baseUrl();
|
||||
static final searchUrl = "$_baseUrl/api/v1/media/search";
|
||||
static final editMediaUrl = "$_baseUrl/api/v1/media/edit";
|
||||
static final downloadAllUrl = "$_baseUrl/api/v1/media/downloadall/";
|
||||
static final settingsUrl = "$_baseUrl/api/v1/setting/do";
|
||||
static final settingsGeneralUrl = "$_baseUrl/api/v1/setting/general";
|
||||
static final watchlistTvUrl = "$_baseUrl/api/v1/media/tv/watchlist";
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/server_response.dart';
|
||||
|
||||
var activitiesDataProvider =
|
||||
AsyncNotifierProvider.family<ActivityData, List<Activity>, String>(
|
||||
AsyncNotifierProvider.autoDispose.family<ActivityData, List<Activity>, String>(
|
||||
ActivityData.new);
|
||||
|
||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
@@ -24,7 +24,7 @@ var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||
},
|
||||
);
|
||||
|
||||
class ActivityData extends FamilyAsyncNotifier<List<Activity>, String> {
|
||||
class ActivityData extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String> {
|
||||
@override
|
||||
FutureOr<List<Activity>> build(String arg) async {
|
||||
if (arg == "active") {
|
||||
@@ -69,7 +69,8 @@ class Activity {
|
||||
required this.status,
|
||||
required this.saved,
|
||||
required this.progress,
|
||||
required this.size});
|
||||
required this.size,
|
||||
required this.seedRatio});
|
||||
|
||||
final int? id;
|
||||
final int? mediaId;
|
||||
@@ -81,6 +82,7 @@ class Activity {
|
||||
final String? saved;
|
||||
final int? progress;
|
||||
final int? size;
|
||||
final double seedRatio;
|
||||
|
||||
factory Activity.fromJson(Map<String, dynamic> json) {
|
||||
return Activity(
|
||||
@@ -93,6 +95,7 @@ class Activity {
|
||||
status: json["status"],
|
||||
saved: json["saved"],
|
||||
progress: json["progress"],
|
||||
seedRatio: json["seed_ratio"],
|
||||
size: json["size"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,17 @@ class SeriesDetailData
|
||||
}
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<dynamic> downloadall() async {
|
||||
final dio = APIs.getDio();
|
||||
var resp = await dio.get(APIs.downloadAllUrl + id!);
|
||||
var sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
ref.invalidateSelf();
|
||||
return sp.data;
|
||||
}
|
||||
}
|
||||
|
||||
class SeriesDetails {
|
||||
|
||||
@@ -52,13 +52,19 @@ class GeneralSetting {
|
||||
String? logLevel;
|
||||
String? proxy;
|
||||
bool? enablePlexmatch;
|
||||
bool? allowQiangban;
|
||||
bool? enableNfo;
|
||||
bool? enableAdult;
|
||||
|
||||
GeneralSetting(
|
||||
{this.tmdbApiKey,
|
||||
this.downloadDIr,
|
||||
this.logLevel,
|
||||
this.proxy,
|
||||
this.enablePlexmatch});
|
||||
this.enablePlexmatch,
|
||||
this.enableNfo,
|
||||
this.allowQiangban,
|
||||
this.enableAdult});
|
||||
|
||||
factory GeneralSetting.fromJson(Map<String, dynamic> json) {
|
||||
return GeneralSetting(
|
||||
@@ -66,6 +72,9 @@ 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);
|
||||
}
|
||||
|
||||
@@ -76,6 +85,9 @@ class GeneralSetting {
|
||||
data["log_level"] = logLevel;
|
||||
data["proxy"] = proxy;
|
||||
data["enable_plexmatch"] = enablePlexmatch;
|
||||
data["allow_qiangban"] = allowQiangban;
|
||||
data["enable_nfo"] = enableNfo;
|
||||
data["enable_adult_content"] = enableAdult;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +146,14 @@ class Indexer {
|
||||
double? seedRatio;
|
||||
bool? disabled;
|
||||
|
||||
Indexer({this.name, this.url, this.apiKey, this.id, this.priority=50, this.seedRatio=0, this.disabled});
|
||||
Indexer(
|
||||
{this.name,
|
||||
this.url,
|
||||
this.apiKey,
|
||||
this.id,
|
||||
this.priority = 50,
|
||||
this.seedRatio = 0,
|
||||
this.disabled});
|
||||
|
||||
Indexer.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'];
|
||||
@@ -142,7 +161,7 @@ class Indexer {
|
||||
apiKey = json['api_key'];
|
||||
id = json["id"];
|
||||
priority = json["priority"];
|
||||
seedRatio = json["seed_ratio"]??0;
|
||||
seedRatio = json["seed_ratio"] ?? 0;
|
||||
disabled = json["disabled"] ?? false;
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
|
||||
@@ -34,7 +34,10 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
"download_dir": v.downloadDIr,
|
||||
"log_level": v.logLevel,
|
||||
"proxy": v.proxy,
|
||||
"enable_plexmatch": v.enablePlexmatch
|
||||
"enable_plexmatch": v.enablePlexmatch,
|
||||
"allow_qiangban": v.allowQiangban,
|
||||
"enable_nfo": v.enableNfo,
|
||||
"enable_adult": v.enableAdult,
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -81,8 +84,36 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(decoration: const InputDecoration(icon: Icon(Icons.token)),
|
||||
name: "enable_plexmatch", title: const Text("Plex 刮削支持")),
|
||||
child: FormBuilderSwitch(
|
||||
decoration:
|
||||
const InputDecoration(icon: Icon(Icons.back_hand)),
|
||||
name: "enable_adult",
|
||||
title: const Text("是否显示成人内容")),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
decoration:
|
||||
const InputDecoration(icon: Icon(Icons.token)),
|
||||
name: "enable_plexmatch",
|
||||
title: const Text("Plex 刮削支持")),
|
||||
),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: FormBuilderSwitch(
|
||||
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)),
|
||||
name: "allow_qiangban",
|
||||
title: const Text("是否下载枪版资源")),
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
@@ -102,6 +133,9 @@ class _GeneralState extends ConsumerState<GeneralSettings> {
|
||||
downloadDIr: values["download_dir"],
|
||||
logLevel: values["log_level"],
|
||||
proxy: values["proxy"],
|
||||
allowQiangban: values["allow_qiangban"],
|
||||
enableAdult: values["enable_adult"],
|
||||
enableNfo: values["enable_nfo"],
|
||||
enablePlexmatch:
|
||||
values["enable_plexmatch"]))
|
||||
.then((v) => showSnakeBar("更新成功"));
|
||||
|
||||
@@ -114,7 +114,8 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
"${(widget.details.limiter!.sizeMin).readableFileSize()} - ${(widget.details.limiter!.sizeMax).readableFileSize()}"))
|
||||
: const SizedBox(),
|
||||
MenuAnchor(
|
||||
style: MenuStyle(alignment: Alignment.bottomRight),
|
||||
style:
|
||||
MenuStyle(alignment: Alignment.bottomRight),
|
||||
menuChildren: [
|
||||
ActionChip.elevated(
|
||||
onPressed: () => launchUrl(url),
|
||||
@@ -302,9 +303,16 @@ class _DetailCardState extends ConsumerState<DetailCard> {
|
||||
}
|
||||
|
||||
Widget downloadButton() {
|
||||
return IconButton(
|
||||
return LoadingIconButton(
|
||||
tooltip: widget.details.mediaType == "tv" ? "查找并下载所有监控剧集" : "查找并下载此电影",
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.download_rounded));
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(mediaDetailsProvider(widget.details.id.toString()).notifier)
|
||||
.downloadall()
|
||||
.then((list) => {
|
||||
if (list != null) {showSnakeBar("开始下载:$list")}
|
||||
});
|
||||
},
|
||||
icon: Icons.download_rounded);
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 917 B After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 163 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 163 KiB |