2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Xml
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a base class for parsing metadata xml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class BaseItemXmlParser<T>
|
2012-07-12 06:55:27 +00:00
|
|
|
|
where T : BaseItem, new()
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata for an item from one xml file
|
|
|
|
|
/// </summary>
|
2012-07-12 06:55:27 +00:00
|
|
|
|
public virtual void Fetch(T item, string metadataFile)
|
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// Use XmlReader for best performance
|
2012-07-14 20:45:11 +00:00
|
|
|
|
using (XmlReader reader = XmlReader.Create(metadataFile))
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// Loop through each element
|
2012-07-14 20:45:11 +00:00
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
FetchDataFromXmlNode(reader, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// If dates weren't supplied in metadata, use values from the xml file
|
2012-07-12 06:55:27 +00:00
|
|
|
|
if (item.DateCreated == DateTime.MinValue)
|
|
|
|
|
{
|
|
|
|
|
item.DateCreated = File.GetCreationTime(metadataFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.DateModified == DateTime.MinValue)
|
|
|
|
|
{
|
|
|
|
|
item.DateModified = File.GetLastWriteTime(metadataFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata from one Xml Element
|
|
|
|
|
/// </summary>
|
2012-07-14 20:45:11 +00:00
|
|
|
|
protected virtual void FetchDataFromXmlNode(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// DateCreated
|
2012-07-12 06:55:27 +00:00
|
|
|
|
case "Added":
|
|
|
|
|
DateTime added;
|
2012-07-20 19:03:11 +00:00
|
|
|
|
if (DateTime.TryParse(reader.ReadString() ?? string.Empty, out added))
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
item.DateCreated = added;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// DisplayMediaType
|
2012-07-12 06:55:27 +00:00
|
|
|
|
case "Type":
|
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.DisplayMediaType = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
switch (item.DisplayMediaType.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "blu-ray":
|
|
|
|
|
item.DisplayMediaType = VideoType.BluRay.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case "dvd":
|
|
|
|
|
item.DisplayMediaType = VideoType.DVD.ToString();
|
|
|
|
|
break;
|
|
|
|
|
case "":
|
|
|
|
|
item.DisplayMediaType = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
// TODO: Do we still need this?
|
2012-07-12 06:55:27 +00:00
|
|
|
|
case "banner":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.BannerImagePath = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "LocalTitle":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.Name = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "SortTitle":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.SortName = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Overview":
|
|
|
|
|
case "Description":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.Overview = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "TagLine":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.Tagline = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "ContentRating":
|
|
|
|
|
case "MPAARating":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.OfficialRating = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "CustomRating":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.CustomRating = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "CustomPin":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.CustomPin = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Genre":
|
|
|
|
|
{
|
|
|
|
|
var genres = (item.Genres ?? new string[] { }).ToList();
|
2012-07-20 19:03:11 +00:00
|
|
|
|
genres.AddRange(GetSplitValues(reader.ReadString(), '|'));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
item.Genres = genres;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "AspectRatio":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.AspectRatio = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Network":
|
|
|
|
|
{
|
|
|
|
|
var studios = (item.Studios ?? new string[] { }).ToList();
|
2012-07-20 19:03:11 +00:00
|
|
|
|
studios.AddRange(GetSplitValues(reader.ReadString(), '|'));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
item.Studios = studios;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Director":
|
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
var list = (item.People ?? new PersonInfo[] { }).ToList();
|
2012-07-20 19:03:11 +00:00
|
|
|
|
list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Director }));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
item.People = list;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
2012-07-12 17:09:35 +00:00
|
|
|
|
var list = (item.People ?? new PersonInfo[] { }).ToList();
|
2012-07-20 19:03:11 +00:00
|
|
|
|
list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Writer }));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
item.People = list;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Actors":
|
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
2012-07-12 17:09:35 +00:00
|
|
|
|
var list = (item.People ?? new PersonInfo[] { }).ToList();
|
2012-07-20 19:03:11 +00:00
|
|
|
|
list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Actor }));
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
item.People = list;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Trailer":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.TrailerUrl = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "ProductionYear":
|
|
|
|
|
{
|
|
|
|
|
int ProductionYear;
|
2012-07-20 19:03:11 +00:00
|
|
|
|
if (int.TryParse(reader.ReadString(), out ProductionYear) && ProductionYear > 1850)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
item.ProductionYear = ProductionYear;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Rating":
|
|
|
|
|
case "IMDBrating":
|
|
|
|
|
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string rating = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(rating))
|
2012-07-14 20:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
float val;
|
|
|
|
|
|
|
|
|
|
if (float.TryParse(rating, out val))
|
|
|
|
|
{
|
|
|
|
|
item.UserRating = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2012-08-04 13:33:23 +00:00
|
|
|
|
case "FirstAired":
|
|
|
|
|
{
|
|
|
|
|
string firstAired = reader.ReadString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(firstAired))
|
|
|
|
|
{
|
|
|
|
|
DateTime airDate;
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850)
|
|
|
|
|
{
|
|
|
|
|
item.PremiereDate = airDate;
|
|
|
|
|
item.ProductionYear = airDate.Year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Genres":
|
|
|
|
|
FetchFromGenresNode(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Persons":
|
|
|
|
|
FetchDataFromPersonsNode(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "ParentalRating":
|
|
|
|
|
FetchFromParentalRatingNode(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "Studios":
|
|
|
|
|
FetchFromStudiosNode(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
case "MediaInfo":
|
2012-07-14 20:45:11 +00:00
|
|
|
|
FetchMediaInfo(reader.ReadSubtree(), item);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.Skip();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchMediaInfo(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
var video = item as Video;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (video != null)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
FetchMediaInfo(reader, video);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchMediaInfo(XmlReader reader, Video item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Audio":
|
|
|
|
|
{
|
|
|
|
|
AudioStream stream = FetchMediaInfoAudio(reader.ReadSubtree());
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
List<AudioStream> streams = item.AudioStreams.ToList();
|
|
|
|
|
streams.Add(stream);
|
|
|
|
|
item.AudioStreams = streams;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Video":
|
|
|
|
|
FetchMediaInfoVideo(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Subtitle":
|
|
|
|
|
FetchMediaInfoSubtitles(reader.ReadSubtree(), item);
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private AudioStream FetchMediaInfoAudio(XmlReader reader)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
AudioStream stream = new AudioStream();
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "BitRate":
|
|
|
|
|
stream.BitRate = reader.ReadIntSafe();
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Channels":
|
|
|
|
|
stream.Channels = reader.ReadIntSafe();
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Language":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
stream.Language = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Codec":
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string codec = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
|
|
|
|
switch (codec.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "dts-es":
|
|
|
|
|
case "dts-es matrix":
|
|
|
|
|
case "dts-es discrete":
|
|
|
|
|
stream.AudioFormat = "DTS";
|
|
|
|
|
stream.AudioProfile = "ES";
|
|
|
|
|
break;
|
|
|
|
|
case "dts-hd hra":
|
|
|
|
|
case "dts-hd high resolution":
|
|
|
|
|
stream.AudioFormat = "DTS";
|
|
|
|
|
stream.AudioProfile = "HRA";
|
|
|
|
|
break;
|
|
|
|
|
case "dts ma":
|
|
|
|
|
case "dts-hd ma":
|
|
|
|
|
case "dts-hd master":
|
|
|
|
|
stream.AudioFormat = "DTS";
|
|
|
|
|
stream.AudioProfile = "MA";
|
|
|
|
|
break;
|
|
|
|
|
case "dolby digital":
|
|
|
|
|
case "dolby digital surround ex":
|
|
|
|
|
case "dolby surround":
|
|
|
|
|
stream.AudioFormat = "AC-3";
|
|
|
|
|
break;
|
|
|
|
|
case "dolby digital plus":
|
|
|
|
|
stream.AudioFormat = "E-AC-3";
|
|
|
|
|
break;
|
|
|
|
|
case "dolby truehd":
|
|
|
|
|
stream.AudioFormat = "AC-3";
|
|
|
|
|
stream.AudioProfile = "TrueHD";
|
|
|
|
|
break;
|
|
|
|
|
case "mp2":
|
|
|
|
|
stream.AudioFormat = "MPEG Audio";
|
|
|
|
|
stream.AudioProfile = "Layer 2";
|
|
|
|
|
break;
|
|
|
|
|
case "other":
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
stream.AudioFormat = codec;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
2012-07-14 20:45:11 +00:00
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchMediaInfoVideo(XmlReader reader, Video item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Width":
|
|
|
|
|
item.Width = reader.ReadIntSafe();
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Height":
|
|
|
|
|
item.Height = reader.ReadIntSafe();
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "BitRate":
|
|
|
|
|
item.VideoBitRate = reader.ReadIntSafe();
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "FrameRate":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.FrameRate = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "ScanType":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
item.ScanType = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Duration":
|
2012-07-31 03:38:00 +00:00
|
|
|
|
item.RunTimeInMilliseconds = reader.ReadIntSafe() * 60000;
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "DurationSeconds":
|
|
|
|
|
int seconds = reader.ReadIntSafe();
|
|
|
|
|
if (seconds > 0)
|
|
|
|
|
{
|
2012-07-31 03:38:00 +00:00
|
|
|
|
item.RunTimeInMilliseconds = seconds * 1000;
|
2012-07-14 20:45:11 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Codec":
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string videoCodec = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
|
|
|
|
switch (videoCodec.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "sorenson h.263":
|
|
|
|
|
item.VideoCodec = "Sorenson H263";
|
|
|
|
|
break;
|
|
|
|
|
case "h.262":
|
|
|
|
|
item.VideoCodec = "MPEG-2 Video";
|
|
|
|
|
break;
|
|
|
|
|
case "h.264":
|
|
|
|
|
item.VideoCodec = "AVC";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
item.VideoCodec = videoCodec;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
2012-07-14 20:45:11 +00:00
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchMediaInfoSubtitles(XmlReader reader, Video item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
List<string> list = (item.Subtitles ?? new string[] { }).ToList();
|
|
|
|
|
|
|
|
|
|
reader.MoveToContent();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Language":
|
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string genre = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(genre))
|
2012-07-14 20:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(genre);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
item.Subtitles = list;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchFromGenresNode(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
List<string> list = (item.Genres ?? new string[] { }).ToList();
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Genre":
|
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string genre = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(genre))
|
2012-07-14 20:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(genre);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
item.Genres = list;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchDataFromPersonsNode(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-12 17:09:35 +00:00
|
|
|
|
List<PersonInfo> list = (item.People ?? new PersonInfo[] { }).ToList();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Person":
|
|
|
|
|
{
|
|
|
|
|
list.Add(GetPersonFromXmlNode(reader));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
break;
|
2012-07-14 20:45:11 +00:00
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.People = list;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchFromStudiosNode(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
|
|
|
|
List<string> list = (item.Studios ?? new string[] { }).ToList();
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Studio":
|
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string studio = reader.ReadString();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(studio))
|
2012-07-14 20:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(studio);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.Studios = list;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private void FetchFromParentalRatingNode(XmlReader reader, T item)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Value":
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string ratingString = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
|
|
|
|
int rating = 7;
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(ratingString))
|
2012-07-14 20:45:11 +00:00
|
|
|
|
{
|
|
|
|
|
int.TryParse(ratingString, out rating);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (rating)
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
item.OfficialRating = "NR";
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
item.OfficialRating = "UR";
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
item.OfficialRating = "G";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
item.OfficialRating = "PG";
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
item.OfficialRating = "PG-13";
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
item.OfficialRating = "NC-17";
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
item.OfficialRating = "R";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
private PersonInfo GetPersonFromXmlNode(XmlReader reader)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-12 17:09:35 +00:00
|
|
|
|
PersonInfo person = new PersonInfo();
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
while (reader.Read())
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-14 20:45:11 +00:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "Name":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
person.Name = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Type":
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-20 19:03:11 +00:00
|
|
|
|
string type = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
|
|
|
|
if (type == "Director")
|
|
|
|
|
{
|
|
|
|
|
person.PersonType = PersonType.Director;
|
|
|
|
|
}
|
|
|
|
|
else if (type == "Actor")
|
|
|
|
|
{
|
|
|
|
|
person.PersonType = PersonType.Actor;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
case "Role":
|
2012-07-20 19:03:11 +00:00
|
|
|
|
person.Overview = reader.ReadString();
|
2012-07-14 20:45:11 +00:00
|
|
|
|
break;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-07-14 20:45:11 +00:00
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
2012-07-12 06:55:27 +00:00
|
|
|
|
return person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected IEnumerable<string> GetSplitValues(string value, char deliminator)
|
|
|
|
|
{
|
|
|
|
|
value = (value ?? string.Empty).Trim(deliminator);
|
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(value) ? new string[] { } : value.Split(deliminator);
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|