コード例 #1
0
ファイル: grabber.cs プロジェクト: jensnielsen/deft_xmltv
 public bool work(SettingsData s)
 {
     try
     {
         doWork(committedsettings.sd);
         return true;
     }
     catch (Exception ex)
     {
         log.error("Failed grabbing, caught " + ex);
     }
     return false;
 }
コード例 #2
0
 public bool work(SettingsData s)
 {
     try
     {
         doWork(committedsettings.sd);
         return(true);
     }
     catch (Exception ex)
     {
         log.error("Failed grabbing, caught " + ex);
     }
     return(false);
 }
コード例 #3
0
        private void domerge(SettingsData s)
        {
            /* All files has to be in same encoding, begin with converting everything to utf-8 */
            if (!Directory.Exists(s.xmltvpath + "mergedir"))
            {
                Directory.CreateDirectory(s.xmltvpath + "mergedir");
            }

            if (Directory.Exists(s.xmltvpath + "xmltv_guides"))
            {
                string[] files = Directory.GetFiles(s.xmltvpath + "xmltv_guides");

                foreach (string file in files)
                {
                    log.debug("encoding " + file);

                    XDocument    xd          = XDocument.Load(file);
                    XDeclaration declaration = xd.Declaration;
                    if (declaration != null)
                    {
                        declaration.Encoding = "utf-8";
                    }
                    xd.Save(s.xmltvpath + "mergedir\\" + Path.GetFileNameWithoutExtension(file) + "-utf8.xml");
                }
            }

            if (!String.IsNullOrEmpty(s.mergefile) && File.Exists(s.mergefile))
            {
                log.debug("encoding mergefile");
                XDocument    xd          = XDocument.Load(s.mergefile);
                XDeclaration declaration = xd.Declaration;
                if (declaration != null)
                {
                    declaration.Encoding = "utf-8";
                }
                xd.Save(s.xmltvpath + "mergedir\\mergefile-utf8.xml");
            }
            /* Go! */
            string[] mergefiles = Directory.GetFiles(s.xmltvpath + "mergedir");
            string   args       = "tv_cat --output tvguide.xml";

            foreach (string file in mergefiles)
            {
                args += " " + file;
            }
            xmltv.exec(s.xmltvpath, args);

            /* Clean up evidence */
            Directory.Delete(s.xmltvpath + "mergedir", true);
        }
コード例 #4
0
ファイル: xmltv_grabber.cs プロジェクト: rvs76/deft_xmltv
        protected override bool grab(SettingsData s)
        {
            //string xmltvpath = s.xmltvpath;
            //string cmd = xmltvpath + "xmltv.exe";
            string args = "" + grabber_id + " --days " + s.grabdays + " --output xmltv_guides\\tvguide_" + grabber_id + ".xml"; /*\"" + s.outputfile + "\""*/;

            //log.notice("running \"" + cmd + "\", args \"" + args + "\"");
            //return true;

            if (!Directory.Exists(s.xmltvpath + "xmltv_guides"))
            {
                Directory.CreateDirectory(s.xmltvpath + "xmltv_guides");
            }

            return(xmltv.exec(s.xmltvpath, args));

            /*System.Diagnostics.ProcessStartInfo procinf = new System.Diagnostics.ProcessStartInfo(cmd, args);//xmltvcmd);
             * procinf.RedirectStandardOutput = true;
             * procinf.UseShellExecute = false;
             * procinf.CreateNoWindow = true;
             * procinf.WorkingDirectory = s.xmltvpath;
             *
             * System.Diagnostics.Process proc = new System.Diagnostics.Process();
             * proc.StartInfo = procinf;
             * try
             * {
             *  proc.Start();
             * }
             * catch
             * {
             *  log.error("Failed to start process");
             *  return false;
             * }
             * log.debug("Started");
             *
             * string result = "";
             * result = proc.StandardOutput.ReadToEnd();
             * if (!string.IsNullOrEmpty(result))
             *  log.notice("xmltv says: " + result);
             *
             * return proc.WaitForExit(300000);*/
        }
