예제 #1
0
 void OnDeserialized(StreamingContext c)
 {
     active       = true;
     siteiniIndex = -1;
     enabled      = (enabled == null || enabled == true) ? true : false;
     xmltv        = new Xmltv();
 }
예제 #2
0
        public Xmltv GetChannelsGuides()
        {
            Xmltv epg = new Xmltv();

            try
            {
                // Combine all xml guides into a single one
                Log.Info("Merging channel guides");

                foreach (var channel in GetChannels(includeOffset: true))
                {
                    if (channel.xmltv.programmes.Count > 0)
                    {
                        epg.programmes.AddRange(channel.xmltv.programmes);
                        epg.postProcessedProgrammes.AddRange(channel.xmltv.postProcessedProgrammes);
                        epg.channels.Add(channel.xmltv.channels[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unable to merge EPGs");
                Log.Error(ex.ToString());
            }
            return(epg);
        }
예제 #3
0
 public void Merge(Xmltv xmltv)
 {
     if (generatorName == "" && generatorUrl == "")
     {
         generatorName = xmltv.generatorName;
         generatorUrl  = xmltv.generatorUrl;
     }
     channels.AddRange(xmltv.channels);
     programmes.AddRange(xmltv.programmes);
 }
예제 #4
0
        public bool CopyChannelXml(Xmltv _xmltv, String channel_id = null)
        {
            try
            {
                // Create a new XElement to force copy by value
                XElement _xmlChannel = null;
                if (channel_id != null)
                {
                    try
                    {
                        // If channel is not found catch the exception
                        _xmlChannel = new XElement(_xmltv.channels.Where(c => c.Attribute("id").Value == channel_id).First());
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                else
                {
                    _xmlChannel = new XElement(_xmltv.channels[0]);
                }

                _xmlChannel.Attribute("id").Value         = xmltv_id;
                _xmlChannel.Element("display-name").Value = name;

                if (Arguments.removeExtraChannelAttributes)
                {
                    foreach (var el in _xmlChannel.Elements())
                    {
                        if (el.Name == "url" || el.Name == "icon")
                        {
                            el.Remove();
                        }
                    }
                }
                xmltv.channels.Add(_xmlChannel);
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("#{0} | {1}", Application.grabbingRound + 1, ex.ToString()));
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// Concatenates all EPGs into a single one
        /// Saves it in the config directory
        /// </summary>
        /// <param name="epgFiles">List of all local EPG files to be merged</param>
        /// <param name="outputFile">File for output.</param>
        public static void MergeEpgs(List <String> epgFiles = null, String outputFile = null)
        {
            if (outputFile == null)
            {
                outputFile = rootConfig.postProcessEnabled ? rootConfig.postProcessOutputFilePath : rootConfig.outputFilePath;
            }

            if (epgFiles == null)
            {
                epgFiles = outputEpgFiles;
            }

            var xmltv = new Xmltv();

            Console.WriteLine("\nMerging EPGs, master EPG will be saved in " + outputFile);
            epgFiles.ForEach(epgFile => {
                try
                {
                    var tempXmltv = new Xmltv(epgFile);
                    report.missingIds.AddRange(tempXmltv.missingChannelIds);
                    report.presentIds.AddRange(tempXmltv.presentChannelIds);
                    xmltv.Merge(tempXmltv);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });

            xmltv.RemoveOrphans();
            if (Arguments.convertTimesToLocal)
            {
                xmltv.ConvertToLocalTime();
            }

            xmltv.Save(outputFile);
            Console.WriteLine("EPG saved to {0}", outputFile);
        }
예제 #6
0
        void ParseOutput()
        {
            //Parse xml file and assign programs to channels
            WriteLog("Parsing XML output of " + config.outputFilePath, LogLevel.DEBUG);
            var grabberXmltv = new Xmltv(config.outputFilePath);

            if (grabberXmltv == null)
            {
                WriteLog("Parsing XML ERROR!", LogLevel.ERROR);
                return;
            }

            // Get postprocessed data
            Xmltv postProcessedXmltv = null;

            if (ActiveSiteini.type == GrabType.SCRUB && config.postProcess.run)
            {
                postProcessedXmltv = new Xmltv(config.postProcess.fileName);
                if (postProcessedXmltv == null)
                {
                    WriteLog("Parsing post processed XML ERROR!", LogLevel.ERROR);
                }
            }

            var i = 0;

            // Loop through all channels in grabber's config and get their programs
            channels.ForEach(
                channel => {
                if (channel.update != UpdateType.None)
                {
                    var channel_id = "";
                    try
                    {
                        channel_id = (ActiveSiteini.type == GrabType.COPY) ? channel.GetActiveSiteIni().site_id : channel.xmltv_id;
                        if (ActiveSiteini.type == GrabType.COPY)
                        {
                            WriteLog(String.Format("Copying data for channel {0} by id {1}", channel.name, channel_id));
                        }

                        if (!channel.CopyChannelXml(grabberXmltv, channel_id))
                        {
                            WriteLog(String.Format("No XML channel {0} with id {1} not found!", channel.name, channel_id), LogLevel.ERROR);
                        }

                        channel.xmltv.programmes = grabberXmltv.GetProgramsById(
                            channel_id, channel.offset, channel.xmltv_id);
                        i += channel.xmltv.programmes.Count;

                        if (!channel.HasPrograms)
                        {
                            WriteLog(String.Format("No XML programms found for channel {0} with id '{1}' found in EPG!",
                                                   channel.name, channel_id), LogLevel.ERROR);
                        }
                        else
                        {
                            channel.update = UpdateType.None;

                            WriteLog(String.Format(" {0} - {1} programs grabbed", channel.name, channel.xmltv.programmes.Count));

                            // Copy post processed data
                            if (ActiveSiteini.type == GrabType.SCRUB && config.postProcess.run && postProcessedXmltv != null)
                            {
                                channel.xmltv.postProcessedProgrammes = postProcessedXmltv.GetProgramsById(channel_id, channel.offset, channel.xmltv_id);
                            }

                            //If channel has timeshifted channels, copy and offset the programs
                            if (channel.HasChildren)
                            {
                                foreach (var timeshifted in channel.timeshifts)
                                {
                                    WriteLog("Generating program for offset channel " + timeshifted.name);

                                    timeshifted.CopyChannelXml(channel.xmltv);
                                    //offset_channel.CopyProgramsXml(channel.xmltv);

                                    // Copy programs from the parent channel xmltv. Apply the offset and rename
                                    timeshifted.xmltv.programmes = channel.xmltv.GetProgramsById(
                                        channel.xmltv_id,
                                        timeshifted.offset,
                                        timeshifted.xmltv_id);

                                    // Copy post processed programs from the parent channel post processed programms
                                    if (ActiveSiteini.type == GrabType.SCRUB && config.postProcess.run && postProcessedXmltv != null)
                                    {
                                        timeshifted.xmltv.postProcessedProgrammes = channel.xmltv.GetProgramsById(
                                            channel.xmltv_id,
                                            timeshifted.offset,
                                            timeshifted.xmltv_id,
                                            true);
                                    }
                                    WriteLog(String.Format(" {0} - {1} programs grabbed", timeshifted.name, timeshifted.xmltv.programmes.Count));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message + ": " + ex.ToString(), LogLevel.ERROR);
                        WriteLog(String.Format("NO programs for channel '{0}' with id '{1}'", channel.name, channel_id), LogLevel.ERROR);
                    }
                }
            });

            if (i == 0)
            {
                WriteLog("No programs grabbed!!!");
            }
        }
        /// <summary>
        /// Start the main application
        /// </summary>
        /// <param name="configDir">Overwrite the configuration directory. (when testing)</param>
        public static void Run(String configDir = null)
        {
            if (configDir != null)
            {
                Arguments.configDir = configDir;
            }

            stopWatch.Start();

            try
            {
                var configFilePath = Arguments.useJsonConfig ? Arguments.jsonConfigFileName : Config.configFileName;
                configFilePath = Path.Combine(Arguments.configDir, configFilePath);
                masterConfig   = Config.DeserializeFromFile(configFilePath);

                // Export json config if we are using xml config
                if (Arguments.exportJsonConfig)
                {
                    masterConfig.Save(
                        Path.Combine(Arguments.configDir, "exported_wgmulti.config.json"), true);
                }

                if (!masterConfig.postProcess.grab)
                {
                    Log.Info("Grabbing disabled. Enable by setting the postprocess 'grab' value to 'on'");
                    return;
                }

                //masterConfig.InitSiteinis();

                // Grab channel programs
                DoGrabbing();

                // Save separate EPG files for each channel
                if (Arguments.saveStandaloneGuides)
                {
                    masterConfig.SaveStandaloneGuides();
                }

                // Create the combined xmltv EPG
                epg = masterConfig.GetChannelsGuides();

                // Save post process EPG file
                if (masterConfig.postProcess.run)
                {
                    epg.Save(masterConfig.postProcess.fileName, true);
                }

                // Save main EPG file
                epg.Save(masterConfig.outputFilePath);

                // Run Postprocess script
                if (Arguments.runPostprocessScript && Arguments.postprocessScript != "")
                {
                    RunPostProcessScript();
                }
            }
            catch (FileNotFoundException fnfe)
            {
                Log.Error(fnfe.ToString());
                return;
            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("annot find the")) //Could come from Linux based OS
                {
                    Log.Error("WebGrab+Plus.exe not found or not executable!");
                }
                else
                {
                    Log.Error(ex.Message);
                }
                return;
            }

            stopWatch.Stop();

            report.Generate(masterConfig);
            if (Arguments.generateReport)
            {
                report.Save();
            }
        }