home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Plugins
How-to for Plugin Developers with Code Examples
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Edalex" data-source="post: 1105744" data-attributes="member: 63839"><p>Hi guys!</p><p>As you maybe know it's a pain in ... to find how to interact with MediaPortal and get needed data from plugin because of MP code's complexity and lack of comments and documentation sometimes. So what about sharing some useful method which could help new plugin devs to code?</p><p>Let me start from my noob point of view <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> :</p><p></p><p><strong>How to get Channel Groups from TV Server</strong></p><p>[CODE=Csharp]using TvDatabase;</p><p>...</p><p>public static TvBusinessLayer layer = new TvBusinessLayer();</p><p>IList<ChannelGroup> tvGroups = ChannelGroup.ListAll();</p><p>IList<RadioChannelGroup> radioGroups = RadioChannelGroup.ListAll();</p><p>IList<Channel> channels = layer.GetChannelsInGroup(selectedGroup);[/CODE]</p><p></p><p><strong>How to check if another plugin is available and enabled:</strong></p><p>[CODE=Csharp]</p><p> publicstatic bool IsAssemblyAvailable(string name,Version ver){</p><p> bool result =false;</p><p> Assembly[] assemblies =AppDomain.CurrentDomain.GetAssemblies();</p><p> foreach(Assembly a in assemblies)</p><p> try</p><p> {</p><p> if(a.GetName().Name== name && a.GetName().Version>= ver)</p><p> {</p><p> result =true;</p><p> break;</p><p> }</p><p> }</p><p> catch</p><p> {</p><p> </p><p> }</p><p> if(!result){</p><p> </p><p> try{</p><p> //Assembly assembly = AppDomain.CurrentDomain.Reflection(new AssemblyName(name));</p><p> Assembly assembly =Assembly.ReflectionOnlyLoad(name);</p><p> result =true;</p><p> }</p><p> catch(Exception e){</p><p> }</p><p> }</p><p> return result;</p><p> }</p><p> public static bool IsPluginEnabled(string name){</p><p> using (MediaPortal.Profile.Settings xmlreader =newMediaPortal.Profile.MPSettings()){</p><p> return xmlreader.GetValueAsBool("plugins", name,false);</p><p> }</p><p> }</p><p>[/CODE]</p><p>Source <a href="https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701" target="_blank">https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701</a></p><p></p><p><strong>How to interact with trakt plugin</strong></p><p>[CODE=Csharp]</p><p>using TraktPlugin.TraktAPI;</p><p>using TraktPlugin.TraktAPI.DataStructures;</p><p>...</p><p> IEnumerable<TraktSearchEpisode> myep = TraktAPI.SearchEpisodes("Scars");</p><p> IEnumerable<TraktMovie> searchmovie = TraktAPI.SearchMovies("Tron");</p><p> IEnumerable<TraktShow> searchshow = TraktAPI.SearchShows("eureka");</p><p> IEnumerable<TraktMovie> recmovies = TraktAPI.GetRecommendedMovies();</p><p> IEnumerable<TraktMovie> tronrelated = TraktAPI.GetRelatedMovies("tt0084827");</p><p> IEnumerable<TraktUserProfile> newfriend = TraktAPI.SearchForFriends("edalex");[/CODE]</p><p></p><p><strong>How to use TMDB provider from Moving Pictures:</strong></p><p>[CODE=Csharp]</p><p>using MediaPortal.Plugins.MovingPictures.DataProviders.TMDbAPI;</p><p>...</p><p>MovieSearch mymovie = TheMovieDbAPI.SearchMovies("Tron");[/CODE]</p><p></p><p>Get Series List from MP-TVSeries:</p><p>[CODE=Csharp] </p><p>using WindowPlugins.GUITVSeries;</p><p>...</p><p> List<DBOnlineSeries> myseries = DBOnlineSeries.getAllSeries();</p><p> foreach (DBOnlineSeries tvshow in myseries)</p><p> {</p><p> DBSeries mytv = Helper.getCorrespondingSeries(tvshow[DBOnlineSeries.cID]);</p><p> if (mytv != null)</p><p> {</p><p> string ishidden = mytv[DBSeries.cHidden];</p><p> if (ishidden != "1")</p><p> { </p><p> }</p><p> }</p><p> } [/CODE]</p><p><strong>How to create own custom GUI Dialog</strong></p><p>1) Choose of existing dialog to modify it. <a href="https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs" target="_blank">https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs</a></p><p>2) Create your own dialog by overriding one of them</p><p>Examples:</p><p><a href="https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUIDIalogPreview.cs" target="_blank">https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUIDIalogPreview.cs</a></p><p><a href="https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUICheckListDialog.cs" target="_blank">https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUICheckListDialog.cs</a></p><p><a href="https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cs" target="_blank">https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cs</a></p><p><a href="https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cs" target="_blank">https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cs</a></p><p><a href="https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cs" target="_blank">https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cs</a></p><p><a href="https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs" target="_blank">https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs</a></p><p>3) Create skin files for your new dialog</p><p>Take skin file of Dialog you overrided and modify it for your needs. Change Windowd ID, add new control etc.</p><p>Skin files for standart skins (better start with supporting them) located here:</p><p><a href="https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/" target="_blank">https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/</a></p><p>4) Now you can use custom dialog just as like as standart one</p><p>[CODE=C#]GUICheckListDialog dlg = (GUICheckListDialog)GUIWindowManager.GetWindow(GUICheckListDialog.ID);</p><p> if (dlg == null)</p><p> return;</p><p> dlg.Reset();</p><p> dlg.SetHeading(...);</p><p> dlg.Add(...);</p><p> dlg.Add(...);</p><p> }</p><p> dlg.DoModal(GUIWindowManager.ActiveWindow);[/CODE]</p><p><strong>How to create custom GUI Control (untested)</strong></p><p>1) Create your control's code overridingone of existing controls or GUIControl class itself</p><p>Examples:</p><p><a href="https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUISudoku/CellControl.cs" target="_blank">https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUISudoku/CellControl.cs</a></p><p><a href="https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUITetris/MyTetrisControl.cs" target="_blank">https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUITetris/MyTetrisControl.cs</a></p><p>2) Register your custom control in Init:</p><p>[CODE=Csharp]GUIControlFactory.RegisterControl("cell", typeof (CellControl));[/CODE]</p><p>3) ...</p><p></p><p>If you would like to continue my efforts, please, share your code samples!</p><p>Many thanks!</p></blockquote><p></p>
[QUOTE="Edalex, post: 1105744, member: 63839"] Hi guys! As you maybe know it's a pain in ... to find how to interact with MediaPortal and get needed data from plugin because of MP code's complexity and lack of comments and documentation sometimes. So what about sharing some useful method which could help new plugin devs to code? Let me start from my noob point of view :) : [B]How to get Channel Groups from TV Server[/B] [CODE=Csharp]using TvDatabase; ... public static TvBusinessLayer layer = new TvBusinessLayer(); IList<ChannelGroup> tvGroups = ChannelGroup.ListAll(); IList<RadioChannelGroup> radioGroups = RadioChannelGroup.ListAll(); IList<Channel> channels = layer.GetChannelsInGroup(selectedGroup);[/CODE] [B]How to check if another plugin is available and enabled:[/B] [CODE=Csharp] publicstatic bool IsAssemblyAvailable(string name,Version ver){ bool result =false; Assembly[] assemblies =AppDomain.CurrentDomain.GetAssemblies(); foreach(Assembly a in assemblies) try { if(a.GetName().Name== name && a.GetName().Version>= ver) { result =true; break; } } catch { } if(!result){ try{ //Assembly assembly = AppDomain.CurrentDomain.Reflection(new AssemblyName(name)); Assembly assembly =Assembly.ReflectionOnlyLoad(name); result =true; } catch(Exception e){ } } return result; } public static bool IsPluginEnabled(string name){ using (MediaPortal.Profile.Settings xmlreader =newMediaPortal.Profile.MPSettings()){ return xmlreader.GetValueAsBool("plugins", name,false); } } [/CODE] Source [url]https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701[/url] [B]How to interact with trakt plugin[/B] [CODE=Csharp] using TraktPlugin.TraktAPI; using TraktPlugin.TraktAPI.DataStructures; ... IEnumerable<TraktSearchEpisode> myep = TraktAPI.SearchEpisodes("Scars"); IEnumerable<TraktMovie> searchmovie = TraktAPI.SearchMovies("Tron"); IEnumerable<TraktShow> searchshow = TraktAPI.SearchShows("eureka"); IEnumerable<TraktMovie> recmovies = TraktAPI.GetRecommendedMovies(); IEnumerable<TraktMovie> tronrelated = TraktAPI.GetRelatedMovies("tt0084827"); IEnumerable<TraktUserProfile> newfriend = TraktAPI.SearchForFriends("edalex");[/CODE] [B]How to use TMDB provider from Moving Pictures:[/B] [CODE=Csharp] using MediaPortal.Plugins.MovingPictures.DataProviders.TMDbAPI; ... MovieSearch mymovie = TheMovieDbAPI.SearchMovies("Tron");[/CODE] Get Series List from MP-TVSeries: [CODE=Csharp] using WindowPlugins.GUITVSeries; ... List<DBOnlineSeries> myseries = DBOnlineSeries.getAllSeries(); foreach (DBOnlineSeries tvshow in myseries) { DBSeries mytv = Helper.getCorrespondingSeries(tvshow[DBOnlineSeries.cID]); if (mytv != null) { string ishidden = mytv[DBSeries.cHidden]; if (ishidden != "1") { } } } [/CODE] [B]How to create own custom GUI Dialog[/B] 1) Choose of existing dialog to modify it. [url]https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs[/url] 2) Create your own dialog by overriding one of them Examples: [url]https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUIDIalogPreview.cs[/url] [url]https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUICheckListDialog.cs[/url] [url]https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cs[/url] [url]https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cs[/url] [url]https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cs[/url] [url]https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs[/url] 3) Create skin files for your new dialog Take skin file of Dialog you overrided and modify it for your needs. Change Windowd ID, add new control etc. Skin files for standart skins (better start with supporting them) located here: [url]https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/[/url] 4) Now you can use custom dialog just as like as standart one [CODE=C#]GUICheckListDialog dlg = (GUICheckListDialog)GUIWindowManager.GetWindow(GUICheckListDialog.ID); if (dlg == null) return; dlg.Reset(); dlg.SetHeading(...); dlg.Add(...); dlg.Add(...); } dlg.DoModal(GUIWindowManager.ActiveWindow);[/CODE] [B]How to create custom GUI Control (untested)[/B] 1) Create your control's code overridingone of existing controls or GUIControl class itself Examples: [url]https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUISudoku/CellControl.cs[/url] [url]https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUITetris/MyTetrisControl.cs[/url] 2) Register your custom control in Init: [CODE=Csharp]GUIControlFactory.RegisterControl("cell", typeof (CellControl));[/CODE] 3) ... If you would like to continue my efforts, please, share your code samples! Many thanks! [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Plugins
How-to for Plugin Developers with Code Examples
Contact us
RSS
Top
Bottom