コード例 #5
0
        private void doWork(SettingsData s)
        {
            log.notice("Grabbing...");
            if (grab(s))
            {
                domerge(s);

                /* Create destination directory if it doesn't exist */
                string path = Path.GetDirectoryName(s.outputfile);
                if (!String.IsNullOrEmpty(path) && !Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (!s.outputfile.Equals(s.xmltvpath + "tvguide.xml", StringComparison.CurrentCultureIgnoreCase))
                {
                    /* Copy completed file to destination */
                    log.notice("Copying finished file (" + s.xmltvpath + "tvguide.xml" + ") to destination " + s.outputfile);
                    File.Copy(s.xmltvpath + "tvguide.xml", s.outputfile, true);
                }

                if (s.copyftr && !s.ftrguidepath.Equals(s.xmltvpath + "tvguide.xml", StringComparison.CurrentCultureIgnoreCase))
                {
                    /* Copy completed file to FTR */
                    log.notice("Copying finished file (" + s.xmltvpath + "tvguide.xml" + ") to For The Record (" + s.ftrguidepath + ")");
                    File.Copy(s.xmltvpath + "tvguide.xml", s.ftrguidepath, true);
                }

                committedsettings.lastgrab = DateTime.Now.ToLocalTime();

                if (s.geticons4tr || s.geticonsmp)
                {
                    fetchicons(s);
                }
            }

            log.debug("Work done");
        }
コード例 #6
0
ファイル: grabber.cs プロジェクト: jensnielsen/deft_xmltv
        private void doWork( SettingsData s )
        {
            log.notice("Grabbing...");
            if (grab(s))
            {
                domerge(s);

                /* Create destination directory if it doesn't exist */
                string path = Path.GetDirectoryName(s.outputfile);
                if (!String.IsNullOrEmpty(path) && !Directory.Exists(path))
                    Directory.CreateDirectory(path);

                if (!s.outputfile.Equals(s.xmltvpath + "tvguide.xml", StringComparison.CurrentCultureIgnoreCase))
                {
                    /* Copy completed file to destination */
                    log.notice("Copying finished file (" + s.xmltvpath + "tvguide.xml" + ") to destination " + s.outputfile);
                    File.Copy(s.xmltvpath + "tvguide.xml", s.outputfile, true);
                }

                if(s.copyftr && !s.ftrguidepath.Equals(s.xmltvpath + "tvguide.xml", StringComparison.CurrentCultureIgnoreCase))
                {
                    /* Copy completed file to FTR */
                    log.notice("Copying finished file (" + s.xmltvpath + "tvguide.xml" + ") to For The Record (" + s.ftrguidepath + ")");
                    File.Copy(s.xmltvpath + "tvguide.xml", s.ftrguidepath, true);
                }

                committedsettings.lastgrab = DateTime.Now.ToLocalTime();

                if (s.geticons4tr || s.geticonsmp)
                {
                    fetchicons(s);
                }
            }

            log.debug("Work done");
        }
コード例 #7
0
ファイル: settings.cs プロジェクト: rvs76/deft_xmltv
 protected virtual void OnSettingsChanged(SettingsData s)
 {
     SettingsChanged(/*s*/);
 }
コード例 #8
0
ファイル: deft_xmltv_gui.cs プロジェクト: rvs76/deft_xmltv
        private void save_Click(object sender, EventArgs e)
        {
            SettingsData sd = ConstructSettingsFromForm();

            SettingsCommit(sd);
        }
コード例 #9
0
ファイル: deft_xmltv_gui.cs プロジェクト: rvs76/deft_xmltv
 private void SettingsCommit(SettingsData sd)
 {
     s.SettingsCommit(sd);
 }
コード例 #10
0
 private void SettingsCommit(SettingsData sd)
 {
     s.SettingsCommit(sd);
 }
コード例 #11
0
ファイル: grabber.cs プロジェクト: jensnielsen/deft_xmltv
 protected abstract bool grab(SettingsData s);
コード例 #12
0
ファイル: settings.cs プロジェクト: jensnielsen/deft_xmltv
        public void SettingsCommit(SettingsData sd)
        {
            if (_committed == false || !sd.Equals(_sd))
            {
                log.notice("Settings changed");
                _committed = true;
                _sd = sd;
                OnSettingsChanged(_sd);
                writecfg();

                RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (sd.winstart)
                {
                    /*delete old path in case exe moved*/
                    rkApp.DeleteValue("deft_xmltv", false);
                    /*enable with current path*/
                    rkApp.SetValue("deft_xmltv", "\"" + Application.ExecutablePath.ToString() + "\" -m");
                }
                else if (!sd.winstart && rkApp.GetValue("deft_xmltv") != null)
                {
                    /*disable*/
                    rkApp.DeleteValue("deft_xmltv", false);
                }
            }
        }
コード例 #13
0
ファイル: settings.cs プロジェクト: jensnielsen/deft_xmltv
        public void init(SettingsData defaultsettings)
        {
            /* default non-gui settings */
            RegistryKey rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\For The Record\\Install", false);
            string ftrpath = ((rkApp != null) ? (string)rkApp.GetValue("", "") : "");

            defaultsettings.ftriconspath = (ftrpath != "" ? ftrpath + "Services\\Channel Logos\\" : ""); //"C:\\xmltv\\icons\\4tr\\"
            defaultsettings.ftrguidepath = (ftrpath != "" ? ftrpath + "Services\\XMLTV\\guide.xml" : "");
            defaultsettings.mpiconspath = Environment.GetEnvironmentVariable("ALLUSERSPROFILE") + "\\Team MediaPortal\\Thumbs\\TV\\Logos\\"; /*"C:\\xmltv\\icons\\mp\\";*/
            defaultsettings.xmltvpath = "C:\\xmltv\\";

            if (!File.Exists(Application.StartupPath + "\\deft-xmltv.cfg"))
            {
                FileInputDialog d = new FileInputDialog("Path to xmltv", "C:\\xmltv");

                d.ShowDialog();
                defaultsettings.xmltvpath = d.path;
                defaultsettings.outputfile = d.path + (d.path.EndsWith("\\") ? "" : "\\") + "tvguide.xml";
            }

            _sd = defaultsettings;

            if (!readcfg())
            {
                log.warning("Error reading config file!");
            }
        }
コード例 #14
0
        private void fetchicons(SettingsData s)
        {
            log.notice("Fetching icons");
            //return;

            XmlTextReader reader = new XmlTextReader(/*s.outputfile*/ s.xmltvpath + "tvguide.xml");

            try
            {
                string url                = "";
                string channelname        = "";
                string ext                = "";
                List <downloadable> dlist = new List <downloadable>();
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.Name == "channel")
                        {
                            url         = "";
                            channelname = "";
                            ext         = "";
                            log.debug("startchannel");
                        }
                        else if (reader.Name == "icon")
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name == "src")
                                {
                                    url = reader.Value;
                                    ext = Path.GetExtension(reader.Value);
                                    log.debug("src: " + url);
                                }
                            }
                        }
                        else if (reader.Name == "display-name")
                        {
                            while (reader.Read() && reader.NodeType != XmlNodeType.Text)
                            {
                                ;
                            }
                            channelname = reader.Value;
                            log.debug("displayname: " + channelname);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name == "channel")
                        {
                            if (url != "" && channelname != "")
                            {
                                string filename;
                                string invalidchars = new string(Path.GetInvalidFileNameChars());
                                if (s.geticons4tr)
                                {
                                    filename = Regex.Replace(channelname, @"[" + invalidchars + "]", "");     //4tr wants to skip invalid chars
                                    filename = s.ftriconspath + filename + ext;
                                    log.debug("storing: " + url + " -> " + filename);
                                    dlist.Add(new downloadable(url, filename));
                                }
                                if (s.geticonsmp)
                                {
                                    filename = Regex.Replace(channelname, @"[" + invalidchars + "]", "_");     //mp wants to replace invalid chars with underscore
                                    filename = s.mpiconspath + filename + ext;
                                    log.debug("storing: " + url + " -> " + filename);
                                    dlist.Add(new downloadable(url, filename));
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }

                WebClient Client = new WebClient();
                foreach (downloadable d in dlist)
                {
                    log.notice("downloading: " + d.url + " -> " + d.file);
                    try
                    {
                        string path = Path.GetDirectoryName(d.file);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        Client.DownloadFile(d.url, d.file);
                    }
                    catch
                    {
                        log.error("fail :(");
                    }
                }
            }
            catch
            {
                log.error("Failed parse of tvguide.xml");
            }
        }
