2014-02-04 15:19:29 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-06-09 12:47:28 -04:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-01 01:18:16 -05:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 15:26:35 -05:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-02-04 15:19:29 -05:00
|
|
|
|
using System;
|
2014-02-08 23:52:52 -05:00
|
|
|
|
using System.Collections.Generic;
|
2013-11-17 10:27:48 -05:00
|
|
|
|
using System.Globalization;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using System.IO;
|
2013-08-12 15:18:31 -04:00
|
|
|
|
using System.Threading;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2013-06-09 12:47:28 -04:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class EpisodeXmlParser
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EpisodeXmlParser : BaseItemXmlParser<Episode>
|
|
|
|
|
{
|
2014-02-08 23:52:52 -05:00
|
|
|
|
private List<LocalImageInfo> _imagesFound;
|
|
|
|
|
|
2014-02-04 15:19:29 -05:00
|
|
|
|
public EpisodeXmlParser(ILogger logger)
|
2013-02-21 15:26:35 -05:00
|
|
|
|
: base(logger)
|
|
|
|
|
{
|
2013-08-12 15:18:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 23:52:52 -05:00
|
|
|
|
public void Fetch(Episode item, List<LocalImageInfo> images, string metadataFile, CancellationToken cancellationToken)
|
2013-08-12 15:18:31 -04:00
|
|
|
|
{
|
2014-02-08 23:52:52 -05:00
|
|
|
|
_imagesFound = images;
|
|
|
|
|
|
|
|
|
|
Fetch(item, metadataFile, cancellationToken);
|
2013-02-21 15:26:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 10:27:48 -05:00
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
2013-12-08 15:33:24 -05:00
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the data from XML node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
protected override void FetchDataFromXmlNode(XmlReader reader, Episode item)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
2013-08-12 15:18:31 -04:00
|
|
|
|
case "Chapters":
|
|
|
|
|
|
2013-08-30 19:55:17 -04:00
|
|
|
|
//_chaptersTask = FetchChaptersFromXmlNode(item, reader.ReadSubtree(), _itemRepo, CancellationToken.None);
|
2013-08-12 15:18:31 -04:00
|
|
|
|
break;
|
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
case "Episode":
|
2013-08-12 15:18:31 -04:00
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
//MB generated metadata is within an "Episode" node
|
|
|
|
|
using (var subTree = reader.ReadSubtree())
|
|
|
|
|
{
|
|
|
|
|
subTree.MoveToContent();
|
|
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
|
while (subTree.Read())
|
|
|
|
|
{
|
|
|
|
|
if (subTree.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromXmlNode(subTree, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "filename":
|
|
|
|
|
{
|
2013-04-18 11:56:50 -04:00
|
|
|
|
var filename = reader.ReadElementContentAsString();
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(filename))
|
|
|
|
|
{
|
2014-02-08 23:52:52 -05:00
|
|
|
|
// Strip off everything but the filename. Some metadata tools like MetaBrowser v1.0 will have an 'episodes' prefix
|
|
|
|
|
// even though it's actually using the metadata folder.
|
|
|
|
|
filename = Path.GetFileName(filename);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-08 23:52:52 -05:00
|
|
|
|
var parentFolder = Path.GetDirectoryName(item.Path);
|
|
|
|
|
filename = Path.Combine(parentFolder, "metadata", filename);
|
|
|
|
|
var file = new FileInfo(filename);
|
2013-04-18 11:56:50 -04:00
|
|
|
|
|
2014-02-08 23:52:52 -05:00
|
|
|
|
if (file.Exists)
|
|
|
|
|
{
|
|
|
|
|
_imagesFound.Add(new LocalImageInfo
|
|
|
|
|
{
|
|
|
|
|
Type = ImageType.Primary,
|
|
|
|
|
FileInfo = file
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "SeasonNumber":
|
|
|
|
|
{
|
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(number, out num))
|
|
|
|
|
{
|
|
|
|
|
item.ParentIndexNumber = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "EpisodeNumber":
|
|
|
|
|
{
|
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(number, out num))
|
|
|
|
|
{
|
|
|
|
|
item.IndexNumber = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 10:26:22 -04:00
|
|
|
|
case "EpisodeNumberEnd":
|
|
|
|
|
{
|
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(number, out num))
|
|
|
|
|
{
|
|
|
|
|
item.IndexNumberEnd = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 15:42:42 -05:00
|
|
|
|
case "absolute_number":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.AbsoluteEpisodeNumber = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-12-08 13:07:45 -05:00
|
|
|
|
case "DVD_episodenumber":
|
|
|
|
|
{
|
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
|
{
|
2013-12-08 15:33:24 -05:00
|
|
|
|
float num;
|
2013-12-08 13:07:45 -05:00
|
|
|
|
|
2013-12-08 15:33:24 -05:00
|
|
|
|
if (float.TryParse(number, NumberStyles.Any, UsCulture, out num))
|
2013-12-08 13:07:45 -05:00
|
|
|
|
{
|
2013-12-08 17:16:59 -05:00
|
|
|
|
item.DvdEpisodeNumber = num;
|
2013-12-08 13:07:45 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "DVD_season":
|
|
|
|
|
{
|
|
|
|
|
var number = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(number))
|
|
|
|
|
{
|
2013-12-08 15:33:24 -05:00
|
|
|
|
float num;
|
2013-12-08 13:07:45 -05:00
|
|
|
|
|
2013-12-08 15:33:24 -05:00
|
|
|
|
if (float.TryParse(number, NumberStyles.Any, UsCulture, out num))
|
2013-12-08 13:07:45 -05:00
|
|
|
|
{
|
2013-12-08 15:33:24 -05:00
|
|
|
|
item.DvdSeasonNumber = Convert.ToInt32(num);
|
2013-12-08 13:07:45 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 10:27:48 -05:00
|
|
|
|
case "airsbefore_episode":
|
2013-11-15 16:31:33 -05:00
|
|
|
|
{
|
2013-11-17 10:27:48 -05:00
|
|
|
|
var val = reader.ReadElementContentAsString();
|
2013-11-15 16:31:33 -05:00
|
|
|
|
|
2013-11-17 10:27:48 -05:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
2013-11-15 16:31:33 -05:00
|
|
|
|
{
|
2013-11-17 10:27:48 -05:00
|
|
|
|
int rval;
|
2013-11-15 16:31:33 -05:00
|
|
|
|
|
2013-11-17 10:27:48 -05:00
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval))
|
2013-11-15 16:31:33 -05:00
|
|
|
|
{
|
2013-11-17 10:27:48 -05:00
|
|
|
|
item.AirsBeforeEpisodeNumber = rval;
|
2013-11-15 16:31:33 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-17 10:27:48 -05:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "airsafter_season":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.AirsAfterSeasonNumber = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "airsbefore_season":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, UsCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.AirsBeforeSeasonNumber = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 16:31:33 -05:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
case "EpisodeName":
|
|
|
|
|
{
|
|
|
|
|
var name = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
item.Name = name;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
base.FetchDataFromXmlNode(reader, item);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|