예제 #1
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);
        }
        /// <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();
            }
        }