The Free Software Media System - Server Backend & API
brace multiline if statements
telans7f307f9082cb
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.csindex cbe4ea643c..5911a73ef1 100644--- a/Emby.Dlna/DlnaManager.cs+++ b/Emby.Dlna/DlnaManager.cs@@ -140,55 +140,73 @@ namespace Emby.Dlnaif (!string.IsNullOrEmpty(profileInfo.DeviceDescription)){if (deviceInfo.DeviceDescription == null || !IsRegexMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.FriendlyName)){if (deviceInfo.FriendlyName == null || !IsRegexMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.Manufacturer)){if (deviceInfo.Manufacturer == null || !IsRegexMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.ManufacturerUrl)){if (deviceInfo.ManufacturerUrl == null || !IsRegexMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.ModelDescription)){if (deviceInfo.ModelDescription == null || !IsRegexMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.ModelName)){if (deviceInfo.ModelName == null || !IsRegexMatch(deviceInfo.ModelName, profileInfo.ModelName))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.ModelNumber)){if (deviceInfo.ModelNumber == null || !IsRegexMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.ModelUrl)){if (deviceInfo.ModelUrl == null || !IsRegexMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))+ {return false;+ }}if (!string.IsNullOrEmpty(profileInfo.SerialNumber)){if (deviceInfo.SerialNumber == null || !IsRegexMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))+ {return false;+ }}return true;diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.csindex c86fc4f374..c5080b90f3 100644--- a/Emby.Dlna/PlayTo/Device.cs+++ b/Emby.Dlna/PlayTo/Device.cs@@ -208,7 +208,9 @@ namespace Emby.Dlna.PlayTovar command = rendererCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetMute");if (command == null)+ {return false;+ }var service = GetServiceRenderingControl();@@ -237,7 +239,9 @@ namespace Emby.Dlna.PlayTovar command = rendererCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetVolume");if (command == null)+ {return;+ }var service = GetServiceRenderingControl();@@ -260,7 +264,9 @@ namespace Emby.Dlna.PlayTovar command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "Seek");if (command == null)+ {return;+ }var service = GetAvTransportService();@@ -285,7 +291,9 @@ namespace Emby.Dlna.PlayTovar command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetAVTransportURI");if (command == null)+ {return;+ }var dictionary = new Dictionary<string, string>{@@ -452,7 +460,9 @@ namespace Emby.Dlna.PlayTo_connectFailureCount = 0;if (_disposed)+ {return;+ }// If we're not playing anything make sure we don't get data more often than neccessry to keep the Session aliveif (transportState.Value == TRANSPORTSTATE.STOPPED)@@ -472,7 +482,9 @@ namespace Emby.Dlna.PlayTocatch (Exception ex){if (_disposed)+ {return;+ }_logger.LogError(ex, "Error updating device info for {DeviceName}", Properties.Name);@@ -573,7 +585,9 @@ namespace Emby.Dlna.PlayTocancellationToken: cancellationToken).ConfigureAwait(false);if (result == null || result.Document == null)+ {return;+ }var valueNode = result.Document.Descendants(uPnpNamespaces.RenderingControl + "GetMuteResponse").Select(i => i.Element("CurrentMute"))diff --git a/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.csindex 503de0b4e9..86a5d8b7d8 100644--- a/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs+++ b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs@@ -19,7 +19,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Books// Only process items that are in a collection folder containing booksif (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))+ {return null;+ }if (args.IsDirectory){@@ -55,7 +57,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Books// Don't return a Book if there is more (or less) than one document in the directoryif (bookFiles.Count != 1)+ {return null;+ }return new Book{diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.csindex 3f1672e94b..a329b531d6 100644--- a/Emby.Server.Implementations/Services/ResponseHelper.cs+++ b/Emby.Server.Implementations/Services/ResponseHelper.cs@@ -40,7 +40,9 @@ namespace Emby.Server.Implementations.Servicesif (httpResult != null){if (httpResult.RequestContext == null)+ {httpResult.RequestContext = request;+ }response.StatusCode = httpResult.Status;}diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.csindex 18d7ab46e7..cbc4b754d2 100644--- a/Emby.Server.Implementations/Services/ServiceExec.cs+++ b/Emby.Server.Implementations/Services/ServiceExec.cs@@ -42,11 +42,15 @@ namespace Emby.Server.Implementations.Services}if (mi.GetParameters().Length != 1)+ {continue;+ }var actionName = mi.Name;if (!AllVerbs.Contains(actionName, StringComparer.OrdinalIgnoreCase))+ {continue;+ }list.Add(mi);}diff --git a/Emby.Server.Implementations/Services/ServicePath.cs b/Emby.Server.Implementations/Services/ServicePath.csindex eb07441893..89538ae729 100644--- a/Emby.Server.Implementations/Services/ServicePath.cs+++ b/Emby.Server.Implementations/Services/ServicePath.cs@@ -445,12 +445,14 @@ namespace Emby.Server.Implementations.Services&& requestComponents.Length >= this.TotalComponentsCount - this.wildcardCount;if (!isValidWildCardPath)+ {throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,"Path Mismatch: Request Path '{0}' has invalid number of components compared to: '{1}'",pathInfo,this.restPath));+ }}var requestKeyValuesMap = new Dictionary<string, string>();diff --git a/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs b/Emby.Server.Implementations/Sorting/DateCreatedComparer.csindex ea981e8402..cbca300d2f 100644--- a/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs+++ b/Emby.Server.Implementations/Sorting/DateCreatedComparer.cs@@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sortingpublic int Compare(BaseItem x, BaseItem y){if (x == null)+ {throw new ArgumentNullException(nameof(x));+ }if (y == null)+ {throw new ArgumentNullException(nameof(y));+ }return DateTime.Compare(x.DateCreated, y.DateCreated);}diff --git a/Emby.Server.Implementations/Sorting/RuntimeComparer.cs b/Emby.Server.Implementations/Sorting/RuntimeComparer.csindex f165123eab..dde44333d5 100644--- a/Emby.Server.Implementations/Sorting/RuntimeComparer.cs+++ b/Emby.Server.Implementations/Sorting/RuntimeComparer.cs@@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sortingpublic int Compare(BaseItem x, BaseItem y){if (x == null)+ {throw new ArgumentNullException(nameof(x));+ }if (y == null)+ {throw new ArgumentNullException(nameof(y));+ }return (x.RunTimeTicks ?? 0).CompareTo(y.RunTimeTicks ?? 0);}diff --git a/Emby.Server.Implementations/Sorting/SortNameComparer.cs b/Emby.Server.Implementations/Sorting/SortNameComparer.csindex 93389fc3e8..f745e193b4 100644--- a/Emby.Server.Implementations/Sorting/SortNameComparer.cs+++ b/Emby.Server.Implementations/Sorting/SortNameComparer.cs@@ -19,10 +19,14 @@ namespace Emby.Server.Implementations.Sortingpublic int Compare(BaseItem x, BaseItem y){if (x == null)+ {throw new ArgumentNullException(nameof(x));+ }if (y == null)+ {throw new ArgumentNullException(nameof(y));+ }return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);}diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.csindex 2ad1c717cf..8e0e63ff0b 100644--- a/MediaBrowser.Controller/Entities/BaseItem.cs+++ b/MediaBrowser.Controller/Entities/BaseItem.cs@@ -2951,7 +2951,9 @@ namespace MediaBrowser.Controller.Entitiespublic IEnumerable<BaseItem> GetTrailers(){if (this is IHasTrailers)+ {return ((IHasTrailers)this).LocalTrailerIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName);+ }elsereturn Array.Empty<BaseItem>();}diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.csindex a8d383a2ad..728efa788d 100644--- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs+++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs@@ -58,7 +58,10 @@ namespace MediaBrowser.MediaEncoding.Subtitlesvar endTime = time[1];var idx = endTime.IndexOf(" ", StringComparison.Ordinal);if (idx > 0)+ {endTime = endTime.Substring(0, idx);+ }+subEvent.EndPositionTicks = GetTicks(endTime);var multiline = new List<string>();while ((line = reader.ReadLine()) != null)diff --git a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.csindex 9a8fcc4316..630a3dce07 100644--- a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs+++ b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs@@ -41,7 +41,9 @@ namespace MediaBrowser.MediaEncoding.SubtitleslineNumber++;if (!eventsStarted)+ {header.AppendLine(line);+ }if (line.Trim().ToLowerInvariant() == "[events]"){@@ -62,17 +64,29 @@ namespace MediaBrowser.MediaEncoding.Subtitlesfor (int i = 0; i < format.Length; i++){if (format[i].Trim().ToLowerInvariant() == "layer")+ {indexLayer = i;+ }else if (format[i].Trim().ToLowerInvariant() == "start")+ {indexStart = i;+ }else if (format[i].Trim().ToLowerInvariant() == "end")+ {indexEnd = i;+ }else if (format[i].Trim().ToLowerInvariant() == "text")+ {indexText = i;+ }else if (format[i].Trim().ToLowerInvariant() == "effect")+ {indexEffect = i;+ }else if (format[i].Trim().ToLowerInvariant() == "style")+ {indexStyle = i;+ }}}}@@ -89,28 +103,48 @@ namespace MediaBrowser.MediaEncoding.Subtitlesstring[] splittedLine;if (s.StartsWith("dialogue:"))+ {splittedLine = line.Substring(10).Split(',');+ }else+ {splittedLine = line.Split(',');+ }for (int i = 0; i < splittedLine.Length; i++){if (i == indexStart)+ {start = splittedLine[i].Trim();+ }else if (i == indexEnd)+ {end = splittedLine[i].Trim();+ }else if (i == indexLayer)+ {layer = splittedLine[i];+ }else if (i == indexEffect)+ {effect = splittedLine[i];+ }else if (i == indexText)+ {text = splittedLine[i];+ }else if (i == indexStyle)+ {style = splittedLine[i];+ }else if (i == indexName)+ {name = splittedLine[i];+ }else if (i > indexText)+ {text += "," + splittedLine[i];+ }}try@@ -169,13 +203,17 @@ namespace MediaBrowser.MediaEncoding.SubtitlesCheckAndAddSubTags(ref fontName, ref extraTags, out italic);text = text.Remove(start, end - start + 1);if (italic)+ {text = text.Insert(start, "<font face=\"" + fontName + "\"" + extraTags + "><i>");+ }elsetext = text.Insert(start, "<font face=\"" + fontName + "\"" + extraTags + ">");int indexOfEndTag = text.IndexOf("{\\fn}", start);if (indexOfEndTag > 0)+ {text = text.Remove(indexOfEndTag, "{\\fn}".Length).Insert(indexOfEndTag, "</font>");+ }elsetext += "</font>";}@@ -194,13 +232,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles{text = text.Remove(start, end - start + 1);if (italic)+ {text = text.Insert(start, "<font size=\"" + fontSize + "\"" + extraTags + "><i>");+ }elsetext = text.Insert(start, "<font size=\"" + fontSize + "\"" + extraTags + ">");int indexOfEndTag = text.IndexOf("{\\fs}", start);if (indexOfEndTag > 0)+ {text = text.Remove(indexOfEndTag, "{\\fs}".Length).Insert(indexOfEndTag, "</font>");+ }elsetext += "</font>";}@@ -226,12 +268,16 @@ namespace MediaBrowser.MediaEncoding.Subtitlestext = text.Remove(start, end - start + 1);if (italic)+ {text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + "><i>");+ }elsetext = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");int indexOfEndTag = text.IndexOf("{\\c}", start);if (indexOfEndTag > 0)+ {text = text.Remove(indexOfEndTag, "{\\c}".Length).Insert(indexOfEndTag, "</font>");+ }elsetext += "</font>";}@@ -256,7 +302,9 @@ namespace MediaBrowser.MediaEncoding.Subtitlestext = text.Remove(start, end - start + 1);if (italic)+ {text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + "><i>");+ }elsetext = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");text += "</font>";@@ -268,19 +316,25 @@ namespace MediaBrowser.MediaEncoding.Subtitlestext = text.Replace(@"{\i0}", "</i>");text = text.Replace(@"{\i}", "</i>");if (CountTagInText(text, "<i>") > CountTagInText(text, "</i>"))+ {text += "</i>";+ }text = text.Replace(@"{\u1}", "<u>");text = text.Replace(@"{\u0}", "</u>");text = text.Replace(@"{\u}", "</u>");if (CountTagInText(text, "<u>") > CountTagInText(text, "</u>"))+ {text += "</u>";+ }text = text.Replace(@"{\b1}", "<b>");text = text.Replace(@"{\b0}", "</b>");text = text.Replace(@"{\b}", "</b>");if (CountTagInText(text, "<b>") > CountTagInText(text, "</b>"))+ {text += "</b>";+ }return text;}@@ -288,7 +342,9 @@ namespace MediaBrowser.MediaEncoding.Subtitlesprivate static bool IsInteger(string s){if (int.TryParse(s, out var i))+ {return true;+ }return false;}@@ -300,7 +356,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles{count++;if (index == text.Length)+ {return count;+ }index = text.IndexOf(tag, index + 1);}diff --git a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.csindex 47cc892107..df10f8c532 100644--- a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs+++ b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs@@ -32,18 +32,25 @@ namespace MediaBrowser.Model.Dlna}if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.AVI };+ }if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.MATROSKA };+ }if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) ||string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))-+ {return new MediaFormatProfile[] { MediaFormatProfile.MPEG_PS_NTSC, MediaFormatProfile.MPEG_PS_PAL };+ }if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.MPEG1 };+ }if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) ||string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) ||@@ -54,10 +61,14 @@ namespace MediaBrowser.Model.Dlna}if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.FLV };+ }if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.WTV };+ }if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase)){@@ -66,7 +77,9 @@ namespace MediaBrowser.Model.Dlna}if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.OGV };+ }return Array.Empty<MediaFormatProfile>();}@@ -111,7 +124,9 @@ namespace MediaBrowser.Model.Dlnaif (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)){if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T };+ }if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase)){@@ -134,14 +149,20 @@ namespace MediaBrowser.Model.Dlna}if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) };+ }if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) };+ }if (string.IsNullOrEmpty(audioCodec) ||string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) };+ }}else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase)){@@ -165,13 +186,24 @@ namespace MediaBrowser.Model.Dlnaelse if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase) || string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase)){if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AAC{0}", suffix)) };+ }+if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG1_L3{0}", suffix)) };+ }+if (string.Equals(audioCodec, "mp2", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_MPEG2_L2{0}", suffix)) };+ }+if (string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))+ {return new MediaFormatProfile[] { ValueOf(string.Format("MPEG4_P2_TS_ASP_AC3{0}", suffix)) };+ }}return new MediaFormatProfile[] { };@@ -187,7 +219,9 @@ namespace MediaBrowser.Model.Dlnaif (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)){if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.AVC_MP4_LPCM;+ }if (string.IsNullOrEmpty(audioCodec) ||string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase)){@@ -204,12 +238,16 @@ namespace MediaBrowser.Model.Dlnaif ((width.Value <= 720) && (height.Value <= 576)){if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.AVC_MP4_MP_SD_AAC_MULT5;+ }}else if ((width.Value <= 1280) && (height.Value <= 720)){if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.AVC_MP4_MP_HD_720p_AAC;+ }}else if ((width.Value <= 1920) && (height.Value <= 1080)){@@ -226,7 +264,9 @@ namespace MediaBrowser.Model.Dlnaif (width.HasValue && height.HasValue && width.Value <= 720 && height.Value <= 576){if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.MPEG4_P2_MP4_ASP_AAC;+ }if (string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase) || string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase)){return MediaFormatProfile.MPEG4_P2_MP4_NDSD;@@ -250,15 +290,22 @@ namespace MediaBrowser.Model.Dlnaif (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)){if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.AVC_3GPP_BL_QCIF15_AAC;+ }}else if (string.Equals(videoCodec, "mpeg4", StringComparison.OrdinalIgnoreCase) ||string.Equals(videoCodec, "msmpeg4", StringComparison.OrdinalIgnoreCase)){if (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "wma", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AAC;+ }+if (string.Equals(audioCodec, "amrnb", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.MPEG4_P2_3GPP_SP_L0B_AMR;+ }}else if (string.Equals(videoCodec, "h263", StringComparison.OrdinalIgnoreCase) && string.Equals(audioCodec, "amrnb", StringComparison.OrdinalIgnoreCase)){@@ -300,11 +347,19 @@ namespace MediaBrowser.Model.Dlnaif (width.HasValue && height.HasValue){if ((width.Value <= 720) && (height.Value <= 576))+ {return MediaFormatProfile.VC1_ASF_AP_L1_WMA;+ }+if ((width.Value <= 1280) && (height.Value <= 720))+ {return MediaFormatProfile.VC1_ASF_AP_L2_WMA;+ }+if ((width.Value <= 1920) && (height.Value <= 1080))+ {return MediaFormatProfile.VC1_ASF_AP_L3_WMA;+ }}}else if (string.Equals(videoCodec, "mpeg2video", StringComparison.OrdinalIgnoreCase))@@ -318,27 +373,41 @@ namespace MediaBrowser.Model.Dlnapublic MediaFormatProfile? ResolveAudioFormat(string container, int? bitrate, int? frequency, int? channels){if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))+ {return ResolveAudioASFFormat(bitrate);+ }if (string.Equals(container, "mp3", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.MP3;+ }if (string.Equals(container, "lpcm", StringComparison.OrdinalIgnoreCase))+ {return ResolveAudioLPCMFormat(frequency, channels);+ }if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase) ||string.Equals(container, "aac", StringComparison.OrdinalIgnoreCase))+ {return ResolveAudioMP4Format(bitrate);+ }if (string.Equals(container, "adts", StringComparison.OrdinalIgnoreCase))+ {return ResolveAudioADTSFormat(bitrate);+ }if (string.Equals(container, "flac", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.FLAC;+ }if (string.Equals(container, "oga", StringComparison.OrdinalIgnoreCase) ||string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.OGG;+ }return null;}@@ -410,13 +479,19 @@ namespace MediaBrowser.Model.Dlnareturn ResolveImageJPGFormat(width, height);if (string.Equals(container, "png", StringComparison.OrdinalIgnoreCase))+ {return ResolveImagePNGFormat(width, height);+ }if (string.Equals(container, "gif", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.GIF_LRG;+ }if (string.Equals(container, "raw", StringComparison.OrdinalIgnoreCase))+ {return MediaFormatProfile.RAW;+ }return null;}@@ -426,10 +501,14 @@ namespace MediaBrowser.Model.Dlnaif (width.HasValue && height.HasValue){if ((width.Value <= 160) && (height.Value <= 160))+ {return MediaFormatProfile.JPEG_TN;+ }if ((width.Value <= 640) && (height.Value <= 480))+ {return MediaFormatProfile.JPEG_SM;+ }if ((width.Value <= 1024) && (height.Value <= 768)){@@ -447,7 +526,9 @@ namespace MediaBrowser.Model.Dlnaif (width.HasValue && height.HasValue){if ((width.Value <= 160) && (height.Value <= 160))+ {return MediaFormatProfile.PNG_TN;+ }}return MediaFormatProfile.PNG_LRG;diff --git a/RSSDP/HttpParserBase.cs b/RSSDP/HttpParserBase.csindex 058bfbf555..00c2b7b45a 100644--- a/RSSDP/HttpParserBase.cs+++ b/RSSDP/HttpParserBase.cs@@ -114,9 +114,13 @@ namespace Rssdp.Infrastructurevar headersToAddTo = IsContentHeader(headerName) ? contentHeaders : headers;if (values.Count > 1)+ {headersToAddTo.TryAddWithoutValidation(headerName, values);+ }else+ {headersToAddTo.TryAddWithoutValidation(headerName, values.First());+ }}private int ParseHeaders(System.Net.Http.Headers.HttpHeaders headers, System.Net.Http.Headers.HttpHeaders contentHeaders, string[] lines)@@ -160,7 +164,9 @@ namespace Rssdp.Infrastructurevar indexOfSeparator = headerValue.IndexOfAny(SeparatorCharacters);if (indexOfSeparator <= 0)+ {values.Add(headerValue);+ }else{var segments = headerValue.Split(SeparatorCharacters);@@ -170,7 +176,9 @@ namespace Rssdp.Infrastructure{var segment = segments[segmentIndex];if (segment.Trim().StartsWith("\"", StringComparison.OrdinalIgnoreCase))+ {segment = CombineQuotedSegments(segments, ref segmentIndex, segment);+ }values.Add(segment);}@@ -199,12 +207,16 @@ namespace Rssdp.Infrastructure}if (index + 1 < segments.Length)+ {trimmedSegment += "," + segments[index + 1].TrimEnd();+ }}segmentIndex = segments.Length;if (trimmedSegment.StartsWith("\"", StringComparison.OrdinalIgnoreCase) && trimmedSegment.EndsWith("\"", StringComparison.OrdinalIgnoreCase))+ {return trimmedSegment.Substring(1, trimmedSegment.Length - 2);+ }elsereturn trimmedSegment;}diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.csindex 6b27fc4df4..7fa42f4669 100644--- a/RSSDP/HttpRequestParser.cs+++ b/RSSDP/HttpRequestParser.cs@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructurefinally{if (retVal != null)+ {retVal.Dispose();+ }}}@@ -64,7 +66,9 @@ namespace Rssdp.Infrastructuremessage.Method = new HttpMethod(parts[0].Trim());Uri requestUri;if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri))+ {message.RequestUri = requestUri;+ }elseSystem.Diagnostics.Debug.WriteLine(parts[1]);diff --git a/RSSDP/HttpResponseParser.cs b/RSSDP/HttpResponseParser.csindex 0337b3e360..0dd4bb45a8 100644--- a/RSSDP/HttpResponseParser.cs+++ b/RSSDP/HttpResponseParser.cs@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructurecatch{if (retVal != null)+ {retVal.Dispose();+ }throw;}@@ -77,7 +79,9 @@ namespace Rssdp.Infrastructureint statusCode = -1;if (!Int32.TryParse(parts[1].Trim(), out statusCode))+ {throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", nameof(data));+ }message.StatusCode = (HttpStatusCode)statusCode;diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.csindex 31ca90424f..e4c4a2017b 100644--- a/RSSDP/SsdpCommunicationsServer.cs+++ b/RSSDP/SsdpCommunicationsServer.cs@@ -480,17 +480,21 @@ namespace Rssdp.Infrastructurevar handlers = this.RequestReceived;if (handlers != null)+ {handlers(this, new RequestReceivedEventArgs(data, remoteEndPoint, receivedOnLocalIpAddress));+ }}private void OnResponseReceived(HttpResponseMessage data, IPEndPoint endPoint, IPAddress localIpAddress){var handlers = this.ResponseReceived;if (handlers != null)+ {handlers(this, new ResponseReceivedEventArgs(data, endPoint){LocalIpAddress = localIpAddress});+ }}}}diff --git a/RSSDP/SsdpDevice.cs b/RSSDP/SsdpDevice.csindex 42f95862c5..7030c6ec12 100644--- a/RSSDP/SsdpDevice.cs+++ b/RSSDP/SsdpDevice.cs@@ -55,7 +55,9 @@ namespace Rssdpvar rootDevice = device as SsdpRootDevice;if (rootDevice == null)+ {rootDevice = ((SsdpEmbeddedDevice)device).RootDevice;+ }return rootDevice;}@@ -163,7 +165,9 @@ namespace Rssdpget{if (String.IsNullOrEmpty(_Udn) && !String.IsNullOrEmpty(this.Uuid))+ {return "uuid:" + this.Uuid;+ }elsereturn _Udn;}@@ -283,7 +287,9 @@ namespace Rssdp}if (wasAdded)+ {OnDeviceAdded(device);+ }}/// <summary>@@ -314,7 +320,9 @@ namespace Rssdp}if (wasRemoved)+ {OnDeviceRemoved(device);+ }}/// <summary>@@ -327,7 +335,9 @@ namespace Rssdp{var handlers = this.DeviceAdded;if (handlers != null)+ {handlers(this, new DeviceEventArgs(device));+ }}/// <summary>@@ -340,7 +350,9 @@ namespace Rssdp{var handlers = this.DeviceRemoved;if (handlers != null)+ {handlers(this, new DeviceEventArgs(device));+ }}}}diff --git a/RSSDP/SsdpDeviceLocator.cs b/RSSDP/SsdpDeviceLocator.csindex a774ee23c8..9a31db7a2e 100644--- a/RSSDP/SsdpDeviceLocator.cs+++ b/RSSDP/SsdpDeviceLocator.cs@@ -217,10 +217,12 @@ namespace Rssdp.Infrastructurevar handlers = this.DeviceAvailable;if (handlers != null)+ {handlers(this, new DeviceAvailableEventArgs(device, isNewDevice){LocalIpAddress = localIpAddress});+ }}/// <summary>@@ -426,7 +428,9 @@ namespace Rssdp.Infrastructure};if (NotificationTypeMatchesFilter(deadDevice))+ {OnDeviceUnavailable(deadDevice, false);+ }}}}@@ -439,7 +443,9 @@ namespace Rssdp.Infrastructure{message.Headers.TryGetValues(headerName, out values);if (values != null)+ {retVal = values.FirstOrDefault();+ }}return retVal;@@ -453,7 +459,9 @@ namespace Rssdp.Infrastructure{message.Headers.TryGetValues(headerName, out values);if (values != null)+ {retVal = values.FirstOrDefault();+ }}return retVal;@@ -467,7 +475,9 @@ namespace Rssdp.Infrastructure{request.Headers.TryGetValues(headerName, out values);if (values != null)+ {value = values.FirstOrDefault();+ }}Uri retVal;@@ -483,7 +493,9 @@ namespace Rssdp.Infrastructure{response.Headers.TryGetValues(headerName, out values);if (values != null)+ {value = values.FirstOrDefault();+ }}Uri retVal;@@ -560,7 +572,9 @@ namespace Rssdp.Infrastructureforeach (var removedDevice in existingDevices){if (NotificationTypeMatchesFilter(removedDevice))+ {OnDeviceUnavailable(removedDevice, expired);+ }}return true;@@ -572,7 +586,9 @@ namespace Rssdp.Infrastructureprivate TimeSpan SearchTimeToMXValue(TimeSpan searchWaitTime){if (searchWaitTime.TotalSeconds < 2 || searchWaitTime == TimeSpan.Zero)+ {return OneSecond;+ }elsereturn searchWaitTime.Subtract(OneSecond);}diff --git a/RSSDP/SsdpDevicePublisher.cs b/RSSDP/SsdpDevicePublisher.csindex 1b64d230dd..7c6e872013 100644--- a/RSSDP/SsdpDevicePublisher.cs+++ b/RSSDP/SsdpDevicePublisher.cs@@ -215,7 +215,9 @@ namespace Rssdp.Infrastructureif (commsServer != null){if (!commsServer.IsShared)+ {commsServer.Dispose();+ }}_RecentSearchRequests = null;@@ -328,7 +330,9 @@ namespace Rssdp.Infrastructure{SendSearchResponse(SsdpConstants.UpnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);if (this.SupportPnpRootDevice)+ {SendSearchResponse(SsdpConstants.PnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);+ }}SendSearchResponse(device.Udn, device, device.Udn, endPoint, receivedOnlocalIpAddress, cancellationToken);@@ -394,7 +398,9 @@ namespace Rssdp.Infrastructure{var lastRequest = _RecentSearchRequests[newRequest.Key];if (lastRequest.IsOld())+ {_RecentSearchRequests[newRequest.Key] = newRequest;+ }elseisDuplicateRequest = true;}@@ -402,7 +408,9 @@ namespace Rssdp.Infrastructure{_RecentSearchRequests.Add(newRequest.Key, newRequest);if (_RecentSearchRequests.Count > 10)+ {CleanUpRecentSearchRequestsAsync();+ }}}@@ -462,7 +470,9 @@ namespace Rssdp.Infrastructure{SendAliveNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken);if (this.SupportPnpRootDevice)+ {SendAliveNotification(device, SsdpConstants.PnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), cancellationToken);+ }}SendAliveNotification(device, device.Udn, device.Udn, cancellationToken);@@ -506,7 +516,9 @@ namespace Rssdp.Infrastructure{tasks.Add(SendByeByeNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken));if (this.SupportPnpRootDevice)+ {tasks.Add(SendByeByeNotification(device, "pnp:rootdevice", GetUsn(device.Udn, "pnp:rootdevice"), cancellationToken));+ }}tasks.Add(SendByeByeNotification(device, device.Udn, device.Udn, cancellationToken));@@ -547,20 +559,27 @@ namespace Rssdp.Infrastructurevar timer = _RebroadcastAliveNotificationsTimer;_RebroadcastAliveNotificationsTimer = null;if (timer != null)+ {timer.Dispose();+ }}private TimeSpan GetMinimumNonZeroCacheLifetime(){- var nonzeroCacheLifetimesQuery = (from device- in _Devices- where device.CacheLifetime != TimeSpan.Zero- select device.CacheLifetime).ToList();+ var nonzeroCacheLifetimesQuery = (+ from device+ in _Devices+ where device.CacheLifetime != TimeSpan.Zero+ select device.CacheLifetime).ToList();if (nonzeroCacheLifetimesQuery.Any())+ {return nonzeroCacheLifetimesQuery.Min();+ }else+ {return TimeSpan.Zero;+ }}private string GetFirstHeaderValue(System.Net.Http.Headers.HttpRequestHeaders httpRequestHeaders, string headerName)@@ -568,7 +587,9 @@ namespace Rssdp.Infrastructurestring retVal = null;IEnumerable<String> values = null;if (httpRequestHeaders.TryGetValues(headerName, out values) && values != null)+ {retVal = values.FirstOrDefault();+ }return retVal;}@@ -588,7 +609,9 @@ namespace Rssdp.Infrastructure{var rootDevice = device as SsdpRootDevice;if (rootDevice != null)+ {WriteTrace(text + " " + device.DeviceType + " - " + device.Uuid + " - " + rootDevice.Location);+ }elseWriteTrace(text + " " + device.DeviceType + " - " + device.Uuid);}