Exemple #1
0
    public async Task <IEnumerable <ChannelInfo> > GetChannels(Stream stream, ILogger <LiveTvService> logger)
    {
        var root = await JsonSerializer.DeserializeAsync <RootObject>(stream, _jsonOptions).ConfigureAwait(false);

        if (root == null)
        {
            logger.LogError("Failed to download channel information");
            throw new JsonException("Failed to download channel information.");
        }

        if (root.Channels != null)
        {
            UtilsHelper.DebugInformation(logger, $"[NextPVR] ChannelResponse: {JsonSerializer.Serialize(root, _jsonOptions)}");
            return(root.Channels.Select(i => new ChannelInfo
            {
                Name = i.ChannelName,
                Number = i.ChannelNumberFormated,
                Id = i.ChannelId.ToString(CultureInfo.InvariantCulture),
                ImageUrl = $"{_baseUrl}/service?method=channel.icon&channel_id={i.ChannelId}",
                ChannelType = ChannelHelper.GetChannelType(i.ChannelType),
                HasImage = i.ChannelIcon
            }));
        }

        return(new List <ChannelInfo>());
    }
        public IEnumerable <ChannelInfo> GetChannels(Stream stream, IJsonSerializer json, ILogger <LiveTvService> logger)
        {
            var root = json.DeserializeFromStream <RootObject>(stream);

            if (root == null)
            {
                logger.LogError("Failed to download channel information.");
                throw new Exception("Failed to download channel information.");
            }

            if (root.channels != null)
            {
                UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ChannelResponse: {0}", json.SerializeToString(root)));
                return(root.channels.Select(i => new ChannelInfo
                {
                    Name = i.channelName,
                    Number = i.channelNumberFormated,
                    Id = i.channelId.ToString(_usCulture),
                    ImageUrl = string.Format("{0}/service?method=channel.icon&channel_id={1}", _baseUrl, i.channelId),
                    ChannelType = ChannelHelper.GetChannelType(i.channelType),
                    HasImage = i.channelIcon
                }));
            }

            return(new List <ChannelInfo>());
        }