@@ -39,11 +39,11 @@ type request struct {
39
39
ClientName string
40
40
}
41
41
42
- type entryTime struct {
43
- e map [string ][]domain.Entry
44
- d map [string ]rls.Release
45
- t time.Time
46
- err error
42
+ type torrentRlsEntries struct {
43
+ entriesMap map [string ][]domain.Entry
44
+ rlsMap map [string ]rls.Release
45
+ lastUpdated time.Time
46
+ err error
47
47
sync.Mutex
48
48
}
49
49
@@ -68,80 +68,80 @@ func newProcessor(log logger.Logger, config *config.AppConfig, notification doma
68
68
}
69
69
70
70
func (p * processor ) getClient (client * domain.Client ) error {
71
- s := qbittorrent.Config {
71
+ clientCfg := qbittorrent.Config {
72
72
Host : fmt .Sprintf ("http://%s:%d" , client .Host , client .Port ),
73
73
Username : client .Username ,
74
74
Password : client .Password ,
75
75
}
76
76
77
- c , ok := clientMap .Load (s )
77
+ c , ok := clientMap .Load (clientCfg )
78
78
if ! ok {
79
- c = qbittorrent .NewClient (s )
79
+ c = qbittorrent .NewClient (clientCfg )
80
80
81
81
if err := c .(* qbittorrent.Client ).Login (); err != nil {
82
82
return errors .Wrap (err , "failed to login to qbittorrent" )
83
83
}
84
84
85
- clientMap .Store (s , c )
85
+ clientMap .Store (clientCfg , c )
86
86
}
87
87
88
88
p .req .Client = c .(* qbittorrent.Client )
89
89
return nil
90
90
}
91
91
92
- func (p * processor ) getAllTorrents (client * domain.Client ) entryTime {
93
- set := qbittorrent.Config {
92
+ func (p * processor ) getAllTorrents (client * domain.Client ) torrentRlsEntries {
93
+ clientCfg := qbittorrent.Config {
94
94
Host : fmt .Sprintf ("http://%s:%d" , client .Host , client .Port ),
95
95
Username : client .Username ,
96
96
Password : client .Password ,
97
97
}
98
98
99
- f := func () * entryTime {
100
- te , ok := torrentMap .Load (set )
99
+ f := func () * torrentRlsEntries {
100
+ tre , ok := torrentMap .Load (clientCfg )
101
101
if ok {
102
- return te .(* entryTime )
102
+ return tre .(* torrentRlsEntries )
103
103
}
104
104
105
- res := & entryTime { d : make (map [string ]rls.Release )}
106
- torrentMap .Store (set , res )
107
- return res
105
+ entries := & torrentRlsEntries { rlsMap : make (map [string ]rls.Release )}
106
+ torrentMap .Store (clientCfg , entries )
107
+ return entries
108
108
}
109
109
110
- res := f ()
110
+ entries := f ()
111
111
cur := time .Now ()
112
- if res . t .After (cur ) {
113
- return * res
112
+ if entries . lastUpdated .After (cur ) {
113
+ return * entries
114
114
}
115
115
116
- res .Lock ()
117
- defer res .Unlock ()
116
+ entries .Lock ()
117
+ defer entries .Unlock ()
118
118
119
- res = f ()
120
- if res . t .After (cur ) {
121
- return * res
119
+ entries = f ()
120
+ if entries . lastUpdated .After (cur ) {
121
+ return * entries
122
122
}
123
123
124
124
ts , err := p .req .Client .GetTorrents (qbittorrent.TorrentFilterOptions {})
125
125
if err != nil {
126
- return entryTime {err : err }
126
+ return torrentRlsEntries {err : err }
127
127
}
128
128
129
- nt := time .Now ()
130
- res = & entryTime { e : make (map [string ][]domain.Entry ), t : nt .Add (nt .Sub (cur )), d : res . d }
129
+ after := time .Now ()
130
+ entries = & torrentRlsEntries { entriesMap : make (map [string ][]domain.Entry ), lastUpdated : after .Add (after .Sub (cur )), rlsMap : entries . rlsMap }
131
131
132
132
for _ , t := range ts {
133
- r , ok := res . d [t .Name ]
133
+ r , ok := entries . rlsMap [t .Name ]
134
134
if ! ok {
135
135
r = rls .ParseString (t .Name )
136
- res . d [t .Name ] = r
136
+ entries . rlsMap [t .Name ] = r
137
137
}
138
138
139
- s := utils .GetFormattedTitle (r )
140
- res . e [ s ] = append (res . e [ s ], domain.Entry {T : t , R : r })
139
+ fmtTitle := utils .GetFormattedTitle (r )
140
+ entries . entriesMap [ fmtTitle ] = append (entries . entriesMap [ fmtTitle ], domain.Entry {T : t , R : r })
141
141
}
142
142
143
- torrentMap .Store (set , res )
144
- return * res
143
+ torrentMap .Store (clientCfg , entries )
144
+ return * entries
145
145
}
146
146
147
147
func (p * processor ) getFiles (hash string ) (* qbittorrent.TorrentFiles , error ) {
@@ -217,76 +217,76 @@ func (p *processor) processSeasonPack() (int, error) {
217
217
return domain .StatusGetClientError , err
218
218
}
219
219
220
- mp := p .getAllTorrents (client )
221
- if mp .err != nil {
222
- return domain .StatusGetTorrentsError , mp .err
220
+ tre := p .getAllTorrents (client )
221
+ if tre .err != nil {
222
+ return domain .StatusGetTorrentsError , tre .err
223
223
}
224
224
225
- requestRls := domain.Entry {R : rls .ParseString (p .req .Name )}
226
- v , ok := mp . e [utils .GetFormattedTitle (requestRls .R )]
225
+ requestEntry := domain.Entry {R : rls .ParseString (p .req .Name )}
226
+ matchingEntries , ok := tre . entriesMap [utils .GetFormattedTitle (requestEntry .R )]
227
227
if ! ok {
228
228
return domain .StatusNoMatches , fmt .Errorf ("no matching releases in client" )
229
229
}
230
230
231
231
announcedPackName := utils .FormatSeasonPackTitle (p .req .Name )
232
232
p .log .Debug ().Msgf ("formatted season pack name: %s" , announcedPackName )
233
233
234
- for _ , child := range v {
235
- if release .CheckCandidates (& requestRls , & child , p .cfg .Config .FuzzyMatching ) == domain .StatusAlreadyInClient {
234
+ for _ , entry := range matchingEntries {
235
+ if release .CheckCandidates (& requestEntry , & entry , p .cfg .Config .FuzzyMatching ) == domain .StatusAlreadyInClient {
236
236
return domain .StatusAlreadyInClient , fmt .Errorf ("release already in client" )
237
237
}
238
238
}
239
239
240
240
var matchedEps []int
241
241
var respCodes []int
242
242
243
- for _ , child := range v {
244
- switch res := release .CheckCandidates (& requestRls , & child , p .cfg .Config .FuzzyMatching ); res {
243
+ for _ , entry := range matchingEntries {
244
+ switch res := release .CheckCandidates (& requestEntry , & entry , p .cfg .Config .FuzzyMatching ); res {
245
245
case domain .StatusResolutionMismatch :
246
246
p .log .Info ().Msgf ("resolution did not match: request(%s => %s), client(%s => %s)" ,
247
- requestRls .R .String (), requestRls .R .Resolution , child .R .String (), child .R .Resolution )
247
+ requestEntry .R .String (), requestEntry .R .Resolution , entry .R .String (), entry .R .Resolution )
248
248
respCodes = append (respCodes , res )
249
249
continue
250
250
251
251
case domain .StatusSourceMismatch :
252
252
p .log .Info ().Msgf ("source did not match: request(%s => %s), client(%s => %s)" ,
253
- requestRls .R .String (), requestRls .R .Source , child .R .String (), child .R .Source )
253
+ requestEntry .R .String (), requestEntry .R .Source , entry .R .String (), entry .R .Source )
254
254
respCodes = append (respCodes , res )
255
255
continue
256
256
257
257
case domain .StatusRlsGrpMismatch :
258
258
p .log .Info ().Msgf ("release group did not match: request(%s => %s), client(%s => %s)" ,
259
- requestRls .R .String (), requestRls .R .Group , child .R .String (), child .R .Group )
259
+ requestEntry .R .String (), requestEntry .R .Group , entry .R .String (), entry .R .Group )
260
260
respCodes = append (respCodes , res )
261
261
continue
262
262
263
263
case domain .StatusCutMismatch :
264
264
p .log .Info ().Msgf ("cut did not match: request(%s => %s), client(%s => %s)" ,
265
- requestRls .R .String (), requestRls .R .Cut , child .R .String (), child .R .Cut )
265
+ requestEntry .R .String (), requestEntry .R .Cut , entry .R .String (), entry .R .Cut )
266
266
respCodes = append (respCodes , res )
267
267
continue
268
268
269
269
case domain .StatusEditionMismatch :
270
270
p .log .Info ().Msgf ("edition did not match: request(%s => %s), client(%s => %s)" ,
271
- requestRls .R .String (), requestRls .R .Edition , child .R .String (), child .R .Edition )
271
+ requestEntry .R .String (), requestEntry .R .Edition , entry .R .String (), entry .R .Edition )
272
272
respCodes = append (respCodes , res )
273
273
continue
274
274
275
275
case domain .StatusRepackStatusMismatch :
276
276
p .log .Info ().Msgf ("repack status did not match: request(%s => %s), client(%s => %s)" ,
277
- requestRls .R .String (), requestRls .R .Other , child .R .String (), child .R .Other )
277
+ requestEntry .R .String (), requestEntry .R .Other , entry .R .String (), entry .R .Other )
278
278
respCodes = append (respCodes , res )
279
279
continue
280
280
281
281
case domain .StatusHdrMismatch :
282
282
p .log .Info ().Msgf ("hdr metadata did not match: request(%s => %s), client(%s => %s)" ,
283
- requestRls .R .String (), requestRls .R .HDR , child .R .String (), child .R .HDR )
283
+ requestEntry .R .String (), requestEntry .R .HDR , entry .R .String (), entry .R .HDR )
284
284
respCodes = append (respCodes , res )
285
285
continue
286
286
287
287
case domain .StatusStreamingServiceMismatch :
288
288
p .log .Info ().Msgf ("streaming service did not match: request(%s => %s), client(%s => %s)" ,
289
- requestRls .R .String (), requestRls .R .Collection , child .R .String (), child .R .Collection )
289
+ requestEntry .R .String (), requestEntry .R .Collection , entry .R .String (), entry .R .Collection )
290
290
respCodes = append (respCodes , res )
291
291
continue
292
292
@@ -297,9 +297,9 @@ func (p *processor) processSeasonPack() (int, error) {
297
297
return domain .StatusNotASeasonPack , fmt .Errorf ("release is not a season pack" )
298
298
299
299
case domain .StatusSuccessfulMatch :
300
- torrentFiles , err := p .getFiles (child .T .Hash )
300
+ torrentFiles , err := p .getFiles (entry .T .Hash )
301
301
if err != nil {
302
- p .log .Error ().Err (err ).Msgf ("error getting files: %s" , child .T .Name )
302
+ p .log .Error ().Err (err ).Msgf ("error getting files: %s" , entry .T .Name )
303
303
continue
304
304
}
305
305
@@ -315,12 +315,12 @@ func (p *processor) processSeasonPack() (int, error) {
315
315
break
316
316
}
317
317
if len (fileName ) == 0 || size == 0 {
318
- p .log .Error ().Err (err ).Msgf ("error getting filename or size: %s" , child .T .Name )
318
+ p .log .Error ().Err (err ).Msgf ("error getting filename or size: %s" , entry .T .Name )
319
319
continue
320
320
}
321
321
322
- epRls := rls .ParseString (child .T .Name )
323
- epPathClient := filepath .Join (child .T .SavePath , fileName )
322
+ epRls := rls .ParseString (entry .T .Name )
323
+ epPathClient := filepath .Join (entry .T .SavePath , fileName )
324
324
announcedEpPath := filepath .Join (client .PreImportPath , announcedPackName , filepath .Base (fileName ))
325
325
326
326
matchedEps = append (matchedEps , epRls .Episode )
@@ -341,7 +341,7 @@ func (p *processor) processSeasonPack() (int, error) {
341
341
newMatches := append (oldMatches .([]matchPaths ), currentMatch ... )
342
342
matchesMap .Store (p .req .Name , newMatches )
343
343
p .log .Debug ().Msgf ("matched torrent from client: name(%s), size(%d), hash(%s)" ,
344
- child .T .Name , size , child .T .Hash )
344
+ entry .T .Name , size , entry .T .Hash )
345
345
respCodes = append (respCodes , res )
346
346
continue
347
347
}
0 commit comments