Example #1
0
        public override void Init(Kernel kernel)
        {
            PluginOptions = new PluginConfiguration <PluginOptions>(kernel, this.GetType().Assembly);
            PluginOptions.Load();

            var trailers = (kernel.ItemRepository.RetrieveItem(TrailersGuid) as MBTrailerFolder) ?? new MBTrailerFolder();

            trailers.Path = "";
            trailers.Id   = TrailersGuid;
            //validate sort value and fill in
            //int sort = 0;
            //int.TryParse(PluginOptions.Instance.SortOrder, out sort);
            //if (sort > 0) trailers.SortName = sort.ToString("000");
            //Logger.ReportInfo("MBTrailers Sort is: " + trailers.SortName);

            kernel.RootFolder.AddVirtualChild(trailers);

            if (Kernel.LoadContext == MBLoadContext.Service || Kernel.LoadContext == MBLoadContext.Core)  //create proxy in core and service (will only listen in service)
            {
                string cachePath = PluginOptions.Instance.CacheDir;
                if (string.IsNullOrEmpty(cachePath) || !System.IO.Directory.Exists(cachePath))
                {
                    cachePath = System.IO.Path.Combine(ApplicationPaths.AppConfigPath, "TrailerCache");
                    if (!Directory.Exists(cachePath))
                    {
                        Directory.CreateDirectory(cachePath);
                    }
                }

                long maxBandwidth = 1000 * 1024;
                long.TryParse(PluginOptions.Instance.MaxBandWidth, out maxBandwidth);
                if (maxBandwidth < 0)
                {
                    maxBandwidth = 1000 * 1024;
                }
                else
                {
                    maxBandwidth = maxBandwidth * 1024L;
                }

                proxy = new HttpProxy(cachePath, ProxyPort);
                if (Kernel.LoadContext == MBLoadContext.Service)
                { //only actually start the proxy in the service
                    Logger.ReportInfo("MBTrailers starting proxy server on port: " + ProxyPort);
                    proxy.Start(PluginOptions.Instance.AutoDownload, maxBandwidth);
                    //and clean up the cache if requested
                    if (PluginOptions.Instance.AutoClearCache)
                    {
                        MediaBrowser.Library.Threading.Async.Queue("MBTrailers cache clear", () =>
                        {
                            while (true)
                            {
                                trailers.CleanCache();
                                System.Threading.Thread.Sleep(24 * 60 * 60000);  //once per day
                            }
                        });
                    }
                }
                else
                {
                    if (proxy.AlreadyRunning())
                    {
                        Logger.ReportInfo("MBTrailers not starting proxy.  Running in service.");
                    }
                    else
                    {
                        Logger.ReportInfo("MBTrailers - no proxy running.  Start Media Browser Service.");
                    }
                }
                //load mytrailers option if specified
                if (PluginOptions.Instance.ShowMyTrailers)
                {
                    localTrailers    = kernel.ItemRepository.RetrieveItem(MyTrailersGuid) as LocalTrailerFolder ?? new LocalTrailerFolder();
                    localTrailers.Id = MyTrailersGuid;
                    kernel.RootFolder.AddVirtualChild(localTrailers);
                    kernel.ItemRepository.SaveItem(localTrailers);

                    //make sure our image cache is there
                    if (!Directory.Exists(Util.ImageCache))
                    {
                        try
                        {
                            Directory.CreateDirectory(Util.ImageCache);
                        }
                        catch (Exception e)
                        {
                            Logger.ReportException("Error Creating MyTrailers Image Cache: " + Util.ImageCache, e);
                        }
                    }

                    //Tell the log we loaded.
                    Logger.ReportInfo("My Trailers Support Loaded.");
                }

                //refresh the paths of trailers, but wait a bit in case the service side isn't up yet (we load before the service)
                MediaBrowser.Library.Threading.Async.Queue("MB Trailers refresh", () => trailers.RefreshProxy(), 3000);

                //tell core our types are playable (for menus)
                kernel.AddExternalPlayableItem(typeof(ITunesTrailer));
                kernel.AddExternalPlayableFolder(typeof(MBTrailerFolder));
            }
            Logger.ReportInfo("MBTrailers (version " + Version + ") Plug-in loaded.");
        }
