Skip to content

Commit

Permalink
Merge pull request #3172 from MediaBrowser/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
LukePulverenti authored Feb 23, 2018
2 parents 0060dbc + 5b8ab71 commit 2a1acb7
Show file tree
Hide file tree
Showing 538 changed files with 6,250 additions and 6,615 deletions.
4 changes: 2 additions & 2 deletions BDInfo/BDROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public delegate bool OnPlaylistFileScanError(
public BDROM(
string path, IFileSystem fileSystem, ITextEncoding textEncoding)
{
if (string.IsNullOrWhiteSpace(path))
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public void Scan()
private FileSystemMetadata GetDirectoryBDMV(
string path)
{
if (string.IsNullOrWhiteSpace(path))
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
Expand Down
26 changes: 23 additions & 3 deletions Emby.Dlna/ContentDirectory/ControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Xml;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Controller.LiveTv;

namespace Emby.Dlna.ContentDirectory
{
Expand Down Expand Up @@ -493,7 +494,7 @@ private QueryResult<ServerItem> GetUserItems(BaseItem item, StubType? stubType,

if (!stubType.HasValue || stubType.Value != StubType.Folder)
{
var collectionFolder = item as ICollectionFolder;
var collectionFolder = item as IHasCollectionType;
if (collectionFolder != null && string.Equals(CollectionType.Music, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
{
return GetMusicFolders(item, user, stubType, sort, startIndex, limit);
Expand All @@ -507,11 +508,14 @@ private QueryResult<ServerItem> GetUserItems(BaseItem item, StubType? stubType,
return GetTvFolders(item, user, stubType, sort, startIndex, limit);
}

var userView = item as UserView;
if (userView != null && string.Equals(CollectionType.Folders, userView.ViewType, StringComparison.OrdinalIgnoreCase))
if (collectionFolder != null && string.Equals(CollectionType.Folders, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
{
return GetFolders(item, user, stubType, sort, startIndex, limit);
}
if (collectionFolder != null && string.Equals(CollectionType.LiveTv, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
{
return GetLiveTvChannels(item, user, stubType, sort, startIndex, limit);
}
}

if (stubType.HasValue)
Expand Down Expand Up @@ -549,6 +553,22 @@ private QueryResult<ServerItem> GetUserItems(BaseItem item, StubType? stubType,
return ToResult(queryResult);
}

private QueryResult<ServerItem> GetLiveTvChannels(BaseItem item, User user, StubType? stubType, SortCriteria sort, int? startIndex, int? limit)
{
var query = new InternalItemsQuery(user)
{
StartIndex = startIndex,
Limit = limit,
};
query.IncludeItemTypes = new[] { typeof(LiveTvChannel).Name };

SetSorting(query, sort, false);

var result = _libraryManager.GetItemsResult(query);

return ToResult(result);
}

private QueryResult<ServerItem> GetMusicFolders(BaseItem item, User user, StubType? stubType, SortCriteria sort, int? startIndex, int? limit)
{
var query = new InternalItemsQuery(user)
Expand Down
172 changes: 75 additions & 97 deletions Emby.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public DidlBuilder(DeviceProfile profile, User user, IImageProcessor imageProces
_user = user;
}

public static string NormalizeDlnaMediaUrl(string url)
{
return url + "&dlnaheaders=true";
}

public string GetItemDidl(DlnaOptions options, BaseItem item, User user, BaseItem context, string deviceId, Filter filter, StreamInfo streamInfo)
{
var settings = new XmlWriterSettings
Expand All @@ -72,28 +77,29 @@ public string GetItemDidl(DlnaOptions options, BaseItem item, User user, BaseIte
ConformanceLevel = ConformanceLevel.Fragment
};

StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);

using (XmlWriter writer = XmlWriter.Create(builder, settings))
using (StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8))
{
//writer.WriteStartDocument();
using (XmlWriter writer = XmlWriter.Create(builder, settings))
{
//writer.WriteStartDocument();

writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);

writer.WriteAttributeString("xmlns", "dc", null, NS_DC);
writer.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
writer.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
//didl.SetAttribute("xmlns:sec", NS_SEC);
writer.WriteAttributeString("xmlns", "dc", null, NS_DC);
writer.WriteAttributeString("xmlns", "dlna", null, NS_DLNA);
writer.WriteAttributeString("xmlns", "upnp", null, NS_UPNP);
//didl.SetAttribute("xmlns:sec", NS_SEC);

WriteXmlRootAttributes(_profile, writer);
WriteXmlRootAttributes(_profile, writer);

WriteItemElement(options, writer, item, user, context, null, deviceId, filter, streamInfo);
WriteItemElement(options, writer, item, user, context, null, deviceId, filter, streamInfo);

writer.WriteFullEndElement();
//writer.WriteEndDocument();
}
writer.WriteFullEndElement();
//writer.WriteEndDocument();
}

return builder.ToString();
return builder.ToString();
}
}

public static void WriteXmlRootAttributes(DeviceProfile profile, XmlWriter writer)
Expand Down Expand Up @@ -301,7 +307,7 @@ private void AddVideoResource(XmlWriter writer, IHasMediaSources video, string d
{
writer.WriteStartElement(string.Empty, "res", NS_DIDL);

var url = streamInfo.ToDlnaUrl(_serverAddress, _accessToken);
var url = NormalizeDlnaMediaUrl(streamInfo.ToUrl(_serverAddress, _accessToken));

var mediaSource = streamInfo.MediaSource;

Expand Down Expand Up @@ -512,7 +518,7 @@ private void AddAudioResource(DlnaOptions options, XmlWriter writer, IHasMediaSo
});
}

var url = streamInfo.ToDlnaUrl(_serverAddress, _accessToken);
var url = NormalizeDlnaMediaUrl(streamInfo.ToUrl(_serverAddress, _accessToken));

var mediaSource = streamInfo.MediaSource;

Expand Down Expand Up @@ -607,7 +613,7 @@ public void WriteFolderElement(XmlWriter writer, BaseItem folder, StubType? stub
{
writer.WriteStartElement(string.Empty, "container", NS_DIDL);

writer.WriteAttributeString("restricted", "0");
writer.WriteAttributeString("restricted", "1");
writer.WriteAttributeString("searchable", "1");
writer.WriteAttributeString("childCount", childCount.ToString(_usCulture));

Expand Down Expand Up @@ -714,21 +720,24 @@ private void AddCommonFields(BaseItem item, StubType? itemStubType, BaseItem con
AddValue(writer, "upnp", "publisher", studio, NS_UPNP);
}

if (filter.Contains("dc:description"))
{
var desc = item.Overview;

if (!string.IsNullOrWhiteSpace(desc))
{
AddValue(writer, "dc", "description", desc, NS_DC);
}
}
if (filter.Contains("upnp:longDescription"))
if (!(item is Folder))
{
if (!string.IsNullOrWhiteSpace(item.Overview))
if (filter.Contains("dc:description"))
{
AddValue(writer, "upnp", "longDescription", item.Overview, NS_UPNP);
var desc = item.Overview;

if (!string.IsNullOrWhiteSpace(desc))
{
AddValue(writer, "dc", "description", desc, NS_DC);
}
}
//if (filter.Contains("upnp:longDescription"))
//{
// if (!string.IsNullOrWhiteSpace(item.Overview))
// {
// AddValue(writer, "upnp", "longDescription", item.Overview, NS_UPNP);
// }
//}
}

if (!string.IsNullOrEmpty(item.OfficialRating))
Expand Down Expand Up @@ -824,37 +833,37 @@ private void WriteObjectClass(XmlWriter writer, BaseItem item, StubType? stubTyp

private void AddPeople(BaseItem item, XmlWriter writer)
{
var types = new[]
{
PersonType.Director,
PersonType.Writer,
PersonType.Producer,
PersonType.Composer,
"Creator"
};
//var types = new[]
//{
// PersonType.Director,
// PersonType.Writer,
// PersonType.Producer,
// PersonType.Composer,
// "Creator"
//};

var people = _libraryManager.GetPeople(item);
//var people = _libraryManager.GetPeople(item);

var index = 0;
//var index = 0;

// Seeing some LG models locking up due content with large lists of people
// The actual issue might just be due to processing a more metadata than it can handle
var limit = 6;
//// Seeing some LG models locking up due content with large lists of people
//// The actual issue might just be due to processing a more metadata than it can handle
//var limit = 6;

foreach (var actor in people)
{
var type = types.FirstOrDefault(i => string.Equals(i, actor.Type, StringComparison.OrdinalIgnoreCase) || string.Equals(i, actor.Role, StringComparison.OrdinalIgnoreCase))
?? PersonType.Actor;
//foreach (var actor in people)
//{
// var type = types.FirstOrDefault(i => string.Equals(i, actor.Type, StringComparison.OrdinalIgnoreCase) || string.Equals(i, actor.Role, StringComparison.OrdinalIgnoreCase))
// ?? PersonType.Actor;

AddValue(writer, "upnp", type.ToLower(), actor.Name, NS_UPNP);
// AddValue(writer, "upnp", type.ToLower(), actor.Name, NS_UPNP);

index++;
// index++;

if (index >= limit)
{
break;
}
}
// if (index >= limit)
// {
// break;
// }
//}
}

private void AddGeneralProperties(BaseItem item, StubType? itemStubType, BaseItem context, XmlWriter writer, Filter filter)
Expand Down Expand Up @@ -960,42 +969,15 @@ private void AddCover(BaseItem item, BaseItem context, StubType? stubType, XmlWr
return;
}

var playbackPercentage = 0;
var unplayedCount = 0;

if (item is Video)
{
var userData = _userDataManager.GetUserDataDto(item, _user);

playbackPercentage = Convert.ToInt32(userData.PlayedPercentage ?? 0);
if (playbackPercentage >= 100 || userData.Played)
{
playbackPercentage = 100;
}
}
else if (item is Series || item is Season || item is BoxSet)
{
var userData = _userDataManager.GetUserDataDto(item, _user);

if (userData.Played)
{
playbackPercentage = 100;
}
else
{
unplayedCount = userData.UnplayedItemCount ?? 0;
}
}

var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, playbackPercentage, unplayedCount, "jpg");
var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, "jpg");

writer.WriteStartElement("upnp", "albumArtURI", NS_UPNP);
writer.WriteAttributeString("dlna", "profileID", NS_DLNA, _profile.AlbumArtPn);
writer.WriteString(albumartUrlInfo.Url);
writer.WriteFullEndElement();

// TOOD: Remove these default values
var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, playbackPercentage, unplayedCount, "jpg");
var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, "jpg");
writer.WriteElementString("upnp", "icon", NS_UPNP, iconUrlInfo.Url);

if (!_profile.EnableAlbumArtInDidl)
Expand All @@ -1010,15 +992,15 @@ private void AddCover(BaseItem item, BaseItem context, StubType? stubType, XmlWr
}
}

AddImageResElement(item, writer, 160, 160, playbackPercentage, unplayedCount, "jpg", "JPEG_TN");
AddImageResElement(item, writer, 160, 160, "jpg", "JPEG_TN");

if (!_profile.EnableSingleAlbumArtLimit)
{
AddImageResElement(item, writer, 4096, 4096, playbackPercentage, unplayedCount, "jpg", "JPEG_LRG");
AddImageResElement(item, writer, 1024, 768, playbackPercentage, unplayedCount, "jpg", "JPEG_MED");
AddImageResElement(item, writer, 640, 480, playbackPercentage, unplayedCount, "jpg", "JPEG_SM");
AddImageResElement(item, writer, 4096, 4096, playbackPercentage, unplayedCount, "png", "PNG_LRG");
AddImageResElement(item, writer, 160, 160, playbackPercentage, unplayedCount, "png", "PNG_TN");
AddImageResElement(item, writer, 4096, 4096, "jpg", "JPEG_LRG");
AddImageResElement(item, writer, 1024, 768, "jpg", "JPEG_MED");
AddImageResElement(item, writer, 640, 480, "jpg", "JPEG_SM");
AddImageResElement(item, writer, 4096, 4096, "png", "PNG_LRG");
AddImageResElement(item, writer, 160, 160, "png", "PNG_TN");
}
}

Expand All @@ -1036,8 +1018,6 @@ private void AddImageResElement(BaseItem item,
XmlWriter writer,
int maxWidth,
int maxHeight,
int playbackPercentage,
int unplayedCount,
string format,
string org_Pn)
{
Expand All @@ -1048,7 +1028,7 @@ private void AddImageResElement(BaseItem item,
return;
}

var albumartUrlInfo = GetImageUrl(imageInfo, maxWidth, maxHeight, playbackPercentage, unplayedCount, format);
var albumartUrlInfo = GetImageUrl(imageInfo, maxWidth, maxHeight, format);

writer.WriteStartElement(string.Empty, "res", NS_DIDL);

Expand Down Expand Up @@ -1210,18 +1190,16 @@ public static string GetClientId(IHasMediaSources item)
return id;
}

private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, int playbackPercentage, int unplayedCount, string format)
private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, string format)
{
var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}/{7}/{8}",
var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}/0/0",
_serverAddress,
info.ItemId,
info.Type,
info.ImageTag,
format,
maxWidth.ToString(CultureInfo.InvariantCulture),
maxHeight.ToString(CultureInfo.InvariantCulture),
playbackPercentage.ToString(CultureInfo.InvariantCulture),
unplayedCount.ToString(CultureInfo.InvariantCulture)
maxHeight.ToString(CultureInfo.InvariantCulture)
);

var width = info.Width;
Expand Down
Loading

0 comments on commit 2a1acb7

Please sign in to comment.