コード例 #1
0
        protected IPEndPoint ReadConfiguredTVServerAddress()
        {
            // Try to read the TV server IP address from MediaPortal's configuration
            if (!Mediaportal.HasValidConfigFile())
            {
                return(null);
            }

            // read the hostname
            Dictionary <string, string> tvSection = Mediaportal.ReadSectionFromConfigFile("tvservice");

            if (tvSection == null || !tvSection.ContainsKey("hostname") || string.IsNullOrWhiteSpace(tvSection["hostname"]))
            {
                return(null);
            }
            string hostname = tvSection["hostname"];

            try
            {
                // Return as IP addresses
                var address = Dns.GetHostAddresses(hostname).First();
                return(new IPEndPoint(address, Configuration.DEFAULT_PORT));
            }
            catch (SocketException)
            {
                Log.Info("Failed to resolve hostname {0} configured as default TV Server", hostname);
                return(null);
            }
        }
コード例 #2
0
        public MPPictureShares(IPluginData data) : base(data)
        {
            if (!Mediaportal.HasValidConfigFile())
            {
                Supported = false;
                return;
            }

            IEnumerable <KeyValuePair <string, string> > list = Mediaportal.ReadSectionFromConfigFile("pictures");

            Extensions = list.Where(x => x.Key == "extensions").Select(x => x.Value).First().Split(',');

            shares = new List <Share>();
            int count = list.Where(x => x.Key.StartsWith("sharename")).Count();

            for (int i = 0; i < count; i++)
            {
                if (list.Where(x => x.Key == "sharetype" + i).Select(x => x.Value).First() == "yes")
                {
                    continue;
                }

                shares.Add(new Share()
                {
                    Name  = list.Where(x => x.Key == "sharename" + i).Select(x => x.Value).First(),
                    Path  = Path.GetFullPath(list.Where(x => x.Key == "sharepath" + i).Select(x => x.Value).First()),
                    Index = i
                });
            }

            shareCache = new Dictionary <string, Share>();
            Supported  = true;
        }
コード例 #3
0
        public ShareLibrary(IPluginData data, string[] sections)
        {
            this.data          = data;
            this.configuration = data.GetConfiguration("MP Shares");

            if (!Mediaportal.HasValidConfigFile())
            {
                Supported = false;
                return;
            }

            var localsharelist = new List <Share>();

            foreach (string section in sections)
            {
                IEnumerable <KeyValuePair <string, string> > list = Mediaportal.ReadSectionFromConfigFile(section);
                string[] extensions = list.Where(x => x.Key == "extensions").Select(x => x.Value).First().Split(',');
                int      count      = list.Where(x => x.Key.StartsWith("sharename")).Count();

                for (int i = 0; i < count; i++)
                {
                    if (list.Where(x => x.Key == "sharetype" + i).Select(x => x.Value).First() == "yes")
                    {
                        continue;
                    }

                    string path = list.Where(x => x.Key == "sharepath" + i).Select(x => x.Value).First();
                    localsharelist.Add(new Share()
                    {
                        Name       = list.Where(x => x.Key == "sharename" + i).Select(x => x.Value).First(),
                        Path       = path,
                        Extensions = extensions.ToList(),
                    });
                }
            }

            // make shares unique
            shares = localsharelist.GroupBy(x => x.Path, (path, gshares) => new Share()
            {
                Name       = gshares.First().Name,
                Path       = path,
                Extensions = gshares.SelectMany(x => x.Extensions).ToList()
            }).ToList();
            int shareNr = 0;

            foreach (Share share in shares)
            {
                share.Id = "s" + (shareNr++);
            }

            Supported = true;
        }
コード例 #4
0
        public ShareLibrary(IPluginData data, string[] sections)
        {
            this.data          = data;
            this.configuration = data.GetConfiguration("MP Shares");
            this.sections      = sections;

            Supported = Mediaportal.HasValidConfigFile();
            if (Supported)
            {
                ReadConfiguration();
                ConfigurationChangeListener.ConfigurationChanged += ReadConfiguration;
                ConfigurationChangeListener.Enable();
            }
        }
