示例#1
0
        public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, LiveTvChannel channel)
        {
            var dto = new TimerInfoDto
            {
                Id = GetInternalTimerId(service.Name, info.Id).ToString("N"),
                Overview = info.Overview,
                EndDate = info.EndDate,
                Name = info.Name,
                StartDate = info.StartDate,
                ExternalId = info.Id,
                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status = info.Status,
                SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                PrePaddingSeconds = info.PrePaddingSeconds,
                PostPaddingSeconds = info.PostPaddingSeconds,
                IsPostPaddingRequired = info.IsPostPaddingRequired,
                IsPrePaddingRequired = info.IsPrePaddingRequired,
                KeepUntil = info.KeepUntil,
                ExternalChannelId = info.ChannelId,
                ExternalSeriesTimerId = info.SeriesTimerId,
                ServiceName = service.Name,
                ExternalProgramId = info.ProgramId,
                Priority = info.Priority,
                RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
                ServerId = _appHost.SystemId
            };

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (program != null)
            {
                dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions());

                if (info.Status != RecordingStatus.Cancelled && info.Status != RecordingStatus.Error)
                {
                    dto.ProgramInfo.TimerId = dto.Id;
                    dto.ProgramInfo.Status = info.Status.ToString();
                }

                dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;
            }

            return dto;
        }
        public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, LiveTvChannel channel)
        {
            var dto = new TimerInfoDto
            {
                Id = GetInternalTimerId(service.Name, info.Id).ToString("N"),
                Overview = info.Overview,
                EndDate = info.EndDate,
                Name = info.Name,
                StartDate = info.StartDate,
                ExternalId = info.Id,
                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status = info.Status,
                SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                PrePaddingSeconds = info.PrePaddingSeconds,
                PostPaddingSeconds = info.PostPaddingSeconds,
                IsPostPaddingRequired = info.IsPostPaddingRequired,
                IsPrePaddingRequired = info.IsPrePaddingRequired,
                ExternalChannelId = info.ChannelId,
                ExternalSeriesTimerId = info.SeriesTimerId,
                ServiceName = service.Name,
                ExternalProgramId = info.ProgramId,
                Priority = info.Priority,
                RunTimeTicks = (info.EndDate - info.StartDate).Ticks
            };

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (program != null)
            {
                dto.ProgramInfo = GetProgramInfoDto(program, channel);

                dto.ProgramInfo.TimerId = dto.Id;
                dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;
            }

            return dto;
        }
        public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, LiveTvChannel channel, User user = null)
        {
            var dto = new ProgramInfoDto
            {
                Id = GetInternalProgramId(item.ServiceName, item.ExternalId).ToString("N"),
                ChannelId = GetInternalChannelId(item.ServiceName, item.ExternalChannelId).ToString("N"),
                Overview = item.Overview,
                Genres = item.Genres,
                ExternalId = item.ExternalId,
                Name = item.Name,
                ServiceName = item.ServiceName,
                StartDate = item.StartDate,
                OfficialRating = item.OfficialRating,
                IsHD = item.IsHD,
                OriginalAirDate = item.PremiereDate,
                Audio = item.Audio,
                CommunityRating = GetClientCommunityRating(item.CommunityRating),
                IsRepeat = item.IsRepeat,
                EpisodeTitle = item.EpisodeTitle,
                IsMovie = item.IsMovie,
                IsSeries = item.IsSeries,
                IsSports = item.IsSports,
                IsLive = item.IsLive,
                IsNews = item.IsNews,
                IsKids = item.IsKids,
                IsPremiere = item.IsPremiere,
                Type = "Program",
                MediaType = item.MediaType
            };

            if (item.EndDate.HasValue)
            {
                dto.EndDate = item.EndDate.Value;

                dto.RunTimeTicks = (item.EndDate.Value - item.StartDate).Ticks;
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;

                if (!string.IsNullOrEmpty(channel.PrimaryImagePath))
                {
                    dto.ChannelPrimaryImageTag = GetImageTag(channel);
                }
            }

            var imageTag = GetImageTag(item);

            if (imageTag != null)
            {
                dto.ImageTags[ImageType.Primary] = imageTag;
                _dtoService.AttachPrimaryImageAspectRatio(dto, item);
            }

            if (user != null)
            {
                dto.UserData = _userDataManager.GetUserDataDto(item, user);

                dto.PlayAccess = item.GetPlayAccess(user);
            }

            return dto;
        }
        /// <summary>
        /// Gets the channel info dto.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="currentProgram">The current program.</param>
        /// <param name="user">The user.</param>
        /// <returns>ChannelInfoDto.</returns>
        public ChannelInfoDto GetChannelInfoDto(LiveTvChannel info, LiveTvProgram currentProgram, User user = null)
        {
            var dto = new ChannelInfoDto
            {
                Name = info.Name,
                ServiceName = info.ServiceName,
                ChannelType = info.ChannelType,
                Number = info.Number,
                Type = info.GetClientTypeName(),
                Id = info.Id.ToString("N"),
                MediaType = info.MediaType,
                ExternalId = info.ExternalId,
                MediaSources = info.GetMediaSources(true).ToList()
            };

            if (user != null)
            {
                dto.UserData = _userDataManager.GetUserDataDto(info, user);

                dto.PlayAccess = info.GetPlayAccess(user);
            }

            var imageTag = GetImageTag(info);

            if (imageTag != null)
            {
                dto.ImageTags[ImageType.Primary] = imageTag;

                _dtoService.AttachPrimaryImageAspectRatio(dto, info);
            }

            if (currentProgram != null)
            {
                dto.CurrentProgram = GetProgramInfoDto(currentProgram, info, user);
            }

            return dto;
        }
        public RecordingInfoDto GetRecordingInfoDto(ILiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
        {
            var info = recording.RecordingInfo;

            var dto = new RecordingInfoDto
            {
                Id = GetInternalRecordingId(service.Name, info.Id).ToString("N"),
                SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                Type = recording.GetClientTypeName(),
                Overview = info.Overview,
                EndDate = info.EndDate,
                Name = info.Name,
                StartDate = info.StartDate,
                ExternalId = info.Id,
                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status = info.Status,
                StatusName = GetStatusName(info.Status),
                Path = info.Path,
                Genres = info.Genres,
                IsRepeat = info.IsRepeat,
                EpisodeTitle = info.EpisodeTitle,
                ChannelType = info.ChannelType,
                MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
                CommunityRating = GetClientCommunityRating(info.CommunityRating),
                OfficialRating = info.OfficialRating,
                Audio = info.Audio,
                IsHD = info.IsHD,
                ServiceName = service.Name,
                IsMovie = info.IsMovie,
                IsSeries = info.IsSeries,
                IsSports = info.IsSports,
                IsLive = info.IsLive,
                IsNews = info.IsNews,
                IsKids = info.IsKids,
                IsPremiere = info.IsPremiere,
                RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
                OriginalAirDate = info.OriginalAirDate,

                MediaSources = recording.GetMediaSources(true).ToList()
            };

            dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToList();

            if (info.Status == RecordingStatus.InProgress)
            {
                var now = DateTime.UtcNow.Ticks;
                var start = info.StartDate.Ticks;
                var end = info.EndDate.Ticks;

                var pct = now - start;
                pct /= end;
                pct *= 100;
                dto.CompletionPercentage = pct;
            }

            var imageTag = GetImageTag(recording);

            if (imageTag != null)
            {
                dto.ImageTags[ImageType.Primary] = imageTag;
                _dtoService.AttachPrimaryImageAspectRatio(dto, recording);
            }

            if (user != null)
            {
                dto.UserData = _userDataManager.GetUserDataDto(recording, user);

                dto.PlayAccess = recording.GetPlayAccess(user);
            }

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (channel != null)
            {
                dto.ChannelName = channel.Name;

                if (!string.IsNullOrEmpty(channel.PrimaryImagePath))
                {
                    dto.ChannelPrimaryImageTag = GetImageTag(channel);
                }
            }

            return dto;
        }
示例#6
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "tvchannels", _fileSystem.GetValidFilename(channelInfo.Name));

            var fileInfo = new DirectoryInfo(path);

            var isNew = false;

            if (!fileInfo.Exists)
            {
                _logger.Debug("Creating directory {0}", path);

                Directory.CreateDirectory(path);
                fileInfo = new DirectoryInfo(path);

                if (!fileInfo.Exists)
                {
                    throw new IOException("Path not created: " + path);
                }

                isNew = true;
            }

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null || !string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            var replaceImages = new List<ImageType>();

            if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }
            if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }

            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;
            
            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions
            {
                ForceSave = isNew,
                ReplaceImages = replaceImages.Distinct().ToList()

            }, cancellationToken);

            return item;
        }