Example #2
0
        public override void Init(Kernel kernel)
        {
            _kernel = kernel;
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            Logger.ReportInfo(string.Format("Tyring to load {0} v{1} loaded by {2}.", Name, LatestVersion.ToString(), AppDomain.CurrentDomain.FriendlyName));
            bool isConfigurator = !AppDomain.CurrentDomain.FriendlyName.Contains("ehExtHost");

            if (Settings.ValidateSettings(kernel.ConfigData.InitialFolder, true))
            {
                if (Settings.Instance.LoadiTunesLibrary)
                {
                    if (Settings.ValidateiTunesLibrary(true))
                    {
                        try
                        {
                            BaseItem itunes;
                            string message = "Refresh iTunes Library is set to true, this will force a rebuild of the iTunes Library, continue?";
                            string heading = "Rebuild iTunes Library Cache";

                            if (Settings.Instance.ForceRefreshiTunesLibrary && (isConfigurator || Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(message, heading, DialogButtons.Yes | DialogButtons.No, 60, true) == DialogResult.Yes))
                            {

                                itunes = iTunesLibrary.GetDetailsFromXml(kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) as iTunesMusicLibrary);
                                Settings.Instance.ForceRefreshiTunesLibrary = false;
                                Settings.SaveSettingsFile();

                            }
                            else
                            {
                                itunes = kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) ?? new iTunesLibrary().Library;
                            }
                            if (((iTunesMusicLibrary) itunes).LastUpdate != DateTime.MinValue && (itunes as iTunesMusicLibrary).LastUpdate < new System.IO.FileInfo(Settings.Instance.iTunesLibraryXMLPath).LastWriteTime)
                            {
                                message = "Your iTunes Library might have changed, do you want to rebuild it?";
                                if (isConfigurator || Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(message, heading, DialogButtons.Yes | DialogButtons.No, 60, true) == DialogResult.Yes)
                                    itunes = iTunesLibrary.GetDetailsFromXml(kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) as iTunesMusicLibrary);

                            }

                            itunes.Path = "";
                            itunes.Id = MusiciTunesGuid;
                            Logger.ReportInfo("Music iTunes id - " + itunes.Id);
                            itunes.Name = Settings.Instance.iTunesLibraryVirtualFolderName;
                            Logger.ReportInfo("Music iTunes vf name - " + itunes.Name);
                            if (!string.IsNullOrEmpty(Settings.Instance.iTunesLibraryIcon))
                                itunes.PrimaryImagePath = Settings.Instance.iTunesLibraryIcon;

                            kernel.RootFolder.AddVirtualChild(itunes);
                            kernel.ItemRepository.SaveItem(itunes);
                            //add types to supported types
                            kernel.AddExternalPlayableItem(typeof(iTunesSong));
                            kernel.AddExternalPlayableFolder(typeof(iTunesAlbum));

                        }
                        catch (Exception ex)
                        {
                            Logger.ReportException("Cannot load iTunes Music Library", ex);
                        }
                    }
                }

                if (Settings.Instance.LoadNormalLibrary)
                {
                    if (Settings.ValidateNormalLibrary(true))
                    {
                        BaseItem music;

                        music = kernel.ItemRepository.RetrieveItem(MusicNormalGuid) ?? new MusicPluginFolder();
                        music.Id = MusicNormalGuid;
                        Logger.ReportInfo("Music normal id - " + music.Id);
                        music.Path = Settings.Instance.NormalLibraryPath;
                        Logger.ReportInfo("Music normal path - " + music.Path);
                        music.Name = Settings.Instance.NormalLibraryVirtualFolderName;
                        Logger.ReportInfo("Music normal name - " + music.Name);
                        if (!string.IsNullOrEmpty(Settings.Instance.NormalLibraryIcon))
                            music.PrimaryImagePath = Settings.Instance.NormalLibraryIcon;
                        kernel.RootFolder.AddVirtualChild(music);
                        kernel.ItemRepository.SaveItem(music);
                        //add types to supported types
                        kernel.AddExternalPlayableItem(typeof(Song));
                        kernel.AddExternalPlayableFolder(typeof(ArtistAlbum));
                    }
                }
            }

            //add our music specific menu items
            if (!isConfigurator)
            {
                kernel.AddMenuItem(new MenuItem("Queue All", "resx://MediaBrowser/MediaBrowser.Resources/Lines", this.queue, new List<Type>() { typeof(ArtistAlbum) }, new List<MenuType>() { MenuType.Item, MenuType.Play }));
                kernel.AddMenuItem(new MenuItem("Queue", "resx://MediaBrowser/MediaBrowser.Resources/Lines", this.queue, new List<Type>() { typeof(Song) }, new List<MenuType>() { MenuType.Item, MenuType.Play }));
            }

            kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new SongResolver());
            kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new ArtistAlbumResolver());
            //kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new AlbumResolver());
            //kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new ArtistResolver());
            PlayableItemFactory.Instance.RegisterType<PlayableMusicFile>();
            PlayableItemFactory.Instance.RegisterType<PlayableMultiFileMusic>();
            //kernel.MetadataProviderFactories.Add(new MetadataProviderFactory(typeof(ArtistAlbumProvider)));
            kernel.PlaybackControllers.Insert(0, new PlaybackControllerMusic());
            MediaBrowser.Library.ItemFactory.Instance.AddFactory(MusicFolderModel.IsOne, typeof(MusicFolderModel));

            if (!Settings.Instance.LoadNormalLibrary && !Settings.Instance.LoadiTunesLibrary)
                Logger.ReportInfo("Music plugin, iTunes nor Normal Music enabled, probably using folder specification (vf files) via configurator, PLEASE DO NOT USE VFs USE PLUGIN CONFIGURATOR.");
        }
