@@ -128,7 +128,6 @@ func (c *BeqClient) MuteCommand(status bool) error {
128
128
func (c * BeqClient ) MakeCommand (payload []byte ) error {
129
129
for _ , v := range c .DeviceInfo {
130
130
endpoint := fmt .Sprintf ("/api/1/devices/%s" , v .Name )
131
- log .Debugf ("ezbeq: Using endpoint %s" , endpoint )
132
131
_ , err := c .makeReq (endpoint , payload , http .MethodPatch )
133
132
if err != nil {
134
133
return err
@@ -171,7 +170,7 @@ func (c *BeqClient) makeReq(endpoint string, payload []byte, methodType string)
171
170
// log.Debugf("Using url %s", req.URL)
172
171
// log.Debugf("Headers from req %v", req.Header)
173
172
// simple retry
174
- res , err := c .makeCallWithRetry (req , 5 , endpoint )
173
+ res , err := c .makeCallWithRetry (req , 20 , endpoint )
175
174
176
175
return res , err
177
176
}
@@ -188,13 +187,15 @@ func (c *BeqClient) makeCallWithRetry(req *http.Request, maxRetries int, endpoin
188
187
res , err = c .HTTPClient .Do (req )
189
188
if err != nil {
190
189
log .Debugf ("Error with request - Retrying %v" , err )
190
+ time .Sleep (time .Second * 2 )
191
191
continue
192
192
}
193
193
defer res .Body .Close ()
194
194
195
195
resp , err = io .ReadAll (res .Body )
196
196
if err != nil {
197
197
log .Debugf ("Reading body failed - Retrying %v" , err )
198
+ time .Sleep (time .Second * 2 )
198
199
continue
199
200
}
200
201
@@ -213,6 +214,7 @@ func (c *BeqClient) makeCallWithRetry(req *http.Request, maxRetries int, endpoin
213
214
log .Debug (string (resp ), status )
214
215
log .Debug ("Retrying request..." )
215
216
err = fmt .Errorf ("error in response: %v" , res .Status )
217
+ time .Sleep (time .Second * 2 )
216
218
continue
217
219
}
218
220
}
@@ -260,15 +262,37 @@ func (c *BeqClient) searchCatalog(m *models.SearchRequest) (models.BeqCatalog, e
260
262
261
263
// search through results and find match
262
264
for _ , val := range payload {
263
- log .Debugf ("Beq results: Title: %v -- Codec %v, ID: %v" , val .Title , val .AudioTypes , val .ID )
265
+ // if skipping TMDB, set the IDs to match
266
+ if config .GetBool ("jellyfin.skiptmdb" ) {
267
+ if m .Title == "" {
268
+ return models.BeqCatalog {}, errors .New ("title is blank, can't skip TMDB" )
269
+ }
270
+ log .Debug ("Skipping TMDB for search" )
271
+ val .MovieDbID = m .TMDB
272
+ if ! strings .EqualFold (val .Title , m .Title ) {
273
+ log .Debugf ("%s did not match with title %s" , val .Title , m .Title )
274
+ continue
275
+ }
276
+ log .Debugf ("%s matched with title %s" , val .Title , m .Title )
277
+ }
278
+ log .Debugf ("Beq results: Title: %v // Codec %v, ID: %v" , val .Title , val .AudioTypes , val .ID )
264
279
// if we find a match, return it. Much easier to match on tmdb since plex provides it also
265
- if val .MovieDbID == m .TMDB && val .Year == m .Year && val .AudioTypes [0 ] == m .Codec {
280
+ var audioMatch bool
281
+ // rationale here is some BEQ entries have multiple audio types in one entry
282
+ for _ , v := range val .AudioTypes {
283
+ if strings .EqualFold (v , m .Codec ) {
284
+ audioMatch = true
285
+ break
286
+ }
287
+ }
288
+ if val .MovieDbID == m .TMDB && val .Year == m .Year && audioMatch {
289
+ log .Debugf ("%s matched with codecs %v, checking further" , val .Title , val .AudioTypes )
266
290
// if it matches, check edition
267
291
if checkEdition (val , m .Edition ) {
268
292
log .Infof ("Found a match in catalog from author %s" , val .Author )
269
293
return val , nil
270
294
} else {
271
- log .Error ("Found a match but editions did not match entry. Not loading" )
295
+ log .Errorf ("Found a potential match but editions did not match entry. Not loading" )
272
296
}
273
297
}
274
298
}
@@ -299,9 +323,6 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
299
323
return nil
300
324
}
301
325
302
- if m .TMDB == "" {
303
- return errors .New ("tmdb is empty. Can't find a match" )
304
- }
305
326
log .Debugf ("beq payload is %#v" , m )
306
327
307
328
// if no devices provided, error
@@ -330,6 +351,37 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
330
351
return err
331
352
}
332
353
}
354
+ // most metadata contains DD+5.1 or something but its actually DD+ Atmos, so try a few options
355
+ } else if m .Codec == "DD+Atmos5.1Maybe" {
356
+ m .Codec = "DD+ Atmos"
357
+ catalog , err = c .searchCatalog (m )
358
+ // else try DD+ 5.1
359
+ if err != nil {
360
+ m .Codec = "DD+ 5.1"
361
+ catalog , err = c .searchCatalog (m )
362
+ if err != nil {
363
+ m .Codec = "DD+"
364
+ catalog , err = c .searchCatalog (m )
365
+ if err != nil {
366
+ return err
367
+ }
368
+ }
369
+ }
370
+ } else if m .Codec == "DD+Atmos7.1Maybe" {
371
+ m .Codec = "DD+ Atmos"
372
+ catalog , err = c .searchCatalog (m )
373
+ // else try DD+ 7.1
374
+ if err != nil {
375
+ m .Codec = "DD+ 7.1"
376
+ catalog , err = c .searchCatalog (m )
377
+ if err != nil {
378
+ m .Codec = "DD+"
379
+ catalog , err = c .searchCatalog (m )
380
+ if err != nil {
381
+ return err
382
+ }
383
+ }
384
+ }
333
385
} else {
334
386
catalog , err = c .searchCatalog (m )
335
387
if err != nil {
@@ -382,8 +434,6 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
382
434
// write payload to each device
383
435
for _ , v := range m .Devices {
384
436
endpoint := fmt .Sprintf ("/api/2/devices/%s" , v )
385
- log .Debugf ("json payload %v" , string (jsonPayload ))
386
- log .Debugf ("using endpoint %s" , endpoint )
387
437
_ , err = c .makeReq (endpoint , jsonPayload , http .MethodPatch )
388
438
if err != nil {
389
439
log .Debugf ("json payload %v" , string (jsonPayload ))
0 commit comments