示例#7
0
        private async Task<LiveTvProgram> GetProgram(ProgramInfo info, LiveTvChannel channel, ChannelType channelType, string serviceName, CancellationToken cancellationToken)
        {
            var id = _tvDtoService.GetInternalProgramId(serviceName, info.Id);

            var item = _libraryManager.GetItemById(id) as LiveTvProgram;
            var isNew = false;
            var forceUpdate = false;

            if (item == null)
            {
                isNew = true;
                item = new LiveTvProgram
                {
                    Name = info.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    ExternalEtag = info.Etag
                };
            }

            //item.ChannelType = channelType;
            if (!string.Equals(item.ServiceName, serviceName, StringComparison.Ordinal))
            {
                forceUpdate = true;
            }
            item.ServiceName = serviceName;

            item.Audio = info.Audio;
            item.ChannelId = channel.Id.ToString("N");
            item.CommunityRating = item.CommunityRating ?? info.CommunityRating;
            item.EndDate = info.EndDate;
            item.EpisodeTitle = info.EpisodeTitle;
            item.ExternalId = info.Id;
            item.Genres = info.Genres;
            item.IsHD = info.IsHD;
            item.IsKids = info.IsKids;
            item.IsLive = info.IsLive;
            item.IsMovie = info.IsMovie;
            item.IsNews = info.IsNews;
            item.IsPremiere = info.IsPremiere;
            item.IsRepeat = info.IsRepeat;
            item.IsSeries = info.IsSeries;
            item.IsSports = info.IsSports;
            item.Name = info.Name;
            item.OfficialRating = item.OfficialRating ?? info.OfficialRating;
            item.Overview = item.Overview ?? info.Overview;
            item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks;
            item.StartDate = info.StartDate;
            item.HomePageUrl = info.HomePageUrl;

            item.ProductionYear = info.ProductionYear;
            item.PremiereDate = info.OriginalAirDate;

            item.IndexNumber = info.EpisodeNumber;
            item.ParentIndexNumber = info.SeasonNumber;

            if (!item.HasImage(ImageType.Primary))
            {
                if (!string.IsNullOrWhiteSpace(info.ImagePath))
                {
                    item.SetImage(new ItemImageInfo
                    {
                        Path = info.ImagePath,
                        Type = ImageType.Primary,
                        IsPlaceholder = true
                    }, 0);
                }
                else if (!string.IsNullOrWhiteSpace(info.ImageUrl))
                {
                    item.SetImage(new ItemImageInfo
                    {
                        Path = info.ImageUrl,
                        Type = ImageType.Primary,
                        IsPlaceholder = true
                    }, 0);
                }
            }

            if (isNew)
            {
                await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
            }
            else if (forceUpdate || string.IsNullOrWhiteSpace(info.Etag))
            {
                await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                // Increment this whenver some internal change deems it necessary
                var etag = info.Etag + "4";

                if (!string.Equals(etag, item.ExternalEtag, StringComparison.OrdinalIgnoreCase))
                {
                    item.ExternalEtag = etag;
                    await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
                }
            }

            _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem));

            return item;
        }
