Пример #1
0
        private async Task<Guid> CreateRecordingRecord(RecordingInfo info, string serviceName, Guid parentFolderId, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalRecordingId(serviceName, info.Id);

            var item = _itemRepo.RetrieveItem(id);

            if (item == null)
            {
                if (info.ChannelType == ChannelType.TV)
                {
                    item = new LiveTvVideoRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow,
                        VideoType = VideoType.VideoFile
                    };
                }
                else
                {
                    item = new LiveTvAudioRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow
                    };
                }

                isNew = true;
            }

            item.ChannelId = _tvDtoService.GetInternalChannelId(serviceName, info.ChannelId).ToString("N");
            item.CommunityRating = info.CommunityRating;
            item.OfficialRating = info.OfficialRating;
            item.Overview = info.Overview;
            item.EndDate = info.EndDate;
            item.Genres = info.Genres;
            item.PremiereDate = info.OriginalAirDate;

            var recording = (ILiveTvRecording)item;

            recording.ExternalId = info.Id;

            var dataChanged = false;

            recording.Audio = info.Audio;
            recording.EndDate = info.EndDate;
            recording.EpisodeTitle = info.EpisodeTitle;
            recording.IsHD = info.IsHD;
            recording.IsKids = info.IsKids;
            recording.IsLive = info.IsLive;
            recording.IsMovie = info.IsMovie;
            recording.IsNews = info.IsNews;
            recording.IsPremiere = info.IsPremiere;
            recording.IsRepeat = info.IsRepeat;
            recording.IsSports = info.IsSports;
            recording.SeriesTimerId = info.SeriesTimerId;
            recording.StartDate = info.StartDate;

            if (!dataChanged)
            {
                dataChanged = recording.IsSeries != info.IsSeries;
            }
            recording.IsSeries = info.IsSeries;

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

            var statusChanged = info.Status != recording.Status;

            recording.Status = info.Status;

            recording.ServiceName = serviceName;

            if (!string.IsNullOrEmpty(info.Path))
            {
                if (!dataChanged)
                {
                    dataChanged = !string.Equals(item.Path, info.Path);
                }
                var fileInfo = _fileSystem.GetFileInfo(info.Path);

                recording.DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo);
                recording.DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo);
                item.Path = info.Path;
            }
            else if (!string.IsNullOrEmpty(info.Url))
            {
                if (!dataChanged)
                {
                    dataChanged = !string.Equals(item.Path, info.Url);
                }
                item.Path = info.Url;
            }

            var metadataRefreshMode = MetadataRefreshMode.Default;

            if (isNew)
            {
                await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
            }
            else if (dataChanged || info.DateLastUpdated > recording.DateLastSaved || statusChanged)
            {
                metadataRefreshMode = MetadataRefreshMode.FullRefresh;
                await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
            }

            _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
            {
                MetadataRefreshMode = metadataRefreshMode
            });

            return item.Id;
        }
Пример #2
0
        private async Task<ILiveTvRecording> GetRecording(RecordingInfo info, string serviceName, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalRecordingId(serviceName, info.Id);

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

            if (item == null)
            {
                if (info.ChannelType == ChannelType.TV)
                {
                    item = new LiveTvVideoRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow,
                        VideoType = VideoType.VideoFile
                    };
                }
                else
                {
                    item = new LiveTvAudioRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow
                    };
                }

                isNew = true;
            }

            item.RecordingInfo = info;
            item.ServiceName = serviceName;

            var originalPath = item.Path;

            if (!string.IsNullOrEmpty(info.Path))
            {
                item.Path = info.Path;
            }
            else if (!string.IsNullOrEmpty(info.Url))
            {
                item.Path = info.Url;
            }

            var pathChanged = !string.Equals(originalPath, item.Path);

            await item.RefreshMetadata(new MetadataRefreshOptions
            {
                ForceSave = isNew || pathChanged

            }, cancellationToken);

            _libraryManager.RegisterItem((BaseItem)item);

            return item;
        }
Пример #3
0
        private async Task<Guid> CreateRecordingRecord(RecordingInfo info, string serviceName, CancellationToken cancellationToken)
        {
            var isNew = false;

            var id = _tvDtoService.GetInternalRecordingId(serviceName, info.Id);

            var item = _itemRepo.RetrieveItem(id);

            if (item == null)
            {
                if (info.ChannelType == ChannelType.TV)
                {
                    item = new LiveTvVideoRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow,
                        VideoType = VideoType.VideoFile
                    };
                }
                else
                {
                    item = new LiveTvAudioRecording
                    {
                        Name = info.Name,
                        Id = id,
                        DateCreated = DateTime.UtcNow,
                        DateModified = DateTime.UtcNow
                    };
                }

                isNew = true;
            }

            item.ChannelId = _tvDtoService.GetInternalChannelId(serviceName, info.ChannelId).ToString("N");
            item.CommunityRating = info.CommunityRating;
            item.OfficialRating = info.OfficialRating;
            item.Overview = info.Overview;
            item.EndDate = info.EndDate;
            item.Genres = info.Genres;

            var recording = (ILiveTvRecording)item;

            recording.ExternalId = info.Id;

            recording.ProgramId = _tvDtoService.GetInternalProgramId(serviceName, info.ProgramId).ToString("N");
            recording.Audio = info.Audio;
            recording.ChannelType = info.ChannelType;
            recording.EndDate = info.EndDate;
            recording.EpisodeTitle = info.EpisodeTitle;
            recording.ProviderImagePath = info.ImagePath;
            recording.ProviderImageUrl = info.ImageUrl;
            recording.IsHD = info.IsHD;
            recording.IsKids = info.IsKids;
            recording.IsLive = info.IsLive;
            recording.IsMovie = info.IsMovie;
            recording.IsNews = info.IsNews;
            recording.IsPremiere = info.IsPremiere;
            recording.IsRepeat = info.IsRepeat;
            recording.IsSeries = info.IsSeries;
            recording.IsSports = info.IsSports;
            recording.OriginalAirDate = info.OriginalAirDate;
            recording.SeriesTimerId = info.SeriesTimerId;
            recording.StartDate = info.StartDate;
            recording.Status = info.Status;

            recording.ServiceName = serviceName;

            var originalPath = item.Path;

            if (!string.IsNullOrEmpty(info.Path))
            {
                item.Path = info.Path;
            }
            else if (!string.IsNullOrEmpty(info.Url))
            {
                item.Path = info.Url;
            }

            var pathChanged = !string.Equals(originalPath, item.Path);

            if (isNew)
            {
                await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
            }
            else if (pathChanged)
            {
                await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
            }

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

            return item.Id;
        }