A bit more error handling #32

pull/140/head
tidusjar 9 years ago
parent 8a3576456c
commit 450fda6070

@ -112,7 +112,7 @@ namespace PlexRequests.Services
matchResult = MovieTvSearch(results, r.Title, releaseDate);
break;
case RequestType.Album:
matchResult = MusicSearch(results, r.Title, r.ArtistName);
matchResult = AlbumSearch(results, r.Title, r.ArtistName);
break;
default:
throw new ArgumentOutOfRangeException();
@ -168,7 +168,7 @@ namespace PlexRequests.Services
case PlexType.TvShow:
return MovieTvSearch(results, title, year);
case PlexType.Music:
return MusicSearch(results, title, artist);
return AlbumSearch(results, title, artist);
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
@ -183,6 +183,9 @@ namespace PlexRequests.Services
/// <returns></returns>
private bool MovieTvSearch(PlexSearch results, string title, string year)
{
try
{
if (!string.IsNullOrEmpty(year))
{
var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase) && x.Year == year);
@ -211,6 +214,13 @@ namespace PlexRequests.Services
return result?.Title != null || directoryResult;
}
}
catch (Exception e)
{
Log.Error("Could not finish the Movie/TV check in Plex because of an exception:");
Log.Error(e);
return false;
}
}
/// <summary>
/// Searches the music on Plex.
@ -219,7 +229,9 @@ namespace PlexRequests.Services
/// <param name="title">The title.</param>
/// <param name="artist">The artist.</param>
/// <returns></returns>
private bool MusicSearch(PlexSearch results, string title, string artist)
private bool AlbumSearch(PlexSearch results, string title, string artist)
{
try
{
foreach (var r in results.Directory)
{
@ -230,6 +242,12 @@ namespace PlexRequests.Services
return true;
}
}
}
catch (Exception e)
{
Log.Error("Could not finish the Album check in Plex because of an exception:");
Log.Error(e);
}
return false;
}

Loading…
Cancel
Save