pull/3742/head
tidusjar 4 years ago
parent 157d173a44
commit 86937d2a1c

@ -44,7 +44,13 @@ namespace Ombi.Api.Plex.Models
public string grandparentTheme { get; set; } public string grandparentTheme { get; set; }
public string chapterSource { get; set; } public string chapterSource { get; set; }
public Medium[] Media { get; set; } public Medium[] Media { get; set; }
public PlexGuids[] Guid { get; set; }
// public Director[] Director { get; set; } // public Director[] Director { get; set; }
// public Writer[] Writer { get; set; } // public Writer[] Writer { get; set; }
} }
public class PlexGuids
{
public string Id { get; set; }
}
} }

@ -41,6 +41,37 @@ namespace Ombi.Helpers.Tests
yield return new TestCaseData("com.plexapp.agents.agent47://456822/999/999?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent, large episode and season"); yield return new TestCaseData("com.plexapp.agents.agent47://456822/999/999?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent, large episode and season");
yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021/2/1?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv episode"); yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021/2/1?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv episode");
yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv show"); yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv show");
yield return new TestCaseData("tmdb://610201", ProviderIdType.MovieDb).Returns("610201").SetName("Themoviedb new plex format");
}
}
[TestCaseSource(nameof(ProviderIdGuidDataV2))]
public void GetProviderIdsFromMetadataTests(string guidInput, ProviderId expected)
{
var param = guidInput.Split('|', StringSplitOptions.RemoveEmptyEntries);
var result = PlexHelper.GetProviderIdsFromMetadata(param);
Assert.AreEqual(expected.ImdbId, result.ImdbId);
Assert.AreEqual(expected.TheMovieDb, result.TheMovieDb);
Assert.AreEqual(expected.TheTvDb, result.TheTvDb);
}
public static IEnumerable<TestCaseData> ProviderIdGuidDataV2
{
get
{
yield return new TestCaseData("plex://movie/5e1632df2d4d84003e48e54e|imdb://tt9178402|tmdb://610201", new ProviderId { ImdbId = "tt9178402", TheMovieDb = "610201" }).SetName("V2 Regular Plex Id");
yield return new TestCaseData("plex://movie/5d7768253c3c2a001fbcab72|imdb://tt0119567|tmdb://330", new ProviderId { ImdbId = "tt0119567", TheMovieDb = "330" }).SetName("V2 Regular Plex Id Another");
yield return new TestCaseData("plex://movie/5d7768253c3c2a001fbcab72|imdb://tt0119567", new ProviderId { ImdbId = "tt0119567" }).SetName("V2 Regular Plex Id Single Imdb");
yield return new TestCaseData("plex://movie/5d7768253c3c2a001fbcab72|tmdb://330", new ProviderId { TheMovieDb = "330" }).SetName("V2 Regular Plex Id Single Tmdb");
yield return new TestCaseData("com.plexapp.agents.thetvdb://269586/2/8?lang=en", new ProviderId { TheTvDb = "269586" }).SetName("V2 Regular TvDb Id");
yield return new TestCaseData("com.plexapp.agents.themoviedb://390043?lang=en", new ProviderId { TheMovieDb = "390043" }).SetName("V2 Regular MovieDb Id");
yield return new TestCaseData("com.plexapp.agents.imdb://tt2543164?lang=en", new ProviderId { ImdbId = "tt2543164" }).SetName("V2 Regular Imdb Id");
yield return new TestCaseData("com.plexapp.agents.agent47://tt2543456?lang=en", new ProviderId { ImdbId = "tt2543456" }).SetName("V2 Unknown IMDB agent");
yield return new TestCaseData("com.plexapp.agents.agent47://456822/1/1?lang=en", new ProviderId { TheTvDb = "456822" }).SetName("V2 Unknown TvDb agent");
yield return new TestCaseData("com.plexapp.agents.agent47://456822/999/999?lang=en", new ProviderId { TheTvDb = "456822" }).SetName("V2 Unknown TvDb agent, large episode and season");
yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021/2/1?lang=xn", new ProviderId { TheTvDb = "153021" }).SetName("V2 xmbc agent, tv episode");
yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021?lang=xn", new ProviderId { TheTvDb = "153021" }).SetName("V2 xmbc agent, tv show");
} }
} }

