Skip to content

Commit

Permalink
Merge pull request #2974 from MediaBrowser/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
LukePulverenti authored Oct 24, 2017
2 parents 1028f81 + ba76fe8 commit 1e9b6c1
Show file tree
Hide file tree
Showing 490 changed files with 8,896 additions and 20,653 deletions.
45 changes: 23 additions & 22 deletions Emby.Dlna/ContentDirectory/ContentDirectoryBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<QueryResult<ChannelItemInfo>> Browse(ContentDirectoryBrowseReq
{
CancellationToken = cancellationToken,
UserAgent = "Emby",
RequestContentType = "text/xml; charset=\"utf-8\"",
RequestContentType = "text/xml",
LogErrorResponseBody = true,
Url = request.ContentDirectoryUrl,
BufferContent = false
Expand All @@ -43,37 +43,38 @@ public async Task<QueryResult<ChannelItemInfo>> Browse(ContentDirectoryBrowseReq

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;
}
}
}

Expand Down
64 changes: 38 additions & 26 deletions Emby.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,75 +393,75 @@ private string GetDisplayName(BaseItem item, StubType? itemStubType, BaseItem co
{
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;
Expand Down Expand Up @@ -1071,8 +1071,10 @@ private void AddImageResElement(BaseItem item,

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);
Expand All @@ -1083,10 +1085,7 @@ private void AddImageResElement(BaseItem item,
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);

Expand Down Expand Up @@ -1138,8 +1137,21 @@ private ImageDownloadInfo GetImageInfo(BaseItem item, ImageType type)

}

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
//{
Expand Down
25 changes: 19 additions & 6 deletions Emby.Dlna/Eventing/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public EventManager(ILogger logger, IHttpClient httpClient)
_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
Expand All @@ -37,10 +39,18 @@ public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, s
// 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)
Expand Down Expand Up @@ -172,7 +182,10 @@ private async Task TriggerEvent(EventSubscription subscription, IDictionary<stri

try
{
await _httpClient.SendAsync(options, "NOTIFY").ConfigureAwait(false);
using (await _httpClient.SendAsync(options, "NOTIFY").ConfigureAwait(false))
{

}
}
catch (OperationCanceledException)
{
Expand Down
45 changes: 31 additions & 14 deletions Emby.Dlna/PlayTo/SsdpHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ public async Task<XDocument> SendCommandAsync(string baseUrl,
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);
}
}
}
}
Expand Down Expand Up @@ -71,15 +72,21 @@ public async Task SubscribeAsync(string url,
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);
options.RequestHeaders["CALLBACK"] = "<" + localIp + ":" + eventport.ToString(_usCulture) + ">";
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)
Expand All @@ -89,16 +96,22 @@ public async Task<XDocument> GetDataAsync(string url)
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);
}
}
}
}
Expand All @@ -118,7 +131,10 @@ private Task<HttpResponseInfo> PostSoapDataAsync(string url,
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;
Expand All @@ -130,7 +146,8 @@ private Task<HttpResponseInfo> PostSoapDataAsync(string url,
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);
Expand Down
4 changes: 2 additions & 2 deletions Emby.Dlna/Service/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public EventSubscriptionResponse CancelEventSubscription(string subscriptionId)
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)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Drawing.ImageMagick/ImageMagickEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public string EncodeImage(string inputPath, DateTime dateModified, string output

var originalImageSize = new ImageSize(originalImage.CurrentImage.Width, originalImage.CurrentImage.Height);

if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize))
if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient)
{
// Just spit out the original file if all the options are default
return inputPath;
Expand Down
Loading

0 comments on commit 1e9b6c1

Please sign in to comment.