diff options
| author | Luke <luke.pulverenti@gmail.com> | 2015-01-10 01:59:48 -0500 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2015-01-10 01:59:48 -0500 |
| commit | 18b5168f05dc325985ac6a7b2b5b390fa4b12042 (patch) | |
| tree | 7e440e3267895f7ce161ac5ae3d5723e0894bd5f /MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs | |
| parent | e3a1c13e7cc8c49eb66b395b4810339f41fdf6b3 (diff) | |
| parent | e97848289600570b489b6fdb608014b383772523 (diff) | |
Merge pull request #971 from MediaBrowser/dev
3.0.5482.4
Diffstat (limited to 'MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index 7a363c54a..698806d09 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Common.Progress; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; @@ -337,16 +338,19 @@ namespace MediaBrowser.Server.Implementations.Sync cancellationToken.ThrowIfCancellationRequested(); - await ProcessJobItem(item, cancellationToken).ConfigureAwait(false); + var innerProgress = new ActionableProgress<double>(); var job = _syncRepo.GetJob(item.JobId); + await ProcessJobItem(job, item, innerProgress, cancellationToken).ConfigureAwait(false); + + job = _syncRepo.GetJob(item.JobId); await UpdateJobStatus(job).ConfigureAwait(false); index++; } } - private async Task ProcessJobItem(SyncJobItem jobItem, CancellationToken cancellationToken) + private async Task ProcessJobItem(SyncJob job, SyncJobItem jobItem, IProgress<double> progress, CancellationToken cancellationToken) { var item = _libraryManager.GetItemById(jobItem.ItemId); if (item == null) @@ -369,15 +373,17 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.Progress = 0; jobItem.Status = SyncJobItemStatus.Converting; + var user = _userManager.GetUserById(job.UserId); + var video = item as Video; if (video != null) { - await Sync(jobItem, video, deviceProfile, cancellationToken).ConfigureAwait(false); + await Sync(jobItem, video, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false); } else if (item is Audio) { - await Sync(jobItem, (Audio)item, deviceProfile, cancellationToken).ConfigureAwait(false); + await Sync(jobItem, (Audio)item, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false); } else if (item is Photo) @@ -391,7 +397,7 @@ namespace MediaBrowser.Server.Implementations.Sync } } - private async Task Sync(SyncJobItem jobItem, Video item, DeviceProfile profile, CancellationToken cancellationToken) + private async Task Sync(SyncJobItem jobItem, Video item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken) { var options = new VideoOptions { @@ -399,7 +405,7 @@ namespace MediaBrowser.Server.Implementations.Sync ItemId = item.Id.ToString("N"), DeviceId = jobItem.TargetId, Profile = profile, - MediaSources = item.GetMediaSources(false).ToList() + MediaSources = item.GetMediaSources(false, user).ToList() }; var streamInfo = new StreamBuilder().BuildVideoItem(options); @@ -410,12 +416,34 @@ namespace MediaBrowser.Server.Implementations.Sync if (streamInfo.PlayMethod == PlayMethod.Transcode) { jobItem.Status = SyncJobItemStatus.Converting; + jobItem.RequiresConversion = true; await _syncRepo.Update(jobItem).ConfigureAwait(false); - jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, profile), new Progress<double>(), cancellationToken); + try + { + jobItem.OutputPath = await _mediaEncoder.EncodeVideo(new EncodingJobOptions(streamInfo, profile), progress, + cancellationToken); + } + catch (OperationCanceledException) + { + jobItem.Status = SyncJobItemStatus.Queued; + } + catch (Exception ex) + { + jobItem.Status = SyncJobItemStatus.Failed; + _logger.ErrorException("Error during sync transcoding", ex); + } + + if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) + { + await _syncRepo.Update(jobItem).ConfigureAwait(false); + return; + } } else { + jobItem.RequiresConversion = false; + if (mediaSource.Protocol == MediaProtocol.File) { jobItem.OutputPath = mediaSource.Path; @@ -435,7 +463,7 @@ namespace MediaBrowser.Server.Implementations.Sync await _syncRepo.Update(jobItem).ConfigureAwait(false); } - private async Task Sync(SyncJobItem jobItem, Audio item, DeviceProfile profile, CancellationToken cancellationToken) + private async Task Sync(SyncJobItem jobItem, Audio item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken) { var options = new AudioOptions { @@ -443,7 +471,7 @@ namespace MediaBrowser.Server.Implementations.Sync ItemId = item.Id.ToString("N"), DeviceId = jobItem.TargetId, Profile = profile, - MediaSources = item.GetMediaSources(false).ToList() + MediaSources = item.GetMediaSources(false, user).ToList() }; var streamInfo = new StreamBuilder().BuildAudioItem(options); @@ -454,12 +482,33 @@ namespace MediaBrowser.Server.Implementations.Sync if (streamInfo.PlayMethod == PlayMethod.Transcode) { jobItem.Status = SyncJobItemStatus.Converting; + jobItem.RequiresConversion = true; await _syncRepo.Update(jobItem).ConfigureAwait(false); - - jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile), new Progress<double>(), cancellationToken); + + try + { + jobItem.OutputPath = await _mediaEncoder.EncodeAudio(new EncodingJobOptions(streamInfo, profile), progress, cancellationToken); + } + catch (OperationCanceledException) + { + jobItem.Status = SyncJobItemStatus.Queued; + } + catch (Exception ex) + { + jobItem.Status = SyncJobItemStatus.Failed; + _logger.ErrorException("Error during sync transcoding", ex); + } + + if (jobItem.Status == SyncJobItemStatus.Failed || jobItem.Status == SyncJobItemStatus.Queued) + { + await _syncRepo.Update(jobItem).ConfigureAwait(false); + return; + } } else { + jobItem.RequiresConversion = false; + if (mediaSource.Protocol == MediaProtocol.File) { jobItem.OutputPath = mediaSource.Path; |