コード例 #15
0
 protected abstract bool grab(SettingsData s);
コード例 #16
0
ファイル: grabber.cs プロジェクト: jensnielsen/deft_xmltv
        private void fetchicons(SettingsData s)
        {
            log.notice("Fetching icons");
            //return;

            XmlTextReader reader = new XmlTextReader (/*s.outputfile*/s.xmltvpath + "tvguide.xml");
            try
            {
                string url = "";
                string channelname = "";
                string ext = "";
                List<downloadable> dlist = new List<downloadable>();
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if(reader.Name == "channel")
                            {
                                url = "";
                                channelname = "";
                                ext = "";
                                log.debug("startchannel");
                            }
                            else if (reader.Name == "icon")
                            {
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "src")
                                    {
                                        url = reader.Value;
                                        ext = Path.GetExtension(reader.Value);
                                        log.debug("src: " + url);
                                    }
                                }
                            }
                            else if(reader.Name == "display-name")
                            {
                                while (reader.Read() && reader.NodeType != XmlNodeType.Text) ;
                                channelname = reader.Value;
                                log.debug("displayname: " + channelname);
                            }
                            break;
                        case XmlNodeType.EndElement:
                            if (reader.Name == "channel")
                            {
                                if (url != "" && channelname != "")
                                {
                                    string filename;
                                    string invalidchars = new string(Path.GetInvalidFileNameChars());
                                    if (s.geticons4tr)
                                    {
                                        filename = Regex.Replace(channelname, @"[" + invalidchars + "]", ""); //4tr wants to skip invalid chars
                                        filename = s.ftriconspath + filename + ext;
                                        log.debug("storing: " + url + " -> " + filename);
                                        dlist.Add(new downloadable(url, filename));
                                    }
                                    if (s.geticonsmp)
                                    {
                                        filename = Regex.Replace(channelname, @"[" + invalidchars + "]", "_"); //mp wants to replace invalid chars with underscore
                                        filename = s.mpiconspath + filename + ext;
                                        log.debug("storing: " + url + " -> " + filename);
                                        dlist.Add(new downloadable(url, filename));
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }

                WebClient Client = new WebClient();
                foreach (downloadable d in dlist)
                {
                    log.notice("downloading: " + d.url + " -> " + d.file);
                    try
                    {
                        string path = Path.GetDirectoryName(d.file);
                        if(!Directory.Exists(path))
                            Directory.CreateDirectory(path);
                        Client.DownloadFile(d.url, d.file);
                    }
                    catch
                    {
                        log.error("fail :(");
                    }
                }
            }
            catch
            {
                log.error("Failed parse of tvguide.xml");
            }
        }
