/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 13:26:09	167
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 13:57:41	168
@@ -17,7 +17,7 @@
         List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
         List<SQLLITE.ICHANNEL> Channels { get; }
         IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
-        List<SQLLITE.IPROGRAMME> GetValidPrograms(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
+        List<SQLLITE.IPROGRAMME> CreateUpdatedProgramsList(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
 
     }
     public class SQLLITE : ISQLLITE
@@ -191,15 +191,15 @@
 
         public interface IPROGRAMME
         {
-            Int64 oid { get; }
-            String name { get; }
-            String sub_title { get; }
-            String description { get; }
-            DateTime start_time { get; }
-            DateTime end_time { get; }
-            Int64 channel_oid { get; }
-            String unique_identifier { get; }
-            String rating { get; }
+            Int64 oid { get; set; }
+            String name { get; set; }
+            String sub_title { get; set; }
+            String description { get; set; }
+            DateTime start_time { get; set; }
+            DateTime end_time { get; set; }
+            Int64 channel_oid { get; set; }
+            String unique_identifier { get; set; }
+            String rating { get; set; }
 
             IProgramDefinition AsXMLTVProgramDefinition(ISQLLITE sqllite);
         }
@@ -231,8 +231,8 @@
                 definition.ChannelName = channel.display_name;
                 definition.ChannelNumber = (int)channel.channel_number;
                 definition.Description = this.description;
-                definition.Start = this.start_time.ToString("");
-                definition.Stop = this.end_time.ToString("");
+                definition.Start = this.start_time.ToDateTimeString();
+                definition.Stop = this.end_time.ToDateTimeString();
                 definition.SubTitle = this.sub_title;
                 definition.Title = this.name;
                 return definition;
@@ -293,11 +293,10 @@
             return range;
         }
 
-        public List<SQLLITE.IPROGRAMME> GetValidPrograms(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
+        public List<SQLLITE.IPROGRAMME> CreateUpdatedProgramsList(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> gbpvr_programs_not_found)
         {
-            source_invalid = new List<IPROGRAMME>();
-            List<SQLLITE.IPROGRAMME> source = new List<IPROGRAMME>(gbpvr_programs.ToArray());
-            source = source.OrderBy(s => s.start_time).ToList();
+            gbpvr_programs_not_found = new List<IPROGRAMME>();
+            gbpvr_programs = gbpvr_programs.OrderBy(s => s.start_time).ToList();            
             List<SQLLITE.IPROGRAMME> source_valid = new List<IPROGRAMME>();
             //if (range == null)
             //{
@@ -306,32 +305,50 @@
             //}
             //gLog.Warn.WriteLine("FilterProgramsByDateRange has not been implemented");
 
-            double total = source.Count;
+            double total = gbpvr_programs.Count;
             double index = 0;
             double progress = 0;
-            foreach (var program in source)
+            foreach (var program in gbpvr_programs)
             {
-                //if (program.start_time >= range.Start &&
-                //    program.start_time <= range.End)
+                ////if (program.start_time >= range.Start &&
+                ////    program.start_time <= range.End)
+                ////{
+                ////    list2.Add(program);
+                ////}
+                ////else
+                ////{
+                ////    removed_programs.Add(program);
+                ////}   
+                //progress = 100.0 * (index / total);
+                //gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Filtering GBPVR Programs: {0:00}%", (int)progress)));
+                //var xmltv_entry = program.AsXMLTVProgramDefinition(this);
+                //if (xmltv_programs.Contains(xmltv_entry))
                 //{
-                //    list2.Add(program);
+                //    source_valid.Add(program);
                 //}
                 //else
                 //{
-                //    removed_programs.Add(program);
-                //}   
-                progress = 100.0 * (index / total);
-                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("Filtering GBPVR Programs: {0:00}%", (int)progress)));
-                var xmltv_entry = program.AsXMLTVProgramDefinition(this);
-                if (xmltv_programs.Contains(xmltv_entry))
+                //    gbpvr_programs_not_found.Add(program);
+                //}
+                //index++;
+                var channel_oid = program.channel_oid;
+                var channel = this.Channels.Find(s => s.oid == channel_oid);
+                var start_date = program.start_time;
+                var xmltv_entry = xmltv_programs.Find(s => s.ChannelNumber == channel.channel_number && s.Start == start_date.ToDateTimeString());
+                if (xmltv_entry == null)
                 {
-                    source_valid.Add(program);
+                    gbpvr_programs_not_found.Add(program);
                 }
                 else
                 {
-                    source_invalid.Add(program);
+                    var updated_program = program;
+                    updated_program.description = xmltv_entry.Description;
+                    updated_program.end_time = DateTime.Parse(xmltv_entry.Stop);
+                    updated_program.name = xmltv_entry.Title;
+                    updated_program.start_time = DateTime.Parse(xmltv_entry.Start);                    
+                    updated_program.sub_title = xmltv_entry.SubTitle;
+                    source_valid.Add(updated_program);
                 }
-                index++;
             }
 
             //for (int i = 0; i < programs.Count(); i++)
@@ -345,12 +362,12 @@
             //}
 
             source_valid = source_valid.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
-            source_invalid = source_invalid.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
+            gbpvr_programs_not_found = gbpvr_programs_not_found.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
 
             gLog.Info.WriteLine("Total XMLTV Programs: 0x{0:x8}", xmltv_programs.Count);
-            gLog.Info.WriteLine("Found: 0x{0:x8} valid GB-PVR Programs", source_valid.Count);
-            gLog.Info.WriteLine("Found: 0x{0:x8} invalid GB-PVR Programs", source_invalid.Count);
-            gLog.Info.WriteLine("Total GB-PVR Programs: 0x{0:x8}", source_valid.Count + source_invalid.Count);
+            gLog.Info.WriteLine("Updated: 0x{0:x8} GB-PVR Programs", source_valid.Count);
+            gLog.Info.WriteLine("Could not find: 0x{0:x8} GB-PVR Programs", gbpvr_programs_not_found.Count);
+            gLog.Info.WriteLine("Total GB-PVR Programs: 0x{0:x8}", source_valid.Count + gbpvr_programs_not_found.Count);
 
             return source_valid;
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22