/// <summary> /// Retrieves a URL for a given action, allows the endpoint to be overriden /// </summary> /// <param name="action">The action.</param> /// <param name="args">The arguments.</param> /// <returns></returns> protected String GetUrl(string baseUrl, DVBViewerOptions configuration, String action, params object[] args) { // ensure it has a trailing / baseUrl = baseUrl.TrimEnd('/') + "/"; return(String.Concat(baseUrl, String.Format(action, args))); }
/// <summary> /// Gets the channel logo. /// </summary> /// <param name="channel">The channel.</param> /// <returns></returns> public String GetChannelLogo(string baseUrl, DVBViewerOptions configuration, Channel channel) { var url = String.Format("{0}/api/{1}", baseUrl.TrimEnd('/'), channel.Logo); if (!string.IsNullOrEmpty(configuration.UserName)) { if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri)) { var builder = new UriBuilder(uri); builder.UserName = configuration.UserName; builder.Password = configuration.Password; url = builder.Uri.ToString(); } } return(url); }
public async Task <List <ProgramInfo> > GetPrograms(string baseUrl, DVBViewerOptions configuration, string channelId, DateTimeOffset startDateUtc, DateTimeOffset endDateUtc, CancellationToken cancellationToken) { var channel = (await GetChannelList(baseUrl, configuration, cancellationToken).ConfigureAwait(false)) .Root .ChannelGroup .SelectMany(c => c.Channel) .FirstOrDefault(c => string.Equals(c.Id, channelId, StringComparison.OrdinalIgnoreCase)); var response = await GetFromService <Guide>(baseUrl, configuration, cancellationToken, typeof(Guide), "api/epg.html?lvl=2&channel={0}&start={1}&end={2}", channel.EPGID, GeneralExtensions.FloatDateTimeOffset(startDateUtc), GeneralExtensions.FloatDateTimeOffset(endDateUtc)).ConfigureAwait(false); Plugin.Logger.Info("Found Programs: {0} for Channel: {1}", response.Program.Count(), channel.Name); return(response.Program.Select(p => { var program = new ProgramInfo() { Name = p.Name, EpisodeNumber = p.EpisodeNumber, SeasonNumber = p.SeasonNumber, ProductionYear = p.ProductionYear, Id = GeneralExtensions.SetEventId(channelId, p.Start, p.Stop), SeriesId = p.Name, ChannelId = channelId, StartDate = GeneralExtensions.GetProgramTime(p.Start), EndDate = GeneralExtensions.GetProgramTime(p.Stop), Overview = p.Overview, Etag = p.EitContent, }; program.IsSeries = true; if (program.IsSeries && p.Name != p.EpisodeTitleRegEx) { program.EpisodeTitle = p.EpisodeTitleRegEx; } return program; }).ToList()); }
public async Task <List <ChannelInfo> > GetChannels(string baseUrl, DVBViewerOptions configuration, CancellationToken cancellationToken) { var channels = await GetChannelList(baseUrl, configuration, cancellationToken).ConfigureAwait(false); return(channels.Root.ChannelGroup.SelectMany(c => c.Channel).Select(c => { var channelInfo = new ChannelInfo() { Id = c.Id, Name = c.Name, ChannelType = (GeneralExtensions.HasVideoFlag(c.Flags)) ? ChannelType.TV : ChannelType.Radio, }; if (!String.IsNullOrEmpty(c.Logo)) { channelInfo.ImageUrl = _wssProxy.GetChannelLogo(baseUrl, configuration, c); } return channelInfo; }).ToList()); }
/// <summary> /// Retrieves data from the service for a given action /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> protected async Task <TResult> GetFromService <TResult>(string baseUrl, DVBViewerOptions configuration, CancellationToken cancellationToken, Type type, String action, params object[] args) { var request = new HttpRequestOptions() { Url = GetUrl(baseUrl, configuration, action, args), RequestContentType = "application/x-www-form-urlencoded", LogErrorResponseBody = true, LogRequest = true, CancellationToken = cancellationToken }; if (!string.IsNullOrEmpty(configuration.UserName)) { string authInfo = String.Format("{0}:{1}", configuration.UserName, configuration.Password); authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); request.RequestHeaders["Authorization"] = "Basic " + authInfo; } using (var stream = await HttpClient.Get(request).ConfigureAwait(false)) { return((TResult)XmlSerializer.DeserializeFromStream(type, stream)); } }
public Task <Channels> GetChannelList(string baseUrl, DVBViewerOptions configuration, CancellationToken cancellationToken) { return(GetFromService <Channels>(baseUrl, configuration, cancellationToken, typeof(Channels), "api/getchannelsxml.html?logo=1")); }