コード例 #17
0
ファイル: settings.cs プロジェクト: jensnielsen/deft_xmltv
 protected virtual void OnSettingsChanged(SettingsData s)
 {
     SettingsChanged(/*s*/);
 }
コード例 #18
0
        private void SetFormFromSettings(SettingsData s)
        {
            winstart.Checked = s.winstart;

            grabdays.Value = s.grabdays;
            outputfile.Text = /*String.IsNullOrEmpty(s.outputfile) ? "tvguide.xml" :*/ s.outputfile;

            copyftr.Checked = s.copyftr;

            autograb.Checked = s.autograb;
            autograbtime.Value = s.autograbtime;//new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, s.autograbtime.Hours, s.autograbtime.Minutes, 0);
            if (s.autograbinterval == 1)
                autograbinterval.SelectedIndex = 0;

            icons4TR.Checked = s.geticons4tr;
            iconsMP.Checked = s.geticonsmp;

            if (s.ftriconspath == "")
            {
                icons4TR.Enabled = false;
            }

            merge.Checked = s.mergegrab;
            mergefile.Text = s.mergefile;
        }
コード例 #19
0
ファイル: grabber.cs プロジェクト: jensnielsen/deft_xmltv
        private void domerge(SettingsData s)
        {
            /* All files has to be in same encoding, begin with converting everything to utf-8 */
            if (!Directory.Exists(s.xmltvpath + "mergedir"))
                Directory.CreateDirectory(s.xmltvpath + "mergedir");

            if (Directory.Exists(s.xmltvpath + "xmltv_guides") )
            {
                string[] files = Directory.GetFiles(s.xmltvpath + "xmltv_guides");

                foreach (string file in files)
                {
                    log.debug("encoding " + file);

                    XDocument xd = XDocument.Load(file);
                    XDeclaration declaration = xd.Declaration;
                    if (declaration != null)
                    {
                        declaration.Encoding = "utf-8";
                    }
                    xd.Save(s.xmltvpath + "mergedir\\" + Path.GetFileNameWithoutExtension(file) + "-utf8.xml");
                }
            }

            if (!String.IsNullOrEmpty(s.mergefile) && File.Exists(s.mergefile))
            {
                log.debug("encoding mergefile");
                XDocument xd = XDocument.Load(s.mergefile);
                XDeclaration declaration = xd.Declaration;
                if (declaration != null)
                {
                    declaration.Encoding = "utf-8";
                }
                xd.Save(s.xmltvpath + "mergedir\\mergefile-utf8.xml");
            }
            /* Go! */
            string[] mergefiles = Directory.GetFiles(s.xmltvpath + "mergedir");
            string args = "tv_cat --output tvguide.xml";
            foreach (string file in mergefiles)
            {
                args += " " + file;
            }
            xmltv.exec(s.xmltvpath, args);

            /* Clean up evidence */
            Directory.Delete(s.xmltvpath + "mergedir", true);
        }