示例#8
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, Guid parentFolderId, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                };

                isNew = true;
            }

            if (!string.Equals(channelInfo.Id, item.ExternalId))
            {
                isNew = true;
            }
            item.ExternalId = channelInfo.Id;

            item.ChannelType = channelInfo.ChannelType;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            //if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            //{
            //    isNew = true;
            //    replaceImages.Add(ImageType.Primary);
            //}
            //if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            //{
            //    isNew = true;
            //    replaceImages.Add(ImageType.Primary);
            //}

            if (!item.HasImage(ImageType.Primary))
            {
                if (!string.IsNullOrWhiteSpace(channelInfo.ImagePath))
                {
                    item.SetImagePath(ImageType.Primary, channelInfo.ImagePath);
                }
                else if (!string.IsNullOrWhiteSpace(channelInfo.ImageUrl))
                {
                    item.SetImagePath(ImageType.Primary, channelInfo.ImageUrl);
                }
            }

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
            {
                ForceSave = isNew

            }, cancellationToken);

            return item;
        }
示例#9
0
        public void AddChannelInfo(BaseItemDto dto, LiveTvChannel channel, DtoOptions options, User user)
        {
            dto.MediaSources = channel.GetMediaSources(true).ToList();

            var now = DateTime.UtcNow;

            var programs = _libraryManager.GetItems(new InternalItemsQuery
            {
                IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
                ChannelIds = new[] { channel.Id.ToString("N") },
                MaxStartDate = now,
                MinEndDate = now,
                Limit = 1,
                SortBy = new[] { "StartDate" }

            }).Items.Cast<LiveTvProgram>();

            var currentProgram = programs.FirstOrDefault();

            if (currentProgram != null)
            {
                dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, options, user);
            }
        }
