diff options
Diffstat (limited to 'Emby.Dlna')
| -rw-r--r-- | Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs | 45 | ||||
| -rw-r--r-- | Emby.Dlna/Didl/DidlBuilder.cs | 64 | ||||
| -rw-r--r-- | Emby.Dlna/Eventing/EventManager.cs | 25 | ||||
| -rw-r--r-- | Emby.Dlna/PlayTo/SsdpHttpClient.cs | 45 | ||||
| -rw-r--r-- | Emby.Dlna/Service/BaseService.cs | 4 |
5 files changed, 113 insertions, 70 deletions
diff --git a/Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs b/Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs index 2b421794ab..61501635fa 100644 --- a/Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs +++ b/Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs @@ -33,7 +33,7 @@ namespace Emby.Dlna.ContentDirectory { CancellationToken = cancellationToken, UserAgent = "Emby", - RequestContentType = "text/xml; charset=\"utf-8\"", + RequestContentType = "text/xml", LogErrorResponseBody = true, Url = request.ContentDirectoryUrl, BufferContent = false @@ -43,37 +43,38 @@ namespace Emby.Dlna.ContentDirectory options.RequestContent = GetRequestBody(request); - var response = await _httpClient.SendAsync(options, "POST"); - - using (var reader = new StreamReader(response.Content)) + using (var response = await _httpClient.SendAsync(options, "POST")) { - var doc = XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); + using (var reader = new StreamReader(response.Content)) + { + var doc = XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); - var queryResult = new QueryResult<ChannelItemInfo>(); + var queryResult = new QueryResult<ChannelItemInfo>(); - if (doc.Document == null) - return queryResult; + if (doc.Document == null) + return queryResult; - var responseElement = doc.Document.Descendants(UNamespace + "BrowseResponse").ToList(); + var responseElement = doc.Document.Descendants(UNamespace + "BrowseResponse").ToList(); - var countElement = responseElement.Select(i => i.Element("TotalMatches")).FirstOrDefault(i => i != null); - var countValue = countElement == null ? null : countElement.Value; + var countElement = responseElement.Select(i => i.Element("TotalMatches")).FirstOrDefault(i => i != null); + var countValue = countElement == null ? null : countElement.Value; - int count; - if (!string.IsNullOrWhiteSpace(countValue) && int.TryParse(countValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out count)) - { - queryResult.TotalRecordCount = count; + int count; + if (!string.IsNullOrWhiteSpace(countValue) && int.TryParse(countValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out count)) + { + queryResult.TotalRecordCount = count; - var resultElement = responseElement.Select(i => i.Element("Result")).FirstOrDefault(i => i != null); - var resultString = (string)resultElement; + var resultElement = responseElement.Select(i => i.Element("Result")).FirstOrDefault(i => i != null); + var resultString = (string)resultElement; - if (resultElement != null) - { - var xElement = XElement.Parse(resultString); + if (resultElement != null) + { + var xElement = XElement.Parse(resultString); + } } - } - return queryResult; + return queryResult; + } } } diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs index 5e200428a7..5b18a2b7c2 100644 --- a/Emby.Dlna/Didl/DidlBuilder.cs +++ b/Emby.Dlna/Didl/DidlBuilder.cs @@ -393,75 +393,75 @@ namespace Emby.Dlna.Didl { if (itemStubType.HasValue && itemStubType.Value == StubType.Latest) { - return _localization.GetLocalizedString("ViewTypeMusicLatest"); + return _localization.GetLocalizedString("Latest"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Playlists) { - return _localization.GetLocalizedString("ViewTypeMusicPlaylists"); + return _localization.GetLocalizedString("Playlists"); } if (itemStubType.HasValue && itemStubType.Value == StubType.AlbumArtists) { - return _localization.GetLocalizedString("ViewTypeMusicAlbumArtists"); + return _localization.GetLocalizedString("HeaderAlbumArtists"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Albums) { - return _localization.GetLocalizedString("ViewTypeMusicAlbums"); + return _localization.GetLocalizedString("Albums"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Artists) { - return _localization.GetLocalizedString("ViewTypeMusicArtists"); + return _localization.GetLocalizedString("Artists"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Songs) { - return _localization.GetLocalizedString("ViewTypeMusicSongs"); + return _localization.GetLocalizedString("Songs"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Genres) { - return _localization.GetLocalizedString("ViewTypeTvGenres"); + return _localization.GetLocalizedString("Genres"); } if (itemStubType.HasValue && itemStubType.Value == StubType.FavoriteAlbums) { - return _localization.GetLocalizedString("ViewTypeMusicFavoriteAlbums"); + return _localization.GetLocalizedString("HeaderFavoriteAlbums"); } if (itemStubType.HasValue && itemStubType.Value == StubType.FavoriteArtists) { - return _localization.GetLocalizedString("ViewTypeMusicFavoriteArtists"); + return _localization.GetLocalizedString("HeaderFavoriteArtists"); } if (itemStubType.HasValue && itemStubType.Value == StubType.FavoriteSongs) { - return _localization.GetLocalizedString("ViewTypeMusicFavoriteSongs"); + return _localization.GetLocalizedString("HeaderFavoriteSongs"); } if (itemStubType.HasValue && itemStubType.Value == StubType.ContinueWatching) { - return _localization.GetLocalizedString("ViewTypeMovieResume"); + return _localization.GetLocalizedString("HeaderContinueWatching"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Movies) { - return _localization.GetLocalizedString("ViewTypeMovieMovies"); + return _localization.GetLocalizedString("Movies"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Collections) { - return _localization.GetLocalizedString("ViewTypeMovieCollections"); + return _localization.GetLocalizedString("Collections"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Favorites) { - return _localization.GetLocalizedString("ViewTypeMovieFavorites"); + return _localization.GetLocalizedString("Favorites"); } if (itemStubType.HasValue && itemStubType.Value == StubType.NextUp) { - return _localization.GetLocalizedString("ViewTypeTvNextUp"); + return _localization.GetLocalizedString("HeaderNextUp"); } if (itemStubType.HasValue && itemStubType.Value == StubType.FavoriteSeries) { - return _localization.GetLocalizedString("ViewTypeTvFavoriteSeries"); + return _localization.GetLocalizedString("HeaderFavoriteShows"); } if (itemStubType.HasValue && itemStubType.Value == StubType.FavoriteEpisodes) { - return _localization.GetLocalizedString("ViewTypeTvFavoriteEpisodes"); + return _localization.GetLocalizedString("HeaderFavoriteEpisodes"); } if (itemStubType.HasValue && itemStubType.Value == StubType.Series) { - return _localization.GetLocalizedString("ViewTypeTvShowSeries"); + return _localization.GetLocalizedString("Shows"); } var episode = item as Episode; @@ -1071,8 +1071,10 @@ namespace Emby.Dlna.Didl writer.WriteStartElement(string.Empty, "res", NS_DIDL); - var width = albumartUrlInfo.Width; - var height = albumartUrlInfo.Height; + // Images must have a reported size or many clients (Bubble upnp), will only use the first thumbnail + // rather than using a larger one when available + var width = albumartUrlInfo.Width ?? maxWidth; + var height = albumartUrlInfo.Height ?? maxHeight; var contentFeatures = new ContentFeatureBuilder(_profile) .BuildImageHeader(format, width, height, imageInfo.IsDirectStream, org_Pn); @@ -1083,10 +1085,7 @@ namespace Emby.Dlna.Didl contentFeatures )); - if (width.HasValue && height.HasValue) - { - writer.WriteAttributeString("resolution", string.Format("{0}x{1}", width.Value, height.Value)); - } + writer.WriteAttributeString("resolution", string.Format("{0}x{1}", width, height)); writer.WriteString(albumartUrlInfo.Url); @@ -1138,8 +1137,21 @@ namespace Emby.Dlna.Didl } - int? width = null; - int? height = null; + int? width = imageInfo.Width; + int? height = imageInfo.Height; + + if (width == 0 || height == 0) + { + //_imageProcessor.GetImageSize(item, imageInfo); + width = null; + height = null; + } + + else if (width == -1 || height == -1) + { + width = null; + height = null; + } //try //{ diff --git a/Emby.Dlna/Eventing/EventManager.cs b/Emby.Dlna/Eventing/EventManager.cs index 0516585ae0..67eac640e1 100644 --- a/Emby.Dlna/Eventing/EventManager.cs +++ b/Emby.Dlna/Eventing/EventManager.cs @@ -26,9 +26,11 @@ namespace Emby.Dlna.Eventing _logger = logger; } - public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string requestedTimeoutString) + public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string notificationType, string requestedTimeoutString, string callbackUrl) { - var subscription = GetSubscription(subscriptionId, true); + var subscription = GetSubscription(subscriptionId, false); + + int timeoutSeconds; // Remove logging for now because some devices are sending this very frequently // TODO re-enable with dlna debug logging setting @@ -37,10 +39,18 @@ namespace Emby.Dlna.Eventing // timeout, // subscription.CallbackUrl); - subscription.TimeoutSeconds = ParseTimeout(requestedTimeoutString) ?? 300; - subscription.SubscriptionTime = DateTime.UtcNow; + if (subscription != null) + { + subscription.TimeoutSeconds = ParseTimeout(requestedTimeoutString) ?? 300; + timeoutSeconds = subscription.TimeoutSeconds; + subscription.SubscriptionTime = DateTime.UtcNow; + } + else + { + timeoutSeconds = 300; + } - return GetEventSubscriptionResponse(subscriptionId, requestedTimeoutString, subscription.TimeoutSeconds); + return GetEventSubscriptionResponse(subscriptionId, requestedTimeoutString, timeoutSeconds); } public EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl) @@ -172,7 +182,10 @@ namespace Emby.Dlna.Eventing try { - await _httpClient.SendAsync(options, "NOTIFY").ConfigureAwait(false); + using (await _httpClient.SendAsync(options, "NOTIFY").ConfigureAwait(false)) + { + + } } catch (OperationCanceledException) { diff --git a/Emby.Dlna/PlayTo/SsdpHttpClient.cs b/Emby.Dlna/PlayTo/SsdpHttpClient.cs index 1aa671b8ff..78b688d92a 100644 --- a/Emby.Dlna/PlayTo/SsdpHttpClient.cs +++ b/Emby.Dlna/PlayTo/SsdpHttpClient.cs @@ -31,14 +31,15 @@ namespace Emby.Dlna.PlayTo bool logRequest = true, string header = null) { - var response = await PostSoapDataAsync(NormalizeServiceUrl(baseUrl, service.ControlUrl), "\"" + service.ServiceType + "#" + command + "\"", postData, header, logRequest) - .ConfigureAwait(false); - - using (var stream = response.Content) + using (var response = await PostSoapDataAsync(NormalizeServiceUrl(baseUrl, service.ControlUrl), "\"" + service.ServiceType + "#" + command + "\"", postData, header, logRequest) + .ConfigureAwait(false)) { - using (var reader = new StreamReader(stream, Encoding.UTF8)) + using (var stream = response.Content) { - return XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); + using (var reader = new StreamReader(stream, Encoding.UTF8)) + { + return XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); + } } } } @@ -71,7 +72,10 @@ namespace Emby.Dlna.PlayTo Url = url, UserAgent = USERAGENT, LogErrorResponseBody = true, - BufferContent = false + BufferContent = false, + + // The periodic requests may keep some devices awake + LogRequestAsDebug = true }; options.RequestHeaders["HOST"] = ip + ":" + port.ToString(_usCulture); @@ -79,7 +83,10 @@ namespace Emby.Dlna.PlayTo options.RequestHeaders["NT"] = "upnp:event"; options.RequestHeaders["TIMEOUT"] = "Second-" + timeOut.ToString(_usCulture); - await _httpClient.SendAsync(options, "SUBSCRIBE").ConfigureAwait(false); + using (await _httpClient.SendAsync(options, "SUBSCRIBE").ConfigureAwait(false)) + { + + } } public async Task<XDocument> GetDataAsync(string url) @@ -89,16 +96,22 @@ namespace Emby.Dlna.PlayTo Url = url, UserAgent = USERAGENT, LogErrorResponseBody = true, - BufferContent = false + BufferContent = false, + + // The periodic requests may keep some devices awake + LogRequestAsDebug = true }; options.RequestHeaders["FriendlyName.DLNA.ORG"] = FriendlyName; - using (var stream = await _httpClient.Get(options).ConfigureAwait(false)) + using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false)) { - using (var reader = new StreamReader(stream, Encoding.UTF8)) + using (var stream = response.Content) { - return XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); + using (var reader = new StreamReader(stream, Encoding.UTF8)) + { + return XDocument.Parse(reader.ReadToEnd(), LoadOptions.PreserveWhitespace); + } } } } @@ -118,7 +131,10 @@ namespace Emby.Dlna.PlayTo UserAgent = USERAGENT, LogRequest = logRequest || _config.GetDlnaConfiguration().EnableDebugLog, LogErrorResponseBody = true, - BufferContent = false + BufferContent = false, + + // The periodic requests may keep some devices awake + LogRequestAsDebug = true }; options.RequestHeaders["SOAPAction"] = soapAction; @@ -130,7 +146,8 @@ namespace Emby.Dlna.PlayTo options.RequestHeaders["contentFeatures.dlna.org"] = header; } - options.RequestContentType = "text/xml; charset=\"utf-8\""; + options.RequestContentType = "text/xml"; + options.AppendCharsetToMimeType = true; options.RequestContent = postData; return _httpClient.Post(options); diff --git a/Emby.Dlna/Service/BaseService.cs b/Emby.Dlna/Service/BaseService.cs index ddc37da095..bc7f01d974 100644 --- a/Emby.Dlna/Service/BaseService.cs +++ b/Emby.Dlna/Service/BaseService.cs @@ -24,9 +24,9 @@ namespace Emby.Dlna.Service return EventManager.CancelEventSubscription(subscriptionId); } - public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string timeoutString) + public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string notificationType, string timeoutString, string callbackUrl) { - return EventManager.RenewEventSubscription(subscriptionId, timeoutString); + return EventManager.RenewEventSubscription(subscriptionId, notificationType, timeoutString, callbackUrl); } public EventSubscriptionResponse CreateEventSubscription(string notificationType, string timeoutString, string callbackUrl) |
