Skip to content

Commit

Permalink
Merge pull request #40 from tphoney/cinema-paradiso_movie_matching
Browse files Browse the repository at this point in the history
(maint) use a better movie title matcher
  • Loading branch information
tphoney authored May 30, 2024
2 parents 9a8b926 + 453846c commit aefe581
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

## bugs

- improve cinema-paradiso movie scrape, many search results are the same page. wasted processing
- mandalorian is not showing up on amazon tv search

## done
Expand Down
11 changes: 6 additions & 5 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

func MarkBestMatchMovie(search *types.SearchResults) types.SearchResults {
expectedYear := YearToDate(search.PlexMovie.Year)
lowerBound := YearToDate(search.PlexMovie.Year).Year() - 1
upperBound := YearToDate(search.PlexMovie.Year).Year() + 1
for i := range search.MovieSearchResults {
// normally a match if the year is within 1 year of each other
resultYear := YearToDate(search.MovieSearchResults[i].Year)
if search.MovieSearchResults[i].FoundTitle == search.PlexMovie.Title && WitinOneYear(resultYear.Year(), expectedYear.Year()) {
if matchTitle(search.PlexMovie.Title, search.MovieSearchResults[i].FoundTitle, resultYear.Year(), lowerBound, upperBound) {
search.MovieSearchResults[i].BestMatch = true
if search.MovieSearchResults[i].Format == types.DiskBluray {
search.MatchesBluray++
Expand All @@ -33,7 +34,7 @@ func MarkBestMatchTV(search *types.SearchResults) types.SearchResults {
lastEpisodeBoundry := search.PlexTVShow.LastEpisodeAired.Year() + 1
for i := range search.TVSearchResults {
resultYear := YearToDate(search.TVSearchResults[i].FirstAiredYear)
if matchTVShow(search.PlexTVShow.Title, search.TVSearchResults[i].FoundTitle,
if matchTitle(search.PlexTVShow.Title, search.TVSearchResults[i].FoundTitle,
resultYear.Year(), firstEpisodeBoundry, lastEpisodeBoundry) {
search.TVSearchResults[i].BestMatch = true
if slices.Contains(search.TVSearchResults[i].Format, types.DiskDVD) {
Expand All @@ -50,7 +51,7 @@ func MarkBestMatchTV(search *types.SearchResults) types.SearchResults {
return *search
}

func matchTVShow(plexTitle, foundTitle string, foundYear, lowerBound, upperBound int) bool {
func matchTitle(plexTitle, foundTitle string, foundYear, lowerBound, upperBound int) bool {
plexTitle = strings.ToLower(plexTitle)
foundTitle = strings.ToLower(foundTitle)
remove := []string{"the"}
Expand Down Expand Up @@ -80,7 +81,7 @@ func YearToDate(yearString string) time.Time {
return time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
}

func CompareTitles(title1, title2 string) bool {
func CompareAlbumTitles(title1, title2 string) bool {
// remove anything between ()
r := regexp.MustCompile(`\((.*?)\)`)
title1 = r.ReplaceAllString(title1, "")
Expand Down
4 changes: 2 additions & 2 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func Test_albumTitlesMatch(t *testing.T) {
}
for _, tt := range tests {
t.Run(fmt.Sprintf("title1=%s, title2=%s", tt.title1, tt.title2), func(t *testing.T) {
if got := CompareTitles(tt.title1, tt.title2); got != tt.want {
if got := CompareAlbumTitles(tt.title1, tt.title2); got != tt.want {
t.Errorf("albumTitlesMatch() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -250,7 +250,7 @@ func Test_matchTVShow(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := matchTVShow(tt.args.plexTitle, tt.args.foundTitle, tt.args.foundYear, tt.args.lowerBound, tt.args.upperBound); got != tt.want {
if got := matchTitle(tt.args.plexTitle, tt.args.foundTitle, tt.args.foundYear, tt.args.lowerBound, tt.args.upperBound); got != tt.want {
t.Errorf("matchTVShow() = %v, want %v", got, tt.want)
}
})
Expand Down
2 changes: 1 addition & 1 deletion web/music/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func removeOwnedAlbums(searchResults []types.SearchResults) []types.SearchResult
for _, plexAlbum := range searchResults[i].PlexMusicArtist.Albums {
// iterate over search results
for _, album := range searchResults[i].MusicSearchResults[0].Albums {
if utils.CompareTitles(plexAlbum.Title, album.Title) {
if utils.CompareAlbumTitles(plexAlbum.Title, album.Title) {
albumsToRemove = append(albumsToRemove, album)
}
}
Expand Down

0 comments on commit aefe581

Please sign in to comment.