瀏覽代碼

dlna didl fixes

Luke Pulverenti 11 年之前
父節點
當前提交
b9aa4ac8be

+ 29 - 30
MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs

@@ -113,11 +113,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
             AddRequestHeaders(request, options);
 
             request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
-            
+
             request.CachePolicy = options.CachePolicy == Net.HttpRequestCachePolicy.None ?
                 new RequestCachePolicy(RequestCacheLevel.BypassCache) :
                 new RequestCachePolicy(RequestCacheLevel.Revalidate);
-            
+
             request.ConnectionGroupName = GetHostFromUrl(options.Url);
             request.KeepAlive = true;
             request.Method = method;
@@ -270,18 +270,18 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
 
                     var httpResponse = (HttpWebResponse)response;
 
-                    EnsureSuccessStatusCode(httpResponse);
+                    EnsureSuccessStatusCode(httpResponse, options);
 
                     options.CancellationToken.ThrowIfCancellationRequested();
 
                     return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse));
                 }
-                
+
                 using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
                 {
                     var httpResponse = (HttpWebResponse)response;
 
-                    EnsureSuccessStatusCode(httpResponse);
+                    EnsureSuccessStatusCode(httpResponse, options);
 
                     options.CancellationToken.ThrowIfCancellationRequested();
 
@@ -345,29 +345,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
         {
             _logger.ErrorException("Error getting response from " + options.Url, ex);
 
-            if (options.LogErrorResponseBody)
-            {
-                try
-                {
-                    using (var stream = ex.Response.GetResponseStream())
-                    {
-                        if (stream != null)
-                        {
-                            using (var reader = new StreamReader(stream))
-                            {
-                                var msg = reader.ReadToEnd();
-
-                                _logger.Error(msg);
-                            }
-                        }
-                    }
-                }
-                catch
-                {
-                    
-                }
-            }
-
             return new HttpException(ex.Message, ex);
         }
 
@@ -496,7 +473,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
                 {
                     var httpResponse = (HttpWebResponse)response;
 
-                    EnsureSuccessStatusCode(httpResponse);
+                    EnsureSuccessStatusCode(httpResponse, options);
 
                     options.CancellationToken.ThrowIfCancellationRequested();
 
@@ -686,13 +663,35 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
             return exception;
         }
 
-        private void EnsureSuccessStatusCode(HttpWebResponse response)
+        private void EnsureSuccessStatusCode(HttpWebResponse response, HttpRequestOptions options)
         {
             var statusCode = response.StatusCode;
             var isSuccessful = statusCode >= HttpStatusCode.OK && statusCode <= (HttpStatusCode)299;
 
             if (!isSuccessful)
             {
+                if (options.LogErrorResponseBody)
+                {
+                    try
+                    {
+                        using (var stream = response.GetResponseStream())
+                        {
+                            if (stream != null)
+                            {
+                                using (var reader = new StreamReader(stream))
+                                {
+                                    var msg = reader.ReadToEnd();
+
+                                    _logger.Error(msg);
+                                }
+                            }
+                        }
+                    }
+                    catch
+                    {
+
+                    }
+                }
                 throw new HttpException(response.StatusDescription) { StatusCode = response.StatusCode };
             }
         }

+ 6 - 1
MediaBrowser.Dlna/PlayTo/Device.cs

@@ -577,6 +577,11 @@ namespace MediaBrowser.Dlna.PlayTo
 
             var trackString = (string) track;
 
+            if (string.IsNullOrWhiteSpace(trackString) || string.Equals(trackString, "NOT_IMPLEMENTED", StringComparison.OrdinalIgnoreCase))
+            {
+                return false;
+            }
+
             XElement uPnpResponse;
             
             try
@@ -586,7 +591,7 @@ namespace MediaBrowser.Dlna.PlayTo
             catch
             {
                 _logger.Error("Unable to parse xml {0}", trackString);
-                throw;
+                return false;
             }
 
             var e = uPnpResponse.Element(uPnpNamespaces.items);

+ 2 - 2
MediaBrowser.Dlna/PlayTo/DidlBuilder.cs

@@ -24,8 +24,8 @@ namespace MediaBrowser.Dlna.PlayTo
         const string DIDL_RELEASEDATE = @"  <dc:date xmlns:dc=""http://purl.org/dc/elements/1.1/"">{0}</dc:date>" + CRLF;
         const string DIDL_GENRE = @"  <upnp:genre xmlns:upnp=""urn:schemas-upnp-org:metadata-1-0/upnp/"">{0}</upnp:genre>" + CRLF;
         const string DESCRIPTION = @"  <dc:description xmlns:dc=""http://purl.org/dc/elements/1.1/"">{0}</dc:description>" + CRLF;
-        const string DIDL_VIDEO_RES = @"  <res bitrate=""{0}"" duration=""{1}"" protocolInfo=""http-get:*:video/x-msvideo:DLNA.ORG_PN=AVI;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000"" resolution=""{2}x{3}"" size=""0"">{4}</res>" + CRLF;
-        const string DIDL_AUDIO_RES = @"  <res bitrate=""{0}"" duration=""{1}"" nrAudioChannels=""2"" protocolInfo=""http-get:*:audio/mp3:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000"" sampleFrequency=""{2}"" size=""0"">{3}</res>" + CRLF;
+        const string DIDL_VIDEO_RES = @"  <res bitrate=""{0}"" duration=""{1}"" protocolInfo=""http-get:*:video/x-msvideo:DLNA.ORG_PN=AVI;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000"" resolution=""{2}x{3}"">{4}</res>" + CRLF;
+        const string DIDL_AUDIO_RES = @"  <res bitrate=""{0}"" duration=""{1}"" nrAudioChannels=""2"" protocolInfo=""http-get:*:audio/mp3:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000"" sampleFrequency=""{2}"">{3}</res>" + CRLF;
         const string DIDL_IMAGE_RES = @"  <res protocolInfo=""http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=00;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00D00000000000000000000000000000"" resolution=""212x320"">{0}</res>" + CRLF;
         const string DIDL_ALBUMIMAGE_RES = @"  <res protocolInfo=""http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_TN;DLNA.ORG_OP=00;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=00D00000000000000000000000000000"" resolution=""320x320"">{0}</res>" + CRLF;
         const string DIDL_RATING = @"  <upnp:rating xmlns:upnp=""urn:schemas-upnp-org:metadata-1-0/upnp/"">{0}</upnp:rating>" + CRLF;