mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Added the music check in the Plex Checker
This commit is contained in:
parent
cf83e0e6d9
commit
c2737b76a8
3 changed files with 36 additions and 45 deletions
|
@ -303,6 +303,8 @@ namespace PlexRequests.Api.Models.Plex
|
|||
public string AddedAt { get; set; }
|
||||
[XmlAttribute(AttributeName = "updatedAt")]
|
||||
public string UpdatedAt { get; set; }
|
||||
[XmlAttribute(AttributeName = "parentTitle")]
|
||||
public string ParentTitle { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -310,7 +312,7 @@ namespace PlexRequests.Api.Models.Plex
|
|||
public class PlexSearch
|
||||
{
|
||||
[XmlElement(ElementName = "Directory")]
|
||||
public Directory1 Directory { get; set; }
|
||||
public List<Directory1> Directory { get; set; }
|
||||
[XmlElement(ElementName = "Video")]
|
||||
public List<Video> Video { get; set; }
|
||||
[XmlElement(ElementName = "Provider")]
|
||||
|
|
|
@ -29,7 +29,6 @@ namespace PlexRequests.Services.Interfaces
|
|||
public interface IAvailabilityChecker
|
||||
{
|
||||
void CheckAndUpdateAll(long check);
|
||||
bool IsAvailable(string title, string year);
|
||||
bool IsAvailable(string title, string year, string artist, PlexType type);
|
||||
}
|
||||
}
|
|
@ -101,23 +101,23 @@ namespace PlexRequests.Services
|
|||
|
||||
Log.Trace("Search results from Plex for the following request: {0}", r.Title);
|
||||
Log.Trace(results.DumpJson());
|
||||
var directoryResultVal = false;
|
||||
bool matchResult;
|
||||
switch (r.Type)
|
||||
{
|
||||
case RequestType.Movie:
|
||||
directoryResultVal = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy"));
|
||||
matchResult = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy"));
|
||||
break;
|
||||
case RequestType.TvShow:
|
||||
directoryResultVal = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy"));
|
||||
matchResult = MovieTvSearch(results, r.Title, r.ReleaseDate.ToString("yyyy"));
|
||||
break;
|
||||
case RequestType.Album:
|
||||
directoryResultVal = MusicSearch(results, r.Title, r.ArtistName);
|
||||
matchResult = MusicSearch(results, r.Title, r.ArtistName);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
if (directoryResultVal)
|
||||
if (matchResult)
|
||||
{
|
||||
r.Available = true;
|
||||
modifiedModel.Add(r);
|
||||
|
@ -137,39 +137,6 @@ namespace PlexRequests.Services
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified search term is available.
|
||||
/// </summary>
|
||||
/// <param name="title">The search term.</param>
|
||||
/// <param name="year">The year.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ApplicationSettingsException">The settings are not configured for Plex or Authentication</exception>
|
||||
public bool IsAvailable(string title, string year)
|
||||
{
|
||||
Log.Trace("Checking if the following {0} {1} is available in Plex", title, year);
|
||||
var plexSettings = Plex.GetSettings();
|
||||
var authSettings = Auth.GetSettings();
|
||||
|
||||
if (!ValidateSettings(plexSettings, authSettings))
|
||||
{
|
||||
Log.Warn("The settings are not configured");
|
||||
throw new ApplicationSettingsException("The settings are not configured for Plex or Authentication");
|
||||
}
|
||||
var results = PlexApi.SearchContent(authSettings.PlexAuthToken, title, plexSettings.FullUri);
|
||||
if (!string.IsNullOrEmpty(year))
|
||||
{
|
||||
var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase) && x.Year == year);
|
||||
var directoryTitle = string.Equals(results.Directory?.Title, title, StringComparison.CurrentCultureIgnoreCase) && results.Directory?.Year == year;
|
||||
return result?.Title != null || directoryTitle;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase));
|
||||
var directoryTitle = string.Equals(results.Directory?.Title, title, StringComparison.CurrentCultureIgnoreCase);
|
||||
return result?.Title != null || directoryTitle;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified title is available.
|
||||
/// </summary>
|
||||
|
@ -218,14 +185,29 @@ namespace PlexRequests.Services
|
|||
if (!string.IsNullOrEmpty(year))
|
||||
{
|
||||
var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase) && x.Year == year);
|
||||
var directoryTitle = string.Equals(results.Directory?.Title, title, StringComparison.CurrentCultureIgnoreCase) && results.Directory?.Year == year;
|
||||
return result?.Title != null || directoryTitle;
|
||||
|
||||
var directoryResult = false;
|
||||
if (results.Directory != null)
|
||||
{
|
||||
if (results.Directory.Any(d => d.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase) && d.Year == year))
|
||||
{
|
||||
directoryResult = true;
|
||||
}
|
||||
}
|
||||
return result?.Title != null || directoryResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = results.Video?.FirstOrDefault(x => x.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase));
|
||||
var directoryTitle = string.Equals(results.Directory?.Title, title, StringComparison.CurrentCultureIgnoreCase);
|
||||
return result?.Title != null || directoryTitle;
|
||||
var directoryResult = false;
|
||||
if (results.Directory != null)
|
||||
{
|
||||
if (results.Directory.Any(d => d.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
directoryResult = true;
|
||||
}
|
||||
}
|
||||
return result?.Title != null || directoryResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +220,15 @@ namespace PlexRequests.Services
|
|||
/// <returns></returns>
|
||||
private bool MusicSearch(PlexSearch results, string title, string artist)
|
||||
{
|
||||
//TODO
|
||||
foreach (var r in results.Directory)
|
||||
{
|
||||
var titleMatch = r.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase);
|
||||
var artistMatch = r.ParentTitle.Equals(artist, StringComparison.CurrentCultureIgnoreCase);
|
||||
if (titleMatch && artistMatch)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue