예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }