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 2
Plugin Development
Need a little help with plugin development
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="Kasimir9735" data-source="post: 1187372" data-attributes="member: 105881"><p>Hey morpheus... Finally i've got it. The Problem was, that i had my test in the tvsetup program. You cannot use references to infrastructure of MP2 Server because it's standalone. For my case it's ok, but maybe should be analyzed i the future. Now i've done my tests in MP2 Server and did a debug attached to it. That works, but in my eyes the resulting code is terrible. Maybe i've understand the framework in the wrong way. So maybe you can take a look at the following and comment it:</p><p></p><p>First get access to the MediaLibrary:</p><p>[code]var mediaLibrary = ServiceRegistration.Get<IMediaLibrary>(false);</p><p>if (mediaLibrary == null)</p><p> throw new Exception("Unable to get reference to IMediaLibary");[/code]</p><p></p><p>I want to query MediaItems with SeriesAspect (is this interpretation right?)</p><p>[code]var serieGuids = new List<Guid> {SeriesAspect.ASPECT_ID};[/code]</p><p></p><p>Prepare the query and add a filter</p><p>[code]var combinationFilter = new BooleanCombinationFilter(BooleanOperator.And, _queryFilters);</p><p></p><p>var query = new MediaItemQuery(serieGuids, combinationFilter);</p><p>// where _queryFilters is a List of Filters like in this case</p><p>// new RelationalFilter(SeriesAspect.ATTR_SERIESNAME, RelationalOperator.EQ, "The Name");[/code]</p><p></p><p>Now execute the query, iterate through the results and create new objects of my SeriesType and add it to a list. Finally return the list:</p><p>[code]var items = mediaLibrary.Search(query, false).ToList();</p><p>if (!items.Any())</p><p> return null;</p><p></p><p>var result = new List<MediaportalSeriesEpisode>();</p><p>items.ForEach(item =></p><p>{</p><p> var resultItem = new MediaportalSeriesEpisode()</p><p> {</p><p> EpisodeName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_EPISODENAME),</p><p> Episode = (IEnumerable<int>)((HashSet<object>)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_EPISODE))?.Cast<int>(),</p><p> Season = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SEASON),</p><p> DvdEpisode = (IEnumerable<double>)((HashSet<object>)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_DVDEPISODE))?.Cast<double>(),</p><p> FirstAired = (DateTime?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_FIRSTAIRED),</p><p> ImdbId = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_IMDB_ID),</p><p> RatingCount = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_RATING_COUNT),</p><p> SeriesName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SERIESNAME),</p><p> SeriesSeasonName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SERIES_SEASON),</p><p> TvDbId = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_TVDB_ID),</p><p> TotalRating = (double?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_TOTAL_RATING)</p><p> };</p><p> result.Add(resultItem);</p><p>});[/code]</p><p></p><p>PossiblyGetMediaItemAspectAttribute is simply a wrapper around "MediaItemAspect.TryGetAttribute(mediaItem.Aspects, seriesAspect, out result);" and returns the result.</p><p></p><p>As you can see there are many casts and check for null values required. For Example results for ATTR_EPISODE are of type HashSet<object>, so i have to use the method .Cast<int> to it. But yes, result could be null, so there's also a null value check required.</p><p></p><p>Do you suggest another approach here? I'm not a fan of such a code <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>One last question: The results i'm getting are ok, but i was wondering why some fields are empty. Especially the TvDbID. It is always null, and that is in my case the query argument :-(</p><p>But i think there is something wrong, because Mediaportal has imported these episodes and if i take a look in the local directories, i can see what it has downloaded from thetvdb, and there are folders with the TvDbIds, but they are missing in the database. Is this a bug in MP2 ? If so, i can try to fix that.</p></blockquote><p></p>
[QUOTE="Kasimir9735, post: 1187372, member: 105881"] Hey morpheus... Finally i've got it. The Problem was, that i had my test in the tvsetup program. You cannot use references to infrastructure of MP2 Server because it's standalone. For my case it's ok, but maybe should be analyzed i the future. Now i've done my tests in MP2 Server and did a debug attached to it. That works, but in my eyes the resulting code is terrible. Maybe i've understand the framework in the wrong way. So maybe you can take a look at the following and comment it: First get access to the MediaLibrary: [code]var mediaLibrary = ServiceRegistration.Get<IMediaLibrary>(false); if (mediaLibrary == null) throw new Exception("Unable to get reference to IMediaLibary");[/code] I want to query MediaItems with SeriesAspect (is this interpretation right?) [code]var serieGuids = new List<Guid> {SeriesAspect.ASPECT_ID};[/code] Prepare the query and add a filter [code]var combinationFilter = new BooleanCombinationFilter(BooleanOperator.And, _queryFilters); var query = new MediaItemQuery(serieGuids, combinationFilter); // where _queryFilters is a List of Filters like in this case // new RelationalFilter(SeriesAspect.ATTR_SERIESNAME, RelationalOperator.EQ, "The Name");[/code] Now execute the query, iterate through the results and create new objects of my SeriesType and add it to a list. Finally return the list: [code]var items = mediaLibrary.Search(query, false).ToList(); if (!items.Any()) return null; var result = new List<MediaportalSeriesEpisode>(); items.ForEach(item => { var resultItem = new MediaportalSeriesEpisode() { EpisodeName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_EPISODENAME), Episode = (IEnumerable<int>)((HashSet<object>)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_EPISODE))?.Cast<int>(), Season = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SEASON), DvdEpisode = (IEnumerable<double>)((HashSet<object>)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_DVDEPISODE))?.Cast<double>(), FirstAired = (DateTime?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_FIRSTAIRED), ImdbId = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_IMDB_ID), RatingCount = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_RATING_COUNT), SeriesName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SERIESNAME), SeriesSeasonName = (string)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_SERIES_SEASON), TvDbId = (int?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_TVDB_ID), TotalRating = (double?)PossiblyGetMediaItemAspectAttributeValue(item, SeriesAspect.ATTR_TOTAL_RATING) }; result.Add(resultItem); });[/code] PossiblyGetMediaItemAspectAttribute is simply a wrapper around "MediaItemAspect.TryGetAttribute(mediaItem.Aspects, seriesAspect, out result);" and returns the result. As you can see there are many casts and check for null values required. For Example results for ATTR_EPISODE are of type HashSet<object>, so i have to use the method .Cast<int> to it. But yes, result could be null, so there's also a null value check required. Do you suggest another approach here? I'm not a fan of such a code :) One last question: The results i'm getting are ok, but i was wondering why some fields are empty. Especially the TvDbID. It is always null, and that is in my case the query argument :-( But i think there is something wrong, because Mediaportal has imported these episodes and if i take a look in the local directories, i can see what it has downloaded from thetvdb, and there are folders with the TvDbIds, but they are missing in the database. Is this a bug in MP2 ? If so, i can try to fix that. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
Plugin Development
Need a little help with plugin development
Contact us
RSS
Top
Bottom