コード例 #5
0
        public MyFilms(IPluginData data)
        {
            try
            {
                // load database path
                if (!Mediaportal.HasValidConfigFile())
                {
                    Supported = false;
                    return;
                }

                string configPath = Path.Combine(Mediaportal.GetLocation(MediaportalDirectory.Config), "MyFilms.xml");
                if (!File.Exists(configPath))
                {
                    Supported = false;
                    return;
                }

                // load config file
                XElement configFile        = XElement.Load(configPath);
                string   currentConfigNode = configFile
                                             .Elements("section")
                                             .First(x => x.Attribute("name").Value == "MyFilms")
                                             .Elements("entry")
                                             .First(x => x.Attribute("name").Value == "Current_Config")
                                             .Value;
                if (currentConfigNode != "pelis")
                {
                    Log.Info("MyFilms: currently selected config is {0}, only pelis (Ant Movie Catalog) is supported at the moment", currentConfigNode);
                    Supported = false;
                    return;
                }

                var pelis = configFile
                            .Elements("section")
                            .First(x => x.Attribute("name").Value == "pelis");

                DatabasePath = pelis
                               .Elements("entry")
                               .First(x => x.Attribute("name").Value == "AntCatalog")
                               .Value;
                if (!File.Exists(DatabasePath))
                {
                    Log.Info("MyFilms: cannot find database {0}", DatabasePath);
                    Supported = false;
                    return;
                }

                PicturePath = pelis
                              .Elements("entry")
                              .First(x => x.Attribute("name").Value == "AntPicture")
                              .Value;
                Supported = true;
            }
            catch (Exception ex)
            {
                Log.Warn("MyFilms: failed to load database path", ex);
                Supported = false;
                return;
            }

            // initialize some regular expressions
            stripActorName = new Regex(@"^([^(]*)(\(.*\))*", RegexOptions.Compiled);
            imdbId         = new Regex(@"^.*imdb.[a-z]+/title/(tt[0-9]+)/*$", RegexOptions.Compiled);
        }
コード例 #6
0
ファイル: MyFilms.cs プロジェクト: regeszter/MPExtended
        public MyFilms(IPluginData data)
        {
            Supported = false;

            try
            {
                // load MyFilms.xml path
                if (!Mediaportal.HasValidConfigFile())
                {
                    return;
                }

                string configPath = Path.Combine(Mediaportal.GetLocation(MediaportalDirectory.Config), "MyFilms.xml");
                if (!File.Exists(configPath))
                {
                    return;
                }

                // load current config section
                XElement configFile;
                using (var handle = File.Open(configPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    configFile = XElement.Load(handle);
                var entries = configFile.Elements("section").First(x => x.Attribute("name").Value == "MyFilms").Elements("entry");
                if (!entries.Any(x => x.Attribute("name").Value == "Default_Config") && !entries.Any(x => x.Attribute("name").Value == "Current_Config"))
                {
                    Log.Info("MyFilms: couldn't find Current_Config or Default_Config value in MyFilms.xml");
                    return;
                }
                var configSectionName = entries.Any(x => x.Attribute("name").Value == "Current_Config") ?
                                        entries.First(x => x.Attribute("name").Value == "Current_Config").Value :
                                        entries.First(x => x.Attribute("name").Value == "Default_Config").Value;

                // look for database path
                var thisSection = configFile.Elements("section").First(x => x.Attribute("name").Value == configSectionName);
                if (!thisSection.Elements("entry").Any(x => x.Attribute("name").Value == "AntCatalog"))
                {
                    Log.Info("MyFilms: couldn't find AntCatalog entry in current section ({0})", configSectionName);
                    return;
                }

                // load database
                DatabasePath = thisSection.Elements("entry").FirstOrDefault(x => x.Attribute("name").Value == "AntCatalog").Value;
                if (!File.Exists(DatabasePath))
                {
                    Log.Info("MyFilms: cannot find database {0}", DatabasePath);
                    return;
                }

                PicturePath = thisSection.Elements("entry").Any(x => x.Attribute("name").Value == "AntPicture") ?
                              thisSection.Elements("entry").FirstOrDefault(x => x.Attribute("name").Value == "AntPicture").Value : String.Empty;
                sourcePrefix = thisSection.Elements("entry").Any(x => x.Attribute("name").Value == "PathStorage") ?
                               thisSection.Elements("entry").FirstOrDefault(x => x.Attribute("name").Value == "PathStorage").Value : String.Empty;
                Supported = true;
            }
            catch (Exception ex)
            {
                Log.Warn("MyFilms: failed to load database path", ex);
                return;
            }

            // initialize some regular expressions
            stripActorName = new Regex(@"^([^(]*)(\(.*\))*", RegexOptions.Compiled);
            imdbId         = new Regex(@"^.*imdb.[a-z]+/title/(tt[0-9]+)/*$", RegexOptions.Compiled);
        }