浏览代码

Made AirDay strongly typed. Added a ReadString extension method.

LukePulverenti Luke Pulverenti luke pulverenti 13 年之前
父节点
当前提交
3f55707755

+ 31 - 31
MediaBrowser.Controller/Xml/BaseItemXmlParser.cs

@@ -55,7 +55,7 @@ namespace MediaBrowser.Controller.Xml
                 // DateCreated
                 // DateCreated
                 case "Added":
                 case "Added":
                     DateTime added;
                     DateTime added;
-                    if (DateTime.TryParse(reader.ReadElementContentAsString() ?? string.Empty, out added))
+                    if (DateTime.TryParse(reader.ReadString() ?? string.Empty, out added))
                     {
                     {
                         item.DateCreated = added;
                         item.DateCreated = added;
                     }
                     }
@@ -64,7 +64,7 @@ namespace MediaBrowser.Controller.Xml
                 // DisplayMediaType
                 // DisplayMediaType
                 case "Type":
                 case "Type":
                     {
                     {
-                        item.DisplayMediaType = reader.ReadElementContentAsString() ?? string.Empty;
+                        item.DisplayMediaType = reader.ReadString();
 
 
                         switch (item.DisplayMediaType.ToLower())
                         switch (item.DisplayMediaType.ToLower())
                         {
                         {
@@ -84,56 +84,56 @@ namespace MediaBrowser.Controller.Xml
 
 
                 // TODO: Do we still need this?
                 // TODO: Do we still need this?
                 case "banner":
                 case "banner":
-                    item.BannerImagePath = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.BannerImagePath = reader.ReadString();
                     break;
                     break;
 
 
                 case "LocalTitle":
                 case "LocalTitle":
-                    item.Name = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Name = reader.ReadString();
                     break;
                     break;
 
 
                 case "SortTitle":
                 case "SortTitle":
-                    item.SortName = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.SortName = reader.ReadString();
                     break;
                     break;
 
 
                 case "Overview":
                 case "Overview":
                 case "Description":
                 case "Description":
-                    item.Overview = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Overview = reader.ReadString();
                     break;
                     break;
 
 
                 case "TagLine":
                 case "TagLine":
-                    item.Tagline = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Tagline = reader.ReadString();
                     break;
                     break;
 
 
                 case "ContentRating":
                 case "ContentRating":
                 case "MPAARating":
                 case "MPAARating":
-                    item.OfficialRating = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.OfficialRating = reader.ReadString();
                     break;
                     break;
 
 
                 case "CustomRating":
                 case "CustomRating":
-                    item.CustomRating = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.CustomRating = reader.ReadString();
                     break;
                     break;
 
 
                 case "CustomPin":
                 case "CustomPin":
-                    item.CustomPin = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.CustomPin = reader.ReadString();
                     break;
                     break;
 
 
                 case "Genre":
                 case "Genre":
                     {
                     {
                         var genres = (item.Genres ?? new string[] { }).ToList();
                         var genres = (item.Genres ?? new string[] { }).ToList();
-                        genres.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|'));
+                        genres.AddRange(GetSplitValues(reader.ReadString(), '|'));
 
 
                         item.Genres = genres;
                         item.Genres = genres;
                         break;
                         break;
                     }
                     }
 
 
                 case "AspectRatio":
                 case "AspectRatio":
-                    item.AspectRatio = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.AspectRatio = reader.ReadString();
                     break;
                     break;
 
 
                 case "Network":
                 case "Network":
                     {
                     {
                         var studios = (item.Studios ?? new string[] { }).ToList();
                         var studios = (item.Studios ?? new string[] { }).ToList();
-                        studios.AddRange(GetSplitValues(reader.ReadElementContentAsString(), '|'));
+                        studios.AddRange(GetSplitValues(reader.ReadString(), '|'));
 
 
                         item.Studios = studios;
                         item.Studios = studios;
                         break;
                         break;
@@ -142,7 +142,7 @@ namespace MediaBrowser.Controller.Xml
                 case "Director":
                 case "Director":
                     {
                     {
                         var list = (item.People ?? new PersonInfo[] { }).ToList();
                         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;
                         item.People = list;
                         break;
                         break;
@@ -150,7 +150,7 @@ namespace MediaBrowser.Controller.Xml
                 case "Writer":
                 case "Writer":
                     {
                     {
                         var list = (item.People ?? new PersonInfo[] { }).ToList();
                         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;
                         item.People = list;
                         break;
                         break;
@@ -160,20 +160,20 @@ namespace MediaBrowser.Controller.Xml
                 case "GuestStars":
                 case "GuestStars":
                     {
                     {
                         var list = (item.People ?? new PersonInfo[] { }).ToList();
                         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;
                         item.People = list;
                         break;
                         break;
                     }
                     }
 
 
                 case "Trailer":
                 case "Trailer":
-                    item.TrailerUrl = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.TrailerUrl = reader.ReadString();
                     break;
                     break;
 
 
                 case "ProductionYear":
                 case "ProductionYear":
                     {
                     {
                         int ProductionYear;
                         int ProductionYear;
-                        if (int.TryParse(reader.ReadElementContentAsString(), out ProductionYear) && ProductionYear > 1850)
+                        if (int.TryParse(reader.ReadString(), out ProductionYear) && ProductionYear > 1850)
                         {
                         {
                             item.ProductionYear = ProductionYear;
                             item.ProductionYear = ProductionYear;
                         }
                         }
@@ -184,7 +184,7 @@ namespace MediaBrowser.Controller.Xml
                 case "Rating":
                 case "Rating":
                 case "IMDBrating":
                 case "IMDBrating":
 
 
-                    string rating = reader.ReadElementContentAsString();
+                    string rating = reader.ReadString();
 
 
                     if (!string.IsNullOrWhiteSpace(rating))
                     if (!string.IsNullOrWhiteSpace(rating))
                     {
                     {
@@ -291,12 +291,12 @@ namespace MediaBrowser.Controller.Xml
                             break;
                             break;
 
 
                         case "Language":
                         case "Language":
-                            stream.Language = reader.ReadElementContentAsString() ?? string.Empty;
+                            stream.Language = reader.ReadString();
                             break;
                             break;
 
 
                         case "Codec":
                         case "Codec":
                             {
                             {
-                                string codec = reader.ReadElementContentAsString() ?? string.Empty;
+                                string codec = reader.ReadString();
 
 
                                 switch (codec.ToLower())
                                 switch (codec.ToLower())
                                 {
                                 {
@@ -376,11 +376,11 @@ namespace MediaBrowser.Controller.Xml
                             break;
                             break;
 
 
                         case "FrameRate":
                         case "FrameRate":
-                            item.FrameRate = reader.ReadElementContentAsString() ?? string.Empty;
+                            item.FrameRate = reader.ReadString();
                             break;
                             break;
 
 
                         case "ScanType":
                         case "ScanType":
-                            item.ScanType = reader.ReadElementContentAsString() ?? string.Empty;
+                            item.ScanType = reader.ReadString();
                             break;
                             break;
 
 
                         case "Duration":
                         case "Duration":
@@ -397,7 +397,7 @@ namespace MediaBrowser.Controller.Xml
 
 
                         case "Codec":
                         case "Codec":
                             {
                             {
-                                string videoCodec = reader.ReadElementContentAsString() ?? string.Empty;
+                                string videoCodec = reader.ReadString();
 
 
                                 switch (videoCodec.ToLower())
                                 switch (videoCodec.ToLower())
                                 {
                                 {
@@ -440,7 +440,7 @@ namespace MediaBrowser.Controller.Xml
                     {
                     {
                         case "Language":
                         case "Language":
                             {
                             {
-                                string genre = reader.ReadElementContentAsString();
+                                string genre = reader.ReadString();
 
 
                                 if (!string.IsNullOrWhiteSpace(genre))
                                 if (!string.IsNullOrWhiteSpace(genre))
                                 {
                                 {
@@ -473,7 +473,7 @@ namespace MediaBrowser.Controller.Xml
                     {
                     {
                         case "Genre":
                         case "Genre":
                             {
                             {
-                                string genre = reader.ReadElementContentAsString();
+                                string genre = reader.ReadString();
 
 
                                 if (!string.IsNullOrWhiteSpace(genre))
                                 if (!string.IsNullOrWhiteSpace(genre))
                                 {
                                 {
@@ -534,7 +534,7 @@ namespace MediaBrowser.Controller.Xml
                     {
                     {
                         case "Studio":
                         case "Studio":
                             {
                             {
-                                string studio = reader.ReadElementContentAsString();
+                                string studio = reader.ReadString();
 
 
                                 if (!string.IsNullOrWhiteSpace(studio))
                                 if (!string.IsNullOrWhiteSpace(studio))
                                 {
                                 {
@@ -565,7 +565,7 @@ namespace MediaBrowser.Controller.Xml
                     {
                     {
                         case "Value":
                         case "Value":
                             {
                             {
-                                string ratingString = reader.ReadElementContentAsString();
+                                string ratingString = reader.ReadString();
 
 
                                 int rating = 7;
                                 int rating = 7;
 
 
@@ -624,12 +624,12 @@ namespace MediaBrowser.Controller.Xml
                     switch (reader.Name)
                     switch (reader.Name)
                     {
                     {
                         case "Name":
                         case "Name":
-                            person.Name = reader.ReadElementContentAsString() ?? string.Empty;
+                            person.Name = reader.ReadString();
                             break;
                             break;
 
 
                         case "Type":
                         case "Type":
                             {
                             {
-                                string type = reader.ReadElementContentAsString() ?? string.Empty;
+                                string type = reader.ReadString();
 
 
                                 if (type == "Director")
                                 if (type == "Director")
                                 {
                                 {
@@ -643,7 +643,7 @@ namespace MediaBrowser.Controller.Xml
                             }
                             }
 
 
                         case "Role":
                         case "Role":
-                            person.Overview = reader.ReadElementContentAsString() ?? string.Empty;
+                            person.Overview = reader.ReadString();
                             break;
                             break;
 
 
                         default:
                         default:

+ 8 - 0
MediaBrowser.Controller/Xml/XmlExtensions.cs

@@ -42,5 +42,13 @@ namespace MediaBrowser.Controller.Xml
 
 
             return value;
             return value;
         }
         }
+
+        /// <summary>
+        /// Reads an int from the current element of an XmlReader
+        /// </summary>
+        public static string ReadString(this XmlReader reader)
+        {
+            return reader.ReadElementContentAsString();
+        }
     }
     }
 }
 }

+ 2 - 2
MediaBrowser.Movies/Metadata/MovieXmlParser.cs

@@ -11,12 +11,12 @@ namespace MediaBrowser.Movies.Metadata
             switch (reader.Name)
             switch (reader.Name)
             {
             {
                 case "TMDbId":
                 case "TMDbId":
-                    item.TmdbId = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.TmdbId = reader.ReadString();
                     break;
                     break;
 
 
                 case "IMDB":
                 case "IMDB":
                 case "IMDbId":
                 case "IMDbId":
-                    string IMDbId = reader.ReadElementContentAsString() ?? string.Empty;
+                    string IMDbId = reader.ReadString();
                     if (!string.IsNullOrWhiteSpace(IMDbId))
                     if (!string.IsNullOrWhiteSpace(IMDbId))
                     {
                     {
                         item.ImdbId = IMDbId;
                         item.ImdbId = IMDbId;

+ 3 - 1
MediaBrowser.TV/Entities/Series.cs

@@ -1,5 +1,7 @@
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.Entities;
 using System;
 using System;
+using System.Linq;
+using System.Collections.Generic;
 
 
 namespace MediaBrowser.TV.Entities
 namespace MediaBrowser.TV.Entities
 {
 {
@@ -7,7 +9,7 @@ namespace MediaBrowser.TV.Entities
     {
     {
         public string TvdbId { get; set; }
         public string TvdbId { get; set; }
         public string Status { get; set; }
         public string Status { get; set; }
-        public string AirDay { get; set; }
+        public IEnumerable<DayOfWeek> AirDays { get; set; }
         public string AirTime { get; set; }
         public string AirTime { get; set; }
     }
     }
 }
 }

+ 5 - 5
MediaBrowser.TV/Metadata/EpisodeXmlParser.cs

@@ -14,7 +14,7 @@ namespace MediaBrowser.TV.Metadata
             {
             {
                 case "filename":
                 case "filename":
                     {
                     {
-                        string filename = reader.ReadElementContentAsString();
+                        string filename = reader.ReadString();
 
 
                         if (!string.IsNullOrWhiteSpace(filename))
                         if (!string.IsNullOrWhiteSpace(filename))
                         {
                         {
@@ -24,7 +24,7 @@ namespace MediaBrowser.TV.Metadata
                         break;
                         break;
                     }
                     }
                 case "EpisodeNumber":
                 case "EpisodeNumber":
-                    string number = reader.ReadElementContentAsString() ?? string.Empty;
+                    string number = reader.ReadString();
 
 
                     if (!string.IsNullOrWhiteSpace(number))
                     if (!string.IsNullOrWhiteSpace(number))
                     {
                     {
@@ -33,16 +33,16 @@ namespace MediaBrowser.TV.Metadata
                     break;
                     break;
 
 
                 case "SeasonNumber":
                 case "SeasonNumber":
-                    item.SeasonNumber = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.SeasonNumber = reader.ReadString();
                     break;
                     break;
 
 
                 case "EpisodeName":
                 case "EpisodeName":
-                    item.Name = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Name = reader.ReadString();
                     break;
                     break;
 
 
                 case "FirstAired":
                 case "FirstAired":
                     {
                     {
-                        string firstAired = reader.ReadElementContentAsString() ?? string.Empty;
+                        string firstAired = reader.ReadString();
 
 
                         if (!string.IsNullOrWhiteSpace(firstAired))
                         if (!string.IsNullOrWhiteSpace(firstAired))
                         {
                         {

+ 33 - 7
MediaBrowser.TV/Metadata/SeriesXmlParser.cs

@@ -12,28 +12,54 @@ namespace MediaBrowser.TV.Metadata
             switch (reader.Name)
             switch (reader.Name)
             {
             {
                 case "id":
                 case "id":
-                    item.TvdbId = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.TvdbId = reader.ReadString();
                     break;
                     break;
 
 
                 case "Airs_DayOfWeek":
                 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":
                 case "Airs_Time":
-                    item.AirTime = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.AirTime = reader.ReadString();
                     break;
                     break;
 
 
                 case "SeriesName":
                 case "SeriesName":
-                    item.Name = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Name = reader.ReadString();
                     break;
                     break;
 
 
                 case "Status":
                 case "Status":
-                    item.Status = reader.ReadElementContentAsString() ?? string.Empty;
+                    item.Status = reader.ReadString();
                     break;
                     break;
 
 
                 case "Runtime":
                 case "Runtime":
                     {
                     {
-                        string text = reader.ReadElementContentAsString() ?? string.Empty;
+                        string text = reader.ReadString();
+
                         if (!string.IsNullOrWhiteSpace(text))
                         if (!string.IsNullOrWhiteSpace(text))
                         {
                         {