public static void CleanupGenres(Series series) { PluginConfiguration config = PluginConfiguration.Instance(); if (config.TidyGenreList) { series.Genres = RemoveRedundantGenres(series.Genres) .Distinct() .ToList(); TidyGenres(series); } var max = config.MaxGenres; if (config.AddAnimeGenre) { series.Genres.Remove("Animation"); series.Genres.Remove("Anime"); max = Math.Max(max - 1, 0); } if (config.MaxGenres > 0) { if (config.MoveExcessGenresToTags) { foreach (string genre in series.Genres.Skip(max)) { if (!series.Tags.Contains(genre)) { series.Tags.Add(genre); } } } series.Genres = series.Genres.Take(max).ToList(); } if (!series.Genres.Contains("Anime") && config.AddAnimeGenre) { if (series.Genres.Contains("Animation")) { series.Genres.Remove("Animation"); } series.AddGenre("Anime"); } series.Genres.Sort(); }
public static void CleanupGenres(Series series) { PluginConfiguration config = Plugin.Instance.Configuration; if (config.TidyGenreList) { series.Genres = RemoveRedundantGenres(series.Genres) .Distinct() .ToList(); TidyGenres(series); } var max = config.MaxGenres; if (config.AddAnimeGenre) { series.Genres.Remove("Animation"); series.Genres.Remove("Anime"); max = Math.Max(max - 1, 0); } if (config.MaxGenres > 0) { series.Genres = series.Genres.Take(max).ToList(); } if (!series.Genres.Contains("Anime") && config.AddAnimeGenre) { if (series.Genres.Contains("Animation")) { series.Genres.Remove("Animation"); } series.AddGenre("Anime"); } series.Genres.Sort(); }
public static void CleanupGenres(Series series) { PluginConfiguration config = Plugin.Instance.Configuration; if (config.TidyGenreList) { series.Genres = RemoveRedundantGenres(series.Genres) .Distinct() .ToArray(); TidyGenres(series); } var max = config.MaxGenres; if (config.AddAnimeGenre) { series.Genres = series.Genres.Except(new[] { "Animation", "Anime" }).ToArray(); max = Math.Max(max - 1, 0); } if (config.MaxGenres > 0) { series.Genres = series.Genres.Take(max).ToArray(); } if (!series.Genres.Contains("Anime") && config.AddAnimeGenre) { series.Genres = series.Genres.Except(new[] { "Animation" }).ToArray(); series.AddGenre("Anime"); } series.Genres = series.Genres.OrderBy(i => i).ToArray(); }
/// <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(); } } }
private void FetchDataFromSeriesNode(Series item, XmlReader reader, CancellationToken cancellationToken) { reader.MoveToContent(); // Loop through each element while (reader.Read()) { cancellationToken.ThrowIfCancellationRequested(); if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "SeriesName": { if (!item.LockedFields.Contains(MetadataFields.Name)) { item.Name = (reader.ReadElementContentAsString() ?? string.Empty).Trim(); } break; } case "Overview": { if (!item.LockedFields.Contains(MetadataFields.Overview)) { item.Overview = (reader.ReadElementContentAsString() ?? string.Empty).Trim(); } break; } case "Airs_DayOfWeek": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { item.AirDays = TVUtils.GetAirDays(val); } break; } case "Airs_Time": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { item.AirTime = val; } break; } case "ContentRating": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { if (!item.LockedFields.Contains(MetadataFields.OfficialRating)) { item.OfficialRating = val; } } break; } case "Rating": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { // Only fill this if it doesn't already have a value, since we get it from imdb which has better data if (!item.CommunityRating.HasValue || string.IsNullOrWhiteSpace(item.GetProviderId(MetadataProviders.Imdb))) { float rval; // float.TryParse is local aware, so it can be probamatic, force us culture if (float.TryParse(val, NumberStyles.AllowDecimalPoint, UsCulture, out rval)) { item.CommunityRating = rval; } } } break; } case "RatingCount": { 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.VoteCount = rval; } } break; } case "IMDB_ID": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { item.SetProviderId(MetadataProviders.Imdb, val); } break; } case "zap2it_id": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { item.SetProviderId(MetadataProviders.Zap2It, val); } break; } case "Status": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { SeriesStatus seriesStatus; if (Enum.TryParse(val, true, out seriesStatus)) { item.Status = seriesStatus; } } break; } case "FirstAired": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { DateTime date; if (DateTime.TryParse(val, out date)) { date = date.ToUniversalTime(); item.PremiereDate = date; item.ProductionYear = date.Year; } } break; } case "Runtime": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val) && !item.LockedFields.Contains(MetadataFields.Runtime)) { 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.RunTimeTicks = TimeSpan.FromMinutes(rval).Ticks; } } break; } case "Genre": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { // Only fill this in if there's no existing genres, because Imdb data from Omdb is preferred if (!item.LockedFields.Contains(MetadataFields.Genres) && (item.Genres.Count == 0 || !string.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, "en", StringComparison.OrdinalIgnoreCase))) { var vals = val .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(i => i.Trim()) .Where(i => !string.IsNullOrWhiteSpace(i)) .ToList(); if (vals.Count > 0) { item.Genres.Clear(); foreach (var genre in vals) { item.AddGenre(genre); } } } } break; } case "Network": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val)) { if (!item.LockedFields.Contains(MetadataFields.Studios)) { var vals = val .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(i => i.Trim()) .Where(i => !string.IsNullOrWhiteSpace(i)) .ToList(); if (vals.Count > 0) { item.Studios.Clear(); foreach (var genre in vals) { item.AddStudio(genre); } } } } break; } default: reader.Skip(); break; } } } }