@ -41,6 +41,7 @@ namespace Ombi.Helpers
//com.plexapp.agents.thetvdb://269586/2/8?lang=en //com.plexapp.agents.thetvdb://269586/2/8?lang=en
//com.plexapp.agents.themoviedb://390043?lang=en //com.plexapp.agents.themoviedb://390043?lang=en
//com.plexapp.agents.imdb://tt2543164?lang=en //com.plexapp.agents.imdb://tt2543164?lang=en
//plex://movie/5e1632df2d4d84003e48e54e
// https://github.com/tidusjar/Ombi/issues/3277 // https://github.com/tidusjar/Ombi/issues/3277
if (string.IsNullOrEmpty(guid)) if (string.IsNullOrEmpty(guid))
{ {
@ -57,7 +58,7 @@ namespace Ombi.Helpers
TheTvDb = guidSplit[1] TheTvDb = guidSplit[1]
}; };
} }
if (guid.Contains("themoviedb", CompareOptions.IgnoreCase)) if (guid.Contains("themoviedb", CompareOptions.IgnoreCase) || guid.Contains("tmdb", CompareOptions.IgnoreCase))
{ {
return new ProviderId return new ProviderId
{ {
@ -71,6 +72,13 @@ namespace Ombi.Helpers
ImdbId = guidSplit[1] ImdbId = guidSplit[1]
}; };
} }
if (guid.Contains("plex://", CompareOptions.IgnoreCase))
{
return new ProviderId
{
Plex = true
};
}
var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled); var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled);
var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled); var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled);
@ -102,6 +110,37 @@ namespace Ombi.Helpers
$"https://app.plex.tv/web/app#!/server/{machineId}/details?key=library%2Fmetadata%2F{mediaId}"; $"https://app.plex.tv/web/app#!/server/{machineId}/details?key=library%2Fmetadata%2F{mediaId}";
return url; return url;
} }
public static ProviderId GetProviderIdsFromMetadata(params string[] guids)
{
var providerIds = new ProviderId();
foreach (var guid in guids)
{
var provider = GetProviderIdFromPlexGuid(guid);
if (provider.Type == ProviderType.Plex)
{
// There are more guids!
continue;
}
switch (provider.Type)
{
case ProviderType.ImdbId:
providerIds.ImdbId = provider.ImdbId;
break;
case ProviderType.TheMovieDbId:
providerIds.TheMovieDb = provider.TheMovieDb;
break;
case ProviderType.TvDbId:
providerIds.TheTvDb = provider.TheTvDb;
break;
default:
throw new ArgumentOutOfRangeException(nameof(provider.Type));
}
}
return providerIds;
}
} }
public class ProviderId public class ProviderId
@ -109,6 +148,7 @@ namespace Ombi.Helpers
public string TheTvDb { get; set; } public string TheTvDb { get; set; }
public string TheMovieDb { get; set; } public string TheMovieDb { get; set; }
public string ImdbId { get; set; } public string ImdbId { get; set; }
public bool Plex { get; set; }
public ProviderType Type public ProviderType Type
{ {
@ -126,6 +166,10 @@ namespace Ombi.Helpers
{ {
return ProviderType.TvDbId; return ProviderType.TvDbId;
} }
if (Plex)
{
return ProviderType.Plex;
}
return ProviderType.ImdbId; return ProviderType.ImdbId;
} }
} }
@ -135,6 +179,7 @@ namespace Ombi.Helpers
{ {
ImdbId, ImdbId,
TheMovieDbId, TheMovieDbId,
TvDbId TvDbId,
Plex
} }
} }

@ -281,9 +281,21 @@ namespace Ombi.Schedule.Jobs.Plex
Logger.LogDebug("Adding movie {0}", movie.title); Logger.LogDebug("Adding movie {0}", movie.title);
var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri, var metaData = await PlexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
movie.ratingKey); movie.ratingKey);
var providerIds = PlexHelper.GetProviderIdFromPlexGuid(metaData.MediaContainer.Metadata
.FirstOrDefault() var meta = metaData.MediaContainer.Metadata.FirstOrDefault();
.guid); var guids = new List<string>
{
meta.guid
};
if (meta.Guid != null)
{
foreach (var g in meta.Guid)
{
guids.Add(g.Id);
}
}
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
var item = new PlexServerContent var item = new PlexServerContent
{ {
@ -296,15 +308,15 @@ namespace Ombi.Schedule.Jobs.Plex
Seasons = new List<PlexSeasonsContent>(), Seasons = new List<PlexSeasonsContent>(),
Quality = movie.Media?.FirstOrDefault()?.videoResolution ?? string.Empty Quality = movie.Media?.FirstOrDefault()?.videoResolution ?? string.Empty
}; };
if (providerIds.Type == ProviderType.ImdbId) if (providerIds.ImdbId.HasValue())
{ {
item.ImdbId = providerIds.ImdbId; item.ImdbId = providerIds.ImdbId;
} }
if (providerIds.Type == ProviderType.TheMovieDbId) if (providerIds.TheMovieDb.HasValue())
{ {
item.TheMovieDbId = providerIds.TheMovieDb; item.TheMovieDbId = providerIds.TheMovieDb;
} }
if (providerIds.Type == ProviderType.TvDbId) if (providerIds.TheTvDb.HasValue())
{ {
item.TvDbId = providerIds.TheTvDb; item.TvDbId = providerIds.TheTvDb;
} }
@ -563,20 +575,31 @@ namespace Ombi.Schedule.Jobs.Plex
private static void GetProviderIds(PlexMetadata showMetadata, PlexServerContent existingContent) private static void GetProviderIds(PlexMetadata showMetadata, PlexServerContent existingContent)
{ {
var metadata = showMetadata.MediaContainer.Metadata.FirstOrDefault();
var guids = new List<string>
{
metadata.guid
};
if (metadata.Guid != null)
{
foreach (var g in metadata.Guid)
{
guids.Add(g.Id);
}
}
var providerIds = var providerIds =
PlexHelper.GetProviderIdFromPlexGuid(showMetadata.MediaContainer.Metadata.FirstOrDefault() PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
.guid); if (providerIds.ImdbId.HasValue())
if (providerIds.Type == ProviderType.ImdbId)
{ {
existingContent.ImdbId = providerIds.ImdbId; existingContent.ImdbId = providerIds.ImdbId;
} }
if (providerIds.Type == ProviderType.TheMovieDbId) if (providerIds.TheMovieDb.HasValue())
{ {
existingContent.TheMovieDbId = providerIds.TheMovieDb; existingContent.TheMovieDbId = providerIds.TheMovieDb;
} }
if (providerIds.Type == ProviderType.TvDbId) if (providerIds.TheTvDb.HasValue())
{ {
existingContent.TvDbId = providerIds.TheTvDb; existingContent.TvDbId = providerIds.TheTvDb;
} }

Loading…
Cancel
Save