Skip to content

Commit ee310cf

Browse files
enforce title matching
1 parent 4c89def commit ee310cf

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

internal/ezbeq/ezbeq.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/iloveicedgreentea/go-plex/internal/common"
1516
"github.com/iloveicedgreentea/go-plex/internal/config"
1617
"github.com/iloveicedgreentea/go-plex/internal/logger"
1718
"github.com/iloveicedgreentea/go-plex/internal/mqtt"
@@ -238,6 +239,10 @@ func buildAuthorWhitelist(preferredAuthors string, endpoint string) string {
238239
return endpoint
239240
}
240241

242+
func checkNameForSearch(searchTitle, MatchTitle string) bool {
243+
return common.InsensitiveContains(searchTitle, MatchTitle)
244+
}
245+
241246
// searchCatalog will use ezbeq to search the catalog and then find the right match. tmdb data comes from plex, matched to ezbeq catalog
242247
func (c *BeqClient) searchCatalog(m *models.SearchRequest) (models.BeqCatalog, error) {
243248
// url encode because of spaces and stuff
@@ -263,15 +268,28 @@ func (c *BeqClient) searchCatalog(m *models.SearchRequest) (models.BeqCatalog, e
263268

264269
// search through results and find match
265270
for _, val := range payload {
271+
// if skipping TMDB, set the IDs to match
272+
if config.GetBool("jellyfin.skiptmdb") {
273+
log.Debug("Skipping TMDB search")
274+
val.MovieDbID = m.TMDB
275+
}
266276
log.Debugf("Beq results: Title: %v -- Codec %v, ID: %v", val.Title, val.AudioTypes, val.ID)
267277
// if we find a match, return it. Much easier to match on tmdb since plex provides it also
268278
if val.MovieDbID == m.TMDB && val.Year == m.Year && val.AudioTypes[0] == m.Codec {
279+
// if tmdb is skipped, the title has to match
280+
if config.GetBool("jellyfin.skiptmdb") {
281+
log.Debug("Using title compare for search")
282+
if !checkNameForSearch(val.Title, m.Title) {
283+
log.Errorf("Title %s did not match %s", val.Title, m.Title)
284+
return models.BeqCatalog{}, errors.New("beq profile was not found in catalog")
285+
}
286+
}
269287
// if it matches, check edition
270288
if checkEdition(val, m.Edition) {
271289
log.Infof("Found a match in catalog from author %s", val.Author)
272290
return val, nil
273291
} else {
274-
log.Error("Found a match but editions did not match entry. Not loading")
292+
log.Errorf("Found a potential match but editions did not match entry. Not loading")
275293
}
276294
}
277295
}
@@ -302,9 +320,6 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
302320
return nil
303321
}
304322

305-
if m.TMDB == "" {
306-
return errors.New("tmdb is empty. Can't find a match")
307-
}
308323
log.Debugf("beq payload is %#v", m)
309324

310325
// if no devices provided, error
@@ -322,6 +337,7 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
322337

323338
// skip searching when resuming for speed
324339
if !m.SkipSearch {
340+
// TODO: do the same for DD+ atmos
325341
// if AtmosMaybe, check if its really truehd 7.1. If fails, its atmos
326342
if m.Codec == "AtmosMaybe" {
327343
m.Codec = "TrueHD 7.1"

internal/handlers/jellyfin_handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func jfEventRouter(jfClient *jellyfin.JellyfinClient, beqClient *ezbeq.BeqClient
115115
}
116116
// add codec
117117
model.Codec = codec
118+
model.Title = data.OriginalTitle // TODO: check this
118119

119120
switch payload.NotificationType {
120121
// unload BEQ on pause OR stop because I never press stop, just pause and then back.

models/ezbeq.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type SearchRequest struct {
1313
MediaType string
1414
Devices []string
1515
Slots []int
16+
Title string
1617
}
1718

1819
type BeqCatalog struct {
@@ -25,7 +26,7 @@ type BeqCatalog struct {
2526
MvAdjust float64 `json:"mvAdjust"`
2627
Edition string `json:"edition"`
2728
MovieDbID string `json:"theMovieDB"`
28-
Author string `json:"author"`
29+
Author string `json:"author"`
2930
}
3031

3132
type BeqDevices struct {

0 commit comments

Comments
 (0)