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, MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = recording.Id }).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.HasValue) { dto.ImageTags[ImageType.Primary] = imageTag.Value; } if (user != null) { dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, recording.GetUserDataKey())); 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); }
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; }
private List<Guid> GetRecordingGroupIds(ILiveTvRecording recording) { return GetRecordingGroupNames(recording).Select(i => i.ToLower() .GetMD5()) .ToList(); }
private IEnumerable<string> GetRecordingGroupNames(ILiveTvRecording recording) { var list = new List<string>(); if (recording.IsSeries) { list.Add(recording.Name); } if (recording.IsKids) { list.Add("Kids"); } if (recording.IsMovie) { list.Add("Movies"); } if (recording.IsNews) { list.Add("News"); } if (recording.IsSports) { list.Add("Sports"); } if (!recording.IsSports && !recording.IsNews && !recording.IsMovie && !recording.IsKids && !recording.IsSeries) { list.Add("Others"); } return list; }
private ILiveTvService GetService(ILiveTvRecording item) { return GetService(item.ServiceName); }
public async Task DeleteRecording(ILiveTvRecording recording) { var service = GetService(recording.ServiceName); try { await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false); } catch (ResourceNotFoundException) { } _lastRecordingRefreshTime = DateTime.MinValue; // This is the responsibility of the live tv service await _libraryManager.DeleteItem((BaseItem)recording, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false); _lastRecordingRefreshTime = DateTime.MinValue; }
private async Task<bool> DownloadImage(ILiveTvRecording item, CancellationToken cancellationToken) { var recordingInfo = item.RecordingInfo; Stream imageStream = null; string contentType = null; if (!string.IsNullOrEmpty(recordingInfo.ImagePath)) { contentType = "image/" + Path.GetExtension(recordingInfo.ImagePath).ToLower(); imageStream = _fileSystem.GetFileStream(recordingInfo.ImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true); } else if (!string.IsNullOrEmpty(recordingInfo.ImageUrl)) { var options = new HttpRequestOptions { CancellationToken = cancellationToken, Url = recordingInfo.ImageUrl }; 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 (recordingInfo.HasImage ?? true) { var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, item.ServiceName, StringComparison.OrdinalIgnoreCase)); if (service != null) { try { var response = await service.GetRecordingImageAsync(recordingInfo.Id, 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 + recordingInfo.Id; await _providerManager.SaveImage((BaseItem)item, imageStream, contentType, ImageType.Primary, null, url, cancellationToken).ConfigureAwait(false); return true; } return false; }