Example #3
0
        public override void Init(Kernel kernel)
        {
            PluginOptions = new PluginConfiguration<PluginOptions>(kernel, this.GetType().Assembly);
            PluginOptions.Load();

            var trailers = (kernel.ItemRepository.RetrieveItem(TrailersGuid) as MBTrailerFolder) ?? new MBTrailerFolder();
            trailers.Path = "";
            trailers.Id = TrailersGuid;
            //validate sort value and fill in
            //int sort = 0;
            //int.TryParse(PluginOptions.Instance.SortOrder, out sort);
            //if (sort > 0) trailers.SortName = sort.ToString("000");
            //Logger.ReportInfo("MBTrailers Sort is: " + trailers.SortName);

            kernel.RootFolder.AddVirtualChild(trailers);

            if (Kernel.LoadContext == MBLoadContext.Service || Kernel.LoadContext == MBLoadContext.Core)  //create proxy in core and service (will only listen in service)
            {
                string cachePath = PluginOptions.Instance.CacheDir;
                if (string.IsNullOrEmpty(cachePath) || !System.IO.Directory.Exists(cachePath))
                {
                    cachePath = System.IO.Path.Combine(ApplicationPaths.AppConfigPath, "TrailerCache");
                    if (!Directory.Exists(cachePath))
                    {
                        Directory.CreateDirectory(cachePath);
                    }
                }

                long maxBandwidth = 1000 * 1024;
                long.TryParse(PluginOptions.Instance.MaxBandWidth, out maxBandwidth);
                if (maxBandwidth < 0)
                    maxBandwidth = 1000 * 1024;
                else
                    maxBandwidth = maxBandwidth * 1024L;

                proxy = new HttpProxy(cachePath, ProxyPort);
                if (Kernel.LoadContext == MBLoadContext.Service)
                { //only actually start the proxy in the service
                    Logger.ReportInfo("MBTrailers starting proxy server on port: " + ProxyPort);
                    proxy.Start(PluginOptions.Instance.AutoDownload, maxBandwidth);
                    //and clean up the cache if requested
                    if (PluginOptions.Instance.AutoClearCache)
                    {
                        MediaBrowser.Library.Threading.Async.Queue("MBTrailers cache clear", () =>
                        {
                             while (true)
                             {
                                 trailers.CleanCache();
                                 System.Threading.Thread.Sleep(24 * 60 * 60000); //once per day
                             }

                        });
                    }
                }
                else
                {
                    if (proxy.AlreadyRunning())
                        Logger.ReportInfo("MBTrailers not starting proxy.  Running in service.");
                    else
                        Logger.ReportInfo("MBTrailers - no proxy running.  Start Media Browser Service.");
                }
                //load mytrailers option if specified
                if (PluginOptions.Instance.ShowMyTrailers)
                {
                    localTrailers = kernel.ItemRepository.RetrieveItem(MyTrailersGuid) as LocalTrailerFolder ?? new LocalTrailerFolder();
                    localTrailers.Id = MyTrailersGuid;
                    kernel.RootFolder.AddVirtualChild(localTrailers);
                    kernel.ItemRepository.SaveItem(localTrailers);

                    //make sure our image cache is there
                    if (!Directory.Exists(Util.ImageCache))
                        try
                        {
                            Directory.CreateDirectory(Util.ImageCache);
                        }
                        catch (Exception e)
                        {
                            Logger.ReportException("Error Creating MyTrailers Image Cache: " + Util.ImageCache, e);
                        }

                    //Tell the log we loaded.
                    Logger.ReportInfo("My Trailers Support Loaded.");
                }

                //refresh the paths of trailers, but wait a bit in case the service side isn't up yet (we load before the service)
                MediaBrowser.Library.Threading.Async.Queue("MB Trailers refresh",() => trailers.RefreshProxy(), 3000);

                //tell core our types are playable (for menus)
                kernel.AddExternalPlayableItem(typeof(ITunesTrailer));
                kernel.AddExternalPlayableFolder(typeof(MBTrailerFolder));
            }
            Logger.ReportInfo("MBTrailers (version "+Version+") Plug-in loaded.");
        }