示例#10
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            var replaceImages = new List<ImageType>();

            if (!string.Equals(item.ProviderImageUrl, channelInfo.ImageUrl, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }
            if (!string.Equals(item.ProviderImagePath, channelInfo.ImagePath, StringComparison.OrdinalIgnoreCase))
            {
                isNew = true;
                replaceImages.Add(ImageType.Primary);
            }

            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            await item.RefreshMetadata(new MetadataRefreshOptions
            {
                ForceSave = isNew,
                ReplaceImages = replaceImages.Distinct().ToList()

            }, cancellationToken);

            return item;
        }
示例#11
0
        private Tuple<LiveTvProgram, bool, bool> GetProgram(ProgramInfo info, Dictionary<Guid, LiveTvProgram> allExistingPrograms, LiveTvChannel channel, ChannelType channelType, string serviceName, CancellationToken cancellationToken)
        {
            var id = _tvDtoService.GetInternalProgramId(serviceName, info.Id);

            LiveTvProgram item = null;
            allExistingPrograms.TryGetValue(id, out item);

            var isNew = false;
            var forceUpdate = false;

            if (item == null)
            {
                isNew = true;
                item = new LiveTvProgram
                {
                    Name = info.Name,
                    Id = id,
                    DateCreated = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    ExternalEtag = info.Etag
                };
            }

            var seriesId = info.SeriesId;

            if (!item.ParentId.Equals(channel.Id))
            {
                forceUpdate = true;
            }
            item.ParentId = channel.Id;

            //item.ChannelType = channelType;
            if (!string.Equals(item.ServiceName, serviceName, StringComparison.Ordinal))
            {
                forceUpdate = true;
            }
            item.ServiceName = serviceName;

            item.Audio = info.Audio;
            item.ChannelId = channel.Id.ToString("N");
            item.CommunityRating = item.CommunityRating ?? info.CommunityRating;

            item.EpisodeTitle = info.EpisodeTitle;
            item.ExternalId = info.Id;
            item.ExternalSeriesIdLegacy = seriesId;

            if (!string.IsNullOrWhiteSpace(seriesId) && !string.Equals(item.ExternalSeriesId, seriesId, StringComparison.Ordinal))
            {
                forceUpdate = true;
            }
            item.ExternalSeriesId = seriesId;

            item.Genres = info.Genres;
            item.IsHD = info.IsHD;
            item.IsKids = info.IsKids;
            item.IsLive = info.IsLive;
            item.IsMovie = info.IsMovie;
            item.IsNews = info.IsNews;
            item.IsPremiere = info.IsPremiere;
            item.IsRepeat = info.IsRepeat;
            item.IsSeries = info.IsSeries;
            item.IsSports = info.IsSports;
            item.Name = info.Name;
            item.OfficialRating = item.OfficialRating ?? info.OfficialRating;
            item.Overview = item.Overview ?? info.Overview;
            item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks;

            if (item.StartDate != info.StartDate)
            {
                forceUpdate = true;
            }
            item.StartDate = info.StartDate;

            if (item.EndDate != info.EndDate)
            {
                forceUpdate = true;
            }
            item.EndDate = info.EndDate;

            item.HomePageUrl = info.HomePageUrl;

            item.ProductionYear = info.ProductionYear;

            if (!info.IsSeries || info.IsRepeat)
            {
                item.PremiereDate = info.OriginalAirDate;
            }

            item.IndexNumber = info.EpisodeNumber;
            item.ParentIndexNumber = info.SeasonNumber;

            if (!item.HasImage(ImageType.Primary))
            {
                if (!string.IsNullOrWhiteSpace(info.ImagePath))
                {
                    item.SetImage(new ItemImageInfo
                    {
                        Path = info.ImagePath,
                        Type = ImageType.Primary,
                        IsPlaceholder = true
                    }, 0);
                }
                else if (!string.IsNullOrWhiteSpace(info.ImageUrl))
                {
                    item.SetImage(new ItemImageInfo
                    {
                        Path = info.ImageUrl,
                        Type = ImageType.Primary,
                        IsPlaceholder = true
                    }, 0);
                }
            }

            var isUpdated = false;
            if (isNew)
            {
            }
            else if (forceUpdate || string.IsNullOrWhiteSpace(info.Etag))
            {
                isUpdated = true;
            }
            else
            {
                // Increment this whenver some internal change deems it necessary
                var etag = info.Etag + "4";

                if (!string.Equals(etag, item.ExternalEtag, StringComparison.OrdinalIgnoreCase))
                {
                    item.ExternalEtag = etag;
                    isUpdated = true;
                }
            }

            return new Tuple<LiveTvProgram, bool, bool>(item, isNew, isUpdated);
        }
        private async Task<bool> DownloadImage(LiveTvChannel item, CancellationToken cancellationToken)
        {
            Stream imageStream = null;
            string contentType = null;

            if (!string.IsNullOrEmpty(item.ProviderImagePath))
            {
                contentType = "image/" + Path.GetExtension(item.ProviderImagePath).ToLower();
                imageStream = _fileSystem.GetFileStream(item.ProviderImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true);
            }
            else if (!string.IsNullOrEmpty(item.ProviderImageUrl))
            {
                var options = new HttpRequestOptions
                {
                    CancellationToken = cancellationToken,
                    Url = item.ProviderImageUrl
                };

                var response = await _httpClient.GetResponse(options).ConfigureAwait(false);

                if (!response.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
                {
                    Logger.Error("Provider did not return an image content type.");
                    return false;
                }

                imageStream = response.Content;
                contentType = response.ContentType;
            }
            else if (item.HasProviderImage ?? true)
            {
                var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, item.ServiceName, StringComparison.OrdinalIgnoreCase));

                if (service != null)
                {
                    try
                    {
                        var response = await service.GetChannelImageAsync(item.ExternalId, cancellationToken).ConfigureAwait(false);

                        if (response != null)
                        {
                            imageStream = response.Stream;
                            contentType = response.MimeType;
                        }
                    }
                    catch (NotImplementedException)
                    {
                        return false;
                    }
                }
            }

            if (imageStream != null)
            {
                // Dummy up the original url
                var url = item.ServiceName + item.ExternalId;

                await _providerManager.SaveImage(item, imageStream, contentType, ImageType.Primary, null, url, cancellationToken).ConfigureAwait(false);
                return true;
            }

            return false;
        }
