Esempio n. 1
0
    public async Task <Either <BaseError, List <JellyfinMovie> > > GetMovieLibraryItems(
        string address,
        string apiKey,
        int mediaSourceId,
        string libraryId)
    {
        try
        {
            if (_memoryCache.TryGetValue($"jellyfin_admin_user_id.{mediaSourceId}", out string userId))
            {
                IJellyfinApi service = RestService.For <IJellyfinApi>(address);
                JellyfinLibraryItemsResponse items = await service.GetMovieLibraryItems(apiKey, userId, libraryId);

                return(items.Items
                       .Map(ProjectToMovie)
                       .Somes()
                       .ToList());
            }

            return(BaseError.New("Jellyfin admin user id is not available"));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin movie library items");
            return(BaseError.New(ex.Message));
        }
    }
Esempio n. 2
0
    public async Task <Either <BaseError, List <JellyfinCollection> > > GetCollectionLibraryItems(
        string address,
        string apiKey,
        int mediaSourceId)
    {
        try
        {
            if (_memoryCache.TryGetValue($"jellyfin_admin_user_id.{mediaSourceId}", out string userId))
            {
                // TODO: should we enumerate collection libraries here?

                if (_memoryCache.TryGetValue("jellyfin_collections_library_item_id", out string itemId))
                {
                    IJellyfinApi service = RestService.For <IJellyfinApi>(address);
                    JellyfinLibraryItemsResponse items =
                        await service.GetCollectionLibraryItems(apiKey, userId, itemId);

                    return(items.Items
                           .Map(ProjectToCollection)
                           .Somes()
                           .ToList());
                }

                return(BaseError.New("Jellyfin collection item id is not available"));
            }

            return(BaseError.New("Jellyfin admin user id is not available"));
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting jellyfin collection library items");
            return(BaseError.New(ex.Message));
        }
    }