本文整理汇总了C#中System.Xml.XmlDocument.SafeGetSingle方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.SafeGetSingle方法的具体用法?C# XmlDocument.SafeGetSingle怎么用?C# XmlDocument.SafeGetSingle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.SafeGetSingle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fetch
public override void Fetch()
{
Episode episode = Episode;
Debug.Assert(episode != null);
// store the location so we do not fetch again
metadataFile = XmlLocation;
// no data, do nothing
if (metadataFile == null) return;
metadataFileDate = new FileInfo(metadataFile).LastWriteTimeUtc;
string metadataFolder = Path.GetDirectoryName(metadataFile);
XmlDocument metadataDoc = new XmlDocument();
metadataDoc.Load(metadataFile);
var p = metadataDoc.SafeGetString("Item/filename");
if (p != null && p.Length > 0) {
string image = System.IO.Path.Combine(metadataFolder, System.IO.Path.GetFileName(p));
if (File.Exists(image))
Item.PrimaryImagePath = image;
}
episode.Overview = metadataDoc.SafeGetString("Item/Overview");
episode.EpisodeNumber = metadataDoc.SafeGetString("Item/EpisodeNumber");
episode.Name = episode.EpisodeNumber + " - " + metadataDoc.SafeGetString("Item/EpisodeName");
episode.SeasonNumber = metadataDoc.SafeGetString("Item/SeasonNumber");
episode.ImdbRating = metadataDoc.SafeGetSingle("Item/Rating", (float)-1, 10);
episode.FirstAired = metadataDoc.SafeGetString("Item/FirstAired");
string writers = metadataDoc.SafeGetString("Item/Writer");
if (writers != null)
episode.Writers = new List<string>(writers.Trim('|').Split('|'));
string directors = metadataDoc.SafeGetString("Item/Director");
if (directors != null)
episode.Directors = new List<string>(directors.Trim('|').Split('|'));
var actors = ActorListFromString(metadataDoc.SafeGetString("Item/GuestStars"));
if (actors != null) {
if (episode.Actors == null)
episode.Actors = new List<Actor>();
episode.Actors = actors;
}
}
示例2: Fetch
public override void Fetch()
{
var movie = Item as IMovie;
Debug.Assert(movie != null);
string mfile = XmlLocation();
string location = Path.GetDirectoryName(mfile);
if (File.Exists(mfile))
{
DateTime modTime = new FileInfo(mfile).LastWriteTimeUtc;
lastWriteTime = modTime;
myMovieFile = mfile;
XmlDocument doc = new XmlDocument();
doc.Load(mfile);
string s = doc.SafeGetString("Title/LocalTitle");
if ((s == null) || (s == ""))
s = doc.SafeGetString("Title/OriginalTitle");
movie.Name = s;
movie.SortName = doc.SafeGetString("Title/SortTitle");
movie.Overview = doc.SafeGetString("Title/Description");
if (movie.Overview != null)
movie.Overview = movie.Overview.Replace("\n\n", "\n");
movie.TagLine = doc.SafeGetString("Title/TagLine");
movie.Plot = doc.SafeGetString("Title/Plot");
//if added date is in xml override the file/folder date - this isn't gonna work cuz it's already filled in...
DateTime added = DateTime.MinValue;
DateTime.TryParse(doc.SafeGetString("Title/Added"), out added);
if (added > DateTime.MinValue) movie.DateCreated = added;
string front = doc.SafeGetString("Title/Covers/Front");
if ((front != null) && (front.Length > 0))
{
front = Path.Combine(location, front);
if (File.Exists(front))
Item.PrimaryImagePath = front;
}
if (string.IsNullOrEmpty(movie.DisplayMediaType))
{
movie.DisplayMediaType = doc.SafeGetString("Title/Type", "");
switch (movie.DisplayMediaType.ToLower())
{
case "blu-ray":
movie.DisplayMediaType = MediaType.BluRay.ToString();
break;
case "dvd":
movie.DisplayMediaType = MediaType.DVD.ToString();
break;
case "hd dvd":
movie.DisplayMediaType = MediaType.HDDVD.ToString();
break;
case "":
movie.DisplayMediaType = null;
break;
}
}
if (movie.ProductionYear == null)
{
int y = doc.SafeGetInt32("Title/ProductionYear", 0);
if (y > 1850)
movie.ProductionYear = y;
}
if (movie.ImdbRating == null)
{
float i = doc.SafeGetSingle("Title/IMDBrating", (float)-1, (float)10);
if (i >= 0)
movie.ImdbRating = i;
}
if (movie.ImdbID == null)
{
if (!string.IsNullOrEmpty(doc.SafeGetString("Title/IMDB")))
{
movie.ImdbID = doc.SafeGetString("Title/IMDB");
}
else
{
movie.ImdbID = doc.SafeGetString("Title/IMDbId");
}
}
if (movie.TmdbID == null)
{
movie.TmdbID = doc.SafeGetString("Title/TMDbId");
}
foreach (XmlNode node in doc.SelectNodes("Title/Persons/Person[Type='Actor']"))
{
try
{
if (movie.Actors == null)
movie.Actors = new List<Actor>();
var name = node.SelectSingleNode("Name").InnerText;
var role = node.SafeGetString("Role", "");
var actor = new Actor() { Name = name, Role = role };
//.........这里部分代码省略.........
示例3: GetSeriesDetails
public Item GetSeriesDetails(Item item)
{
DataProviderId dp = item.ProvidersId.Find(p => p.Name == this.Name);
if (dp == null) return null;
if (!LoadSeriesDetails(dp.Id))
return null;
Item series = new Item();
series.ProvidersId = new List<DataProviderId> { dp };
XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(Path.Combine(XmlPath, dp.Id), lang + ".xml"));
if (doc == null) return null;
series.Title = series.SeriesName = doc.SafeGetString("//SeriesName");
series.Overview = doc.SafeGetString("//Overview");
series.Rating = doc.SafeGetSingle("//Rating", 0, 10);
series.RunningTime = doc.SafeGetInt32("//Runtime");
series.MPAARating = doc.SafeGetString("//ContentRating");
string g = doc.SafeGetString("//Genre");
if (g != null)
{
string[] genres = g.Trim('|').Split('|');
if (g.Length > 0)
{
series.Genres = new List<string>();
series.Genres.AddRange(genres);
}
}
XmlDocument actorsDoc = new XmlDocument();
actorsDoc.Load(Path.Combine(Path.Combine(XmlPath, dp.Id), "actors.xml"));
if (actorsDoc != null)
{
series.Actors = new List<Actor>();
foreach (XmlNode actorNode in actorsDoc.SelectNodes("//Actor"))
{
string name = actorNode.SafeGetString("Name");
if (!string.IsNullOrEmpty(name))
{
Actor actor = new Actor();
actor.Name = name;
actor.Role = actorNode.SafeGetString("Role");
actor.ImagePath = BannerUrl + actorNode.SafeGetString("Image");
if (series.Actors == null) series.Actors = new List<Actor>();
series.Actors.Add(actor);
}
}
}
else
{
string actors = doc.SafeGetString("//Actors");
if (actors != null)
{
string[] a = actors.Trim('|').Split('|');
if (a.Length > 0)
{
series.Actors = new List<Actor>();
series.Actors.AddRange(
a.Select(actor => new Actor { Name = actor }));
}
}
}
XmlDocument banners = new XmlDocument();
banners.Load(Path.Combine(Path.Combine(XmlPath, dp.Id), "banners.xml"));
if (banners != null)
{
series.BackdropImagePaths = new List<Poster>();
series.ImagesPaths = new List<Poster>();
series.BannersPaths = new List<Poster>();
foreach (XmlNode node in banners.SelectNodes("//Banner"))
{
if (node.SafeGetString("BannerType") == "poster")
{
Poster poster = new Poster();
string path = node.SafeGetString("BannerPath");
string thumb = node.SafeGetString("ThumbnailPath");
if (!string.IsNullOrEmpty(thumb))
poster.Thumb = BannerUrl + thumb;
poster.Image = BannerUrl + path;
if (!string.IsNullOrEmpty(path))
series.ImagesPaths.Add(poster);
}
else if (node.SafeGetString("BannerType") == "fanart")
{
Poster poster = new Poster();
poster.Checked = false;
string path = node.SafeGetString("BannerPath");
string thumb = node.SafeGetString("ThumbnailPath");
string size = node.SafeGetString("BannerType2");
if (size.Contains("x"))
{
poster.width = size.Substring(0, size.IndexOf("x"));
poster.height = size.Substring(size.IndexOf("x") + 1);
}
if (!string.IsNullOrEmpty(thumb))
poster.Thumb = BannerUrl + thumb;
poster.Image = BannerUrl + path;
//.........这里部分代码省略.........
示例4: FetchEpisodeData
//.........这里部分代码省略.........
if (!episode.HasImage(ImageType.Primary))
{
var p = doc.SafeGetString("//filename");
if (p != null)
{
try
{
var url = TVUtils.BannerUrl + p;
await _providerManager.SaveImage(episode, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
.ConfigureAwait(false);
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
if (!episode.LockedFields.Contains(MetadataFields.Overview))
{
var extraOverview = extraEpisodesNode.Aggregate("", (current, xmlDocument) => current + ("\r\n\r\n" + xmlDocument.SafeGetString("//Overview")));
episode.Overview = doc.SafeGetString("//Overview") + extraOverview;
}
if (usingAbsoluteData)
episode.IndexNumber = doc.SafeGetInt32("//absolute_number", -1);
if (episode.IndexNumber < 0)
episode.IndexNumber = doc.SafeGetInt32("//EpisodeNumber");
if (!episode.LockedFields.Contains(MetadataFields.Name))
{
var extraNames = extraEpisodesNode.Aggregate("", (current, xmlDocument) => current + (", " + xmlDocument.SafeGetString("//EpisodeName")));
episode.Name = doc.SafeGetString("//EpisodeName") + extraNames;
}
episode.CommunityRating = doc.SafeGetSingle("//Rating", -1, 10);
var firstAired = doc.SafeGetString("//FirstAired");
DateTime airDate;
if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850)
{
episode.PremiereDate = airDate.ToUniversalTime();
episode.ProductionYear = airDate.Year;
}
if (!episode.LockedFields.Contains(MetadataFields.Cast))
{
episode.People.Clear();
var actors = doc.SafeGetString("//GuestStars");
if (actors != null)
{
// Sometimes tvdb actors have leading spaces
//Regex Info:
//The first block are the posible delimitators (open-parentheses should be there cause if dont the next block will fail)
//The second block Allow the delimitators to be part of the text if they're inside parentheses
var persons = Regex.Matches(actors, @"(?<delimitators>([^|,(])|(?<ignoreinParentheses>\([^)]*\)*))+")
.Cast<Match>()
.Select(m => m.Value)
.Where(i => !string.IsNullOrWhiteSpace(i) && !string.IsNullOrEmpty(i));
foreach (var person in persons.Select(str =>
{
var nameGroup = str.Split(new[] { '(' }, 2, StringSplitOptions.RemoveEmptyEntries);
var name = nameGroup[0].Trim();
var roles = nameGroup.Count() > 1 ? nameGroup[1].Trim() : null;
if (roles != null)
roles = roles.EndsWith(")") ? roles.Substring(0, roles.Length - 1) : roles;
return new PersonInfo { Type = PersonType.GuestStar, Name = name, Role = roles };
}))
示例5: Fetch
//.........这里部分代码省略.........
if (File.Exists(bannerFile))
Item.BannerImagePath = bannerFile;
else {
// we don't have the banner file!
}
}
Item.Overview = seriesNode.SafeGetString("Overview");
if (Item.Overview != null)
Item.Overview = Item.Overview.Replace("\n\n", "\n");
Item.Name = seriesNode.SafeGetString("SeriesName");
//used for extended actor information. will fetch actors with roles stored in <Persons> tag
foreach (XmlNode node in seriesNode.SelectNodes("Persons/Person[Type='Actor']"))
{
try
{
if (series.Actors == null)
series.Actors = new List<Actor>();
var name = node.SelectSingleNode("Name").InnerText;
var role = node.SafeGetString("Role", "");
var actor = new Actor() { Name = name, Role = role };
series.Actors.Add(actor);
}
catch
{
// fall through i dont care, one less actor
}
}
//used for backwards compatibility. Will fetch actors stored in the <Actors> tag
if (series.Actors == null || series.Actors.Count == 0)
{
string actors = seriesNode.SafeGetString("Actors");
if (actors != null)
{
if (series.Actors == null)
series.Actors = new List<Actor>();
foreach (string n in actors.Trim('|').Split('|'))
{
series.Actors.Add(new Actor { Name = n });
}
}
}
string genres = seriesNode.SafeGetString("Genre");
if (genres != null)
series.Genres = new List<string>(genres.Trim('|').Split('|'));
series.MpaaRating = seriesNode.SafeGetString("ContentRating");
string runtimeString = seriesNode.SafeGetString("Runtime");
if (!string.IsNullOrEmpty(runtimeString)) {
int runtime;
if (int.TryParse(runtimeString.Split(' ')[0], out runtime))
series.RunningTime = runtime;
}
// this causes a problem on localized windows version with a comma seperator in regional options
// http://community.mediabrowser.tv/permalinks/3263/ratings-for-series-aren-t-calculated-properly-with-non-us-regional-settings
//string ratingString = seriesNode.SafeGetString("Rating",);
//if (ratingString != null) {
// float imdbRating;
// if (float.TryParse(ratingString, out imdbRating)) {
// series.ImdbRating = imdbRating;
// }
//}
//SafeGetSingle only works directly from metadataDoc
//temporary fix, should be handled better
series.ImdbRating = metadataDoc.SafeGetSingle("Series/Rating", (float)-1, 10);
series.Status = seriesNode.SafeGetString("Status");
series.AirDay = seriesNode.SafeGetString("Airs_DayOfWeek");
series.AirTime = seriesNode.SafeGetString("Airs_Time");
string studios = seriesNode.SafeGetString("Network");
if (studios != null) {
series.Studios = new List<string>(studios.Split('|'));
//series.Studios = new List<Studio>();
//foreach (string n in studios.Split('|'))
//{
// series.Studios.Add(new Studio { Name = n });
//}
}
series.CustomRating = seriesNode.SafeGetString("CustomRating");
series.CustomPIN = seriesNode.SafeGetString("CustomPIN");
// Some XML files may have incorrect series ids so do not try to set the item,
// this would really mess up the internet provid
}
示例6: ProcessDocument
protected virtual void ProcessDocument(XmlDocument doc, bool ignoreImages)
{
Movie movie = Item as Movie;
if (doc != null)
{
// This is problematic for foreign films we want to keep the alt title.
//if (store.Name == null)
// store.Name = doc.SafeGetString("//movie/title");
movie.Name = doc.SafeGetString("//movie/name");
movie.Overview = doc.SafeGetString("//movie/overview");
if (movie.Overview != null)
movie.Overview = movie.Overview.Replace("\n\n", "\n");
movie.TagLine = doc.SafeGetString("//movie/tagline");
movie.ImdbID = doc.SafeGetString("//movie/imdb_id");
movie.ImdbRating = doc.SafeGetSingle("//movie/rating", -1, 10);
string release = doc.SafeGetString("//movie/released");
if (!string.IsNullOrEmpty(release))
movie.ProductionYear = Int32.Parse(release.Substring(0, 4));
movie.RunningTime = doc.SafeGetInt32("//movie/runtime");
if (movie.MediaInfo != null && movie.MediaInfo.RunTime > 0) movie.RunningTime = movie.MediaInfo.RunTime;
movie.MpaaRating = doc.SafeGetString("//movie/certification");
movie.Studios = null;
foreach (XmlNode n in doc.SelectNodes("//studios/studio"))
{
if (movie.Studios == null)
movie.Studios = new List<string>();
string name = n.SafeGetString("@name");
if (!string.IsNullOrEmpty(name))
movie.Studios.Add(name);
}
movie.Directors = null;
foreach (XmlNode n in doc.SelectNodes("//cast/person[@job='Director']"))
{
if (movie.Directors == null)
movie.Directors = new List<string>();
string name = n.SafeGetString("@name");
if (!string.IsNullOrEmpty(name))
movie.Directors.Add(name);
}
movie.Writers = null;
foreach (XmlNode n in doc.SelectNodes("//cast/person[@job='Author']"))
{
if (movie.Writers == null)
movie.Writers = new List<string>();
string name = n.SafeGetString("@name");
if (!string.IsNullOrEmpty(name))
movie.Writers.Add(name);
}
movie.Actors = null;
foreach (XmlNode n in doc.SelectNodes("//cast/person[@job='Actor']"))
{
if (movie.Actors == null)
movie.Actors = new List<Actor>();
string name = n.SafeGetString("@name");
string role = n.SafeGetString("@character");
if (!string.IsNullOrEmpty(name))
movie.Actors.Add(new Actor { Name = name, Role = role });
}
XmlNodeList nodes = doc.SelectNodes("//movie/categories/category[@type='genre']/@name");
List<string> genres = new List<string>();
foreach (XmlNode node in nodes)
{
string n = MapGenre(node.InnerText);
if ((!string.IsNullOrEmpty(n)) && (!genres.Contains(n)))
genres.Add(n);
}
movie.Genres = genres;
if (!ignoreImages)
{
string img = doc.SafeGetString("//movie/images/image[@type='poster' and @size='" + Kernel.Instance.ConfigData.FetchedPosterSize + "']/@url");
if (img == null)
{
img = doc.SafeGetString("//movie/images/image[@type='poster' and @size='original']/@url"); //couldn't find preferred size
}
if (img != null)
{
if (Kernel.Instance.ConfigData.SaveLocalMeta)
{
//download and save locally
RemoteImage cover = new RemoteImage() { Path = img };
string ext = Path.GetExtension(img).ToLower();
string fn = (Path.Combine(Item.Path,"folder" + ext));
try
{
Kernel.IgnoreFileSystemMods = true;
cover.DownloadImage().Save(fn, ext == ".png" ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
Kernel.IgnoreFileSystemMods = false;
//.........这里部分代码省略.........
示例7: Fetch
public override void Fetch()
{
var movie = Item as Movie;
Debug.Assert(movie != null);
string mfile = XmlLocation();
string location = Path.GetDirectoryName(mfile);
if (File.Exists(mfile))
{
DateTime modTime = new FileInfo(mfile).LastWriteTimeUtc;
lastWriteTime = modTime;
myMovieFile = mfile;
XmlDocument doc = new XmlDocument();
doc.Load(mfile);
string s = doc.SafeGetString("Title/LocalTitle");
if ((s == null) || (s == ""))
s = doc.SafeGetString("Title/OriginalTitle");
movie.Name = s;
movie.SortName = doc.SafeGetString("Title/SortTitle");
movie.Overview = doc.SafeGetString("Title/Description");
if (movie.Overview != null)
movie.Overview = movie.Overview.Replace("\n\n", "\n");
string front = doc.SafeGetString("Title/Covers/Front");
if ((front != null) && (front.Length > 0))
{
front = Path.Combine(location, front);
if (File.Exists(front))
Item.PrimaryImagePath = front;
}
string back = doc.SafeGetString("Title/Covers/Back");
if ((back != null) && (back.Length > 0))
{
back = Path.Combine(location, back);
if (File.Exists(back))
Item.SecondaryImagePath = back;
}
if (movie.RunningTime == null)
{
int rt = doc.SafeGetInt32("Title/RunningTime",0);
if (rt > 0)
movie.RunningTime = rt;
}
if (movie.ProductionYear == null)
{
int y = doc.SafeGetInt32("Title/ProductionYear",0);
if (y > 1900)
movie.ProductionYear = y;
}
if (movie.ImdbRating == null)
{
float i = doc.SafeGetSingle("Title/IMDBrating", (float)-1, (float)10);
if (i >= 0)
movie.ImdbRating = i;
}
foreach (XmlNode node in doc.SelectNodes("Title/Persons/Person[Type='Actor']"))
{
try
{
if (movie.Actors == null)
movie.Actors = new List<Actor>();
movie.Actors.Add(new Actor { Name = node.SelectSingleNode("Name").InnerText, Role = node.SelectSingleNode("Role").InnerText });
}
catch
{
// fall through i dont care, one less actor
}
}
foreach (XmlNode node in doc.SelectNodes("Title/Persons/Person[Type='Director']"))
{
try
{
if (movie.Directors == null)
movie.Directors = new List<string>();
movie.Directors.Add(node.SelectSingleNode("Name").InnerText);
}
catch
{
// fall through i dont care, one less director
}
}
foreach (XmlNode node in doc.SelectNodes("Title/Genres/Genre"))
{
try
{
if (movie.Genres == null)
movie.Genres = new List<string>();
movie.Genres.Add(node.InnerText);
}
catch
{
// fall through i dont care, one less genre
//.........这里部分代码省略.........
示例8: FetchMainInfo
/// <summary>
/// Fetches the main info.
/// </summary>
/// <param name="series">The series.</param>
/// <param name="doc">The doc.</param>
private void FetchMainInfo(Series series, XmlDocument doc)
{
if (!series.LockedFields.Contains(MetadataFields.Name))
{
series.Name = doc.SafeGetString("//SeriesName");
}
if (!series.LockedFields.Contains(MetadataFields.Overview))
{
series.Overview = doc.SafeGetString("//Overview");
}
series.CommunityRating = doc.SafeGetSingle("//Rating", 0, 10);
series.AirDays = TVUtils.GetAirDays(doc.SafeGetString("//Airs_DayOfWeek"));
series.AirTime = doc.SafeGetString("//Airs_Time");
SeriesStatus seriesStatus;
if(Enum.TryParse(doc.SafeGetString("//Status"), true, out seriesStatus))
series.Status = seriesStatus;
series.PremiereDate = doc.SafeGetDateTime("//FirstAired");
if (series.PremiereDate.HasValue)
series.ProductionYear = series.PremiereDate.Value.Year;
series.RunTimeTicks = TimeSpan.FromMinutes(doc.SafeGetInt32("//Runtime")).Ticks;
if (!series.LockedFields.Contains(MetadataFields.Studios))
{
string s = doc.SafeGetString("//Network");
if (!string.IsNullOrWhiteSpace(s))
{
series.Studios.Clear();
foreach (var studio in s.Trim().Split('|'))
{
series.AddStudio(studio);
}
}
}
series.OfficialRating = doc.SafeGetString("//ContentRating");
if (!series.LockedFields.Contains(MetadataFields.Genres))
{
string g = doc.SafeGetString("//Genre");
if (g != null)
{
string[] genres = g.Trim('|').Split('|');
if (g.Length > 0)
{
series.Genres.Clear();
foreach (var genre in genres)
{
series.AddGenre(genre);
}
}
}
}
if (series.Status == SeriesStatus.Ended) {
var document = XDocument.Load(new XmlNodeReader(doc));
var dates = document.Descendants("Episode").Where(x => {
var seasonNumber = x.Element("SeasonNumber");
var firstAired = x.Element("FirstAired");
return firstAired != null && seasonNumber != null && (!string.IsNullOrEmpty(seasonNumber.Value) && seasonNumber.Value != "0") && !string.IsNullOrEmpty(firstAired.Value);
}).Select(x => {
DateTime? date = null;
DateTime tempDate;
var firstAired = x.Element("FirstAired");
if (firstAired != null && DateTime.TryParse(firstAired.Value, out tempDate))
{
date = tempDate;
}
return date;
}).ToList();
if(dates.Any(x=>x.HasValue))
series.EndDate = dates.Where(x => x.HasValue).Max();
}
}
示例9: FetchEpisodeData
/// <summary>
/// Fetches the episode data.
/// </summary>
/// <param name="seriesXml">The series XML.</param>
/// <param name="episode">The episode.</param>
/// <param name="seriesId">The series id.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
private async Task<ProviderRefreshStatus> FetchEpisodeData(XmlDocument seriesXml, Episode episode, string seriesId, CancellationToken cancellationToken)
{
var status = ProviderRefreshStatus.Success;
if (episode.IndexNumber == null)
{
return status;
}
var seasonNumber = episode.ParentIndexNumber ?? TVUtils.GetSeasonNumberFromEpisodeFile(episode.Path);
if (seasonNumber == null)
{
return status;
}
var usingAbsoluteData = false;
var episodeNode = seriesXml.SelectSingleNode("//Episode[EpisodeNumber='" + episode.IndexNumber.Value + "'][SeasonNumber='" + seasonNumber.Value + "']");
if (episodeNode == null)
{
if (seasonNumber.Value == 1)
{
episodeNode = seriesXml.SelectSingleNode("//Episode[absolute_number='" + episode.IndexNumber.Value + "']");
usingAbsoluteData = true;
}
}
// If still null, nothing we can do
if (episodeNode == null)
{
return status;
}
var doc = new XmlDocument();
doc.LoadXml(episodeNode.OuterXml);
if (!episode.HasImage(ImageType.Primary))
{
var p = doc.SafeGetString("//filename");
if (p != null)
{
if (!Directory.Exists(episode.MetaLocation)) Directory.CreateDirectory(episode.MetaLocation);
try
{
episode.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(episode, TVUtils.BannerUrl + p, Path.GetFileName(p), ConfigurationManager.Configuration.SaveLocalMeta, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken);
}
catch (HttpException)
{
status = ProviderRefreshStatus.CompletedWithErrors;
}
}
}
episode.Overview = doc.SafeGetString("//Overview");
if (usingAbsoluteData)
episode.IndexNumber = doc.SafeGetInt32("//absolute_number", -1);
if (episode.IndexNumber < 0)
episode.IndexNumber = doc.SafeGetInt32("//EpisodeNumber");
episode.Name = doc.SafeGetString("//EpisodeName");
episode.CommunityRating = doc.SafeGetSingle("//Rating", -1, 10);
var firstAired = doc.SafeGetString("//FirstAired");
DateTime airDate;
if (DateTime.TryParse(firstAired, out airDate) && airDate.Year > 1850)
{
episode.PremiereDate = airDate.ToUniversalTime();
episode.ProductionYear = airDate.Year;
}
episode.People.Clear();
var actors = doc.SafeGetString("//GuestStars");
if (actors != null)
{
foreach (var person in actors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(str => new PersonInfo { Type = PersonType.GuestStar, Name = str }))
{
episode.AddPerson(person);
}
}
var directors = doc.SafeGetString("//Director");
if (directors != null)
{
foreach (var person in directors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(str => new PersonInfo { Type = PersonType.Director, Name = str }))
//.........这里部分代码省略.........
示例10: FetchXmlMovie
private static void FetchXmlMovie(Item movie)
{
string mfile = Path.Combine(location, videofilename + ".nfo");
if (File.Exists(mfile))
{
XmlDocument doc = new XmlDocument();
doc.Load(mfile);
movie.Title = doc.SafeGetString("movie/title");
movie.OriginalTitle = doc.SafeGetString("movie/originaltitle");
movie.SortTitle = doc.SafeGetString("movie/sorttitle");
DateTime added;
DateTime.TryParse(doc.SafeGetString("movie/added"), out added);
if (added != null) movie.DateAdded = added;
int? y = doc.SafeGetInt32("movie/year", 0);
if (y.IsValidYear()) movie.Year = y;
int? rt = doc.SafeGetInt32("movie/runtime", 0);
if (rt.IsValidRunningTime()) movie.RunningTime = rt;
movie.Rating = doc.SafeGetSingle("movie/rating", (float)-1, (float)10);
movie.MPAARating = doc.SafeGetString("movie/mpaa");
movie.Overview = doc.SafeGetString("movie/plot");
movie.Mediatype = doc.SafeGetString("movie/type");
movie.AspectRatio = doc.SafeGetString("movie/aspectratio");
foreach (XmlNode node in doc.SelectNodes("movie/actor"))
{
if (movie.Actors == null)
movie.Actors = new List<Actor>();
Actor actor = new Actor();
actor.Name = node.SafeGetString("name");
actor.Role = node.SafeGetString("role");
actor.ImagePath = node.SafeGetString("thumb");
if (string.IsNullOrEmpty(actor.ImagePath) && Directory.Exists(PluginOptions.Instance.ActorsThumbPath))
{
string actorImage = Path.Combine(PluginOptions.Instance.ActorsThumbPath, actor.Name + ".tbn");
if (File.Exists(actorImage))
actor.ImagePath = actorImage;
}
movie.Actors.Add(actor);
}
foreach (XmlNode node in doc.SelectNodes("movie/director"))
{
if (movie.Crew == null) movie.Crew = new List<CrewMember>();
movie.Crew.Add(new CrewMember { Name = node.InnerText, Activity = "Director" });
}
foreach (XmlNode node in doc.SelectNodes("movie/genre"))
{
if (movie.Genres == null) movie.Genres = new List<string>();
movie.Genres.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("movie/studio"))
{
if (movie.Studios == null) movie.Studios = new List<string>();
movie.Studios.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("movie/country"))
{
if (movie.Countries == null) movie.Countries = new List<string>();
movie.Countries.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("movie/tagline"))
{
if (movie.TagLines == null) movie.TagLines = new List<string>();
movie.TagLines.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("movie/trailer"))
{
if (movie.TrailerFiles == null) movie.TrailerFiles = new List<string>();
movie.TrailerFiles.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("movie/thumb"))
{
if (movie.ImagesPaths == null) movie.ImagesPaths = new List<Poster>();
movie.ImagesPaths.AddDistinctPoster(new Poster { Image = node.InnerText });
}
foreach (XmlNode node in doc.SelectNodes("movie/fanart/thumb"))
{
if (movie.BackdropImagePaths == null) movie.BackdropImagePaths = new List<Poster>();
movie.BackdropImagePaths.AddDistinctPoster(new Poster { Image = node.InnerText });
}
}
}
示例11: FetchSeries
private static void FetchSeries(Item series)
{
string mfile = Path.Combine(location, "tvshow.nfo");
if (File.Exists(mfile))
{
XmlDocument doc = new XmlDocument();
doc.Load(mfile);
series.SeriesName = series.Title = doc.SafeGetString("tvshow/title");
series.Rating = doc.SafeGetSingle("tvshow/rating", (float)-1, (float)10);
string id = doc.SafeGetString("tvshow/id");
if (!string.IsNullOrEmpty(id))
{
series.ProvidersId = new List<DataProviderId>();
series.ProvidersId.Add(new DataProviderId { Id = id, Name = "TheTVDB", Url = "http://thetvdb.com/?tab=series&id=" + id });
}
series.Overview = doc.SafeGetString("tvshow/overview");
foreach (XmlNode node in doc.SelectNodes("tvshow/actor"))
{
if (series.Actors == null)
series.Actors = new List<Actor>();
Actor actor = new Actor();
actor.Name = node.SafeGetString("name");
actor.Role = node.SafeGetString("role");
actor.ImagePath = node.SafeGetString("thumb");
if (string.IsNullOrEmpty(actor.ImagePath) && Directory.Exists(PluginOptions.Instance.ActorsThumbPath))
{
string actorImage = Path.Combine(PluginOptions.Instance.ActorsThumbPath, actor.Name + ".tbn");
if (File.Exists(actorImage))
actor.ImagePath = actorImage;
}
series.Actors.Add(actor);
}
foreach (XmlNode node in doc.SelectNodes("tvshow/genre"))
{
if (series.Genres == null) series.Genres = new List<string>();
series.Genres.Add(node.InnerText);
}
series.MPAARating = doc.SafeGetString("mpaa");
int? rt = doc.SafeGetInt32("tvshow/runtime", 0);
if (rt.IsValidRunningTime()) series.RunningTime = rt;
series.Rating = doc.SafeGetSingle("tvshow/rating", (float)-1, (float)10);
foreach (XmlNode node in doc.SelectNodes("tvshow/studio"))
{
if (series.Studios == null) series.Studios = new List<string>();
series.Studios.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("tvshow/tagline"))
{
if (series.TagLines == null) series.TagLines = new List<string>();
series.TagLines.Add(node.InnerText);
}
foreach (XmlNode node in doc.SelectNodes("tvshow/thumb"))
{
if (series.BannersPaths == null) series.BannersPaths = new List<Poster>();
series.BannersPaths.AddDistinctPoster(new Poster { Image = node.InnerText });
}
}
}
示例12: FetchEpisode
private static void FetchEpisode(Item episode)
{
var mfile = Path.Combine(location, videofilename + ".nfo");
if (File.Exists(mfile))
{
XmlDocument doc = new XmlDocument();
doc.Load(mfile);
episode.Overview = doc.SafeGetString("episodedetails/plot");
episode.EpisodeNumber = doc.SafeGetString("episodedetails/episode");
episode.Title = doc.SafeGetString("episodedetails/title");
episode.SeasonNumber = doc.SafeGetString("episodedetails/season");
episode.Rating = doc.SafeGetSingle("episodedetails/rating", (float)-1, 10);
foreach (XmlNode node in doc.SelectNodes("episodedetails/actor"))
{
if (episode.Actors == null)
episode.Actors = new List<Actor>();
Actor actor = new Actor();
actor.Name = node.SafeGetString("name");
actor.Role = node.SafeGetString("role");
actor.ImagePath = node.SafeGetString("thumb");
if (string.IsNullOrEmpty(actor.ImagePath) && Directory.Exists(PluginOptions.Instance.ActorsThumbPath))
{
string actorImage = Path.Combine(PluginOptions.Instance.ActorsThumbPath, actor.Name + ".tbn");
if (File.Exists(actorImage))
actor.ImagePath = actorImage;
}
episode.Actors.Add(actor);
}
foreach (XmlNode node in doc.SelectNodes("episodedetails/director"))
{
if (episode.Crew == null) episode.Crew = new List<CrewMember>();
episode.Crew.Add(new CrewMember { Name = node.InnerText, Activity = "Director" });
}
foreach (XmlNode node in doc.SelectNodes("episodedetails/credit"))
{
if (episode.Crew == null) episode.Crew = new List<CrewMember>();
episode.Crew.Add(new CrewMember { Name = node.InnerText, Activity = "Writer" });
}
}
}
示例13: Fetch
public override void Fetch()
{
Episode episode = Episode;
Debug.Assert(episode != null);
// store the location so we do not fetch again
metadataFile = XmlLocation;
// no data, do nothing
if (metadataFile == null) return;
metadataFileDate = new FileInfo(metadataFile).LastWriteTimeUtc;
string metadataFolder = Path.GetDirectoryName(metadataFile);
XmlDocument metadataDoc = new XmlDocument();
metadataDoc.Load(metadataFile);
var p = metadataDoc.SafeGetString("//filename");
if (p != null && p.Length > 0)
{
string image = System.IO.Path.Combine(metadataFolder, System.IO.Path.GetFileName(p));
if (File.Exists(image))
Item.PrimaryImagePath = image;
}
else
{
string primaryExt = ".jpg";
string secondaryExt = ".png";
if (Config.Instance.PNGTakesPrecedence)
{
primaryExt = ".png";
secondaryExt = ".jpg";
}
string file = Path.GetFileNameWithoutExtension(Item.Path);
string image = System.IO.Path.Combine(metadataFolder, file + primaryExt);
if (File.Exists(image))
{
Item.PrimaryImagePath = image;
}
else
{
image = System.IO.Path.Combine(metadataFolder, file + secondaryExt);
if (File.Exists(image))
Item.PrimaryImagePath = image;
}
}
//if added date is in xml override the file/folder date
DateTime added = DateTime.MinValue;
DateTime.TryParse(metadataDoc.SafeGetString("//Added"), out added);
if (added > DateTime.MinValue) episode.DateCreated = added;
episode.Overview = metadataDoc.SafeGetString("//Overview");
episode.EpisodeNumber = metadataDoc.SafeGetString("//EpisodeNumber");
episode.Name = episode.EpisodeNumber + " - " + metadataDoc.SafeGetString("//EpisodeName");
episode.SeasonNumber = metadataDoc.SafeGetString("//SeasonNumber");
episode.ImdbRating = metadataDoc.SafeGetSingle("//Rating", (float)-1, 10);
episode.FirstAired = metadataDoc.SafeGetString("//FirstAired");
DateTime airDate;
int y = DateTime.TryParse(episode.FirstAired, out airDate) ? airDate.Year : -1;
if (y > 1850) {
episode.ProductionYear = y;
}
string writers = metadataDoc.SafeGetString("//Writer");
if (writers != null)
episode.Writers = new List<string>(writers.Trim('|').Split('|'));
string directors = metadataDoc.SafeGetString("//Director");
if (directors != null)
episode.Directors = new List<string>(directors.Trim('|').Split('|'));
var actors = ActorListFromString(metadataDoc.SafeGetString("//GuestStars"));
if (actors != null) {
if (episode.Actors == null)
episode.Actors = new List<Actor>();
episode.Actors = actors;
}
if (string.IsNullOrEmpty(episode.DisplayMediaType))
{
episode.DisplayMediaType = metadataDoc.SafeGetString("//Type", "");
switch (episode.DisplayMediaType.ToLower())
{
case "blu-ray":
episode.DisplayMediaType = MediaType.BluRay.ToString();
break;
case "dvd":
episode.DisplayMediaType = MediaType.DVD.ToString();
break;
case "hd dvd":
episode.DisplayMediaType = MediaType.HDDVD.ToString();
break;
case "":
//.........这里部分代码省略.........