private ProgramInfo GetProgram(Channel channel, EpgEvent2 epg)
        {
            var info = new ProgramInfo
            {
                ChannelId = channel.channelOID.ToString(_usCulture),
                Id = epg.OID.ToString(_usCulture),
                Overview = epg.Desc,
                StartDate = DateTime.Parse(epg.StartTime).ToUniversalTime(),
                EndDate = DateTime.Parse(epg.EndTime).ToUniversalTime(),
                Genres = epg.Genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList(),
                OriginalAirDate = DateTime.Parse(epg.OriginalAirdate).ToUniversalTime(),
                Name = epg.Title,
                OfficialRating = epg.Rating,
                CommunityRating = ParseCommunityRating(epg.StarRating),
                EpisodeTitle = epg.Subtitle,
                Audio = ParseAudio(epg.Audio),
                IsHD = string.Equals(epg.Quality, "hdtv", StringComparison.OrdinalIgnoreCase),
                IsRepeat = !epg.FirstRun,
                IsSeries = !string.IsNullOrEmpty(epg.Subtitle),
                ImageUrl = string.IsNullOrEmpty(epg.FanArt) ? null : (_baseUrl + "/" + epg.FanArt),
                HasImage = !string.IsNullOrEmpty(epg.FanArt),
                IsNews = epg.Genres.Contains("news", StringComparer.OrdinalIgnoreCase),
                IsMovie = epg.Genres.Contains("movie", StringComparer.OrdinalIgnoreCase),
                IsKids = epg.Genres.Contains("kids", StringComparer.OrdinalIgnoreCase),

                IsSports = epg.Genres.Contains("sports", StringComparer.OrdinalIgnoreCase) ||
                    epg.Genres.Contains("Sports non-event", StringComparer.OrdinalIgnoreCase) ||
                    epg.Genres.Contains("Sports event", StringComparer.OrdinalIgnoreCase) ||
                    epg.Genres.Contains("Sports talk", StringComparer.OrdinalIgnoreCase) ||
                    epg.Genres.Contains("Sports news", StringComparer.OrdinalIgnoreCase)
            };

            return info;
        }
 /// <summary>
 /// Gets the channel info dto.
 /// </summary>
 /// <param name="info">The info.</param>
 /// <returns>ChannelInfoDto.</returns>
 public ChannelInfoDto GetChannelInfoDto(Channel info)
 {
     return new ChannelInfoDto
     {
         Name = info.Name,
         ServiceName = info.ServiceName,
         ChannelType = info.ChannelType,
         ChannelId = info.ChannelId,
         Number = info.ChannelNumber,
         PrimaryImageTag = GetLogoImageTag(info),
         Type = info.GetType().Name,
         Id = info.Id.ToString("N"),
         MediaType = info.MediaType
     };
 }
        private async Task<Channel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
        {
            var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(serviceName), _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, channelInfo.Name);

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

            if (item == null)
            {
                item = new Channel
                {
                    Name = channelInfo.Name,
                    Id = id,
                    DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
                    DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
                    Path = path,
                    ChannelId = channelInfo.Id,
                    ChannelNumber = channelInfo.Number,
                    ServiceName = serviceName,
                    HasProviderImage = channelInfo.HasImage
                };

                isNew = true;
            }

            // 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;
        }
        private Guid? GetLogoImageTag(Channel info)
        {
            var path = info.PrimaryImagePath;

            if (string.IsNullOrEmpty(path))
            {
                return null;
            }

            try
            {
                return _imageProcessor.GetImageCacheTag(info, ImageType.Primary, path);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error getting channel image info for {0}", ex, info.Name);
            }

            return null;
        }
        public ProgramInfoDto GetProgramInfoDto(ProgramInfo program, Channel channel, User user = null)
        {
            var dto = new ProgramInfoDto
            {
                Id = GetInternalProgramId(channel.ServiceName, program.Id).ToString("N"),
                ChannelId = channel.Id.ToString("N"),
                Overview = program.Overview,
                EndDate = program.EndDate,
                Genres = program.Genres,
                ExternalId = program.Id,
                Name = program.Name,
                ServiceName = channel.ServiceName,
                StartDate = program.StartDate,
                OfficialRating = program.OfficialRating,
                IsHD = program.IsHD,
                OriginalAirDate = program.OriginalAirDate,
                Audio = program.Audio,
                CommunityRating = program.CommunityRating,
                AspectRatio = program.AspectRatio,
                IsRepeat = program.IsRepeat,
                EpisodeTitle = program.EpisodeTitle,
                ChannelName = program.ChannelName,
                IsMovie = program.IsMovie,
                IsSeries = program.IsSeries,
                IsSports = program.IsSports
            };

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

            return dto;
        }
        /// <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(Channel info, User user = null)
        {
            var dto = new ChannelInfoDto
            {
                Name = info.Name,
                ServiceName = info.ServiceName,
                ChannelType = info.ChannelType,
                Number = info.ChannelNumber,
                Type = info.GetType().Name,
                Id = info.Id.ToString("N"),
                MediaType = info.MediaType,
                ExternalId = info.ChannelId
            };

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

            var imageTag = GetLogoImageTag(info);

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

            return dto;
        }