mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	Merge pull request #7241 from Bond-009/async5
This commit is contained in:
		
						commit
						b6489e73ab
					
				@ -343,7 +343,8 @@ namespace Emby.Dlna
 | 
				
			|||||||
                        var fileOptions = AsyncFile.WriteOptions;
 | 
					                        var fileOptions = AsyncFile.WriteOptions;
 | 
				
			||||||
                        fileOptions.Mode = FileMode.Create;
 | 
					                        fileOptions.Mode = FileMode.Create;
 | 
				
			||||||
                        fileOptions.PreallocationSize = length;
 | 
					                        fileOptions.PreallocationSize = length;
 | 
				
			||||||
                        using (var fileStream = new FileStream(path, fileOptions))
 | 
					                        var fileStream = new FileStream(path, fileOptions);
 | 
				
			||||||
 | 
					                        await using (fileStream.ConfigureAwait(false))
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            await stream.CopyToAsync(fileStream).ConfigureAwait(false);
 | 
					                            await stream.CopyToAsync(fileStream).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
				
			|||||||
@ -180,7 +180,7 @@ namespace Emby.Dlna.PlayTo
 | 
				
			|||||||
                    _currentPlaylistIndex = currentItemIndex;
 | 
					                    _currentPlaylistIndex = currentItemIndex;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await SendNextTrackMessage(currentItemIndex, CancellationToken.None);
 | 
					                await SendNextTrackMessage(currentItemIndex, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception ex)
 | 
					            catch (Exception ex)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -453,7 +453,7 @@ namespace Emby.Dlna.PlayTo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
					                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
				
			||||||
                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
					                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
				
			||||||
                    await SendNextTrackMessage(newItemIndex, CancellationToken.None);
 | 
					                    await SendNextTrackMessage(newItemIndex, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -654,7 +654,7 @@ namespace Emby.Dlna.PlayTo
 | 
				
			|||||||
            await _device.SetAvTransport(currentitem.StreamUrl, GetDlnaHeaders(currentitem), currentitem.Didl, cancellationToken).ConfigureAwait(false);
 | 
					            await _device.SetAvTransport(currentitem.StreamUrl, GetDlnaHeaders(currentitem), currentitem.Didl, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
					            // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
				
			||||||
            await SendNextTrackMessage(index, cancellationToken);
 | 
					            await SendNextTrackMessage(index, cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var streamInfo = currentitem.StreamInfo;
 | 
					            var streamInfo = currentitem.StreamInfo;
 | 
				
			||||||
            if (streamInfo.StartPositionTicks > 0 && EnableClientSideSeek(streamInfo))
 | 
					            if (streamInfo.StartPositionTicks > 0 && EnableClientSideSeek(streamInfo))
 | 
				
			||||||
@ -771,7 +771,7 @@ namespace Emby.Dlna.PlayTo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
					                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
				
			||||||
                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
					                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
				
			||||||
                    await SendNextTrackMessage(newItemIndex, CancellationToken.None);
 | 
					                    await SendNextTrackMessage(newItemIndex, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (EnableClientSideSeek(newItem.StreamInfo))
 | 
					                    if (EnableClientSideSeek(newItem.StreamInfo))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -800,7 +800,7 @@ namespace Emby.Dlna.PlayTo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
					                    // Send a message to the DLNA device to notify what is the next track in the play list.
 | 
				
			||||||
                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
					                    var newItemIndex = _playlist.FindIndex(item => item.StreamUrl == newItem.StreamUrl);
 | 
				
			||||||
                    await SendNextTrackMessage(newItemIndex, CancellationToken.None);
 | 
					                    await SendNextTrackMessage(newItemIndex, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (EnableClientSideSeek(newItem.StreamInfo) && newPosition > 0)
 | 
					                    if (EnableClientSideSeek(newItem.StreamInfo) && newPosition > 0)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
				
			|||||||
@ -2014,16 +2014,16 @@ namespace Emby.Server.Implementations.Library
 | 
				
			|||||||
        public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
 | 
					        public Task UpdateItemAsync(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
 | 
				
			||||||
            => UpdateItemsAsync(new[] { item }, parent, updateReason, cancellationToken);
 | 
					            => UpdateItemsAsync(new[] { item }, parent, updateReason, cancellationToken);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason)
 | 
					        public async Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (item.IsFileProtocol)
 | 
					            if (item.IsFileProtocol)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                ProviderManager.SaveMetadata(item, updateReason);
 | 
					                await ProviderManager.SaveMetadataAsync(item, updateReason).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            item.DateLastSaved = DateTime.UtcNow;
 | 
					            item.DateLastSaved = DateTime.UtcNow;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate);
 | 
					            await UpdateImagesAsync(item, updateReason >= ItemUpdateType.ImageUpdate).ConfigureAwait(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            Directory.CreateDirectory(Path.GetDirectoryName(targetFile) ?? throw new ArgumentException("Path can't be a root directory.", nameof(targetFile)));
 | 
					            Directory.CreateDirectory(Path.GetDirectoryName(targetFile) ?? throw new ArgumentException("Path can't be a root directory.", nameof(targetFile)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var output = new FileStream(targetFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous))
 | 
					            await using (var output = new FileStream(targetFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                onStarted();
 | 
					                onStarted();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -56,14 +56,16 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                using var durationToken = new CancellationTokenSource(duration);
 | 
					                using var durationToken = new CancellationTokenSource(duration);
 | 
				
			||||||
                using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token);
 | 
					                using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token);
 | 
				
			||||||
                var linkedCancellationToken = cancellationTokenSource.Token;
 | 
					                var linkedCancellationToken = cancellationTokenSource.Token;
 | 
				
			||||||
 | 
					                var fileStream = new ProgressiveFileStream(directStreamProvider.GetStream());
 | 
				
			||||||
                await using var fileStream = new ProgressiveFileStream(directStreamProvider.GetStream());
 | 
					                await using (fileStream.ConfigureAwait(false))
 | 
				
			||||||
                await _streamHelper.CopyToAsync(
 | 
					                {
 | 
				
			||||||
                    fileStream,
 | 
					                    await _streamHelper.CopyToAsync(
 | 
				
			||||||
                    output,
 | 
					                        fileStream,
 | 
				
			||||||
                    IODefaults.CopyToBufferSize,
 | 
					                        output,
 | 
				
			||||||
                    1000,
 | 
					                        IODefaults.CopyToBufferSize,
 | 
				
			||||||
                    linkedCancellationToken).ConfigureAwait(false);
 | 
					                        1000,
 | 
				
			||||||
 | 
					                        linkedCancellationToken).ConfigureAwait(false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _logger.LogInformation("Recording completed: {FilePath}", targetFile);
 | 
					            _logger.LogInformation("Recording completed: {FilePath}", targetFile);
 | 
				
			||||||
 | 
				
			|||||||
@ -1819,16 +1819,16 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (timer.IsProgramSeries)
 | 
					                if (timer.IsProgramSeries)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    SaveSeriesNfo(timer, seriesPath);
 | 
					                    await SaveSeriesNfoAsync(timer, seriesPath).ConfigureAwait(false);
 | 
				
			||||||
                    SaveVideoNfo(timer, recordingPath, program, false);
 | 
					                    await SaveVideoNfoAsync(timer, recordingPath, program, false).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (!timer.IsMovie || timer.IsSports || timer.IsNews)
 | 
					                else if (!timer.IsMovie || timer.IsSports || timer.IsNews)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    SaveVideoNfo(timer, recordingPath, program, true);
 | 
					                    await SaveVideoNfoAsync(timer, recordingPath, program, true).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    SaveVideoNfo(timer, recordingPath, program, false);
 | 
					                    await SaveVideoNfoAsync(timer, recordingPath, program, false).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                await SaveRecordingImages(recordingPath, program).ConfigureAwait(false);
 | 
					                await SaveRecordingImages(recordingPath, program).ConfigureAwait(false);
 | 
				
			||||||
@ -1839,7 +1839,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void SaveSeriesNfo(TimerInfo timer, string seriesPath)
 | 
					        private async Task SaveSeriesNfoAsync(TimerInfo timer, string seriesPath)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var nfoPath = Path.Combine(seriesPath, "tvshow.nfo");
 | 
					            var nfoPath = Path.Combine(seriesPath, "tvshow.nfo");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1848,61 +1848,62 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var stream = new FileStream(nfoPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
 | 
					            await using (var stream = new FileStream(nfoPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var settings = new XmlWriterSettings
 | 
					                var settings = new XmlWriterSettings
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Indent = true,
 | 
					                    Indent = true,
 | 
				
			||||||
                    Encoding = Encoding.UTF8
 | 
					                    Encoding = Encoding.UTF8,
 | 
				
			||||||
 | 
					                    Async = true
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                using (var writer = XmlWriter.Create(stream, settings))
 | 
					                await using (var writer = XmlWriter.Create(stream, settings))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteStartDocument(true);
 | 
					                    await writer.WriteStartDocumentAsync(true).ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteStartElement("tvshow");
 | 
					                    await writer.WriteStartElementAsync(null, "tvshow", null).ConfigureAwait(false);
 | 
				
			||||||
                    string id;
 | 
					                    string id;
 | 
				
			||||||
                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Tvdb.ToString(), out id))
 | 
					                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Tvdb.ToString(), out id))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("id", id);
 | 
					                        await writer.WriteElementStringAsync(null, "id", null, id).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out id))
 | 
					                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Imdb.ToString(), out id))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("imdb_id", id);
 | 
					                        await writer.WriteElementStringAsync(null, "imdb_id", null, id).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out id))
 | 
					                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out id))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("tmdbid", id);
 | 
					                        await writer.WriteElementStringAsync(null, "tmdbid", null, id).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Zap2It.ToString(), out id))
 | 
					                    if (timer.SeriesProviderIds.TryGetValue(MetadataProvider.Zap2It.ToString(), out id))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("zap2itid", id);
 | 
					                        await writer.WriteElementStringAsync(null, "zap2itid", null, id).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrWhiteSpace(timer.Name))
 | 
					                    if (!string.IsNullOrWhiteSpace(timer.Name))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("title", timer.Name);
 | 
					                        await writer.WriteElementStringAsync(null, "title", null, timer.Name).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrWhiteSpace(timer.OfficialRating))
 | 
					                    if (!string.IsNullOrWhiteSpace(timer.OfficialRating))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("mpaa", timer.OfficialRating);
 | 
					                        await writer.WriteElementStringAsync(null, "mpaa", null, timer.OfficialRating).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    foreach (var genre in timer.Genres)
 | 
					                    foreach (var genre in timer.Genres)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("genre", genre);
 | 
					                        await writer.WriteElementStringAsync(null, "genre", null, genre).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteEndElement();
 | 
					                    await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteEndDocument();
 | 
					                    await writer.WriteEndDocumentAsync().ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void SaveVideoNfo(TimerInfo timer, string recordingPath, BaseItem item, bool lockData)
 | 
					        private async Task SaveVideoNfoAsync(TimerInfo timer, string recordingPath, BaseItem item, bool lockData)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var nfoPath = Path.ChangeExtension(recordingPath, ".nfo");
 | 
					            var nfoPath = Path.ChangeExtension(recordingPath, ".nfo");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1911,29 +1912,30 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var stream = new FileStream(nfoPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
 | 
					            await using (var stream = new FileStream(nfoPath, FileMode.CreateNew, FileAccess.Write, FileShare.None))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var settings = new XmlWriterSettings
 | 
					                var settings = new XmlWriterSettings
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Indent = true,
 | 
					                    Indent = true,
 | 
				
			||||||
                    Encoding = Encoding.UTF8
 | 
					                    Encoding = Encoding.UTF8,
 | 
				
			||||||
 | 
					                    Async = true
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var options = _config.GetNfoConfiguration();
 | 
					                var options = _config.GetNfoConfiguration();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var isSeriesEpisode = timer.IsProgramSeries;
 | 
					                var isSeriesEpisode = timer.IsProgramSeries;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                using (var writer = XmlWriter.Create(stream, settings))
 | 
					                await using (var writer = XmlWriter.Create(stream, settings))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteStartDocument(true);
 | 
					                    await writer.WriteStartDocumentAsync(true).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (isSeriesEpisode)
 | 
					                    if (isSeriesEpisode)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteStartElement("episodedetails");
 | 
					                        await writer.WriteStartElementAsync(null, "episodedetails", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (!string.IsNullOrWhiteSpace(timer.EpisodeTitle))
 | 
					                        if (!string.IsNullOrWhiteSpace(timer.EpisodeTitle))
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("title", timer.EpisodeTitle);
 | 
					                            await writer.WriteElementStringAsync(null, "title", null, timer.EpisodeTitle).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        var premiereDate = item.PremiereDate ?? (!timer.IsRepeat ? DateTime.UtcNow : null);
 | 
					                        var premiereDate = item.PremiereDate ?? (!timer.IsRepeat ? DateTime.UtcNow : null);
 | 
				
			||||||
@ -1942,76 +1944,84 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            var formatString = options.ReleaseDateFormat;
 | 
					                            var formatString = options.ReleaseDateFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            writer.WriteElementString(
 | 
					                            await writer.WriteElementStringAsync(
 | 
				
			||||||
 | 
					                                null,
 | 
				
			||||||
                                "aired",
 | 
					                                "aired",
 | 
				
			||||||
                                premiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture));
 | 
					                                null,
 | 
				
			||||||
 | 
					                                premiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (item.IndexNumber.HasValue)
 | 
					                        if (item.IndexNumber.HasValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("episode", item.IndexNumber.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                            await writer.WriteElementStringAsync(null, "episode", null, item.IndexNumber.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (item.ParentIndexNumber.HasValue)
 | 
					                        if (item.ParentIndexNumber.HasValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("season", item.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                            await writer.WriteElementStringAsync(null, "season", null, item.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteStartElement("movie");
 | 
					                        await writer.WriteStartElementAsync(null, "movie", null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (!string.IsNullOrWhiteSpace(item.Name))
 | 
					                        if (!string.IsNullOrWhiteSpace(item.Name))
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("title", item.Name);
 | 
					                            await writer.WriteElementStringAsync(null, "title", null, item.Name).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (!string.IsNullOrWhiteSpace(item.OriginalTitle))
 | 
					                        if (!string.IsNullOrWhiteSpace(item.OriginalTitle))
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("originaltitle", item.OriginalTitle);
 | 
					                            await writer.WriteElementStringAsync(null, "originaltitle", null, item.OriginalTitle).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (item.PremiereDate.HasValue)
 | 
					                        if (item.PremiereDate.HasValue)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            var formatString = options.ReleaseDateFormat;
 | 
					                            var formatString = options.ReleaseDateFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            writer.WriteElementString(
 | 
					                            await writer.WriteElementStringAsync(
 | 
				
			||||||
 | 
					                                null,
 | 
				
			||||||
                                "premiered",
 | 
					                                "premiered",
 | 
				
			||||||
                                item.PremiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture));
 | 
					                                null,
 | 
				
			||||||
                            writer.WriteElementString(
 | 
					                                item.PremiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
 | 
					                            await writer.WriteElementStringAsync(
 | 
				
			||||||
 | 
					                                null,
 | 
				
			||||||
                                "releasedate",
 | 
					                                "releasedate",
 | 
				
			||||||
                                item.PremiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture));
 | 
					                                null,
 | 
				
			||||||
 | 
					                                item.PremiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteElementString(
 | 
					                    await writer.WriteElementStringAsync(
 | 
				
			||||||
 | 
					                        null,
 | 
				
			||||||
                        "dateadded",
 | 
					                        "dateadded",
 | 
				
			||||||
                        DateTime.Now.ToString(DateAddedFormat, CultureInfo.InvariantCulture));
 | 
					                        null,
 | 
				
			||||||
 | 
					                        DateTime.Now.ToString(DateAddedFormat, CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (item.ProductionYear.HasValue)
 | 
					                    if (item.ProductionYear.HasValue)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("year", item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                        await writer.WriteElementStringAsync(null, "year", null, item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrEmpty(item.OfficialRating))
 | 
					                    if (!string.IsNullOrEmpty(item.OfficialRating))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("mpaa", item.OfficialRating);
 | 
					                        await writer.WriteElementStringAsync(null, "mpaa", null, item.OfficialRating).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var overview = (item.Overview ?? string.Empty)
 | 
					                    var overview = (item.Overview ?? string.Empty)
 | 
				
			||||||
                        .StripHtml()
 | 
					                        .StripHtml()
 | 
				
			||||||
                        .Replace(""", "'", StringComparison.Ordinal);
 | 
					                        .Replace(""", "'", StringComparison.Ordinal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteElementString("plot", overview);
 | 
					                    await writer.WriteElementStringAsync(null, "plot", null, overview).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (item.CommunityRating.HasValue)
 | 
					                    if (item.CommunityRating.HasValue)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("rating", item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                        await writer.WriteElementStringAsync(null, "rating", null, item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    foreach (var genre in item.Genres)
 | 
					                    foreach (var genre in item.Genres)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("genre", genre);
 | 
					                        await writer.WriteElementStringAsync(null, "genre", null, genre).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var people = item.Id.Equals(Guid.Empty) ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
 | 
					                    var people = item.Id.Equals(Guid.Empty) ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
 | 
				
			||||||
@ -2023,7 +2033,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    foreach (var person in directors)
 | 
					                    foreach (var person in directors)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("director", person);
 | 
					                        await writer.WriteElementStringAsync(null, "director", null, person).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var writers = people
 | 
					                    var writers = people
 | 
				
			||||||
@ -2034,19 +2044,19 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    foreach (var person in writers)
 | 
					                    foreach (var person in writers)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("writer", person);
 | 
					                        await writer.WriteElementStringAsync(null, "writer", null, person).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    foreach (var person in writers)
 | 
					                    foreach (var person in writers)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("credits", person);
 | 
					                        await writer.WriteElementStringAsync(null, "credits", null, person).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var tmdbCollection = item.GetProviderId(MetadataProvider.TmdbCollection);
 | 
					                    var tmdbCollection = item.GetProviderId(MetadataProvider.TmdbCollection);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrEmpty(tmdbCollection))
 | 
					                    if (!string.IsNullOrEmpty(tmdbCollection))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("collectionnumber", tmdbCollection);
 | 
					                        await writer.WriteElementStringAsync(null, "collectionnumber", null, tmdbCollection).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var imdb = item.GetProviderId(MetadataProvider.Imdb);
 | 
					                    var imdb = item.GetProviderId(MetadataProvider.Imdb);
 | 
				
			||||||
@ -2054,10 +2064,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        if (!isSeriesEpisode)
 | 
					                        if (!isSeriesEpisode)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            writer.WriteElementString("id", imdb);
 | 
					                            await writer.WriteElementStringAsync(null, "id", null, imdb).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        writer.WriteElementString("imdbid", imdb);
 | 
					                        await writer.WriteElementStringAsync(null, "imdbid", null, imdb).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // No need to lock if we have identified the content already
 | 
					                        // No need to lock if we have identified the content already
 | 
				
			||||||
                        lockData = false;
 | 
					                        lockData = false;
 | 
				
			||||||
@ -2066,7 +2076,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                    var tvdb = item.GetProviderId(MetadataProvider.Tvdb);
 | 
					                    var tvdb = item.GetProviderId(MetadataProvider.Tvdb);
 | 
				
			||||||
                    if (!string.IsNullOrEmpty(tvdb))
 | 
					                    if (!string.IsNullOrEmpty(tvdb))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("tvdbid", tvdb);
 | 
					                        await writer.WriteElementStringAsync(null, "tvdbid", null, tvdb).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // No need to lock if we have identified the content already
 | 
					                        // No need to lock if we have identified the content already
 | 
				
			||||||
                        lockData = false;
 | 
					                        lockData = false;
 | 
				
			||||||
@ -2075,7 +2085,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
                    var tmdb = item.GetProviderId(MetadataProvider.Tmdb);
 | 
					                    var tmdb = item.GetProviderId(MetadataProvider.Tmdb);
 | 
				
			||||||
                    if (!string.IsNullOrEmpty(tmdb))
 | 
					                    if (!string.IsNullOrEmpty(tmdb))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("tmdbid", tmdb);
 | 
					                        await writer.WriteElementStringAsync(null, "tmdbid", null, tmdb).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // No need to lock if we have identified the content already
 | 
					                        // No need to lock if we have identified the content already
 | 
				
			||||||
                        lockData = false;
 | 
					                        lockData = false;
 | 
				
			||||||
@ -2083,26 +2093,26 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    if (lockData)
 | 
					                    if (lockData)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("lockdata", true.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
 | 
					                        await writer.WriteElementStringAsync(null, "lockdata", null, "true").ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (item.CriticRating.HasValue)
 | 
					                    if (item.CriticRating.HasValue)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("criticrating", item.CriticRating.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                        await writer.WriteElementStringAsync(null, "criticrating", null, item.CriticRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrWhiteSpace(item.Tagline))
 | 
					                    if (!string.IsNullOrWhiteSpace(item.Tagline))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("tagline", item.Tagline);
 | 
					                        await writer.WriteElementStringAsync(null, "tagline", null, item.Tagline).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    foreach (var studio in item.Studios)
 | 
					                    foreach (var studio in item.Studios)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("studio", studio);
 | 
					                        await writer.WriteElementStringAsync(null, "studio", null, studio).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteEndElement();
 | 
					                    await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteEndDocument();
 | 
					                    await writer.WriteEndDocumentAsync().ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -186,7 +186,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            var resolved = false;
 | 
					            var resolved = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read))
 | 
					            var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read);
 | 
				
			||||||
 | 
					            await using (fileStream.ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                while (true)
 | 
					                while (true)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 | 
				
			|||||||
@ -97,7 +97,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public Stream GetStream()
 | 
					        public Stream GetStream()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var stream = GetInputStream(TempFilePath);
 | 
					            var stream = new FileStream(
 | 
				
			||||||
 | 
					                TempFilePath,
 | 
				
			||||||
 | 
					                FileMode.Open,
 | 
				
			||||||
 | 
					                FileAccess.Read,
 | 
				
			||||||
 | 
					                FileShare.ReadWrite,
 | 
				
			||||||
 | 
					                IODefaults.FileStreamBufferSize,
 | 
				
			||||||
 | 
					                FileOptions.SequentialScan | FileOptions.Asynchronous);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            bool seekFile = (DateTime.UtcNow - DateOpened).TotalSeconds > 10;
 | 
					            bool seekFile = (DateTime.UtcNow - DateOpened).TotalSeconds > 10;
 | 
				
			||||||
            if (seekFile)
 | 
					            if (seekFile)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -107,15 +114,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
 | 
				
			|||||||
            return stream;
 | 
					            return stream;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected FileStream GetInputStream(string path)
 | 
					 | 
				
			||||||
            => new FileStream(
 | 
					 | 
				
			||||||
                path,
 | 
					 | 
				
			||||||
                FileMode.Open,
 | 
					 | 
				
			||||||
                FileAccess.Read,
 | 
					 | 
				
			||||||
                FileShare.ReadWrite,
 | 
					 | 
				
			||||||
                IODefaults.FileStreamBufferSize,
 | 
					 | 
				
			||||||
                FileOptions.SequentialScan | FileOptions.Asynchronous);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        protected async Task DeleteTempFiles(string path, int retryCount = 0)
 | 
					        protected async Task DeleteTempFiles(string path, int retryCount = 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (retryCount == 0)
 | 
					            if (retryCount == 0)
 | 
				
			||||||
 | 
				
			|||||||
@ -125,18 +125,20 @@ namespace Jellyfin.Server.Infrastructure
 | 
				
			|||||||
            // Copied from SendFileFallback.SendFileAsync
 | 
					            // Copied from SendFileFallback.SendFileAsync
 | 
				
			||||||
            const int BufferSize = 1024 * 16;
 | 
					            const int BufferSize = 1024 * 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await using var fileStream = new FileStream(
 | 
					            var fileStream = new FileStream(
 | 
				
			||||||
                filePath,
 | 
					                filePath,
 | 
				
			||||||
                FileMode.Open,
 | 
					                FileMode.Open,
 | 
				
			||||||
                FileAccess.Read,
 | 
					                FileAccess.Read,
 | 
				
			||||||
                FileShare.ReadWrite,
 | 
					                FileShare.ReadWrite,
 | 
				
			||||||
                bufferSize: BufferSize,
 | 
					                bufferSize: BufferSize,
 | 
				
			||||||
                options: FileOptions.Asynchronous | FileOptions.SequentialScan);
 | 
					                options: FileOptions.Asynchronous | FileOptions.SequentialScan);
 | 
				
			||||||
 | 
					            await using (fileStream.ConfigureAwait(false))
 | 
				
			||||||
            fileStream.Seek(offset, SeekOrigin.Begin);
 | 
					            {
 | 
				
			||||||
            await StreamCopyOperation
 | 
					                fileStream.Seek(offset, SeekOrigin.Begin);
 | 
				
			||||||
                .CopyToAsync(fileStream, response.Body, count, BufferSize, CancellationToken.None)
 | 
					                await StreamCopyOperation
 | 
				
			||||||
                .ConfigureAwait(true);
 | 
					                    .CopyToAsync(fileStream, response.Body, count, BufferSize, CancellationToken.None)
 | 
				
			||||||
 | 
					                    .ConfigureAwait(true);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static bool IsSymLink(string path) => (File.GetAttributes(path) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
 | 
					        private static bool IsSymLink(string path) => (File.GetAttributes(path) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
 | 
				
			||||||
 | 
				
			|||||||
@ -14,10 +14,6 @@
 | 
				
			|||||||
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
 | 
					    <GenerateDocumentationFile>true</GenerateDocumentationFile>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
 | 
					 | 
				
			||||||
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <Compile Include="..\SharedVersion.cs" />
 | 
					    <Compile Include="..\SharedVersion.cs" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
				
			|||||||
@ -549,12 +549,15 @@ namespace Jellyfin.Server
 | 
				
			|||||||
            // Get a stream of the resource contents
 | 
					            // Get a stream of the resource contents
 | 
				
			||||||
            // NOTE: The .csproj name is used instead of the assembly name in the resource path
 | 
					            // NOTE: The .csproj name is used instead of the assembly name in the resource path
 | 
				
			||||||
            const string ResourcePath = "Jellyfin.Server.Resources.Configuration.logging.json";
 | 
					            const string ResourcePath = "Jellyfin.Server.Resources.Configuration.logging.json";
 | 
				
			||||||
            await using Stream resource = typeof(Program).Assembly.GetManifestResourceStream(ResourcePath)
 | 
					            Stream resource = typeof(Program).Assembly.GetManifestResourceStream(ResourcePath)
 | 
				
			||||||
                ?? throw new InvalidOperationException($"Invalid resource path: '{ResourcePath}'");
 | 
					                ?? throw new InvalidOperationException($"Invalid resource path: '{ResourcePath}'");
 | 
				
			||||||
 | 
					            Stream dst = new FileStream(configPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
 | 
				
			||||||
            // Copy the resource contents to the expected file path for the config file
 | 
					            await using (resource.ConfigureAwait(false))
 | 
				
			||||||
            await using Stream dst = new FileStream(configPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
 | 
					            await using (dst.ConfigureAwait(false))
 | 
				
			||||||
            await resource.CopyToAsync(dst).ConfigureAwait(false);
 | 
					            {
 | 
				
			||||||
 | 
					                // Copy the resource contents to the expected file path for the config file
 | 
				
			||||||
 | 
					                await resource.CopyToAsync(dst).ConfigureAwait(false);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
 | 
				
			|||||||
@ -13,9 +13,4 @@ namespace MediaBrowser.Controller.Library
 | 
				
			|||||||
        /// <returns>System.String.</returns>
 | 
					        /// <returns>System.String.</returns>
 | 
				
			||||||
        string GetSavePath(BaseItem item);
 | 
					        string GetSavePath(BaseItem item);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public interface IConfigurableProvider
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        bool IsEnabled { get; }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,5 @@
 | 
				
			|||||||
#nullable disable
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using System.Threading;
 | 
					using System.Threading;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using MediaBrowser.Controller.Entities;
 | 
					using MediaBrowser.Controller.Entities;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace MediaBrowser.Controller.Library
 | 
					namespace MediaBrowser.Controller.Library
 | 
				
			||||||
@ -29,6 +28,7 @@ namespace MediaBrowser.Controller.Library
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="cancellationToken">The cancellation token.</param>
 | 
					        /// <param name="cancellationToken">The cancellation token.</param>
 | 
				
			||||||
        void Save(BaseItem item, CancellationToken cancellationToken);
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        Task SaveAsync(BaseItem item, CancellationToken cancellationToken);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -156,7 +156,8 @@ namespace MediaBrowser.Controller.Providers
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="updateType">Type of the update.</param>
 | 
					        /// <param name="updateType">Type of the update.</param>
 | 
				
			||||||
        void SaveMetadata(BaseItem item, ItemUpdateType updateType);
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        Task SaveMetadataAsync(BaseItem item, ItemUpdateType updateType);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Saves the metadata.
 | 
					        /// Saves the metadata.
 | 
				
			||||||
@ -164,7 +165,8 @@ namespace MediaBrowser.Controller.Providers
 | 
				
			|||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="updateType">Type of the update.</param>
 | 
					        /// <param name="updateType">Type of the update.</param>
 | 
				
			||||||
        /// <param name="savers">The metadata savers.</param>
 | 
					        /// <param name="savers">The metadata savers.</param>
 | 
				
			||||||
        void SaveMetadata(BaseItem item, ItemUpdateType updateType, IEnumerable<string> savers);
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        Task SaveMetadataAsync(BaseItem item, ItemUpdateType updateType, IEnumerable<string> savers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets the metadata options.
 | 
					        /// Gets the metadata options.
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ using System.IO;
 | 
				
			|||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading;
 | 
					using System.Threading;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using System.Xml;
 | 
					using System.Xml;
 | 
				
			||||||
using MediaBrowser.Controller.Configuration;
 | 
					using MediaBrowser.Controller.Configuration;
 | 
				
			||||||
using MediaBrowser.Controller.Entities;
 | 
					using MediaBrowser.Controller.Entities;
 | 
				
			||||||
@ -20,11 +21,6 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
    /// <inheritdoc />
 | 
					    /// <inheritdoc />
 | 
				
			||||||
    public abstract class BaseXmlSaver : IMetadataFileSaver
 | 
					    public abstract class BaseXmlSaver : IMetadataFileSaver
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// Gets the date added format.
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        public const string DateAddedFormat = "yyyy-MM-dd HH:mm:ss";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Initializes a new instance of the <see cref="BaseXmlSaver"/> class.
 | 
					        /// Initializes a new instance of the <see cref="BaseXmlSaver"/> class.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
@ -82,9 +78,7 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <returns>System.String.</returns>
 | 
					        /// <returns>System.String.</returns>
 | 
				
			||||||
        protected virtual string GetRootElementName(BaseItem item)
 | 
					        protected virtual string GetRootElementName(BaseItem item)
 | 
				
			||||||
        {
 | 
					            => "Item";
 | 
				
			||||||
            return "Item";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Determines whether [is enabled for] [the specified item].
 | 
					        /// Determines whether [is enabled for] [the specified item].
 | 
				
			||||||
@ -95,23 +89,10 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        public abstract bool IsEnabledFor(BaseItem item, ItemUpdateType updateType);
 | 
					        public abstract bool IsEnabledFor(BaseItem item, ItemUpdateType updateType);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        public void Save(BaseItem item, CancellationToken cancellationToken)
 | 
					        public async Task SaveAsync(BaseItem item, CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var path = GetSavePath(item);
 | 
					            var path = GetSavePath(item);
 | 
				
			||||||
 | 
					            var directory = Path.GetDirectoryName(path) ?? throw new InvalidDataException($"Provided path ({path}) is not valid.");
 | 
				
			||||||
            using var memoryStream = new MemoryStream();
 | 
					 | 
				
			||||||
            Save(item, memoryStream);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            memoryStream.Position = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            cancellationToken.ThrowIfCancellationRequested();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            SaveToFile(memoryStream, path);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        private void SaveToFile(Stream stream, string path)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));
 | 
					 | 
				
			||||||
            Directory.CreateDirectory(directory);
 | 
					            Directory.CreateDirectory(directory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // On Windows, savint the file will fail if the file is hidden or readonly
 | 
					            // On Windows, savint the file will fail if the file is hidden or readonly
 | 
				
			||||||
@ -121,13 +102,41 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                Mode = FileMode.Create,
 | 
					                Mode = FileMode.Create,
 | 
				
			||||||
                Access = FileAccess.Write,
 | 
					                Access = FileAccess.Write,
 | 
				
			||||||
                Share = FileShare.None,
 | 
					                Share = FileShare.None
 | 
				
			||||||
                PreallocationSize = stream.Length
 | 
					 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var filestream = new FileStream(path, fileStreamOptions))
 | 
					            var filestream = new FileStream(path, fileStreamOptions);
 | 
				
			||||||
 | 
					            await using (filestream.ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                stream.CopyTo(filestream);
 | 
					                var settings = new XmlWriterSettings
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Indent = true,
 | 
				
			||||||
 | 
					                    Encoding = Encoding.UTF8,
 | 
				
			||||||
 | 
					                    Async = true
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var writer = XmlWriter.Create(filestream, settings);
 | 
				
			||||||
 | 
					                await using (writer.ConfigureAwait(false))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var root = GetRootElementName(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await writer.WriteStartDocumentAsync(true).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await writer.WriteStartElementAsync(null, root, null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    var baseItem = item;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (baseItem != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        await AddCommonNodesAsync(baseItem, writer).ConfigureAwait(false);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await WriteCustomElementsAsync(item, writer).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await writer.WriteEndDocumentAsync().ConfigureAwait(false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (ConfigurationManager.Configuration.SaveMetadataHidden)
 | 
					            if (ConfigurationManager.Configuration.SaveMetadataHidden)
 | 
				
			||||||
@ -148,107 +157,76 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Save(BaseItem item, Stream stream)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            var settings = new XmlWriterSettings
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Indent = true,
 | 
					 | 
				
			||||||
                Encoding = Encoding.UTF8,
 | 
					 | 
				
			||||||
                CloseOutput = false
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            using (var writer = XmlWriter.Create(stream, settings))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                var root = GetRootElementName(item);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                writer.WriteStartDocument(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                writer.WriteStartElement(root);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                var baseItem = item;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (baseItem != null)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    AddCommonNodes(baseItem, writer, LibraryManager);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                WriteCustomElements(item, writer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                writer.WriteEndElement();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                writer.WriteEndDocument();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Write custom elements.
 | 
					        /// Write custom elements.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="writer">The xml writer.</param>
 | 
					        /// <param name="writer">The xml writer.</param>
 | 
				
			||||||
        protected abstract void WriteCustomElements(BaseItem item, XmlWriter writer);
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        protected abstract Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Adds the common nodes.
 | 
					        /// Adds the common nodes.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="writer">The xml writer.</param>
 | 
					        /// <param name="writer">The xml writer.</param>
 | 
				
			||||||
        /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
        public static void AddCommonNodes(BaseItem item, XmlWriter writer, ILibraryManager libraryManager)
 | 
					        private async Task AddCommonNodesAsync(BaseItem item, XmlWriter writer)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.OfficialRating))
 | 
					            if (!string.IsNullOrEmpty(item.OfficialRating))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("ContentRating", item.OfficialRating);
 | 
					                await writer.WriteElementStringAsync(null, "ContentRating", null, item.OfficialRating).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            writer.WriteElementString("Added", item.DateCreated.ToLocalTime().ToString("G", CultureInfo.InvariantCulture));
 | 
					            await writer.WriteElementStringAsync(null, "Added", null, item.DateCreated.ToLocalTime().ToString("G", CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            writer.WriteElementString("LockData", item.IsLocked.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
 | 
					            await writer.WriteElementStringAsync(null, "LockData", null, item.IsLocked.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.LockedFields.Length > 0)
 | 
					            if (item.LockedFields.Length > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("LockedFields", string.Join('|', item.LockedFields));
 | 
					                await writer.WriteElementStringAsync(null, "LockedFields", null, string.Join('|', item.LockedFields)).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.CriticRating.HasValue)
 | 
					            if (item.CriticRating.HasValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("CriticRating", item.CriticRating.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                await writer.WriteElementStringAsync(null, "CriticRating", null, item.CriticRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.Overview))
 | 
					            if (!string.IsNullOrEmpty(item.Overview))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("Overview", item.Overview);
 | 
					                await writer.WriteElementStringAsync(null, "Overview", null, item.Overview).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.OriginalTitle))
 | 
					            if (!string.IsNullOrEmpty(item.OriginalTitle))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("OriginalTitle", item.OriginalTitle);
 | 
					                await writer.WriteElementStringAsync(null, "OriginalTitle", null, item.OriginalTitle).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.CustomRating))
 | 
					            if (!string.IsNullOrEmpty(item.CustomRating))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("CustomRating", item.CustomRating);
 | 
					                await writer.WriteElementStringAsync(null, "CustomRating", null, item.CustomRating).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.Name) && item is not Episode)
 | 
					            if (!string.IsNullOrEmpty(item.Name) && item is not Episode)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("LocalTitle", item.Name);
 | 
					                await writer.WriteElementStringAsync(null, "LocalTitle", null, item.Name).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var forcedSortName = item.ForcedSortName;
 | 
					            var forcedSortName = item.ForcedSortName;
 | 
				
			||||||
            if (!string.IsNullOrEmpty(forcedSortName))
 | 
					            if (!string.IsNullOrEmpty(forcedSortName))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("SortTitle", forcedSortName);
 | 
					                await writer.WriteElementStringAsync(null, "SortTitle", null, forcedSortName).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.PremiereDate.HasValue)
 | 
					            if (item.PremiereDate.HasValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (item is Person)
 | 
					                if (item is Person)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("BirthDate", item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
 | 
					                    await writer.WriteElementStringAsync(null, "BirthDate", null, item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (item is not Episode)
 | 
					                else if (item is not Episode)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("PremiereDate", item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
 | 
					                    await writer.WriteElementStringAsync(null, "PremiereDate", null, item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -256,69 +234,69 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                if (item is Person)
 | 
					                if (item is Person)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("DeathDate", item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
 | 
					                    await writer.WriteElementStringAsync(null, "DeathDate", null, item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (item is not Episode)
 | 
					                else if (item is not Episode)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("EndDate", item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
 | 
					                    await writer.WriteElementStringAsync(null, "EndDate", null, item.EndDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.RemoteTrailers.Count > 0)
 | 
					            if (item.RemoteTrailers.Count > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Trailers");
 | 
					                await writer.WriteStartElementAsync(null, "Trailers", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var trailer in item.RemoteTrailers)
 | 
					                foreach (var trailer in item.RemoteTrailers)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("Trailer", trailer.Url);
 | 
					                    await writer.WriteElementStringAsync(null, "Trailer", null, trailer.Url).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.ProductionLocations.Length > 0)
 | 
					            if (item.ProductionLocations.Length > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Countries");
 | 
					                await writer.WriteStartElementAsync(null, "Countries", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var name in item.ProductionLocations)
 | 
					                foreach (var name in item.ProductionLocations)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("Country", name);
 | 
					                    await writer.WriteElementStringAsync(null, "Country", null, name).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item is IHasDisplayOrder hasDisplayOrder && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
 | 
					            if (item is IHasDisplayOrder hasDisplayOrder && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("DisplayOrder", hasDisplayOrder.DisplayOrder);
 | 
					                await writer.WriteElementStringAsync(null, "DisplayOrder", null, hasDisplayOrder.DisplayOrder).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.CommunityRating.HasValue)
 | 
					            if (item.CommunityRating.HasValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("Rating", item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                await writer.WriteElementStringAsync(null, "Rating", null, item.CommunityRating.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.ProductionYear.HasValue && item is not Person)
 | 
					            if (item.ProductionYear.HasValue && item is not Person)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("ProductionYear", item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                await writer.WriteElementStringAsync(null, "ProductionYear", null, item.ProductionYear.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item is IHasAspectRatio hasAspectRatio)
 | 
					            if (item is IHasAspectRatio hasAspectRatio)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
 | 
					                if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("AspectRatio", hasAspectRatio.AspectRatio);
 | 
					                    await writer.WriteElementStringAsync(null, "AspectRatio", null, hasAspectRatio.AspectRatio).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.PreferredMetadataLanguage))
 | 
					            if (!string.IsNullOrEmpty(item.PreferredMetadataLanguage))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("Language", item.PreferredMetadataLanguage);
 | 
					                await writer.WriteElementStringAsync(null, "Language", null, item.PreferredMetadataLanguage).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(item.PreferredMetadataCountryCode))
 | 
					            if (!string.IsNullOrEmpty(item.PreferredMetadataCountryCode))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("CountryCode", item.PreferredMetadataCountryCode);
 | 
					                await writer.WriteElementStringAsync(null, "CountryCode", null, item.PreferredMetadataCountryCode).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Use original runtime here, actual file runtime later in MediaInfo
 | 
					            // Use original runtime here, actual file runtime later in MediaInfo
 | 
				
			||||||
@ -328,7 +306,7 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
 | 
					                var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteElementString("RunningTime", Math.Floor(timespan.TotalMinutes).ToString(CultureInfo.InvariantCulture));
 | 
					                await writer.WriteElementStringAsync(null, "RunningTime", null, Math.Floor(timespan.TotalMinutes).ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.ProviderIds != null)
 | 
					            if (item.ProviderIds != null)
 | 
				
			||||||
@ -338,94 +316,94 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
                    var providerId = item.ProviderIds[providerKey];
 | 
					                    var providerId = item.ProviderIds[providerKey];
 | 
				
			||||||
                    if (!string.IsNullOrEmpty(providerId))
 | 
					                    if (!string.IsNullOrEmpty(providerId))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString(providerKey + "Id", providerId);
 | 
					                        await writer.WriteElementStringAsync(null, providerKey + "Id", null, providerId).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrWhiteSpace(item.Tagline))
 | 
					            if (!string.IsNullOrWhiteSpace(item.Tagline))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Taglines");
 | 
					                await writer.WriteStartElementAsync(null, "Taglines", null).ConfigureAwait(false);
 | 
				
			||||||
                writer.WriteElementString("Tagline", item.Tagline);
 | 
					                await writer.WriteElementStringAsync(null, "Tagline", null, item.Tagline).ConfigureAwait(false);
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.Genres.Length > 0)
 | 
					            if (item.Genres.Length > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Genres");
 | 
					                await writer.WriteStartElementAsync(null, "Genres", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var genre in item.Genres)
 | 
					                foreach (var genre in item.Genres)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("Genre", genre);
 | 
					                    await writer.WriteElementStringAsync(null, "Genre", null, genre).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.Studios.Length > 0)
 | 
					            if (item.Studios.Length > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Studios");
 | 
					                await writer.WriteStartElementAsync(null, "Studios", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var studio in item.Studios)
 | 
					                foreach (var studio in item.Studios)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("Studio", studio);
 | 
					                    await writer.WriteElementStringAsync(null, "Studio", null, studio).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item.Tags.Length > 0)
 | 
					            if (item.Tags.Length > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Tags");
 | 
					                await writer.WriteStartElementAsync(null, "Tags", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var tag in item.Tags)
 | 
					                foreach (var tag in item.Tags)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteElementString("Tag", tag);
 | 
					                    await writer.WriteElementStringAsync(null, "Tag", null, tag).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var people = libraryManager.GetPeople(item);
 | 
					            var people = LibraryManager.GetPeople(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (people.Count > 0)
 | 
					            if (people.Count > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Persons");
 | 
					                await writer.WriteStartElementAsync(null, "Persons", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var person in people)
 | 
					                foreach (var person in people)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteStartElement("Person");
 | 
					                    await writer.WriteStartElementAsync(null, "Person", null).ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteElementString("Name", person.Name);
 | 
					                    await writer.WriteElementStringAsync(null, "Name", null, person.Name).ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteElementString("Type", person.Type);
 | 
					                    await writer.WriteElementStringAsync(null, "Type", null, person.Type).ConfigureAwait(false);
 | 
				
			||||||
                    writer.WriteElementString("Role", person.Role);
 | 
					                    await writer.WriteElementStringAsync(null, "Role", null, person.Role).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (person.SortOrder.HasValue)
 | 
					                    if (person.SortOrder.HasValue)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("SortOrder", person.SortOrder.Value.ToString(CultureInfo.InvariantCulture));
 | 
					                        await writer.WriteElementStringAsync(null, "SortOrder", null, person.SortOrder.Value.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteEndElement();
 | 
					                    await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item is BoxSet boxset)
 | 
					            if (item is BoxSet boxset)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                AddLinkedChildren(boxset, writer, "CollectionItems", "CollectionItem");
 | 
					                await AddLinkedChildren(boxset, writer, "CollectionItems", "CollectionItem").ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item is Playlist playlist && !Playlist.IsPlaylistFile(playlist.Path))
 | 
					            if (item is Playlist playlist && !Playlist.IsPlaylistFile(playlist.Path))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                AddLinkedChildren(playlist, writer, "PlaylistItems", "PlaylistItem");
 | 
					                await AddLinkedChildren(playlist, writer, "PlaylistItems", "PlaylistItem").ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (item is IHasShares hasShares)
 | 
					            if (item is IHasShares hasShares)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                AddShares(hasShares, writer);
 | 
					                await AddSharesAsync(hasShares, writer).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            AddMediaInfo(item, writer);
 | 
					            await AddMediaInfo(item, writer).ConfigureAwait(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@ -433,23 +411,26 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="writer">The xml writer.</param>
 | 
					        /// <param name="writer">The xml writer.</param>
 | 
				
			||||||
        public static void AddShares(IHasShares item, XmlWriter writer)
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        private static async Task AddSharesAsync(IHasShares item, XmlWriter writer)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            writer.WriteStartElement("Shares");
 | 
					            await writer.WriteStartElementAsync(null, "Shares", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (var share in item.Shares)
 | 
					            foreach (var share in item.Shares)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteStartElement("Share");
 | 
					                await writer.WriteStartElementAsync(null, "Share", null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteElementString("UserId", share.UserId);
 | 
					                await writer.WriteElementStringAsync(null, "UserId", null, share.UserId).ConfigureAwait(false);
 | 
				
			||||||
                writer.WriteElementString(
 | 
					                await writer.WriteElementStringAsync(
 | 
				
			||||||
 | 
					                    null,
 | 
				
			||||||
                    "CanEdit",
 | 
					                    "CanEdit",
 | 
				
			||||||
                    share.CanEdit.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
 | 
					                    null,
 | 
				
			||||||
 | 
					                    share.CanEdit.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.WriteEndElement();
 | 
					                await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            writer.WriteEndElement();
 | 
					            await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@ -458,33 +439,29 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="writer">The xml writer.</param>
 | 
					        /// <param name="writer">The xml writer.</param>
 | 
				
			||||||
        /// <typeparam name="T">Type of item.</typeparam>
 | 
					        /// <typeparam name="T">Type of item.</typeparam>
 | 
				
			||||||
        public static void AddMediaInfo<T>(T item, XmlWriter writer)
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        private static Task AddMediaInfo<T>(T item, XmlWriter writer)
 | 
				
			||||||
            where T : BaseItem
 | 
					            where T : BaseItem
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (item is Video video)
 | 
					            if (item is Video video && video.Video3DFormat.HasValue)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (video.Video3DFormat.HasValue)
 | 
					                return video.Video3DFormat switch
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    switch (video.Video3DFormat.Value)
 | 
					                    Video3DFormat.FullSideBySide =>
 | 
				
			||||||
                    {
 | 
					                        writer.WriteElementStringAsync(null, "Format3D", null, "FSBS"),
 | 
				
			||||||
                        case Video3DFormat.FullSideBySide:
 | 
					                    Video3DFormat.FullTopAndBottom =>
 | 
				
			||||||
                            writer.WriteElementString("Format3D", "FSBS");
 | 
					                        writer.WriteElementStringAsync(null, "Format3D", null, "FTAB"),
 | 
				
			||||||
                            break;
 | 
					                    Video3DFormat.HalfSideBySide =>
 | 
				
			||||||
                        case Video3DFormat.FullTopAndBottom:
 | 
					                        writer.WriteElementStringAsync(null, "Format3D", null, "HSBS"),
 | 
				
			||||||
                            writer.WriteElementString("Format3D", "FTAB");
 | 
					                    Video3DFormat.HalfTopAndBottom =>
 | 
				
			||||||
                            break;
 | 
					                        writer.WriteElementStringAsync(null, "Format3D", null, "HTAB"),
 | 
				
			||||||
                        case Video3DFormat.HalfSideBySide:
 | 
					                    Video3DFormat.MVC =>
 | 
				
			||||||
                            writer.WriteElementString("Format3D", "HSBS");
 | 
					                        writer.WriteElementStringAsync(null, "Format3D", null, "MVC"),
 | 
				
			||||||
                            break;
 | 
					                    _ => Task.CompletedTask
 | 
				
			||||||
                        case Video3DFormat.HalfTopAndBottom:
 | 
					                };
 | 
				
			||||||
                            writer.WriteElementString("Format3D", "HTAB");
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                        case Video3DFormat.MVC:
 | 
					 | 
				
			||||||
                            writer.WriteElementString("Format3D", "MVC");
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return Task.CompletedTask;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@ -494,7 +471,8 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        /// <param name="writer">The xml writer.</param>
 | 
					        /// <param name="writer">The xml writer.</param>
 | 
				
			||||||
        /// <param name="pluralNodeName">The plural node name.</param>
 | 
					        /// <param name="pluralNodeName">The plural node name.</param>
 | 
				
			||||||
        /// <param name="singularNodeName">The singular node name.</param>
 | 
					        /// <param name="singularNodeName">The singular node name.</param>
 | 
				
			||||||
        public static void AddLinkedChildren(Folder item, XmlWriter writer, string pluralNodeName, string singularNodeName)
 | 
					        /// <returns>The task object representing the asynchronous operation.</returns>
 | 
				
			||||||
 | 
					        private static async Task AddLinkedChildren(Folder item, XmlWriter writer, string pluralNodeName, string singularNodeName)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var items = item.LinkedChildren
 | 
					            var items = item.LinkedChildren
 | 
				
			||||||
                .Where(i => i.Type == LinkedChildType.Manual)
 | 
					                .Where(i => i.Type == LinkedChildType.Manual)
 | 
				
			||||||
@ -505,28 +483,28 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            writer.WriteStartElement(pluralNodeName);
 | 
					            await writer.WriteStartElementAsync(null, pluralNodeName, null).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach (var link in items)
 | 
					            foreach (var link in items)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (!string.IsNullOrWhiteSpace(link.Path) || !string.IsNullOrWhiteSpace(link.LibraryItemId))
 | 
					                if (!string.IsNullOrWhiteSpace(link.Path) || !string.IsNullOrWhiteSpace(link.LibraryItemId))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    writer.WriteStartElement(singularNodeName);
 | 
					                    await writer.WriteStartElementAsync(null, singularNodeName, null).ConfigureAwait(false);
 | 
				
			||||||
                    if (!string.IsNullOrWhiteSpace(link.Path))
 | 
					                    if (!string.IsNullOrWhiteSpace(link.Path))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("Path", link.Path);
 | 
					                        await writer.WriteElementStringAsync(null, "Path", null, link.Path).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!string.IsNullOrWhiteSpace(link.LibraryItemId))
 | 
					                    if (!string.IsNullOrWhiteSpace(link.LibraryItemId))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        writer.WriteElementString("ItemId", link.LibraryItemId);
 | 
					                        await writer.WriteElementStringAsync(null, "ItemId", null, link.LibraryItemId).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    writer.WriteEndElement();
 | 
					                    await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            writer.WriteEndElement();
 | 
					            await writer.WriteEndElementAsync().ConfigureAwait(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using System.Xml;
 | 
					using System.Xml;
 | 
				
			||||||
using MediaBrowser.Controller.Configuration;
 | 
					using MediaBrowser.Controller.Configuration;
 | 
				
			||||||
using MediaBrowser.Controller.Entities;
 | 
					using MediaBrowser.Controller.Entities;
 | 
				
			||||||
@ -38,9 +39,8 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
 | 
					        protected override Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer)
 | 
				
			||||||
        {
 | 
					            => Task.CompletedTask;
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        protected override string GetLocalSavePath(BaseItem item)
 | 
					        protected override string GetLocalSavePath(BaseItem item)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using System.Xml;
 | 
					using System.Xml;
 | 
				
			||||||
using MediaBrowser.Controller.Configuration;
 | 
					using MediaBrowser.Controller.Configuration;
 | 
				
			||||||
using MediaBrowser.Controller.Entities;
 | 
					using MediaBrowser.Controller.Entities;
 | 
				
			||||||
@ -43,14 +44,16 @@ namespace MediaBrowser.LocalMetadata.Savers
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
 | 
					        protected override Task WriteCustomElementsAsync(BaseItem item, XmlWriter writer)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var game = (Playlist)item;
 | 
					            var game = (Playlist)item;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!string.IsNullOrEmpty(game.PlaylistMediaType))
 | 
					            if (string.IsNullOrEmpty(game.PlaylistMediaType))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                writer.WriteElementString("PlaylistMediaType", game.PlaylistMediaType);
 | 
					                return Task.CompletedTask;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return writer.WriteElementStringAsync(null, "PlaylistMediaType", null, game.PlaylistMediaType);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 | 
				
			|||||||
@ -671,8 +671,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (!string.Equals(text, newText, StringComparison.Ordinal))
 | 
					            if (!string.Equals(text, newText, StringComparison.Ordinal))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous))
 | 
					                var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
 | 
				
			||||||
                using (var writer = new StreamWriter(fileStream, encoding))
 | 
					                var writer = new StreamWriter(fileStream, encoding);
 | 
				
			||||||
 | 
					                await using (fileStream.ConfigureAwait(false))
 | 
				
			||||||
 | 
					                await using (writer.ConfigureAwait(false))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    await writer.WriteAsync(newText.AsMemory(), cancellationToken).ConfigureAwait(false);
 | 
					                    await writer.WriteAsync(newText.AsMemory(), cancellationToken).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
@ -128,9 +128,7 @@ namespace MediaBrowser.Providers.Manager
 | 
				
			|||||||
            _metadataProviders = metadataProviders.ToArray();
 | 
					            _metadataProviders = metadataProviders.ToArray();
 | 
				
			||||||
            _externalIds = externalIds.OrderBy(i => i.ProviderName).ToArray();
 | 
					            _externalIds = externalIds.OrderBy(i => i.ProviderName).ToArray();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _savers = metadataSavers
 | 
					            _savers = metadataSavers.ToArray();
 | 
				
			||||||
                .Where(i => i is not IConfigurableProvider configurable || configurable.IsEnabled)
 | 
					 | 
				
			||||||
                .ToArray();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc/>
 | 
					        /// <inheritdoc/>
 | 
				
			||||||
@ -653,16 +651,12 @@ namespace MediaBrowser.Providers.Manager
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc/>
 | 
					        /// <inheritdoc/>
 | 
				
			||||||
        public void SaveMetadata(BaseItem item, ItemUpdateType updateType)
 | 
					        public Task SaveMetadataAsync(BaseItem item, ItemUpdateType updateType)
 | 
				
			||||||
        {
 | 
					            => SaveMetadataAsync(item, updateType, _savers);
 | 
				
			||||||
            SaveMetadata(item, updateType, _savers);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc/>
 | 
					        /// <inheritdoc/>
 | 
				
			||||||
        public void SaveMetadata(BaseItem item, ItemUpdateType updateType, IEnumerable<string> savers)
 | 
					        public Task SaveMetadataAsync(BaseItem item, ItemUpdateType updateType, IEnumerable<string> savers)
 | 
				
			||||||
        {
 | 
					            => SaveMetadataAsync(item, updateType, _savers.Where(i => savers.Contains(i.Name, StringComparison.OrdinalIgnoreCase)));
 | 
				
			||||||
            SaveMetadata(item, updateType, _savers.Where(i => savers.Contains(i.Name, StringComparison.OrdinalIgnoreCase)));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Saves the metadata.
 | 
					        /// Saves the metadata.
 | 
				
			||||||
@ -670,7 +664,7 @@ namespace MediaBrowser.Providers.Manager
 | 
				
			|||||||
        /// <param name="item">The item.</param>
 | 
					        /// <param name="item">The item.</param>
 | 
				
			||||||
        /// <param name="updateType">Type of the update.</param>
 | 
					        /// <param name="updateType">Type of the update.</param>
 | 
				
			||||||
        /// <param name="savers">The savers.</param>
 | 
					        /// <param name="savers">The savers.</param>
 | 
				
			||||||
        private void SaveMetadata(BaseItem item, ItemUpdateType updateType, IEnumerable<IMetadataSaver> savers)
 | 
					        private async Task SaveMetadataAsync(BaseItem item, ItemUpdateType updateType, IEnumerable<IMetadataSaver> savers)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var libraryOptions = _libraryManager.GetLibraryOptions(item);
 | 
					            var libraryOptions = _libraryManager.GetLibraryOptions(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -695,7 +689,7 @@ namespace MediaBrowser.Providers.Manager
 | 
				
			|||||||
                    try
 | 
					                    try
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        _libraryMonitor.ReportFileSystemChangeBeginning(path);
 | 
					                        _libraryMonitor.ReportFileSystemChangeBeginning(path);
 | 
				
			||||||
                        saver.Save(item, CancellationToken.None);
 | 
					                        await saver.SaveAsync(item, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    catch (Exception ex)
 | 
					                    catch (Exception ex)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -710,7 +704,7 @@ namespace MediaBrowser.Providers.Manager
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    try
 | 
					                    try
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        saver.Save(item, CancellationToken.None);
 | 
					                        await saver.SaveAsync(item, CancellationToken.None).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    catch (Exception ex)
 | 
					                    catch (Exception ex)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
				
			|||||||
@ -248,8 +248,11 @@ namespace MediaBrowser.Providers.Subtitles
 | 
				
			|||||||
                    var fileOptions = AsyncFile.WriteOptions;
 | 
					                    var fileOptions = AsyncFile.WriteOptions;
 | 
				
			||||||
                    fileOptions.Mode = FileMode.CreateNew;
 | 
					                    fileOptions.Mode = FileMode.CreateNew;
 | 
				
			||||||
                    fileOptions.PreallocationSize = stream.Length;
 | 
					                    fileOptions.PreallocationSize = stream.Length;
 | 
				
			||||||
                    using var fs = new FileStream(savePath, fileOptions);
 | 
					                    var fs = new FileStream(savePath, fileOptions);
 | 
				
			||||||
                    await stream.CopyToAsync(fs).ConfigureAwait(false);
 | 
					                    await using (fs.ConfigureAwait(false))
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        await stream.CopyToAsync(fs).ConfigureAwait(false);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
@ -47,7 +47,7 @@ namespace MediaBrowser.XbmcMetadata
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                if (!string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
 | 
					                if (!string.IsNullOrWhiteSpace(_config.GetNfoConfiguration().UserId))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    SaveMetadataForItem(e.Item, ItemUpdateType.MetadataDownload);
 | 
					                    _ = SaveMetadataForItemAsync(e.Item, ItemUpdateType.MetadataDownload);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -58,7 +58,7 @@ namespace MediaBrowser.XbmcMetadata
 | 
				
			|||||||
            _userDataManager.UserDataSaved -= OnUserDataSaved;
 | 
					            _userDataManager.UserDataSaved -= OnUserDataSaved;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void SaveMetadataForItem(BaseItem item, ItemUpdateType updateReason)
 | 
					        private async Task SaveMetadataForItemAsync(BaseItem item, ItemUpdateType updateReason)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (!item.IsFileProtocol || !item.SupportsLocalMetadata)
 | 
					            if (!item.IsFileProtocol || !item.SupportsLocalMetadata)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -67,7 +67,7 @@ namespace MediaBrowser.XbmcMetadata
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                _providerManager.SaveMetadata(item, updateReason, new[] { BaseNfoSaver.SaverName });
 | 
					                await _providerManager.SaveMetadataAsync(item, updateReason, new[] { BaseNfoSaver.SaverName }).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception ex)
 | 
					            catch (Exception ex)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ using System.Linq;
 | 
				
			|||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Text.RegularExpressions;
 | 
					using System.Text.RegularExpressions;
 | 
				
			||||||
using System.Threading;
 | 
					using System.Threading;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using System.Xml;
 | 
					using System.Xml;
 | 
				
			||||||
using Jellyfin.Extensions;
 | 
					using Jellyfin.Extensions;
 | 
				
			||||||
using MediaBrowser.Common.Extensions;
 | 
					using MediaBrowser.Common.Extensions;
 | 
				
			||||||
@ -180,7 +181,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        public void Save(BaseItem item, CancellationToken cancellationToken)
 | 
					        public async Task SaveAsync(BaseItem item, CancellationToken cancellationToken)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var path = GetSavePath(item);
 | 
					            var path = GetSavePath(item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -192,11 +193,11 @@ namespace MediaBrowser.XbmcMetadata.Savers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                cancellationToken.ThrowIfCancellationRequested();
 | 
					                cancellationToken.ThrowIfCancellationRequested();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                SaveToFile(memoryStream, path);
 | 
					                await SaveToFileAsync(memoryStream, path).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void SaveToFile(Stream stream, string path)
 | 
					        private async Task SaveToFileAsync(Stream stream, string path)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));
 | 
					            var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));
 | 
				
			||||||
            Directory.CreateDirectory(directory);
 | 
					            Directory.CreateDirectory(directory);
 | 
				
			||||||
@ -209,12 +210,14 @@ namespace MediaBrowser.XbmcMetadata.Savers
 | 
				
			|||||||
                Mode = FileMode.Create,
 | 
					                Mode = FileMode.Create,
 | 
				
			||||||
                Access = FileAccess.Write,
 | 
					                Access = FileAccess.Write,
 | 
				
			||||||
                Share = FileShare.None,
 | 
					                Share = FileShare.None,
 | 
				
			||||||
                PreallocationSize = stream.Length
 | 
					                PreallocationSize = stream.Length,
 | 
				
			||||||
 | 
					                Options = FileOptions.Asynchronous
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            using (var filestream = new FileStream(path, fileStreamOptions))
 | 
					            var filestream = new FileStream(path, fileStreamOptions);
 | 
				
			||||||
 | 
					            await using (filestream.ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                stream.CopyTo(filestream);
 | 
					                await stream.CopyToAsync(filestream).ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (ConfigurationManager.Configuration.SaveMetadataHidden)
 | 
					            if (ConfigurationManager.Configuration.SaveMetadataHidden)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user