Jump to content

Help with ILibraryManager


pünktchen

Recommended Posts

pünktchen

I try to duplicate some of Emby's tv schedules methodes to my live tv plugins, but the implementation of "ILibraryManager" doesn't work.

I get a System.argument.Null.Exception. What i'm doing wrong?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Tasks;

namespace MediaBrowser.Plugins.MediaPortal.Helpers
{
    public class CheckTimers
    {
        //private readonly ILibraryManager _libraryManager;

        public void SkipTimers(CancellationToken cancellationToken)
        {
            MediaPortal1TvService tvservice = new MediaPortal1TvService();
            var timers = tvservice.GetTimersAsync(cancellationToken).Result;

            foreach ( var timer in timers)
            {
                if (IsAlreadyInLibrary(timer))
                {
                    tvservice.CancelTimerAsync(timer.Id, cancellationToken);
                }
            }
        }

        public bool IsAlreadyInLibrary(TimerInfo timer)
        {
            if ((timer.EpisodeNumber.HasValue && timer.SeasonNumber.HasValue) || !string.IsNullOrWhiteSpace(timer.EpisodeTitle))
            {
                var seriesIds = (this as ILibraryManager).GetItemIds(new InternalItemsQuery
                {
                    IncludeItemTypes = new[] { typeof(Series).Name },
                    Name = timer.Name

                }).Select(i => i.ToString("N")).ToArray();
                
                // It never reaches this point. System.Argument.Null.Exception
                
                if (seriesIds.Length == 0)
                {
                    return false;
                }

                //if (timer.EpisodeNumber.HasValue && timer.SeasonNumber.HasValue)
                //{
                //    var episode = _libraryManager.GetItemIds(new InternalItemsQuery
                //    {
                //        IncludeItemTypes = new[] { typeof(Episode).Name },
                //        ParentIndexNumber = timer.SeasonNumber.Value,

                //        IndexNumber = timer.EpisodeNumber.Value,
                //        AncestorIds = seriesIds,
                //        IsVirtualItem = false,
                //        Limit = 1
                //    });

                //    if (episode.Count > 0)
                //    {
                //        return true;
                //    }
                //}
            }
            return false;
        }
    }
}

Edited by pünktchen
Link to comment
Share on other sites

Ok, your reference to _libraryManager is null. Try putting it into the constructor of your CheckTimers class.

Link to comment
Share on other sites

pünktchen

And that's my problem. How to do this without the need of implementing all methods of ILibraryManager?

public class CheckTimers : ILibraryManager
Link to comment
Share on other sites

You don't need to do that. Create a constructor for CheckTimers

public CheckTimers(ILibraryManager libraryManager){
_libraryManager = libraryManager;
}
Link to comment
Share on other sites

pünktchen

But if i do this

public class CheckTimers
{
    private readonly ILibraryManager _libraryManager;

    public CheckTimers(ILibraryManager libraryManager)
    {
        _libraryManager = libraryManager;
    }

    //Do something
}

what would be the parameter here

public Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken)
{
    Plugin.TvProxy.CreateSeriesSchedule(cancellationToken, info);

    CheckTimers checkTimers = new CheckTimers(); //Missing ILibraryManager Parameter
    checkTimers.SkipTimers(cancellationToken);

    return Task.Delay(0, cancellationToken);
}
Link to comment
Share on other sites

Same concept in that class. Add it to the constructor all the way up your call chain.

Link to comment
Share on other sites

Success! You're the man!

I really don't understand those constructors  :unsure:

 

Google "dependency injection c#" for some light reading :).

  • Like 1
Link to comment
Share on other sites

chef

Google "dependency injection c#" for some light reading :).

I find being able to call the interfaces in the constructor sooo much easy to reuse class style structures.

 

Make coding with the API very easy

Edited by chef
Link to comment
Share on other sites

pünktchen

@@Luke is there a property to query for "Original Title" in ILibraryManager?

var seriesIds = _libraryManager.GetItemIds(new InternalItemsQuery
{
    IncludeItemTypes = new[] { typeof(Series).Name },
    // OriginalName = seriesName

}).Select(i => i.ToString("N")).ToArray();
Link to comment
Share on other sites

Do you want the collection folders from library setup? or the actual folder paths within them?

Link to comment
Share on other sites

pünktchen

Do you want the collection folders from library setup? or the actual folder paths within them?

Only the collections folder.
Link to comment
Share on other sites

Try this.

var folders = _libraryManager.GetUserRootFolder().Children.ToList();
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...