Fix Radarr url nfo files

This commit is contained in:
David 2021-03-10 17:04:15 +01:00
parent 8a74d76598
commit 954148eb6d
5 changed files with 38 additions and 40 deletions

View File

@ -63,7 +63,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
protected virtual bool SupportsUrlAfterClosingXmlTag => false;
protected virtual string MovieDbParserSearchString => "themoviedb.org/movie/";
protected virtual string TmdbRegex => "themoviedb\\.org\\/movie\\/([0-9]+)";
/// <summary>
/// Fetches metadata for an item from one xml file.
@ -181,8 +181,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
else
{
// If the file is just an Imdb url, handle that
// If the file is just provider urls, handle that
ParseProviderLinks(item.Item, xml);
return;
@ -221,50 +220,31 @@ namespace MediaBrowser.XbmcMetadata.Parsers
protected void ParseProviderLinks(T item, string xml)
{
// Look for a match for the Regex pattern "tt" followed by 7 or 8 digits
var m = Regex.Match(xml, "tt([0-9]{7,8})", RegexOptions.IgnoreCase);
if (m.Success)
// IMDB:
// https://www.imdb.com/title/tt4154796
var imdbRegex = Regex.Match(xml, "tt([0-9]{7,8})", RegexOptions.Compiled);
if (imdbRegex.Success)
{
item.SetProviderId(MetadataProvider.Imdb, m.Value);
item.SetProviderId(MetadataProvider.Imdb, imdbRegex.Value);
}
// Support Tmdb
// https://www.themoviedb.org/movie/30287-fallo
var srch = MovieDbParserSearchString;
var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
if (index != -1)
// TMDB:
// https://www.themoviedb.org/movie/30287-fallo (movie)
// https://www.themoviedb.org/tv/1668-friends (tv)
var tmdbRegex = Regex.Match(xml, TmdbRegex, RegexOptions.Compiled);
if (tmdbRegex.Success)
{
var tmdbId = xml.AsSpan().Slice(index + srch.Length).TrimEnd('/');
index = tmdbId.IndexOf('-');
if (index != -1)
{
tmdbId = tmdbId.Slice(0, index);
}
if (!tmdbId.IsEmpty
&& !tmdbId.IsWhiteSpace()
&& int.TryParse(tmdbId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
{
item.SetProviderId(MetadataProvider.Tmdb, value.ToString(UsCulture));
}
item.SetProviderId(MetadataProvider.Tmdb, tmdbRegex.Groups[1].Value);
}
// TVDB:
// https://www.thetvdb.com/?tab=series&id=121361
if (item is Series)
{
srch = "thetvdb.com/?tab=series&id=";
index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
if (index != -1)
var tvdbRegex = Regex.Match(xml, "thetvdb\\.com\\/\\?tab=series\\&id=([0-9]+)", RegexOptions.Compiled);
if (tvdbRegex.Success)
{
var tvdbId = xml.AsSpan().Slice(index + srch.Length).TrimEnd('/');
if (!tvdbId.IsEmpty
&& !tvdbId.IsWhiteSpace()
&& int.TryParse(tvdbId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
{
item.SetProviderId(MetadataProvider.Tvdb, value.ToString(UsCulture));
}
item.SetProviderId(MetadataProvider.Tvdb, tvdbRegex.Groups[1].Value);
}
}
}

View File

@ -36,7 +36,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
protected override bool SupportsUrlAfterClosingXmlTag => true;
/// <inheritdoc />
protected override string MovieDbParserSearchString => "themoviedb.org/tv/";
protected override string TmdbRegex => "themoviedb\\.org\\/tv\\/([0-9]+)";
/// <inheritdoc />
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Series> itemResult)

View File

@ -152,6 +152,21 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(id, item.ProviderIds[provider]);
}
[Fact]
public void Parse_RadarrUrlFile_Success()
{
var result = new MetadataResult<Video>()
{
Item = new Movie()
};
_parser.Fetch(result, "Test Data/Radarr.nfo", CancellationToken.None);
var item = (Movie)result.Item;
Assert.Equal("583689", item.ProviderIds[MetadataProvider.Tmdb.ToString()]);
Assert.Equal("tt4154796", item.ProviderIds[MetadataProvider.Imdb.ToString()]);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{

View File

@ -91,7 +91,8 @@
</fanart>
<mpaa>Australia:M</mpaa>
<id>tt0974015</id>
<uniqueid type="imdb" default="true">tt0974015</uniqueid>
<uniqueid type="imdb">tt0974015</uniqueid>
<uniqueid type="tmdb">141052</uniqueid>
<genre>Action</genre>
<genre>Adventure</genre>
<genre>Fantasy</genre>

View File

@ -0,0 +1,2 @@
https://www.themoviedb.org/movie/583689
https://www.imdb.com/title/tt4154796