From 3f557077550b79e2c209a4041a9318886b79ed14 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Fri, 20 Jul 2012 15:03:11 -0400 Subject: [PATCH] Made AirDay strongly typed. Added a ReadString extension method. --- .../Xml/BaseItemXmlParser.cs | 62 +++++++++---------- MediaBrowser.Controller/Xml/XmlExtensions.cs | 8 +++ .../Metadata/MovieXmlParser.cs | 4 +- MediaBrowser.TV/Entities/Series.cs | 4 +- MediaBrowser.TV/Metadata/EpisodeXmlParser.cs | 10 +-- MediaBrowser.TV/Metadata/SeriesXmlParser.cs | 40 +++++++++--- 6 files changed, 82 insertions(+), 46 deletions(-) diff --git a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs index ffaf732a6..4602a3778 100644 --- a/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Xml/BaseItemXmlParser.cs @@ -55,7 +55,7 @@ namespace MediaBrowser.Controller.Xml // DateCreated case "Added": DateTime added; - if (DateTime.TryParse(reader.ReadElementContentAsString() ?? string.Empty, out added)) + if (DateTime.TryParse(reader.ReadString() ?? string.Empty, out added)) { item.DateCreated = added; } @@ -64,7 +64,7 @@ namespace MediaBrowser.Controller.Xml // DisplayMediaType case "Type": { - item.DisplayMediaType = reader.ReadElementContentAsString() ?? string.Empty; + item.DisplayMediaType = reader.ReadString(); switch (item.DisplayMediaType.ToLower()) { @@ -84,56 +84,56 @@ namespace MediaBrowser.Controller.Xml // TODO: Do we still need this? case "banner": - item.BannerImagePath = reader.ReadElementContentAsString() ?? string.Empty; + item.BannerImagePath = reader.ReadString(); break; case "LocalTitle": - item.Name = reader.ReadElementContentAsString() ?? string.Empty; + item.Name = reader.ReadString(); break; case "SortTitle": - item.SortName = reader.ReadElementContentAsString() ?? string.Empty; + item.SortName = reader.ReadString(); break; case "Overview": case "Description": - item.Overview = reader.ReadElementContentAsString() ?? string.Empty; + item.Overview = reader.ReadString(); break; case "TagLine": - item.Tagline = reader.ReadElementContentAsString() ?? string.Empty; + item.Tagline = reader.ReadString(); break; case "ContentRating": case "MPAARating": - item.OfficialRating = reader.ReadElementContentAsString() ?? string.Empty; + item.OfficialRating = reader.ReadString(); break; case "CustomRating": - item.CustomRating = reader.ReadElementContentAsString() ?? string.Empty; + item.CustomRating = reader.ReadString(); break; case "CustomPin": - item.CustomPin = reader.ReadElementContentAsString() ?? string.Empty; + item.CustomPin = reader.ReadString(); break; case "Genre": { var genres = (item.Genres ?? new string[] { }).ToList(); - genres.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|')); + genres.AddRange(GetSplitValues(reader.ReadString(), '|')); item.Genres = genres; break; } case "AspectRatio": - item.AspectRatio = reader.ReadElementContentAsString() ?? string.Empty; + item.AspectRatio = reader.ReadString(); break; case "Network": { var studios = (item.Studios ?? new string[] { }).ToList(); - studios.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|')); + studios.AddRange(GetSplitValues(reader.ReadString(), '|')); item.Studios = studios; break; @@ -142,7 +142,7 @@ namespace MediaBrowser.Controller.Xml case "Director": { var list = (item.People ?? new PersonInfo[] { }).ToList(); - list.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Director })); + list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Director })); item.People = list; break; @@ -150,7 +150,7 @@ namespace MediaBrowser.Controller.Xml case "Writer": { var list = (item.People ?? new PersonInfo[] { }).ToList(); - list.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Writer })); + list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Writer })); item.People = list; break; @@ -160,20 +160,20 @@ namespace MediaBrowser.Controller.Xml case "GuestStars": { var list = (item.People ?? new PersonInfo[] { }).ToList(); - list.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Actor })); + list.AddRange(GetSplitValues(reader.ReadString(), '|').Select(v => new PersonInfo() { Name = v, PersonType = PersonType.Actor })); item.People = list; break; } case "Trailer": - item.TrailerUrl = reader.ReadElementContentAsString() ?? string.Empty; + item.TrailerUrl = reader.ReadString(); break; case "ProductionYear": { int ProductionYear; - if (int.TryParse(reader.ReadElementContentAsString(), out ProductionYear) && ProductionYear > 1850) + if (int.TryParse(reader.ReadString(), out ProductionYear) && ProductionYear > 1850) { item.ProductionYear = ProductionYear; } @@ -184,7 +184,7 @@ namespace MediaBrowser.Controller.Xml case "Rating": case "IMDBrating": - string rating = reader.ReadElementContentAsString(); + string rating = reader.ReadString(); if (!string.IsNullOrWhiteSpace(rating)) { @@ -291,12 +291,12 @@ namespace MediaBrowser.Controller.Xml break; case "Language": - stream.Language = reader.ReadElementContentAsString() ?? string.Empty; + stream.Language = reader.ReadString(); break; case "Codec": { - string codec = reader.ReadElementContentAsString() ?? string.Empty; + string codec = reader.ReadString(); switch (codec.ToLower()) { @@ -376,11 +376,11 @@ namespace MediaBrowser.Controller.Xml break; case "FrameRate": - item.FrameRate = reader.ReadElementContentAsString() ?? string.Empty; + item.FrameRate = reader.ReadString(); break; case "ScanType": - item.ScanType = reader.ReadElementContentAsString() ?? string.Empty; + item.ScanType = reader.ReadString(); break; case "Duration": @@ -397,7 +397,7 @@ namespace MediaBrowser.Controller.Xml case "Codec": { - string videoCodec = reader.ReadElementContentAsString() ?? string.Empty; + string videoCodec = reader.ReadString(); switch (videoCodec.ToLower()) { @@ -440,7 +440,7 @@ namespace MediaBrowser.Controller.Xml { case "Language": { - string genre = reader.ReadElementContentAsString(); + string genre = reader.ReadString(); if (!string.IsNullOrWhiteSpace(genre)) { @@ -473,7 +473,7 @@ namespace MediaBrowser.Controller.Xml { case "Genre": { - string genre = reader.ReadElementContentAsString(); + string genre = reader.ReadString(); if (!string.IsNullOrWhiteSpace(genre)) { @@ -534,7 +534,7 @@ namespace MediaBrowser.Controller.Xml { case "Studio": { - string studio = reader.ReadElementContentAsString(); + string studio = reader.ReadString(); if (!string.IsNullOrWhiteSpace(studio)) { @@ -565,7 +565,7 @@ namespace MediaBrowser.Controller.Xml { case "Value": { - string ratingString = reader.ReadElementContentAsString(); + string ratingString = reader.ReadString(); int rating = 7; @@ -624,12 +624,12 @@ namespace MediaBrowser.Controller.Xml switch (reader.Name) { case "Name": - person.Name = reader.ReadElementContentAsString() ?? string.Empty; + person.Name = reader.ReadString(); break; case "Type": { - string type = reader.ReadElementContentAsString() ?? string.Empty; + string type = reader.ReadString(); if (type == "Director") { @@ -643,7 +643,7 @@ namespace MediaBrowser.Controller.Xml } case "Role": - person.Overview = reader.ReadElementContentAsString() ?? string.Empty; + person.Overview = reader.ReadString(); break; default: diff --git a/MediaBrowser.Controller/Xml/XmlExtensions.cs b/MediaBrowser.Controller/Xml/XmlExtensions.cs index e706baa61..6b74a2820 100644 --- a/MediaBrowser.Controller/Xml/XmlExtensions.cs +++ b/MediaBrowser.Controller/Xml/XmlExtensions.cs @@ -42,5 +42,13 @@ namespace MediaBrowser.Controller.Xml return value; } + + /// + /// Reads an int from the current element of an XmlReader + /// + public static string ReadString(this XmlReader reader) + { + return reader.ReadElementContentAsString(); + } } } diff --git a/MediaBrowser.Movies/Metadata/MovieXmlParser.cs b/MediaBrowser.Movies/Metadata/MovieXmlParser.cs index 67650fa98..0cfeab60d 100644 --- a/MediaBrowser.Movies/Metadata/MovieXmlParser.cs +++ b/MediaBrowser.Movies/Metadata/MovieXmlParser.cs @@ -11,12 +11,12 @@ namespace MediaBrowser.Movies.Metadata switch (reader.Name) { case "TMDbId": - item.TmdbId = reader.ReadElementContentAsString() ?? string.Empty; + item.TmdbId = reader.ReadString(); break; case "IMDB": case "IMDbId": - string IMDbId = reader.ReadElementContentAsString() ?? string.Empty; + string IMDbId = reader.ReadString(); if (!string.IsNullOrWhiteSpace(IMDbId)) { item.ImdbId = IMDbId; diff --git a/MediaBrowser.TV/Entities/Series.cs b/MediaBrowser.TV/Entities/Series.cs index 5e73122a0..9e38652c2 100644 --- a/MediaBrowser.TV/Entities/Series.cs +++ b/MediaBrowser.TV/Entities/Series.cs @@ -1,5 +1,7 @@ using MediaBrowser.Model.Entities; using System; +using System.Linq; +using System.Collections.Generic; namespace MediaBrowser.TV.Entities { @@ -7,7 +9,7 @@ namespace MediaBrowser.TV.Entities { public string TvdbId { get; set; } public string Status { get; set; } - public string AirDay { get; set; } + public IEnumerable AirDays { get; set; } public string AirTime { get; set; } } } diff --git a/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs b/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs index 7df64b405..da6a9dcb4 100644 --- a/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs +++ b/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.TV.Metadata { case "filename": { - string filename = reader.ReadElementContentAsString(); + string filename = reader.ReadString(); if (!string.IsNullOrWhiteSpace(filename)) { @@ -24,7 +24,7 @@ namespace MediaBrowser.TV.Metadata break; } case "EpisodeNumber": - string number = reader.ReadElementContentAsString() ?? string.Empty; + string number = reader.ReadString(); if (!string.IsNullOrWhiteSpace(number)) { @@ -33,16 +33,16 @@ namespace MediaBrowser.TV.Metadata break; case "SeasonNumber": - item.SeasonNumber = reader.ReadElementContentAsString() ?? string.Empty; + item.SeasonNumber = reader.ReadString(); break; case "EpisodeName": - item.Name = reader.ReadElementContentAsString() ?? string.Empty; + item.Name = reader.ReadString(); break; case "FirstAired": { - string firstAired = reader.ReadElementContentAsString() ?? string.Empty; + string firstAired = reader.ReadString(); if (!string.IsNullOrWhiteSpace(firstAired)) { diff --git a/MediaBrowser.TV/Metadata/SeriesXmlParser.cs b/MediaBrowser.TV/Metadata/SeriesXmlParser.cs index 279454754..092cf9b30 100644 --- a/MediaBrowser.TV/Metadata/SeriesXmlParser.cs +++ b/MediaBrowser.TV/Metadata/SeriesXmlParser.cs @@ -12,28 +12,54 @@ namespace MediaBrowser.TV.Metadata switch (reader.Name) { case "id": - item.TvdbId = reader.ReadElementContentAsString() ?? string.Empty; + item.TvdbId = reader.ReadString(); break; case "Airs_DayOfWeek": - item.AirDay = reader.ReadElementContentAsString() ?? string.Empty; - break; + { + string day = reader.ReadString(); + + if (!string.IsNullOrWhiteSpace(day)) + { + if (day.Equals("Daily", StringComparison.OrdinalIgnoreCase)) + { + item.AirDays = new DayOfWeek[] { + DayOfWeek.Sunday, + DayOfWeek.Monday, + DayOfWeek.Tuesday, + DayOfWeek.Wednesday, + DayOfWeek.Thursday, + DayOfWeek.Friday, + DayOfWeek.Saturday + }; + } + else + { + item.AirDays = new DayOfWeek[] { + (DayOfWeek)Enum.Parse(typeof(DayOfWeek), day, true) + }; + } + } + + break; + } case "Airs_Time": - item.AirTime = reader.ReadElementContentAsString() ?? string.Empty; + item.AirTime = reader.ReadString(); break; case "SeriesName": - item.Name = reader.ReadElementContentAsString() ?? string.Empty; + item.Name = reader.ReadString(); break; case "Status": - item.Status = reader.ReadElementContentAsString() ?? string.Empty; + item.Status = reader.ReadString(); break; case "Runtime": { - string text = reader.ReadElementContentAsString() ?? string.Empty; + string text = reader.ReadString(); + if (!string.IsNullOrWhiteSpace(text)) {