Merge pull request #5166 from netpok/index-number-end-from-nfo

pull/5301/head
Bond-009 3 years ago committed by GitHub
commit 92e5a5c6e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,19 +43,23 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
item.ResetPeople();
var xml = streamReader.ReadToEnd();
var xmlFile = streamReader.ReadToEnd();
var srch = "</episodedetails>";
var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
var index = xmlFile.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
var xml = xmlFile;
if (index != -1)
{
xml = xml.Substring(0, index + srch.Length);
xml = xmlFile.Substring(0, index + srch.Length);
xmlFile = xmlFile.Substring(index + srch.Length);
}
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
try
{
// Extract episode details from the first episodedetails block
using (var stringReader = new StringReader(xml))
using (var reader = XmlReader.Create(stringReader, settings))
{
@ -77,6 +81,25 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
}
// Extract the last episode number from nfo
// This is needed because XBMC metadata uses multiple episodedetails blocks instead of episodenumberend tag
while ((index = xmlFile.IndexOf(srch, StringComparison.OrdinalIgnoreCase)) != -1)
{
xml = xmlFile.Substring(0, index + srch.Length);
xmlFile = xmlFile.Substring(index + srch.Length);
using (var stringReader = new StringReader(xml))
using (var reader = XmlReader.Create(stringReader, settings))
{
reader.MoveToContent();
if (reader.ReadToDescendant("episode") && int.TryParse(reader.ReadElementContentAsString(), out var num))
{
item.Item.IndexNumberEnd = Math.Max(num, item.Item.IndexNumberEnd ?? num);
}
}
}
}
catch (XmlException)
{

@ -42,7 +42,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<Episode>()
{
@ -97,6 +97,26 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
Assert.Equal(new DateTime(2017, 10, 7, 14, 25, 47), item.DateCreated);
}
[Fact]
public void Fetch_Valid_MultiEpisode_Success()
{
var result = new MetadataResult<Episode>()
{
Item = new Episode()
};
_parser.Fetch(result, "Test Data/Rising.nfo", CancellationToken.None);
var item = result.Item;
Assert.Equal("Rising (1)", item.Name);
Assert.Equal(1, item.IndexNumber);
Assert.Equal(2, item.IndexNumberEnd);
Assert.Equal(1, item.ParentIndexNumber);
Assert.Equal("A new Stargate team embarks on a dangerous mission to a distant galaxy, where they discover a mythical lost city -- and a deadly new enemy.", item.Overview);
Assert.Equal(new DateTime(2004, 7, 16), item.PremiereDate);
Assert.Equal(2004, item.ProductionYear);
}
[Fact]
public void Fetch_WithNullItem_ThrowsArgumentException()
{

@ -57,7 +57,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<Video>()
{

@ -43,7 +43,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<MusicAlbum>()
{

@ -40,7 +40,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<MusicArtist>()
{

@ -36,7 +36,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<Season>()
{

@ -34,7 +34,7 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
}
[Fact]
public void Fetch_Valid_Succes()
public void Fetch_Valid_Success()
{
var result = new MetadataResult<Series>()
{

@ -0,0 +1,20 @@
<episodedetails>
<title>Rising (1)</title>
<season>1</season>
<episode>1</episode>
<aired>2004-07-16</aired>
<plot>A new Stargate team embarks on a dangerous mission to a distant galaxy, where they discover a mythical lost city -- and a deadly new enemy.</plot>
<thumb>https://artworks.thetvdb.com/banners/episodes/70851/25333.jpg</thumb>
<watched>false</watched>
<rating>8.0</rating>
</episodedetails>
<episodedetails>
<title>Rising (2)</title>
<season>1</season>
<episode>2</episode>
<aired>2004-07-16</aired>
<plot>Sheppard tries to convince Weir to mount a rescue mission to free Colonel Sumner, Teyla, and the others captured by the Wraith.</plot>
<thumb>https://artworks.thetvdb.com/banners/episodes/70851/25334.jpg</thumb>
<watched>false</watched>
<rating>7.9</rating>
</episodedetails>
Loading…
Cancel
Save