Example #4
0
        public override void Init(Kernel kernel)
        {
            _kernel = kernel;
            //AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            Logger.ReportInfo(string.Format("Tyring to load {0} v{1} loaded by {2}.", Name, LatestVersion.ToString(), AppDomain.CurrentDomain.FriendlyName));
            bool isConfigurator = !AppDomain.CurrentDomain.FriendlyName.Contains("ehExtHost");

            if (Settings.ValidateSettings(kernel.ConfigData.InitialFolder, true))
            {
                if (Settings.Instance.LoadiTunesLibrary)
                {
                    if (Settings.ValidateiTunesLibrary(true))
                    {
                        try
                        {
                            BaseItem itunes;
                            string   message = "Refresh iTunes Library is set to true, this will force a rebuild of the iTunes Library, continue?";
                            string   heading = "Rebuild iTunes Library Cache";

                            if (Settings.Instance.ForceRefreshiTunesLibrary && (isConfigurator || Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(message, heading, DialogButtons.Yes | DialogButtons.No, 60, true) == DialogResult.Yes))
                            {
                                itunes = iTunesLibrary.GetDetailsFromXml(kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) as iTunesMusicLibrary);
                                Settings.Instance.ForceRefreshiTunesLibrary = false;
                                Settings.SaveSettingsFile();
                            }
                            else
                            {
                                itunes = kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) ?? new iTunesLibrary().Library;
                            }
                            if (((iTunesMusicLibrary)itunes).LastUpdate != DateTime.MinValue && (itunes as iTunesMusicLibrary).LastUpdate < new System.IO.FileInfo(Settings.Instance.iTunesLibraryXMLPath).LastWriteTime)
                            {
                                message = "Your iTunes Library might have changed, do you want to rebuild it?";
                                if (isConfigurator || Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(message, heading, DialogButtons.Yes | DialogButtons.No, 60, true) == DialogResult.Yes)
                                {
                                    itunes = iTunesLibrary.GetDetailsFromXml(kernel.ItemRepository.RetrieveItem(MusiciTunesGuid) as iTunesMusicLibrary);
                                }
                            }

                            itunes.Path = "";
                            itunes.Id   = MusiciTunesGuid;
                            Logger.ReportInfo("Music iTunes id - " + itunes.Id);
                            itunes.Name = Settings.Instance.iTunesLibraryVirtualFolderName;
                            Logger.ReportInfo("Music iTunes vf name - " + itunes.Name);
                            if (!string.IsNullOrEmpty(Settings.Instance.iTunesLibraryIcon))
                            {
                                itunes.PrimaryImagePath = Settings.Instance.iTunesLibraryIcon;
                            }

                            kernel.RootFolder.AddVirtualChild(itunes);
                            kernel.ItemRepository.SaveItem(itunes);
                            //add types to supported types
                            kernel.AddExternalPlayableItem(typeof(iTunesSong));
                            kernel.AddExternalPlayableFolder(typeof(iTunesAlbum));
                        }
                        catch (Exception ex)
                        {
                            Logger.ReportException("Cannot load iTunes Music Library", ex);
                        }
                    }
                }

                if (Settings.Instance.LoadNormalLibrary)
                {
                    if (Settings.ValidateNormalLibrary(true))
                    {
                        BaseItem music;

                        music    = kernel.ItemRepository.RetrieveItem(MusicNormalGuid) ?? new MusicPluginFolder();
                        music.Id = MusicNormalGuid;
                        Logger.ReportInfo("Music normal id - " + music.Id);
                        music.Path = Settings.Instance.NormalLibraryPath;
                        Logger.ReportInfo("Music normal path - " + music.Path);
                        music.Name = Settings.Instance.NormalLibraryVirtualFolderName;
                        Logger.ReportInfo("Music normal name - " + music.Name);
                        if (!string.IsNullOrEmpty(Settings.Instance.NormalLibraryIcon))
                        {
                            music.PrimaryImagePath = Settings.Instance.NormalLibraryIcon;
                        }
                        kernel.RootFolder.AddVirtualChild(music);
                        kernel.ItemRepository.SaveItem(music);
                        //add types to supported types
                        kernel.AddExternalPlayableItem(typeof(Song));
                        kernel.AddExternalPlayableFolder(typeof(ArtistAlbum));
                    }
                }
            }

            //add our music specific menu items
            if (!isConfigurator)
            {
                kernel.AddMenuItem(new MenuItem("Queue All", "resx://MediaBrowser/MediaBrowser.Resources/Lines", this.queue, new List <Type>()
                {
                    typeof(ArtistAlbum)
                }, new List <MenuType>()
                {
                    MenuType.Item, MenuType.Play
                }));
                kernel.AddMenuItem(new MenuItem("Queue", "resx://MediaBrowser/MediaBrowser.Resources/Lines", this.queue, new List <Type>()
                {
                    typeof(Song)
                }, new List <MenuType>()
                {
                    MenuType.Item, MenuType.Play
                }));
            }

            kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new SongResolver());
            kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new ArtistAlbumResolver());
            //kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new AlbumResolver());
            //kernel.EntityResolver.Insert(kernel.EntityResolver.Count - 2, new ArtistResolver());
            PlayableItemFactory.Instance.RegisterType <PlayableMusicFile>();
            PlayableItemFactory.Instance.RegisterType <PlayableMultiFileMusic>();
            //kernel.MetadataProviderFactories.Add(new MetadataProviderFactory(typeof(ArtistAlbumProvider)));
            kernel.PlaybackControllers.Insert(0, new PlaybackControllerMusic());
            MediaBrowser.Library.ItemFactory.Instance.AddFactory(MusicFolderModel.IsOne, typeof(MusicFolderModel));

            if (!Settings.Instance.LoadNormalLibrary && !Settings.Instance.LoadiTunesLibrary)
            {
                Logger.ReportInfo("Music plugin, iTunes nor Normal Music enabled, probably using folder specification (vf files) via configurator, PLEASE DO NOT USE VFs USE PLUGIN CONFIGURATOR.");
            }
        }