pull/3297/head
tidusjar 5 years ago
parent 3bd9b18b33
commit faba87cdc6

@ -39,6 +39,8 @@ namespace Ombi.Helpers.Tests
yield return new TestCaseData("com.plexapp.agents.agent47://tt2543456?lang=en", ProviderIdType.Imdb).Returns("tt2543456").SetName("Unknown IMDB agent"); yield return new TestCaseData("com.plexapp.agents.agent47://tt2543456?lang=en", ProviderIdType.Imdb).Returns("tt2543456").SetName("Unknown IMDB agent");
yield return new TestCaseData("com.plexapp.agents.agent47://456822/1/1?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent"); yield return new TestCaseData("com.plexapp.agents.agent47://456822/1/1?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent");
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?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv show");
} }
} }

@ -33,14 +33,15 @@ namespace Ombi.Helpers
{ {
public class PlexHelper public class PlexHelper
{ {
private const string ImdbMatchExpression = "tt([0-9]{1,10})"; private const string ImdbMatchExpression = "tt([0-9]{1,10})";
private const string TvDbIdMatchExpression = "//[0-9]+/([0-9]{1,3})/([0-9]{1,3})"; private const string TvDbIdMatchExpression = "//[0-9]+/?([0-9]{1,3})/?([0-9]{1,3})";
public static ProviderId GetProviderIdFromPlexGuid(string guid) public static ProviderId GetProviderIdFromPlexGuid(string guid)
{ {
//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
// https://github.com/tidusjar/Ombi/issues/3277
if (string.IsNullOrEmpty(guid)) if (string.IsNullOrEmpty(guid))
{ {
return new ProviderId(); return new ProviderId();
@ -55,7 +56,7 @@ namespace Ombi.Helpers
{ {
TheTvDb = guidSplit[1] TheTvDb = guidSplit[1]
}; };
} else }
if (guid.Contains("themoviedb", CompareOptions.IgnoreCase)) if (guid.Contains("themoviedb", CompareOptions.IgnoreCase))
{ {
return new ProviderId return new ProviderId
@ -63,7 +64,6 @@ namespace Ombi.Helpers
TheMovieDb = guidSplit[1] TheMovieDb = guidSplit[1]
}; };
} }
else
if (guid.Contains("imdb", CompareOptions.IgnoreCase)) if (guid.Contains("imdb", CompareOptions.IgnoreCase))
{ {
return new ProviderId return new ProviderId
@ -71,72 +71,29 @@ namespace Ombi.Helpers
ImdbId = guidSplit[1] ImdbId = guidSplit[1]
}; };
} }
else
var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled);
var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled);
var imdbMatch = imdbRegex.IsMatch(guid);
if (imdbMatch)
{ {
var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled); return new ProviderId
var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled);
var imdbMatch = imdbRegex.IsMatch(guid);
if (imdbMatch)
{
return new ProviderId
{
ImdbId = guidSplit[1]
};
}
else
{ {
// Check if it matches the TvDb pattern ImdbId = guidSplit[1]
var tvdbMatch = tvdbRegex.IsMatch(guid); };
if (tvdbMatch)
{
return new ProviderId
{
TheTvDb = guidSplit[1]
};
}
}
} }
}
return new ProviderId();
}
public static EpisodeModelHelper GetSeasonsAndEpisodesFromPlexGuid(string guid) // Check if it matches the TvDb pattern
{ var tvdbMatch = tvdbRegex.IsMatch(guid);
var ep = new EpisodeModelHelper(); if (tvdbMatch)
//com.plexapp.agents.thetvdb://269586/2/8?lang=en
//com.plexapp.agents.themoviedb://390043?lang=en
//com.plexapp.agents.imdb://tt2543164?lang=en
if (string.IsNullOrEmpty(guid))
return null;
try
{
var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries);
if (guidSplit.Length > 2)
{ {
if (guid.Contains("thetvdb", CompareOptions.IgnoreCase)) return new ProviderId
{
ep.ProviderId = new ProviderId {TheTvDb = guidSplit[1]};
}
if (guid.Contains("themoviedb", CompareOptions.IgnoreCase))
{
ep.ProviderId = new ProviderId { TheMovieDb = guidSplit[1] };
}
if (guid.Contains("imdb", CompareOptions.IgnoreCase))
{ {
ep.ProviderId = new ProviderId { ImdbId = guidSplit[1] }; TheTvDb = guidSplit[1]
};
}
ep.SeasonNumber = int.Parse(guidSplit[2]);
ep.EpisodeNumber = int.Parse(guidSplit[3]);
} }
return ep;
}
catch (Exception)
{
return ep;
} }
return new ProviderId();
} }
public static string GetPlexMediaUrl(string machineId, int mediaId) public static string GetPlexMediaUrl(string machineId, int mediaId)
@ -147,13 +104,6 @@ namespace Ombi.Helpers
} }
} }
public class EpisodeModelHelper
{
public ProviderId ProviderId { get; set; }
public int SeasonNumber { get; set; }
public int EpisodeNumber { get; set; }
}
public class ProviderId public class ProviderId
{ {
public string TheTvDb { get; set; } public string TheTvDb { get; set; }

Loading…
Cancel
Save