Example #1
0
    private static TraktListItem ProjectItem(TraktList list, TraktListItemWithGuids item)
    {
        var result = new TraktListItem
        {
            TraktList = list,
            Kind      = item.Kind,
            TraktId   = item.TraktId,
            Rank      = item.Rank,
            Title     = item.Title,
            Year      = item.Year,
            Season    = item.Season,
            Episode   = item.Episode
        };

        result.Guids = item.Guids.Map(g => new TraktListItemGuid {
            Guid = g, TraktListItem = result
        }).ToList();

        return(result);
    }
Example #2
0
    public async Task <Either <BaseError, List <TraktListItemWithGuids> > > GetUserListItems(string user, string list)
    {
        try
        {
            var result = new List <TraktListItemWithGuids>();

            List <TraktListItemResponse> apiItems = await _traktApi.GetUserListItems(
                _traktConfiguration.Value.ClientId,
                user,
                list);

            foreach (TraktListItemResponse apiItem in apiItems)
            {
                TraktListItemWithGuids item = apiItem.Type.ToLowerInvariant() switch
                {
                    "movie" => new TraktListItemWithGuids(
                        apiItem.Id,
                        apiItem.Rank,
                        $"{apiItem.Movie.Title} ({apiItem.Movie.Year})",
                        apiItem.Movie.Title,
                        apiItem.Movie.Year,
                        0,
                        0,
                        TraktListItemKind.Movie,
                        GuidsFromIds(apiItem.Movie.Ids)),
                    "show" => new TraktListItemWithGuids(
                        apiItem.Id,
                        apiItem.Rank,
                        $"{apiItem.Show.Title} ({apiItem.Show.Year})",
                        apiItem.Show.Title,
                        apiItem.Show.Year,
                        0,
                        0,
                        TraktListItemKind.Show,
                        GuidsFromIds(apiItem.Show.Ids)),
                    "season" => new TraktListItemWithGuids(
                        apiItem.Id,
                        apiItem.Rank,
                        $"{apiItem.Show.Title} ({apiItem.Show.Year}) S{apiItem.Season.Number:00}",
                        apiItem.Show.Title,
                        apiItem.Show.Year,
                        apiItem.Season.Number,
                        0,
                        TraktListItemKind.Season,
                        GuidsFromIds(apiItem.Season.Ids)),
                    "episode" => new TraktListItemWithGuids(
                        apiItem.Id,
                        apiItem.Rank,
                        $"{apiItem.Show.Title} ({apiItem.Show.Year}) S{apiItem.Episode.Season:00}E{apiItem.Episode.Number:00}",
                        apiItem.Show.Title,
                        apiItem.Show.Year,
                        apiItem.Episode.Season,
                        apiItem.Episode.Number,
                        TraktListItemKind.Episode,
                        GuidsFromIds(apiItem.Episode.Ids)),
                    _ => null
                };

                if (item != null)
                {
                    result.Add(item);
                }
            }

            return(result);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error getting trakt list items");
            return(BaseError.New(ex.Message));
        }
    }