@@ -16,14 +16,14 @@ import (
16
16
"github.com/pkg/errors"
17
17
)
18
18
19
- func (c * Engine ) DownloadEpisodeTorrent (r1 torznab.Result , seriesId , seasonNum int , episodeNums ... int ) (* string , error ) {
19
+ func (c * Engine ) DownloadEpisodeTorrent (r1 torznab.Result , op DownloadOptions ) (* string , error ) {
20
20
21
- series , err := c .db .GetMedia (seriesId )
21
+ series , err := c .db .GetMedia (op . MediaId )
22
22
if err != nil {
23
- return nil , fmt .Errorf ("no tv series of id %v" , seriesId )
23
+ return nil , fmt .Errorf ("no tv series of id %v" , op . MediaId )
24
24
}
25
25
26
- return c .downloadTorrent (series , r1 , seasonNum , episodeNums ... )
26
+ return c .downloadTorrent (series , r1 , op )
27
27
}
28
28
29
29
/*
83
83
m .ParseExtraDescription (r .Description )
84
84
if len (episodeNums ) == 0 { //want season pack
85
85
if m .IsSeasonPack {
86
- name , err := c .DownloadEpisodeTorrent (r , seriesId , seasonNum )
86
+ name , err := c .DownloadEpisodeTorrent (r , DownloadOptions {
87
+ SeasonNum : seasonNum ,
88
+ MediaId : seriesId ,
89
+ HashFilterFn : c .hashInBlacklist ,
90
+ })
87
91
if err != nil {
88
- return nil , err
92
+ log .Warnf ("download season pack error, continue next item: %v" , err )
93
+ continue lo
89
94
}
90
95
torrentNames = append (torrentNames , * name )
91
96
break lo
98
103
}
99
104
torrentEpisodes = append (torrentEpisodes , i )
100
105
}
101
- name , err := c .DownloadEpisodeTorrent (r , seriesId , seasonNum , torrentEpisodes ... )
106
+ name , err := c .DownloadEpisodeTorrent (r , DownloadOptions {
107
+ SeasonNum : seasonNum ,
108
+ MediaId : seriesId ,
109
+ EpisodeNums : torrentEpisodes ,
110
+ HashFilterFn : c .hashInBlacklist ,
111
+ })
102
112
if err != nil {
103
- return nil , err
113
+ log .Warnf ("download episode error, continue next item: %v" , err )
114
+ continue lo
104
115
}
105
116
torrentNames = append (torrentNames , * name )
106
117
@@ -116,10 +127,27 @@ lo:
116
127
}
117
128
118
129
func (c * Engine ) DownloadMovie (m * ent.Media , r1 torznab.Result ) (* string , error ) {
119
- return c .downloadTorrent (m , r1 , 0 )
130
+ return c .downloadTorrent (m , r1 , DownloadOptions {
131
+ SeasonNum : 0 ,
132
+ MediaId : m .ID ,
133
+ })
134
+ }
135
+
136
+ func (c * Engine ) hashInBlacklist (hash string ) bool {
137
+ blacklist , err := c .db .GetTorrentBlacklist ()
138
+ if err != nil {
139
+ log .Warnf ("get torrent blacklist error: %v" , err )
140
+ return false
141
+ }
142
+ for _ , b := range blacklist {
143
+ if b .TorrentHash == hash {
144
+ return true
145
+ }
146
+ }
147
+ return false
120
148
}
121
149
122
- func (c * Engine ) downloadTorrent (m * ent.Media , r1 torznab.Result , seasonNum int , episodeNums ... int ) (* string , error ) {
150
+ func (c * Engine ) downloadTorrent (m * ent.Media , r1 torznab.Result , op DownloadOptions ) (* string , error ) {
123
151
trc , dlc , err := c .GetDownloadClient ()
124
152
if err != nil {
125
153
return nil , errors .Wrap (err , "get download client" )
@@ -137,21 +165,21 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
137
165
var name = r1 .Name
138
166
var targetDir = m .TargetDir
139
167
if m .MediaType == media .MediaTypeTv { //tv download
140
- targetDir = fmt .Sprintf ("%s/Season %02d/" , m .TargetDir , seasonNum )
168
+ targetDir = fmt .Sprintf ("%s/Season %02d/" , m .TargetDir , op . SeasonNum )
141
169
142
- if len (episodeNums ) > 0 {
143
- for _ , epNum := range episodeNums {
144
- ep , err := c .db .GetEpisode (m .ID , seasonNum , epNum )
170
+ if len (op . EpisodeNums ) > 0 {
171
+ for _ , epNum := range op . EpisodeNums {
172
+ ep , err := c .db .GetEpisode (m .ID , op . SeasonNum , epNum )
145
173
if err != nil {
146
- return nil , errors .Errorf ("no episode of season %d episode %d" , seasonNum , epNum )
174
+ return nil , errors .Errorf ("no episode of season %d episode %d" , op . SeasonNum , epNum )
147
175
148
176
}
149
177
if ep .Status == episode .StatusMissing {
150
178
c .db .SetEpisodeStatus (ep .ID , episode .StatusDownloading )
151
179
}
152
180
}
153
181
buff := & bytes.Buffer {}
154
- for i , ep := range episodeNums {
182
+ for i , ep := range op . EpisodeNums {
155
183
if i != 0 {
156
184
buff .WriteString ("," )
157
185
@@ -162,7 +190,7 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
162
190
163
191
} else { //season package download
164
192
name = fmt .Sprintf ("全集 (%s)" , name )
165
- c .db .SetSeasonAllEpisodeStatus (m .ID , seasonNum , episode .StatusDownloading )
193
+ c .db .SetSeasonAllEpisodeStatus (m .ID , op . SeasonNum , episode .StatusDownloading )
166
194
}
167
195
168
196
} else {//movie download
@@ -177,12 +205,17 @@ func (c *Engine) downloadTorrent(m *ent.Media, r1 torznab.Result, seasonNum int,
177
205
if err != nil {
178
206
return nil , errors .Wrap (err , "get hash" )
179
207
}
208
+
209
+ if op .HashFilterFn != nil && op .HashFilterFn (hash ) {
210
+ return nil , errors .Errorf ("hash is filtered: %s" , hash )
211
+ }
212
+
180
213
r1 .Link = link
181
214
182
215
history , err := c .db .SaveHistoryRecord (ent.History {
183
216
MediaID : m .ID ,
184
- EpisodeNums : episodeNums ,
185
- SeasonNum : seasonNum ,
217
+ EpisodeNums : op . EpisodeNums ,
218
+ SeasonNum : op . SeasonNum ,
186
219
SourceTitle : r1 .Name ,
187
220
TargetDir : targetDir ,
188
221
Status : history .StatusRunning ,
0 commit comments