private UPnPError OnCreateScheduleByTime(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context) { outParams = new List <object>(); IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync; IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync; if (scheduleControl == null || channelAndGroupInfo == null) { return(new UPnPError(500, "IChannelAndGroupInfo or IScheduleControl service not available")); } int channelId = (int)inParams[0]; DateTime startTime = (DateTime)inParams[1]; DateTime endTime = (DateTime)inParams[2]; ScheduleRecordingType recordingType = (ScheduleRecordingType)inParams[3]; ISchedule schedule = null; AsyncResult <IChannel> result = channelAndGroupInfo.GetChannelAsync(channelId).Result; if (result.Success) { var scheduleResult = scheduleControl.CreateScheduleByTimeAsync(result.Result, startTime, endTime, recordingType).Result; if (scheduleResult.Success) { schedule = scheduleResult.Result; } } outParams = new List <object> { result.Success, schedule }; return(null); }
private UPnPError OnGetChannel(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context) { outParams = new List <object>(); IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync; if (channelAndGroupInfo == null) { return(new UPnPError(500, "IChannelAndGroupInfo service not available")); } int channelId = (int)inParams[0]; AsyncResult <IChannel> result = channelAndGroupInfo.GetChannelAsync(channelId).Result; outParams = new List <object> { result.Success, new List <IChannel> { result.Result } }; return(null); }
public override void Initialise(string sortCriteria, uint?offset = null, uint?count = null) { base.Initialise(sortCriteria, offset, count); if (ServiceRegistration.IsRegistered <ITvProvider>()) { IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync; var res = channelAndGroupInfo?.GetChannelAsync(ChannelId).Result; if (res?.Success ?? false) { var dlnaItem = Client.GetLiveDlnaItem(ChannelId); if (dlnaItem == null) { var mediaItem = Client.StoreLiveDlnaItem(ChannelId); if (mediaItem == null) { Logger.Error("MediaServer: Error analyzing channel {0} stream", ChannelId); return; } } IChannel channel = res.Result; try { if (channel.MediaType == MediaType.TV) { Add(new MediaLibraryVideoBroadcastItem(channel.Name, channel.ChannelId, Client)); } else if (channel.MediaType == MediaType.Radio) { Add(new MediaLibraryAudioBroadcastItem(channel.Name, channel.ChannelId, Client)); } } catch (Exception ex) { Logger.Error("MediaServer: Error analyzing channel {0}", ex, ChannelId); } } } }
public static async Task<WebChannelState> ProcessAsync(IOwinContext context, string channelId, string userName) { if (!ServiceRegistration.IsRegistered<ITvProvider>()) throw new BadRequestException("GetChannelState: ITvProvider not found"); if (channelId == null) throw new BadRequestException("GetChannelState: channelId is null"); if (userName == null) throw new BadRequestException("GetChannelState: userName is null"); IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get<ITvProvider>() as IChannelAndGroupInfoAsync; var channel = await channelAndGroupInfo.GetChannelAsync(int.Parse(channelId)); if (!channel.Success) throw new BadRequestException(string.Format("GetChannelState: Couldn't get channel with id: {0}", channelId)); WebChannelState webChannelState = new WebChannelState { ChannelId = channel.Result.ChannelId, State = ChannelState.Tunable // TODO: implement in SlimTv }; return webChannelState; }
internal static WebScheduledRecording ScheduledRecording(ISchedule schedule) { IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync; var channel = channelAndGroupInfo.GetChannelAsync(schedule.ChannelId).Result; string channelName = ""; if (!channel.Success) { channelName = channel.Result.Name; } WebScheduledRecording webScheduledRecording = new WebScheduledRecording { Title = schedule.Name, ChannelId = schedule.ChannelId, EndTime = schedule.EndTime, StartTime = schedule.StartTime, ScheduleId = schedule.ScheduleId, //ProgramId = schedule, ChannelName = channelName }; return(webScheduledRecording); }
internal static IList <FanArtImage> GetFanArtImages(IOwinContext context, string id, bool isTvRadio, bool isRecording, string fanartType, string fanArtMediaType) { ISet <Guid> necessaryMIATypes = new HashSet <Guid>(); necessaryMIATypes.Add(MediaAspect.ASPECT_ID); ISet <Guid> optionalMIATypes = new HashSet <Guid>(); optionalMIATypes.Add(VideoAspect.ASPECT_ID); optionalMIATypes.Add(MovieAspect.ASPECT_ID); optionalMIATypes.Add(SeriesAspect.ASPECT_ID); optionalMIATypes.Add(SeasonAspect.ASPECT_ID); optionalMIATypes.Add(EpisodeAspect.ASPECT_ID); optionalMIATypes.Add(AudioAspect.ASPECT_ID); optionalMIATypes.Add(ImageAspect.ASPECT_ID); MediaItem item = null; if (!isTvRadio) { item = MediaLibraryAccess.GetMediaItemById(context, id, necessaryMIATypes, optionalMIATypes); } if (item == null && !isTvRadio) { throw new BadRequestException(String.Format("GetFanArtImages: No MediaItem found with id: {0}", id)); } string name = id; if (isTvRadio) { IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>(false) as IChannelAndGroupInfoAsync; if (channelAndGroupInfo != null) { int idInt = int.Parse(id); var channel = channelAndGroupInfo.GetChannelAsync(idInt).Result; if (channel.Success) { name = channel.Result.Name; } else { throw new BadRequestException(String.Format("GetFanArtImages: No Channel found with id: {0}", id)); } } } IList <FanArtImage> fanart = ServiceRegistration.Get <IFanArtService>().GetFanArt(fanArtMediaType, fanartType, name, 0, 0, false); if (fanart == null || fanart.Count == 0) { Logger.Debug("GetFanArtImages: no fanart found - fanArtMediaType: {0}, fanartType: {1}, name: {2}", fanArtMediaType, fanartType, name); // We return a transparent image instead of throwing an exception Bitmap newImage = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics graphic = Graphics.FromImage(newImage); graphic.Clear(Color.Transparent); MemoryStream ms = new MemoryStream(); newImage.Save(ms, ImageFormat.Png); return(new List <FanArtImage> { new FanArtImage { Name = NO_FANART_IMAGE_NAME, BinaryData = ms.ToArray() } }); } return(fanart); }
public void SetProgram(IProgram program, IChannel channel = null) { IProgramRecordingStatus recordingStatus = program as IProgramRecordingStatus; if (recordingStatus != null) { UpdateState(recordingStatus.RecordingStatus); } try { if (channel == null && program != null) { IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvHandler>().ChannelAndGroupInfo; if (channelAndGroupInfo != null) { var result = channelAndGroupInfo.GetChannelAsync(program.ChannelId).Result; if (result.Success) { channel = result.Result; } } } ChannelName = channel?.Name ?? ""; ChannelNumber = channel?.ChannelNumber ?? 0; ChannelLogoType = channel.GetFanArtMediaType(); _settingProgram = true; IProgramSeries series = program as IProgramSeries; if (series != null) { SeasonNumber = series.SeasonNumber; EpisodeNumber = series.EpisodeNumber; EpisodeTitle = series.EpisodeTitle; Series = BuildSeriesText(this); } else { SeasonNumber = string.Empty; EpisodeNumber = string.Empty; EpisodeTitle = string.Empty; Series = string.Empty; } if (program != null) { ProgramId = program.ProgramId; Title = program.Title; Description = program.Description; StartTime = program.StartTime; EndTime = program.EndTime; Genre = program.Genre; EpgGenreId = program.EpgGenreId; EpgGenreColor = program.EpgGenreColor; } else { ProgramId = -1; Title = string.Empty; Description = string.Empty; StartTime = DateTime.Now.GetDay(); EndTime = StartTime.AddDays(1); Genre = string.Empty; EpgGenreId = 0; EpgGenreColor = string.Empty; } NoProgramData = ProgramId == -1; UpdateDuration(); } finally { _settingProgram = false; } }
public async Task <(bool Success, MediaItem LiveMediaItem)> StartTuningAsync(string clientId, int channelId) { try { var client = _clientChannels.FirstOrDefault(c => c.Value.ChannelId == channelId); if (client.Value?.Channel?.MediaItem != null) { //Check if already streaming if (client.Key == clientId) { return(true, client.Value.Channel.MediaItem); } //Use same stream url as other channel if (!_clientChannels.TryAdd(clientId, client.Value)) { return(false, null); } else { return(true, client.Value.Channel.MediaItem); } } if (ServiceRegistration.IsRegistered <ITvProvider>()) { IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync; var channelResult = await channelAndGroupInfo.GetChannelAsync(channelId).ConfigureAwait(false); if (!channelResult.Success) { _logger.Error("SlimTvHandler: Couldn't find channel {0}", channelId); return(false, null); } var slotIndex = GetFreeSlot(); if (slotIndex == null) { _logger.Error("SlimTvHandler: Couldn't find free slot for channel {0}", channelId); return(false, null); } ITimeshiftControlEx timeshiftControl = ServiceRegistration.Get <ITvProvider>() as ITimeshiftControlEx; var mediaItem = (await timeshiftControl.StartTimeshiftAsync(TV_USER_NAME, slotIndex.Value, channelResult.Result).ConfigureAwait(false)); if (!mediaItem.Success) { _logger.Error("SlimTvHandler: Couldn't start timeshifting for channel {0}", channelId); return(false, null); } try { //Initiate channel cache ChannelInfo newChannel = new ChannelInfo { Channel = new TranscodeChannel(), SlotIndex = slotIndex.Value, ChannelId = channelId, }; if (!_clientChannels.TryAdd(clientId, newChannel)) { await timeshiftControl.StopTimeshiftAsync(TV_USER_NAME, slotIndex.Value); return(false, null); } newChannel.Channel.SetChannel(mediaItem.Result); } catch { _clientChannels.TryRemove(clientId, out ChannelInfo c); await timeshiftControl.StopTimeshiftAsync(TV_USER_NAME, slotIndex.Value); throw; } return(true, mediaItem.Result); } return(false, null); } catch (Exception ex) { _logger.Error("SlimTvHandler: Error starting tuning of channel {0}", ex, channelId); return(false, null); } }