コード例 #20
0
        protected override bool grab(SettingsData s)
        {
            //string xmltvpath = s.xmltvpath;
            //string cmd = xmltvpath + "xmltv.exe";
            string args = "" + grabber_id + " --days " + s.grabdays + " --output xmltv_guides\\tvguide_" + grabber_id + ".xml";/*\"" + s.outputfile + "\""*/ ;
            //log.notice("running \"" + cmd + "\", args \"" + args + "\"");
            //return true;

            if (!Directory.Exists(s.xmltvpath + "xmltv_guides"))
                Directory.CreateDirectory(s.xmltvpath + "xmltv_guides");

            return xmltv.exec(s.xmltvpath, args);
            /*System.Diagnostics.ProcessStartInfo procinf = new System.Diagnostics.ProcessStartInfo(cmd, args);//xmltvcmd);
            procinf.RedirectStandardOutput = true;
            procinf.UseShellExecute = false;
            procinf.CreateNoWindow = true;
            procinf.WorkingDirectory = s.xmltvpath;

            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procinf;
            try
            {
                proc.Start();
            }
            catch
            {
                log.error("Failed to start process");
                return false;
            }
            log.debug("Started");

            string result = "";
            result = proc.StandardOutput.ReadToEnd();
            if (!string.IsNullOrEmpty(result))
                log.notice("xmltv says: " + result);

            return proc.WaitForExit(300000);*/
        }