Normal
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 :How to get Channel Groups from TV Server[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]How to check if another plugin is available and enabled:[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 https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701How to interact with trakt plugin[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]How to use TMDB provider from Moving Pictures:[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]How to create own custom GUI Dialog1) Choose of existing dialog to modify it. https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs2) Create your own dialog by overriding one of themExamples:https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUIDIalogPreview.cshttps://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUICheckListDialog.cshttps://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cshttps://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cshttps://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cshttps://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs3) Create skin files for your new dialogTake 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:https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/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]How to create custom GUI Control (untested)1) Create your control's code overridingone of existing controls or GUIControl class itselfExamples:https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUISudoku/CellControl.cshttps://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUITetris/MyTetrisControl.cs2) 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!
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 :
How to get Channel Groups from TV Server
[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]
How to check if another plugin is available and enabled:
[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);
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 https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/Helper.cs#701
How to interact with trakt plugin
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]
How to use TMDB provider from Moving Pictures:
using MediaPortal.Plugins.MovingPictures.DataProviders.TMDbAPI;
MovieSearch mymovie = TheMovieDbAPI.SearchMovies("Tron");[/CODE]
Get Series List from MP-TVSeries:
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]
How to create own custom GUI Dialog
1) Choose of existing dialog to modify it. https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/Dialogs/Dialogs
2) Create your own dialog by overriding one of them
Examples:
https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUIDIalogPreview.cs
https://code.google.com/p/mediaportal-russian-logos/source/browse/trunk/LogoManager/LogoManager/GUICheckListDialog.cs
https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIPinCodeDialog.cs
https://code.google.com/p/moving-pictures/source/browse/trunk/Cornerstone.MP/GUIGeneralRating.cs
https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIUserRating.cs
https://code.google.com/p/mptvseries/source/browse/trunk/MP-TVSeries/GUIPinCode.cs
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:
https://github.com/MediaPortal/MediaPortal-1/tree/master/mediaportal/MediaPortal.Base/skin/
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.DoModal(GUIWindowManager.ActiveWindow);[/CODE]
How to create custom GUI Control (untested)
1) Create your control's code overridingone of existing controls or GUIControl class itself
https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUISudoku/CellControl.cs
https://github.com/MediaPortal/MediaPortal-1/blob/master/mediaportal/WindowPlugins/GUITetris/MyTetrisControl.cs
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!