コード例 #1
0
ファイル: TuneInChannel.cs プロジェクト: algel/Emby.Channels
        public async Task<IEnumerable<ChannelMediaInfo>> GetChannelItemMediaInfo(string id,
            CancellationToken cancellationToken)
        {
            var channelID = id.Split('_');
            var items = new List<ChannelMediaInfo>();

            using (var site = await _httpClient.Get(channelID[1] + "&formats=mp3,aac", CancellationToken.None).ConfigureAwait(false))
            {
                using (var reader = new StreamReader(site))
                {
                    while (!reader.EndOfStream)
                    {
                        var url = reader.ReadLine();
                        _logger.Debug("FILE NAME : " + url.Split('/').Last().Split('?').First());

                        var ext = Path.GetExtension(url.Split('/').Last().Split('?').First());

                        _logger.Debug("URL : " + url);
                        if (!string.IsNullOrEmpty(ext))
                        {
                            _logger.Debug("Extension : " + ext);
                            if (ext == ".pls")
                            {
                                try
                                {
                                    using (var value = await _httpClient.Get(url, CancellationToken.None).ConfigureAwait(false))
                                    {
                                        var parser = new IniParser(value);
                                        var count = Convert.ToInt16(parser.GetSetting("playlist", "NumberOfEntries"));
                                        _logger.Debug("COUNT : " + count);
                                        for (var i = 0; i < count; i++)
                                        {
                                            var file = parser.GetSetting("playlist", "File" + count);
                                            _logger.Debug("FILE : " + count + " - " + file);

                                            items.Add(new ChannelMediaInfo
                                            {
                                                Path = file.ToLower()
                                            });
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(ex.ToString());
                                }
                            }
                            else if (ext == ".m3u")
                            {
                                try
                                {
                                    using (var value = await _httpClient.Get(url, CancellationToken.None).ConfigureAwait(false))
                                    {
                                        using (var reader2 = new StreamReader(value))
                                        {
                                            while (!reader2.EndOfStream)
                                            {
                                                var url2 = reader2.ReadLine();
                                                items.Add(new ChannelMediaInfo
                                                {
                                                    Path = url2
                                                });
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _logger.Error(ex.ToString());
                                }
                            }
                            else
                            {
                                items.Add(new ChannelMediaInfo
                                {
                                    Path = url
                                });
                            }
                        }
                        else
                        {
                            _logger.Debug("Normal URL");

                            items.Add(new ChannelMediaInfo
                            {
                                Path = url
                            });
                        }
                    }
                }
            }

            return items;
        }