示例#13
0
        /// <summary>
        /// Gets the channel info dto.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="currentProgram">The current program.</param>
        /// <param name="user">The user.</param>
        /// <returns>ChannelInfoDto.</returns>
        public ChannelInfoDto GetChannelInfoDto(LiveTvChannel info, LiveTvProgram currentProgram, User user = null)
        {
            var dto = new ChannelInfoDto
            {
                Name = info.Name,
                ServiceName = info.ServiceName,
                ChannelType = info.ChannelType,
                Number = info.Number,
                Type = info.GetClientTypeName(),
                Id = info.Id.ToString("N"),
                MediaType = info.MediaType,
                ExternalId = info.ExternalId,
                MediaSources = _dtoService.GetMediaSources(info)
            };

            if (user != null)
            {
                dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));

                dto.PlayAccess = info.GetPlayAccess(user);
            }

            var imageTag = GetImageTag(info);

            if (imageTag.HasValue)
            {
                dto.ImageTags[ImageType.Primary] = imageTag.Value;
            }

            if (currentProgram != null)
            {
                dto.CurrentProgram = GetProgramInfoDto(currentProgram, info, user);
            }

            return dto;
        }
示例#14
0
        private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name));

            var fileInfo = new DirectoryInfo(path);

            var isNew = false;

            if (!fileInfo.Exists)
            {
                Directory.CreateDirectory(path);
                fileInfo = new DirectoryInfo(path);

                if (!fileInfo.Exists)
                {
                    throw new IOException("Path not created: " + path);
                }

                isNew = true;
            }

            var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id);

            var item = _itemRepo.RetrieveItem(id) as LiveTvChannel;

            if (item == null)
            {
                item = new LiveTvChannel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path
                };

                isNew = true;
            }

            item.ChannelType = channelInfo.ChannelType;
            item.ProviderImageUrl = channelInfo.ImageUrl;
            item.HasProviderImage = channelInfo.HasImage;
            item.ProviderImagePath = channelInfo.ImagePath;
            item.ExternalId = channelInfo.Id;
            item.ServiceName = serviceName;
            item.Number = channelInfo.Number;

            if (string.IsNullOrEmpty(item.Name))
            {
                item.Name = channelInfo.Name;
            }

            // Set this now so we don't cause additional file system access during provider executions
            item.ResetResolveArgs(fileInfo);

            await item.RefreshMetadata(cancellationToken, forceSave: isNew, resetResolveArgs: false);

            return item;
        }
        /// <summary>
        /// Gets the channel info dto.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="user">The user.</param>
        /// <returns>ChannelInfoDto.</returns>
        public ChannelInfoDto GetChannelInfoDto(LiveTvChannel info, User user = null)
        {
            var channelInfo = info.ChannelInfo;

            var dto = new ChannelInfoDto
            {
                Name = info.Name,
                ServiceName = info.ServiceName,
                ChannelType = channelInfo.ChannelType,
                Number = channelInfo.Number,
                Type = info.GetClientTypeName(),
                Id = info.Id.ToString("N"),
                MediaType = info.MediaType,
                ExternalId = channelInfo.Id
            };

            if (user != null)
            {
                dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
            }

            var imageTag = GetImageTag(info);

            if (imageTag.HasValue)
            {
                dto.ImageTags[ImageType.Primary] = imageTag.Value;
            }

            return dto;
        }
        public RecordingInfoDto GetRecordingInfoDto(LiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
        {
            var info = recording.RecordingInfo;
            
            var dto = new RecordingInfoDto
            {
                Id = GetInternalRecordingId(service.Name, info.Id).ToString("N"),
                SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
                Type = recording.GetClientTypeName(),
                Overview = info.Overview,
                EndDate = info.EndDate,
                Name = info.Name,
                StartDate = info.StartDate,
                ExternalId = info.Id,
                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
                Status = info.Status,
                Path = info.Path,
                Genres = info.Genres,
                IsRepeat = info.IsRepeat,
                EpisodeTitle = info.EpisodeTitle,
                ChannelType = info.ChannelType,
                MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
                CommunityRating = GetClientCommunityRating(info.CommunityRating),
                OfficialRating = info.OfficialRating,
                Audio = info.Audio,
                IsHD = info.IsHD,
                ServiceName = service.Name,
                Url = info.Url,
                IsMovie = info.IsMovie,
                IsSeries = info.IsSeries,
                IsSports = info.IsSports,
                IsLive = info.IsLive,
                IsNews = info.IsNews,
                IsKids = info.IsKids,
                IsPremiere = info.IsPremiere,
                RunTimeTicks = (info.EndDate - info.StartDate).Ticks
            };

            var imageTag = GetImageTag(recording);

            if (imageTag.HasValue)
            {
                dto.ImageTags[ImageType.Primary] = imageTag.Value;
            }

            if (user != null)
            {
                dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, recording.GetUserDataKey()));
            }

            if (!string.IsNullOrEmpty(info.ProgramId))
            {
                dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
            }

            if (channel != null)
            {
                dto.ChannelName = channel.ChannelInfo.Name;
            }
            
            return dto;
        }