From f02c3260273a09f465c4e7a97d8b90f0f6909734 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 8 May 2014 16:09:53 -0400 Subject: Removed guids from the model project --- MediaBrowser.Model/Web/QueryStringDictionary.cs | 44 ------------------------- 1 file changed, 44 deletions(-) (limited to 'MediaBrowser.Model/Web/QueryStringDictionary.cs') diff --git a/MediaBrowser.Model/Web/QueryStringDictionary.cs b/MediaBrowser.Model/Web/QueryStringDictionary.cs index 905fbb215..6b035fa45 100644 --- a/MediaBrowser.Model/Web/QueryStringDictionary.cs +++ b/MediaBrowser.Model/Web/QueryStringDictionary.cs @@ -122,50 +122,6 @@ namespace MediaBrowser.Model.Web } } - /// - /// Adds the specified name. - /// - /// The name. - /// The value. - /// value - public void Add(string name, Guid value) - { - if (value == Guid.Empty) - { - throw new ArgumentNullException("value"); - } - - Add(name, value.ToString()); - } - - /// - /// Adds if not empty. - /// - /// The name. - /// The value. - public void AddIfNotEmpty(string name, Guid value) - { - if (value != Guid.Empty) - { - Add(name, value); - } - - Add(name, value); - } - - /// - /// Adds if not null. - /// - /// The name. - /// The value. - public void AddIfNotNull(string name, Guid? value) - { - if (value.HasValue) - { - Add(name, value.Value); - } - } - /// /// Adds the specified name. /// -- cgit v1.2.3 From e653b41000c2116c555691f866710f2239553322 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 8 May 2014 16:44:17 -0400 Subject: removed implicit typing from the model project --- .../Configuration/NotificationOptions.cs | 8 ++-- .../Configuration/ServerConfiguration.cs | 2 +- MediaBrowser.Model/Dlna/CodecProfile.cs | 2 +- MediaBrowser.Model/Dlna/ConditionProcessor.cs | 4 +- MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs | 44 +++++++++++----------- MediaBrowser.Model/Dlna/DeviceProfile.cs | 22 +++++------ MediaBrowser.Model/Dlna/DlnaMaps.cs | 4 +- .../Dlna/MediaFormatProfileResolver.cs | 12 +++--- MediaBrowser.Model/Drawing/DrawingUtils.cs | 6 +-- MediaBrowser.Model/Entities/DisplayPreferences.cs | 6 +-- MediaBrowser.Model/Web/QueryStringDictionary.cs | 8 ++-- 11 files changed, 59 insertions(+), 59 deletions(-) (limited to 'MediaBrowser.Model/Web/QueryStringDictionary.cs') diff --git a/MediaBrowser.Model/Configuration/NotificationOptions.cs b/MediaBrowser.Model/Configuration/NotificationOptions.cs index 7034bd39e..0ed43ae1e 100644 --- a/MediaBrowser.Model/Configuration/NotificationOptions.cs +++ b/MediaBrowser.Model/Configuration/NotificationOptions.cs @@ -75,14 +75,14 @@ namespace MediaBrowser.Model.Configuration public bool IsEnabled(string type) { - var opt = GetOptions(type); + NotificationOption opt = GetOptions(type); return opt != null && opt.Enabled; } public bool IsServiceEnabled(string service, string notificationType) { - var opt = GetOptions(notificationType); + NotificationOption opt = GetOptions(notificationType); return opt == null || !opt.DisabledServices.Contains(service, StringComparer.OrdinalIgnoreCase); @@ -90,7 +90,7 @@ namespace MediaBrowser.Model.Configuration public bool IsEnabledToMonitorUser(string type, string userId) { - var opt = GetOptions(type); + NotificationOption opt = GetOptions(type); return opt != null && opt.Enabled && !opt.DisabledMonitorUsers.Contains(userId, StringComparer.OrdinalIgnoreCase); @@ -98,7 +98,7 @@ namespace MediaBrowser.Model.Configuration public bool IsEnabledToSendToUser(string type, string userId, UserConfiguration userConfig) { - var opt = GetOptions(type); + NotificationOption opt = GetOptions(type); if (opt != null && opt.Enabled) { diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 36598b245..c19039439 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -271,7 +271,7 @@ namespace MediaBrowser.Model.Configuration EnableRealtimeMonitor = true; - var options = new List + List options = new List { new MetadataOptions(1, 1280) {ItemType = "Book"}, new MetadataOptions(1, 1280) {ItemType = "MusicAlbum"}, diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs index 7d7e0057e..61eb2f639 100644 --- a/MediaBrowser.Model/Dlna/CodecProfile.cs +++ b/MediaBrowser.Model/Dlna/CodecProfile.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Model.Dlna public bool ContainsCodec(string codec) { - var codecs = GetCodecs(); + List codecs = GetCodecs(); return codecs.Count == 0 || codecs.Contains(codec, StringComparer.OrdinalIgnoreCase); } diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index 27c4850e8..488d742f5 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -136,7 +136,7 @@ namespace MediaBrowser.Model.Dlna return !condition.IsRequired; } - var expected = condition.Value; + string expected = condition.Value; switch (condition.Condition) { @@ -186,7 +186,7 @@ namespace MediaBrowser.Model.Dlna return !condition.IsRequired; } - var expected = (TransportStreamTimestamp)Enum.Parse(typeof(TransportStreamTimestamp), condition.Value, true); + TransportStreamTimestamp expected = (TransportStreamTimestamp)Enum.Parse(typeof(TransportStreamTimestamp), condition.Value, true); switch (condition.Condition) { diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs index 5a6be389d..5309df131 100644 --- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs +++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs @@ -17,30 +17,30 @@ namespace MediaBrowser.Model.Dlna int? width, int? height) { - var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue(); + string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue(); // 0 = native, 1 = transcoded const string orgCi = ";DLNA.ORG_CI=0"; - var flagValue = DlnaFlags.StreamingTransferMode | + DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.DlnaV15; - var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", + string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", FlagsToString(flagValue)); - var mediaProfile = _profile.GetImageMediaProfile(container, + ResponseProfile mediaProfile = _profile.GetImageMediaProfile(container, width, height); - var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; + string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { orgPn = GetImageOrgPnValue(container, width, height); } - var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; + string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); } @@ -55,12 +55,12 @@ namespace MediaBrowser.Model.Dlna TranscodeSeekInfo transcodeSeekInfo) { // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none - var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); + string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded - var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; + string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; - var flagValue = DlnaFlags.StreamingTransferMode | + DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.DlnaV15; @@ -73,22 +73,22 @@ namespace MediaBrowser.Model.Dlna //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_TIME_BASED_SEEK; } - var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", + string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", FlagsToString(flagValue)); - var mediaProfile = _profile.GetAudioMediaProfile(container, + ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(container, audioCodec, audioChannels, audioBitrate); - var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; + string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels); } - var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; + string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); } @@ -118,12 +118,12 @@ namespace MediaBrowser.Model.Dlna TranscodeSeekInfo transcodeSeekInfo) { // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none - var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); + string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded - var orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; + string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; - var flagValue = DlnaFlags.StreamingTransferMode | + DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.DlnaV15; @@ -136,10 +136,10 @@ namespace MediaBrowser.Model.Dlna //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_TIME_BASED_SEEK; } - var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", + string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", FlagsToString(flagValue)); - var mediaProfile = _profile.GetVideoMediaProfile(container, + ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container, audioCodec, videoCodec, audioBitrate, @@ -154,7 +154,7 @@ namespace MediaBrowser.Model.Dlna packetLength, timestamp); - var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; + string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { @@ -165,14 +165,14 @@ namespace MediaBrowser.Model.Dlna orgPn = (orgPn ?? string.Empty).Split(',').FirstOrDefault(); } - var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; + string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); } private string GetImageOrgPnValue(string container, int? width, int? height) { - var format = new MediaFormatProfileResolver() + MediaFormatProfile? format = new MediaFormatProfileResolver() .ResolveImageFormat(container, width, height); @@ -182,7 +182,7 @@ namespace MediaBrowser.Model.Dlna private string GetAudioOrgPnValue(string container, int? audioBitrate, int? audioSampleRate, int? audioChannels) { - var format = new MediaFormatProfileResolver() + MediaFormatProfile? format = new MediaFormatProfileResolver() .ResolveAudioFormat(container, audioBitrate, audioSampleRate, diff --git a/MediaBrowser.Model/Dlna/DeviceProfile.cs b/MediaBrowser.Model/Dlna/DeviceProfile.cs index b23ad876c..e0b682e4a 100644 --- a/MediaBrowser.Model/Dlna/DeviceProfile.cs +++ b/MediaBrowser.Model/Dlna/DeviceProfile.cs @@ -174,19 +174,19 @@ namespace MediaBrowser.Model.Dlna return false; } - var containers = i.GetContainers().ToList(); + List containers = i.GetContainers().ToList(); if (containers.Count > 0 && !containers.Contains(container)) { return false; } - var audioCodecs = i.GetAudioCodecs().ToList(); + List audioCodecs = i.GetAudioCodecs().ToList(); if (audioCodecs.Count > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty)) { return false; } - var conditionProcessor = new ConditionProcessor(); + ConditionProcessor conditionProcessor = new ConditionProcessor(); return i.Conditions.All(c => conditionProcessor.IsAudioConditionSatisfied(c, audioChannels, audioBitrate)); @@ -204,13 +204,13 @@ namespace MediaBrowser.Model.Dlna return false; } - var containers = i.GetContainers().ToList(); + List containers = i.GetContainers().ToList(); if (containers.Count > 0 && !containers.Contains(container)) { return false; } - var conditionProcessor = new ConditionProcessor(); + ConditionProcessor conditionProcessor = new ConditionProcessor(); return i.Conditions.All(c => conditionProcessor.IsImageConditionSatisfied(c, width, height)); @@ -241,25 +241,25 @@ namespace MediaBrowser.Model.Dlna return false; } - var containers = i.GetContainers().ToList(); + List containers = i.GetContainers().ToList(); if (containers.Count > 0 && !containers.Contains(container)) { return false; } - var audioCodecs = i.GetAudioCodecs().ToList(); + List audioCodecs = i.GetAudioCodecs().ToList(); if (audioCodecs.Count > 0 && !audioCodecs.Contains(audioCodec ?? string.Empty)) { return false; } - var videoCodecs = i.GetVideoCodecs().ToList(); + List videoCodecs = i.GetVideoCodecs().ToList(); if (videoCodecs.Count > 0 && !videoCodecs.Contains(videoCodec ?? string.Empty)) { return false; } - var conditionProcessor = new ConditionProcessor(); + ConditionProcessor conditionProcessor = new ConditionProcessor(); return i.Conditions.All(c => conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, @@ -286,13 +286,13 @@ namespace MediaBrowser.Model.Dlna return false; } - var containers = i.GetContainers().ToList(); + List containers = i.GetContainers().ToList(); if (containers.Count > 0 && !containers.Contains(container)) { return false; } - var conditionProcessor = new ConditionProcessor(); + ConditionProcessor conditionProcessor = new ConditionProcessor(); return i.Conditions.All(c => conditionProcessor.IsImageConditionSatisfied(c, width, height)); diff --git a/MediaBrowser.Model/Dlna/DlnaMaps.cs b/MediaBrowser.Model/Dlna/DlnaMaps.cs index 0a4069d8f..036c1fc74 100644 --- a/MediaBrowser.Model/Dlna/DlnaMaps.cs +++ b/MediaBrowser.Model/Dlna/DlnaMaps.cs @@ -25,7 +25,7 @@ { if (hasKnownRuntime) { - var orgOp = string.Empty; + string orgOp = string.Empty; // Time-based seeking currently only possible when transcoding orgOp += isDirectStream ? "0" : "1"; @@ -42,7 +42,7 @@ public static string GetImageOrgOpValue() { - var orgOp = string.Empty; + string orgOp = string.Empty; // Time-based seeking currently only possible when transcoding orgOp += "0"; diff --git a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs index b5f5dd138..3c35ca0f6 100644 --- a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs +++ b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs @@ -10,13 +10,13 @@ namespace MediaBrowser.Model.Dlna { if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase)) { - var val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height); + MediaFormatProfile? val = ResolveVideoASFFormat(videoCodec, audioCodec, width, height); return val.HasValue ? new List { val.Value } : new List(); } if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase)) { - var val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height); + MediaFormatProfile? val = ResolveVideoMP4Format(videoCodec, audioCodec, width, height); return val.HasValue ? new List { val.Value } : new List(); } @@ -50,7 +50,7 @@ namespace MediaBrowser.Model.Dlna if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase)) { - var val = ResolveVideo3GPFormat(videoCodec, audioCodec); + MediaFormatProfile? val = ResolveVideo3GPFormat(videoCodec, audioCodec); return val.HasValue ? new List { val.Value } : new List(); } @@ -62,7 +62,7 @@ namespace MediaBrowser.Model.Dlna private IEnumerable ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestampType) { - var suffix = ""; + string suffix = ""; switch (timestampType) { @@ -74,7 +74,7 @@ namespace MediaBrowser.Model.Dlna break; } - var resolution = "S"; + string resolution = "S"; if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576)) { resolution = "H"; @@ -82,7 +82,7 @@ namespace MediaBrowser.Model.Dlna if (string.Equals(videoCodec, "mpeg2video", StringComparison.OrdinalIgnoreCase)) { - var list = new List(); + List list = new List(); list.Add(ValueOf("MPEG_TS_SD_NA" + suffix)); list.Add(ValueOf("MPEG_TS_SD_EU" + suffix)); diff --git a/MediaBrowser.Model/Drawing/DrawingUtils.cs b/MediaBrowser.Model/Drawing/DrawingUtils.cs index 7f679a826..fcc5ddd16 100644 --- a/MediaBrowser.Model/Drawing/DrawingUtils.cs +++ b/MediaBrowser.Model/Drawing/DrawingUtils.cs @@ -30,7 +30,7 @@ /// ImageSize. public static ImageSize Scale(ImageSize size, double scaleFactor) { - var newWidth = size.Width * scaleFactor; + double newWidth = size.Width * scaleFactor; return Resize(size.Width, size.Height, newWidth, null, null, null); } @@ -120,7 +120,7 @@ /// System.Double. private static double GetNewWidth(double currentHeight, double currentWidth, double newHeight) { - var scaleFactor = newHeight; + double scaleFactor = newHeight; scaleFactor /= currentHeight; scaleFactor *= currentWidth; @@ -136,7 +136,7 @@ /// System.Double. private static double GetNewHeight(double currentHeight, double currentWidth, double newWidth) { - var scaleFactor = newWidth; + double scaleFactor = newWidth; scaleFactor /= currentWidth; scaleFactor *= currentHeight; diff --git a/MediaBrowser.Model/Entities/DisplayPreferences.cs b/MediaBrowser.Model/Entities/DisplayPreferences.cs index 2fdab9799..56a2c6194 100644 --- a/MediaBrowser.Model/Entities/DisplayPreferences.cs +++ b/MediaBrowser.Model/Entities/DisplayPreferences.cs @@ -103,9 +103,9 @@ namespace MediaBrowser.Model.Entities /// public void IncreaseImageSize() { - var newWidth = PrimaryImageWidth / ImageScale; + double newWidth = PrimaryImageWidth / ImageScale; - var size = DrawingUtils.Resize(PrimaryImageWidth, PrimaryImageHeight, newWidth, null, null, null); + ImageSize size = DrawingUtils.Resize(PrimaryImageWidth, PrimaryImageHeight, newWidth, null, null, null); PrimaryImageWidth = Convert.ToInt32(size.Width); PrimaryImageHeight = Convert.ToInt32(size.Height); @@ -116,7 +116,7 @@ namespace MediaBrowser.Model.Entities /// public void DecreaseImageSize() { - var size = DrawingUtils.Scale(PrimaryImageWidth, PrimaryImageHeight, ImageScale); + ImageSize size = DrawingUtils.Scale(PrimaryImageWidth, PrimaryImageHeight, ImageScale); PrimaryImageWidth = Convert.ToInt32(size.Width); PrimaryImageHeight = Convert.ToInt32(size.Height); diff --git a/MediaBrowser.Model/Web/QueryStringDictionary.cs b/MediaBrowser.Model/Web/QueryStringDictionary.cs index 6b035fa45..b532358ff 100644 --- a/MediaBrowser.Model/Web/QueryStringDictionary.cs +++ b/MediaBrowser.Model/Web/QueryStringDictionary.cs @@ -164,7 +164,7 @@ namespace MediaBrowser.Model.Web throw new ArgumentNullException("value"); } - var paramValue = string.Join(",", value.ToArray()); + string paramValue = string.Join(",", value.ToArray()); Add(name, paramValue); } @@ -196,7 +196,7 @@ namespace MediaBrowser.Model.Web throw new ArgumentNullException("value"); } - var paramValue = string.Join(delimiter, value.ToArray()); + string paramValue = string.Join(delimiter, value.ToArray()); Add(name, paramValue); } @@ -221,7 +221,7 @@ namespace MediaBrowser.Model.Web /// System.String. public string GetQueryString() { - var queryParams = this.Select(i => string.Format("{0}={1}", i.Key, GetEncodedValue(i.Value))).ToArray(); + string[] queryParams = this.Select(i => string.Format("{0}={1}", i.Key, GetEncodedValue(i.Value))).ToArray(); return string.Join("&", queryParams); } @@ -243,7 +243,7 @@ namespace MediaBrowser.Model.Web /// System.String. public string GetUrl(string prefix) { - var query = GetQueryString(); + string query = GetQueryString(); if (string.IsNullOrEmpty(query)) { -- cgit v1.2.3 From 1a323767be3808f8cdd055e8481ca8c1ea0b1582 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 9 May 2014 00:38:12 -0400 Subject: Do better to make sure hls files are cleaned up --- MediaBrowser.Api/ApiEntryPoint.cs | 36 +--- .../DefaultTheme/DefaultThemeService.cs | 13 +- MediaBrowser.Api/Playback/BaseStreamingService.cs | 2 +- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 4 +- MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 4 +- .../Playback/Progressive/VideoService.cs | 4 +- MediaBrowser.Controller/Entities/TV/Episode.cs | 8 +- .../Configuration/MetadataOptions.cs | 20 ++- .../Configuration/NotificationOptions.cs | 6 +- .../Configuration/NotificationType.cs | 1 + MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs | 31 ++-- MediaBrowser.Model/Dlna/Filter.cs | 7 +- MediaBrowser.Model/Dlna/TranscodingProfile.cs | 1 - MediaBrowser.Model/Entities/MediaStream.cs | 18 +- MediaBrowser.Model/Web/QueryStringDictionary.cs | 11 +- .../EntryPoints/Notifications/Notifications.cs | 21 ++- .../Localization/Server/server.json | 7 +- .../Notifications/CoreNotificationTypes.cs | 7 + OpenSubtitlesHandler/OpenSubtitles.cs | 181 +++++++++++++++++++++ 19 files changed, 297 insertions(+), 85 deletions(-) (limited to 'MediaBrowser.Model/Web/QueryStringDictionary.cs') diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index f35ade432..9b04ec011 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -71,8 +71,7 @@ namespace MediaBrowser.Api /// private void DeleteEncodedMediaCache() { - foreach (var file in Directory.EnumerateFiles(_appPaths.TranscodingTempPath) - .Where(i => EntityResolutionHelper.VideoFileExtensions.Contains(Path.GetExtension(i))) + foreach (var file in Directory.EnumerateFiles(_appPaths.TranscodingTempPath, "*", SearchOption.AllDirectories) .ToList()) { File.Delete(file); @@ -116,11 +115,10 @@ namespace MediaBrowser.Api /// The path. /// The type. /// The process. - /// if set to true [is video]. /// The start time ticks. /// The source path. /// The device id. - public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, bool isVideo, long? startTimeTicks, string sourcePath, string deviceId) + public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, long? startTimeTicks, string sourcePath, string deviceId) { lock (_activeTranscodingJobs) { @@ -130,7 +128,6 @@ namespace MediaBrowser.Api Path = path, Process = process, ActiveRequestCount = 1, - IsVideo = isVideo, StartTimeTicks = startTimeTicks, SourcePath = sourcePath, DeviceId = deviceId @@ -261,7 +258,7 @@ namespace MediaBrowser.Api { // This is really only needed for HLS. // Progressive streams can stop on their own reliably - jobs.AddRange(_activeTranscodingJobs.Where(i => isVideo == i.IsVideo && string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase))); + jobs.AddRange(_activeTranscodingJobs.Where(i => string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase))); } foreach (var job in jobs) @@ -325,37 +322,15 @@ namespace MediaBrowser.Api } } - // Determine if it exited successfully - var hasExitedSuccessfully = false; - - try - { - hasExitedSuccessfully = process.ExitCode == 0; - } - catch (InvalidOperationException) - { - - } - catch (NotSupportedException) - { - - } - // Dispose the process process.Dispose(); - // If it didn't complete successfully cleanup the partial files - // Also don't cache output from resume points - // Also don't cache video - if (!hasExitedSuccessfully || job.StartTimeTicks.HasValue || job.IsVideo) - { - DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); - } + DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } private async void DeletePartialStreamFiles(string path, TranscodingJobType jobType, int retryCount, int delayMs) { - if (retryCount >= 5) + if (retryCount >= 10) { return; } @@ -455,7 +430,6 @@ namespace MediaBrowser.Api /// The kill timer. public Timer KillTimer { get; set; } - public bool IsVideo { get; set; } public long? StartTimeTicks { get; set; } public string SourcePath { get; set; } public string DeviceId { get; set; } diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index cd04a8212..6acecd342 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -24,6 +24,8 @@ namespace MediaBrowser.Api.DefaultTheme [ApiMember(Name = "RecentlyPlayedGamesLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int RecentlyPlayedGamesLimit { get; set; } + + public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/TV", "GET")] @@ -49,6 +51,8 @@ namespace MediaBrowser.Api.DefaultTheme [ApiMember(Name = "LatestEpisodeLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int LatestEpisodeLimit { get; set; } + + public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/Movies", "GET")] @@ -71,6 +75,8 @@ namespace MediaBrowser.Api.DefaultTheme [ApiMember(Name = "LatestTrailersLimit", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public int LatestTrailersLimit { get; set; } + + public string ParentId { get; set; } } [Route("/MBT/DefaultTheme/Favorites", "GET")] @@ -224,7 +230,7 @@ namespace MediaBrowser.Api.DefaultTheme { var user = _userManager.GetUserById(request.UserId); - var items = user.RootFolder.GetRecursiveChildren(user, i => i is Game || i is GameSystem) + var items = GetAllLibraryItems(user.Id, _userManager, _libraryManager, request.ParentId).Where(i => i is Game || i is GameSystem) .ToList(); var gamesWithImages = items.OfType().Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)).ToList(); @@ -280,7 +286,7 @@ namespace MediaBrowser.Api.DefaultTheme var user = _userManager.GetUserById(request.UserId); - var series = user.RootFolder.GetRecursiveChildren(user) + var series = GetAllLibraryItems(user.Id, _userManager, _libraryManager, request.ParentId) .OfType() .ToList(); @@ -403,7 +409,8 @@ namespace MediaBrowser.Api.DefaultTheme { var user = _userManager.GetUserById(request.UserId); - var items = user.RootFolder.GetRecursiveChildren(user, i => i is Movie || i is Trailer || i is BoxSet) + var items = GetAllLibraryItems(user.Id, _userManager, _libraryManager, request.ParentId) + .Where(i => i is Movie || i is Trailer || i is BoxSet) .ToList(); var view = new MoviesView(); diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 7e352e4de..23209b59c 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -903,7 +903,7 @@ namespace MediaBrowser.Api.Playback EnableRaisingEvents = true }; - ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process, state.IsInputVideo, state.Request.StartTimeTicks, state.MediaPath, state.Request.DeviceId); + ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process, state.Request.StartTimeTicks, state.MediaPath, state.Request.DeviceId); var commandLineLogMessage = process.StartInfo.FileName + " " + process.StartInfo.Arguments; Logger.Info(commandLineLogMessage); diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index c86550404..fd93ef685 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -273,9 +273,7 @@ namespace MediaBrowser.Api.Playback.Hls const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))"; - var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsExternal && - (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || - state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1); + var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg; diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index efd98616f..77ac95815 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -168,9 +168,7 @@ namespace MediaBrowser.Api.Playback.Hls " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+1))" : " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))"; - var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsExternal && - (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || - state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1); + var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; var args = "-codec:v:0 " + codec + " " + GetVideoQualityParam(state, "libx264", true) + keyFrameArg; diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index f21e69290..d7061ae75 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -146,9 +146,7 @@ namespace MediaBrowser.Api.Playback.Progressive args += keyFrameArg; - var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsExternal && - (state.SubtitleStream.Codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || - state.SubtitleStream.Codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1); + var hasGraphicalSubs = state.SubtitleStream != null && state.SubtitleStream.IsGraphicalSubtitleStream; var request = state.VideoRequest; diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 503d1513c..be761ef66 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -305,13 +305,7 @@ namespace MediaBrowser.Controller.Entities.TV if (!ParentIndexNumber.HasValue && !string.IsNullOrEmpty(Path)) { - ParentIndexNumber = TVUtils.GetSeasonNumberFromPath(Path); - - // If a change was made record it - if (ParentIndexNumber.HasValue) - { - hasChanges = true; - } + ParentIndexNumber = TVUtils.GetSeasonNumberFromEpisodeFile(Path); } // If a change was made record it diff --git a/MediaBrowser.Model/Configuration/MetadataOptions.cs b/MediaBrowser.Model/Configuration/MetadataOptions.cs index 88fa486f9..fdfbbf4f4 100644 --- a/MediaBrowser.Model/Configuration/MetadataOptions.cs +++ b/MediaBrowser.Model/Configuration/MetadataOptions.cs @@ -52,14 +52,30 @@ namespace MediaBrowser.Model.Configuration public int GetLimit(ImageType type) { - ImageOption option = ImageOptions.FirstOrDefault(i => i.Type == type); + ImageOption option = null; + foreach (ImageOption i in ImageOptions) + { + if (i.Type == type) + { + option = i; + break; + } + } return option == null ? 1 : option.Limit; } public int GetMinWidth(ImageType type) { - ImageOption option = ImageOptions.FirstOrDefault(i => i.Type == type); + ImageOption option = null; + foreach (ImageOption i in ImageOptions) + { + if (i.Type == type) + { + option = i; + break; + } + } return option == null ? 0 : option.MinWidth; } diff --git a/MediaBrowser.Model/Configuration/NotificationOptions.cs b/MediaBrowser.Model/Configuration/NotificationOptions.cs index 0ed43ae1e..d6517e895 100644 --- a/MediaBrowser.Model/Configuration/NotificationOptions.cs +++ b/MediaBrowser.Model/Configuration/NotificationOptions.cs @@ -70,7 +70,11 @@ namespace MediaBrowser.Model.Configuration public NotificationOption GetOptions(string type) { - return Options.FirstOrDefault(i => string.Equals(type, i.Type, StringComparison.OrdinalIgnoreCase)); + foreach (NotificationOption i in Options) + { + if (string.Equals(type, i.Type, StringComparison.OrdinalIgnoreCase)) return i; + } + return null; } public bool IsEnabled(string type) diff --git a/MediaBrowser.Model/Configuration/NotificationType.cs b/MediaBrowser.Model/Configuration/NotificationType.cs index eaafb651c..0ddcf4251 100644 --- a/MediaBrowser.Model/Configuration/NotificationType.cs +++ b/MediaBrowser.Model/Configuration/NotificationType.cs @@ -12,6 +12,7 @@ namespace MediaBrowser.Model.Configuration PluginUpdateInstalled, PluginUninstalled, NewLibraryContent, + NewLibraryContentMultiple, ServerRestartRequired, TaskFailed, VideoPlayback diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs index 5309df131..a7ad49cba 100644 --- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs +++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs @@ -1,6 +1,5 @@ using MediaBrowser.Model.MediaInfo; using System.Collections.Generic; -using System.Linq; namespace MediaBrowser.Model.Dlna { @@ -158,11 +157,21 @@ namespace MediaBrowser.Model.Dlna if (string.IsNullOrEmpty(orgPn)) { - orgPn = GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp) - .FirstOrDefault(); + foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp)) + { + orgPn = s; + break; + } + } + if (string.IsNullOrEmpty(orgPn)) + { // TODO: Support multiple values and return multiple headers? - orgPn = (orgPn ?? string.Empty).Split(',').FirstOrDefault(); + foreach (string s in (orgPn ?? string.Empty).Split(',')) + { + orgPn = s; + break; + } } string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; @@ -191,16 +200,12 @@ namespace MediaBrowser.Model.Dlna return format.HasValue ? format.Value.ToString() : null; } - private IEnumerable GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestamp) + private List GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestamp) { - return new MediaFormatProfileResolver() - .ResolveVideoFormat(container, - videoCodec, - audioCodec, - width, - height, - timestamp) - .Select(i => i.ToString()); + List list = new List(); + foreach (MediaFormatProfile i in new MediaFormatProfileResolver().ResolveVideoFormat(container, videoCodec, audioCodec, width, height, timestamp)) + list.Add(i.ToString()); + return list; } } } diff --git a/MediaBrowser.Model/Dlna/Filter.cs b/MediaBrowser.Model/Dlna/Filter.cs index c8940734b..760adb585 100644 --- a/MediaBrowser.Model/Dlna/Filter.cs +++ b/MediaBrowser.Model/Dlna/Filter.cs @@ -19,9 +19,10 @@ namespace MediaBrowser.Model.Dlna { _all = string.Equals(filter, "*", StringComparison.OrdinalIgnoreCase); - _fields = (filter ?? string.Empty) - .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) - .ToList(); + List list = new List(); + foreach (string s in (filter ?? string.Empty).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)) + list.Add(s); + _fields = list; } public bool Contains(string field) diff --git a/MediaBrowser.Model/Dlna/TranscodingProfile.cs b/MediaBrowser.Model/Dlna/TranscodingProfile.cs index bee5f2a69..51f4bfe61 100644 --- a/MediaBrowser.Model/Dlna/TranscodingProfile.cs +++ b/MediaBrowser.Model/Dlna/TranscodingProfile.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Xml.Serialization; namespace MediaBrowser.Model.Dlna diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 66163c1ef..9f64b36e4 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -1,4 +1,6 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; +using System.Runtime.Serialization; namespace MediaBrowser.Model.Entities { @@ -128,6 +130,20 @@ namespace MediaBrowser.Model.Entities /// true if this instance is external; otherwise, false. public bool IsExternal { get; set; } + [IgnoreDataMember] + public bool IsGraphicalSubtitleStream + { + get + { + if (IsExternal) return false; + + var codec = Codec ?? string.Empty; + + return codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) != -1 || + codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) != -1; + } + } + /// /// Gets or sets the filename. /// diff --git a/MediaBrowser.Model/Web/QueryStringDictionary.cs b/MediaBrowser.Model/Web/QueryStringDictionary.cs index b532358ff..b011d4d9c 100644 --- a/MediaBrowser.Model/Web/QueryStringDictionary.cs +++ b/MediaBrowser.Model/Web/QueryStringDictionary.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; namespace MediaBrowser.Model.Web @@ -24,7 +25,7 @@ namespace MediaBrowser.Model.Web /// The value. public void Add(string name, int value) { - Add(name, value.ToString()); + Add(name, value.ToString(CultureInfo.InvariantCulture)); } /// @@ -34,7 +35,7 @@ namespace MediaBrowser.Model.Web /// The value. public void Add(string name, long value) { - Add(name, value.ToString()); + Add(name, value.ToString(CultureInfo.InvariantCulture)); } /// @@ -44,7 +45,7 @@ namespace MediaBrowser.Model.Web /// The value. public void Add(string name, double value) { - Add(name, value.ToString()); + Add(name, value.ToString(CultureInfo.InvariantCulture)); } /// @@ -135,7 +136,7 @@ namespace MediaBrowser.Model.Web throw new ArgumentNullException("value"); } - Add(name, string.Join(",", value.Select(v => v.ToString()).ToArray())); + Add(name, string.Join(",", value.Select(v => v.ToString(CultureInfo.InvariantCulture)).ToArray())); } /// @@ -188,7 +189,7 @@ namespace MediaBrowser.Model.Web /// The name. /// The value. /// The delimiter. - /// value + /// value public void Add(string name, IEnumerable value, string delimiter) { if (value == null) diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs index 7607ec98a..fdc81db37 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Events; +using System.Globalization; +using MediaBrowser.Common.Events; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.Updates; @@ -247,10 +248,10 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications DisposeLibraryUpdateTimer(); } - var item = items.FirstOrDefault(); - - if (item != null) + if (items.Count == 1) { + var item = items.First(); + var notification = new NotificationRequest { NotificationType = NotificationType.NewLibraryContent.ToString() @@ -258,10 +259,16 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications notification.Variables["Name"] = item.Name; - if (items.Count > 1) + await SendNotification(notification).ConfigureAwait(false); + } + else + { + var notification = new NotificationRequest { - notification.Name = items.Count + " new library items."; - } + NotificationType = NotificationType.NewLibraryContentMultiple.ToString() + }; + + notification.Variables["ItemCount"] = items.Count.ToString(CultureInfo.InvariantCulture); await SendNotification(notification).ConfigureAwait(false); } diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 781a4c5b7..bcd04f4ae 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -568,6 +568,7 @@ "NotificationOptionTaskFailed": "Scheduled task failure", "NotificationOptionInstallationFailed": "Installation failure", "NotificationOptionNewLibraryContent": "New content added", + "NotificationOptionNewLibraryContentMultiple": "New content added (multiple)", "SendNotificationHelp": "By default, notifications are delivered to the dashboard inbox. Browse the plugin catalog to install additional notification options.", "NotificationOptionServerRestartRequired": "Server restart required", "LabelNotificationEnabled": "Enable this notification", @@ -716,5 +717,9 @@ "LabelDownloadLanguages": "Download languages:", "ButtonRegister": "Register", "LabelSkipIfAudioTrackPresent": "Skip if the default audio track matches the download language", - "LabelSkipIfAudioTrackPresentHelp": "Uncheck this to ensure all videos have subtitles, regardless of audio language." + "LabelSkipIfAudioTrackPresentHelp": "Uncheck this to ensure all videos have subtitles, regardless of audio language.", + "HeaderSendMessage": "Send Message", + "ButtonSend": "Send", + "LabelMessageText": "Message text:", + "LabelMessageTitle": "Message title:" } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs b/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs index f712949d9..012b5ae92 100644 --- a/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs +++ b/MediaBrowser.Server.Implementations/Notifications/CoreNotificationTypes.cs @@ -90,6 +90,13 @@ namespace MediaBrowser.Server.Implementations.Notifications Variables = new List{"Name"} }, + new NotificationTypeInfo + { + Type = NotificationType.NewLibraryContentMultiple.ToString(), + DefaultTitle = "{ItemCount} new items have been added to your media library.", + Variables = new List{"ItemCount"} + }, + new NotificationTypeInfo { Type = NotificationType.AudioPlayback.ToString(), diff --git a/OpenSubtitlesHandler/OpenSubtitles.cs b/OpenSubtitlesHandler/OpenSubtitles.cs index e810dad69..9452c25ec 100644 --- a/OpenSubtitlesHandler/OpenSubtitles.cs +++ b/OpenSubtitlesHandler/OpenSubtitles.cs @@ -440,6 +440,187 @@ namespace OpenSubtitlesHandler } return new MethodResponseError("Fail", "Search Subtitles call failed !"); } + + public static async Task SearchSubtitlesAsync(SubtitleSearchParameters[] parameters, CancellationToken cancellationToken) + { + if (TOKEN == "") + { + OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error); + return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first."); + } + if (parameters == null) + { + OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle search parameter passed"); ; + } + if (parameters.Length == 0) + { + OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle search parameter passed"); ; + } + // Method call .. + List parms = new List(); + // Add token param + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + // Add subtitle search parameters. Each one will be like 'array' of structs. + XmlRpcValueArray array = new XmlRpcValueArray(); + foreach (SubtitleSearchParameters param in parameters) + { + XmlRpcValueStruct strct = new XmlRpcValueStruct(new List()); + // sublanguageid member + XmlRpcStructMember member = new XmlRpcStructMember("sublanguageid", + new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + // moviehash member + if (param.MovieHash.Length > 0 && param.MovieByteSize > 0) + { + member = new XmlRpcStructMember("moviehash", + new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + // moviehash member + member = new XmlRpcStructMember("moviebytesize", + new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int)); + strct.Members.Add(member); + } + if (param.Query.Length > 0) + { + member = new XmlRpcStructMember("query", + new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + } + + if (param.Episode.Length > 0 && param.Season.Length > 0) + { + member = new XmlRpcStructMember("season", + new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + member = new XmlRpcStructMember("episode", + new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + } + + // imdbid member + if (param.IMDbID.Length > 0) + { + member = new XmlRpcStructMember("imdbid", + new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String)); + strct.Members.Add(member); + } + // Add the struct to the array + array.Values.Add(strct); + } + // Add the array to the parameters + parms.Add(array); + // Call ! + XmlRpcMethodCall call = new XmlRpcMethodCall("SearchSubtitles", parms); + OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good); + // Send the request to the server + string response = Utilities.GetStreamString(await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false)); + + if (!response.Contains("ERROR:")) + { + // No error occur, get and decode the response. + XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response); + if (calls.Length > 0) + { + if (calls[0].Parameters.Count > 0) + { + // We expect Struct of 3 members: + //* the first is status + //* the second is [array of structs, each one includes subtitle file]. + //* the third is [double basic value] represent seconds token by server. + XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0]; + // Create the response, we'll need it later + MethodResponseSubtitleSearch R = new MethodResponseSubtitleSearch(); + // To make sure response is not currepted by server, do it in loop + foreach (XmlRpcStructMember MEMBER in mainStruct.Members) + { + if (MEMBER.Name == "status") + { + R.Status = (string)MEMBER.Data.Data; + OSHConsole.WriteLine("Status= " + R.Status); + } + else if (MEMBER.Name == "seconds") + { + R.Seconds = (double)MEMBER.Data.Data; + OSHConsole.WriteLine("Seconds= " + R.Seconds); + } + else if (MEMBER.Name == "data") + { + if (MEMBER.Data is XmlRpcValueArray) + { + OSHConsole.WriteLine("Search results: "); + + XmlRpcValueArray rarray = (XmlRpcValueArray)MEMBER.Data; + foreach (IXmlRpcValue subStruct in rarray.Values) + { + if (subStruct == null) continue; + if (!(subStruct is XmlRpcValueStruct)) continue; + + SubtitleSearchResult result = new SubtitleSearchResult(); + foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members) + { + // To avoid errors of arranged info or missing ones, let's do it with switch.. + switch (submember.Name) + { + case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break; + case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break; + case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break; + case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break; + case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break; + case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break; + case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break; + case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break; + case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break; + case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break; + case "MovieName": result.MovieName = submember.Data.Data.ToString(); break; + case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break; + case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break; + case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break; + case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break; + case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break; + case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break; + case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break; + case "SubBad": result.SubBad = submember.Data.Data.ToString(); break; + case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break; + case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break; + case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break; + case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break; + case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break; + case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break; + case "SubHash": result.SubHash = submember.Data.Data.ToString(); break; + case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break; + case "SubRating": result.SubRating = submember.Data.Data.ToString(); break; + case "SubSize": result.SubSize = submember.Data.Data.ToString(); break; + case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break; + case "UserID": result.UserID = submember.Data.Data.ToString(); break; + case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break; + case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break; + } + } + R.Results.Add(result); + OSHConsole.WriteLine(">" + result.ToString()); + } + } + else// Unknown data ? + { + OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning); + } + } + } + // Return the response to user !! + return R; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "Search Subtitles call failed !"); + } + /// /// Download subtitle file(s) /// -- cgit v1.2.3