2016-10-29 22:22:20 +00:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-10-29 22:34:54 +00:00
|
|
|
|
using Emby.Dlna.Didl;
|
|
|
|
|
using Emby.Dlna.Server;
|
|
|
|
|
using Emby.Dlna.Service;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
using MediaBrowser.Model.Dlna;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
2016-11-04 08:31:05 +00:00
|
|
|
|
using System.IO;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
2017-05-21 07:25:49 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2016-12-20 07:31:30 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2017-07-22 23:00:48 +00:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2017-08-02 07:30:17 +00:00
|
|
|
|
using MediaBrowser.Controller.TV;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
using MediaBrowser.Model.Globalization;
|
2016-11-04 08:31:05 +00:00
|
|
|
|
using MediaBrowser.Model.Xml;
|
2017-08-09 19:56:38 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-10-29 22:34:54 +00:00
|
|
|
|
namespace Emby.Dlna.ContentDirectory
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
public class ControlHandler : BaseControlHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly User _user;
|
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
2017-08-02 07:30:17 +00:00
|
|
|
|
private readonly ITVSeriesManager _tvSeriesManager;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
private const string NS_DC = "http://purl.org/dc/elements/1.1/";
|
|
|
|
|
private const string NS_DIDL = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/";
|
|
|
|
|
private const string NS_DLNA = "urn:schemas-dlna-org:metadata-1-0/";
|
|
|
|
|
private const string NS_UPNP = "urn:schemas-upnp-org:metadata-1-0/upnp/";
|
|
|
|
|
|
|
|
|
|
private readonly int _systemUpdateId;
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
private readonly DidlBuilder _didlBuilder;
|
|
|
|
|
|
|
|
|
|
private readonly DeviceProfile _profile;
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
public ControlHandler(ILogger logger, ILibraryManager libraryManager, DeviceProfile profile, string serverAddress, string accessToken, IImageProcessor imageProcessor, IUserDataManager userDataManager, User user, int systemUpdateId, IServerConfigurationManager config, ILocalizationManager localization, IChannelManager channelManager, IMediaSourceManager mediaSourceManager, IUserViewManager userViewManager, IMediaEncoder mediaEncoder, IXmlReaderSettingsFactory xmlReaderSettingsFactory, ITVSeriesManager tvSeriesManager)
|
2016-11-04 08:31:05 +00:00
|
|
|
|
: base(config, logger, xmlReaderSettingsFactory)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
|
_user = user;
|
|
|
|
|
_systemUpdateId = systemUpdateId;
|
|
|
|
|
_channelManager = channelManager;
|
|
|
|
|
_userViewManager = userViewManager;
|
2017-08-02 07:30:17 +00:00
|
|
|
|
_tvSeriesManager = tvSeriesManager;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
_profile = profile;
|
|
|
|
|
_config = config;
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
_didlBuilder = new DidlBuilder(profile, user, imageProcessor, serverAddress, accessToken, userDataManager, localization, mediaSourceManager, Logger, libraryManager, mediaEncoder);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-04 21:30:38 +00:00
|
|
|
|
protected override IEnumerable<KeyValuePair<string, string>> GetResult(string methodName, IDictionary<string, string> methodParams)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
var deviceId = "test";
|
|
|
|
|
|
|
|
|
|
var user = _user;
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "GetSearchCapabilities", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleGetSearchCapabilities();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "GetSortCapabilities", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleGetSortCapabilities();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "GetSortExtensionCapabilities", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleGetSortExtensionCapabilities();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "GetSystemUpdateID", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleGetSystemUpdateID();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "Browse", StringComparison.OrdinalIgnoreCase))
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return HandleBrowse(methodParams, user, deviceId);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "X_GetFeatureList", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleXGetFeatureList();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "GetFeatureList", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleGetFeatureList();
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "X_SetBookmark", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return HandleXSetBookmark(methodParams, user);
|
|
|
|
|
|
|
|
|
|
if (string.Equals(methodName, "Search", StringComparison.OrdinalIgnoreCase))
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return HandleSearch(methodParams, user, deviceId);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-12-14 20:58:55 +00:00
|
|
|
|
if (string.Equals(methodName, "X_BrowseByLetter", StringComparison.OrdinalIgnoreCase))
|
2017-05-26 06:48:54 +00:00
|
|
|
|
return HandleX_BrowseByLetter(methodParams, user, deviceId);
|
2016-12-14 20:58:55 +00:00
|
|
|
|
|
2016-10-29 22:22:20 +00:00
|
|
|
|
throw new ResourceNotFoundException("Unexpected control request name: " + methodName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleXSetBookmark(IDictionary<string, string> sparams, User user)
|
|
|
|
|
{
|
|
|
|
|
var id = sparams["ObjectID"];
|
|
|
|
|
|
|
|
|
|
var serverItem = GetItemFromObjectId(id, user);
|
|
|
|
|
|
|
|
|
|
var item = serverItem.Item;
|
|
|
|
|
|
|
|
|
|
var newbookmark = int.Parse(sparams["PosSecond"], _usCulture);
|
|
|
|
|
|
|
|
|
|
var userdata = _userDataManager.GetUserData(user, item);
|
|
|
|
|
|
|
|
|
|
userdata.PlaybackPositionTicks = TimeSpan.FromSeconds(newbookmark).Ticks;
|
|
|
|
|
|
|
|
|
|
_userDataManager.SaveUserData(user.Id, item, userdata, UserDataSaveReason.TogglePlayed,
|
|
|
|
|
CancellationToken.None);
|
|
|
|
|
|
2016-12-14 20:58:55 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleGetSearchCapabilities()
|
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
{
|
|
|
|
|
{ "SearchCaps", "res@resolution,res@size,res@duration,dc:title,dc:creator,upnp:actor,upnp:artist,upnp:genre,upnp:album,dc:date,upnp:class,@id,@refID,@protocolInfo,upnp:author,dc:description,pv:avKeywords" }
|
|
|
|
|
};
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleGetSortCapabilities()
|
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
{ "SortCaps", "res@duration,res@size,res@bitrate,dc:date,dc:title,dc:size,upnp:album,upnp:artist,upnp:albumArtist,upnp:episodeNumber,upnp:genre,upnp:originalTrackNumber,upnp:rating" }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleGetSortExtensionCapabilities()
|
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
{ "SortExtensionCaps", "res@duration,res@size,res@bitrate,dc:date,dc:title,dc:size,upnp:album,upnp:artist,upnp:albumArtist,upnp:episodeNumber,upnp:genre,upnp:originalTrackNumber,upnp:rating" }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleGetSystemUpdateID()
|
|
|
|
|
{
|
2016-12-14 20:58:55 +00:00
|
|
|
|
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
headers.Add("Id", _systemUpdateId.ToString(_usCulture));
|
|
|
|
|
return headers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleGetFeatureList()
|
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
{ "FeatureList", GetFeatureListXml() }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleXGetFeatureList()
|
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
{ "FeatureList", GetFeatureListXml() }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetFeatureListXml()
|
|
|
|
|
{
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
|
|
|
builder.Append("<Features xmlns=\"urn:schemas-upnp-org:av:avs\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd\">");
|
|
|
|
|
|
|
|
|
|
builder.Append("<Feature name=\"samsung.com_BASICVIEW\" version=\"1\">");
|
|
|
|
|
builder.Append("<container id=\"I\" type=\"object.item.imageItem\"/>");
|
|
|
|
|
builder.Append("<container id=\"A\" type=\"object.item.audioItem\"/>");
|
|
|
|
|
builder.Append("<container id=\"V\" type=\"object.item.videoItem\"/>");
|
|
|
|
|
builder.Append("</Feature>");
|
|
|
|
|
|
|
|
|
|
builder.Append("</Features>");
|
|
|
|
|
|
|
|
|
|
return builder.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-04 21:30:38 +00:00
|
|
|
|
public string GetValueOrDefault(IDictionary<string, string> sparams, string key, string defaultValue)
|
|
|
|
|
{
|
|
|
|
|
string val;
|
|
|
|
|
|
|
|
|
|
if (sparams.TryGetValue(key, out val))
|
|
|
|
|
{
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleBrowse(IDictionary<string, string> sparams, User user, string deviceId)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
var id = sparams["ObjectID"];
|
|
|
|
|
var flag = sparams["BrowseFlag"];
|
2016-12-04 21:30:38 +00:00
|
|
|
|
var filter = new Filter(GetValueOrDefault(sparams, "Filter", "*"));
|
|
|
|
|
var sortCriteria = new SortCriteria(GetValueOrDefault(sparams, "SortCriteria", ""));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
var provided = 0;
|
|
|
|
|
|
|
|
|
|
// Default to null instead of 0
|
|
|
|
|
// Upnp inspector sends 0 as requestedCount when it wants everything
|
|
|
|
|
int? requestedCount = null;
|
|
|
|
|
int? start = 0;
|
|
|
|
|
|
|
|
|
|
int requestedVal;
|
|
|
|
|
if (sparams.ContainsKey("RequestedCount") && int.TryParse(sparams["RequestedCount"], out requestedVal) && requestedVal > 0)
|
|
|
|
|
{
|
|
|
|
|
requestedCount = requestedVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int startVal;
|
|
|
|
|
if (sparams.ContainsKey("StartingIndex") && int.TryParse(sparams["StartingIndex"], out startVal) && startVal > 0)
|
|
|
|
|
{
|
|
|
|
|
start = startVal;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var settings = new XmlWriterSettings
|
|
|
|
|
{
|
|
|
|
|
Encoding = Encoding.UTF8,
|
|
|
|
|
CloseOutput = false,
|
|
|
|
|
OmitXmlDeclaration = true,
|
|
|
|
|
ConformanceLevel = ConformanceLevel.Fragment
|
|
|
|
|
};
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
int totalCount;
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(builder, settings))
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2016-11-04 08:31:05 +00:00
|
|
|
|
//writer.WriteStartDocument();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2016-11-06 17:30:44 +00:00
|
|
|
|
DidlBuilder.WriteXmlRootAttributes(_profile, writer);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var serverItem = GetItemFromObjectId(id, user);
|
|
|
|
|
var item = serverItem.Item;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
if (string.Equals(flag, "BrowseMetadata"))
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2016-11-04 08:31:05 +00:00
|
|
|
|
totalCount = 1;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2017-01-06 04:38:03 +00:00
|
|
|
|
if (item.IsDisplayedAsFolder || serverItem.StubType.HasValue)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var childrenResult = (GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
_didlBuilder.WriteFolderElement(writer, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-26 17:37:49 +00:00
|
|
|
|
_didlBuilder.WriteItemElement(_config.GetDlnaConfiguration(), writer, item, user, null, null, deviceId, filter);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
2016-11-04 08:31:05 +00:00
|
|
|
|
|
|
|
|
|
provided++;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
2016-11-04 08:31:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var childrenResult = (GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount));
|
2016-11-04 08:31:05 +00:00
|
|
|
|
totalCount = childrenResult.TotalRecordCount;
|
|
|
|
|
|
|
|
|
|
provided = childrenResult.Items.Length;
|
|
|
|
|
|
|
|
|
|
foreach (var i in childrenResult.Items)
|
|
|
|
|
{
|
|
|
|
|
var childItem = i.Item;
|
|
|
|
|
var displayStubType = i.StubType;
|
|
|
|
|
|
2017-01-06 04:38:03 +00:00
|
|
|
|
if (childItem.IsDisplayedAsFolder || displayStubType.HasValue)
|
2016-11-04 08:31:05 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var childCount = (GetUserItems(childItem, displayStubType, user, sortCriteria, null, 0))
|
2016-11-04 08:31:05 +00:00
|
|
|
|
.TotalRecordCount;
|
|
|
|
|
|
|
|
|
|
_didlBuilder.WriteFolderElement(writer, childItem, displayStubType, item, childCount, filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-26 17:37:49 +00:00
|
|
|
|
_didlBuilder.WriteItemElement(_config.GetDlnaConfiguration(), writer, childItem, user, item, serverItem.StubType, deviceId, filter);
|
2016-11-04 08:31:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-06 17:30:44 +00:00
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 08:31:05 +00:00
|
|
|
|
//writer.WriteEndDocument();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var resXML = builder.ToString();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
return new List<KeyValuePair<string, string>>
|
2016-11-04 08:31:05 +00:00
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<string,string>("Result", resXML),
|
|
|
|
|
new KeyValuePair<string,string>("NumberReturned", provided.ToString(_usCulture)),
|
|
|
|
|
new KeyValuePair<string,string>("TotalMatches", totalCount.ToString(_usCulture)),
|
|
|
|
|
new KeyValuePair<string,string>("UpdateID", _systemUpdateId.ToString(_usCulture))
|
|
|
|
|
};
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleX_BrowseByLetter(IDictionary<string, string> sparams, User user, string deviceId)
|
2016-12-14 20:58:55 +00:00
|
|
|
|
{
|
|
|
|
|
// TODO: Implement this method
|
|
|
|
|
return HandleSearch(sparams, user, deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private IEnumerable<KeyValuePair<string, string>> HandleSearch(IDictionary<string, string> sparams, User user, string deviceId)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2016-12-04 21:30:38 +00:00
|
|
|
|
var searchCriteria = new SearchCriteria(GetValueOrDefault(sparams, "SearchCriteria", ""));
|
|
|
|
|
var sortCriteria = new SortCriteria(GetValueOrDefault(sparams, "SortCriteria", ""));
|
|
|
|
|
var filter = new Filter(GetValueOrDefault(sparams, "Filter", "*"));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
// sort example: dc:title, dc:date
|
|
|
|
|
|
|
|
|
|
// Default to null instead of 0
|
|
|
|
|
// Upnp inspector sends 0 as requestedCount when it wants everything
|
|
|
|
|
int? requestedCount = null;
|
|
|
|
|
int? start = 0;
|
|
|
|
|
|
|
|
|
|
int requestedVal;
|
|
|
|
|
if (sparams.ContainsKey("RequestedCount") && int.TryParse(sparams["RequestedCount"], out requestedVal) && requestedVal > 0)
|
|
|
|
|
{
|
|
|
|
|
requestedCount = requestedVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int startVal;
|
|
|
|
|
if (sparams.ContainsKey("StartingIndex") && int.TryParse(sparams["StartingIndex"], out startVal) && startVal > 0)
|
|
|
|
|
{
|
|
|
|
|
start = startVal;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var settings = new XmlWriterSettings
|
|
|
|
|
{
|
|
|
|
|
Encoding = Encoding.UTF8,
|
|
|
|
|
CloseOutput = false,
|
|
|
|
|
OmitXmlDeclaration = true,
|
|
|
|
|
ConformanceLevel = ConformanceLevel.Fragment
|
|
|
|
|
};
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
|
|
|
|
|
int totalCount = 0;
|
|
|
|
|
int provided = 0;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(builder, settings))
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2016-11-04 08:31:05 +00:00
|
|
|
|
//writer.WriteStartDocument();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
writer.WriteStartElement(string.Empty, "DIDL-Lite", NS_DIDL);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
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);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-06 17:30:44 +00:00
|
|
|
|
DidlBuilder.WriteXmlRootAttributes(_profile, writer);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var serverItem = GetItemFromObjectId(sparams["ContainerID"], user);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var item = serverItem.Item;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var childrenResult = (GetChildrenSorted(item, user, searchCriteria, sortCriteria, start, requestedCount));
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
totalCount = childrenResult.TotalRecordCount;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
provided = childrenResult.Items.Length;
|
|
|
|
|
|
|
|
|
|
foreach (var i in childrenResult.Items)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2017-01-06 04:38:03 +00:00
|
|
|
|
if (i.IsDisplayedAsFolder)
|
2016-11-04 08:31:05 +00:00
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var childCount = (GetChildrenSorted(i, user, searchCriteria, sortCriteria, null, 0))
|
2016-11-04 08:31:05 +00:00
|
|
|
|
.TotalRecordCount;
|
|
|
|
|
|
|
|
|
|
_didlBuilder.WriteFolderElement(writer, i, null, item, childCount, filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-26 17:37:49 +00:00
|
|
|
|
_didlBuilder.WriteItemElement(_config.GetDlnaConfiguration(), writer, i, user, item, serverItem.StubType, deviceId, filter);
|
2016-11-04 08:31:05 +00:00
|
|
|
|
}
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
2016-11-04 08:31:05 +00:00
|
|
|
|
|
2016-11-06 17:30:44 +00:00
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 08:31:05 +00:00
|
|
|
|
//writer.WriteEndDocument();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 08:31:05 +00:00
|
|
|
|
var resXML = builder.ToString();
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
return new List<KeyValuePair<string, string>>
|
2016-11-04 08:31:05 +00:00
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<string,string>("Result", resXML),
|
|
|
|
|
new KeyValuePair<string,string>("NumberReturned", provided.ToString(_usCulture)),
|
|
|
|
|
new KeyValuePair<string,string>("TotalMatches", totalCount.ToString(_usCulture)),
|
|
|
|
|
new KeyValuePair<string,string>("UpdateID", _systemUpdateId.ToString(_usCulture))
|
|
|
|
|
};
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private QueryResult<BaseItem> GetChildrenSorted(BaseItem item, User user, SearchCriteria search, SortCriteria sort, int? startIndex, int? limit)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
var folder = (Folder)item;
|
|
|
|
|
|
|
|
|
|
var sortOrders = new List<string>();
|
|
|
|
|
if (!folder.IsPreSorted)
|
|
|
|
|
{
|
|
|
|
|
sortOrders.Add(ItemSortBy.SortName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mediaTypes = new List<string>();
|
|
|
|
|
bool? isFolder = null;
|
|
|
|
|
|
|
|
|
|
if (search.SearchType == SearchType.Audio)
|
|
|
|
|
{
|
|
|
|
|
mediaTypes.Add(MediaType.Audio);
|
|
|
|
|
isFolder = false;
|
|
|
|
|
}
|
|
|
|
|
else if (search.SearchType == SearchType.Video)
|
|
|
|
|
{
|
|
|
|
|
mediaTypes.Add(MediaType.Video);
|
|
|
|
|
isFolder = false;
|
|
|
|
|
}
|
|
|
|
|
else if (search.SearchType == SearchType.Image)
|
|
|
|
|
{
|
|
|
|
|
mediaTypes.Add(MediaType.Photo);
|
|
|
|
|
isFolder = false;
|
|
|
|
|
}
|
|
|
|
|
else if (search.SearchType == SearchType.Playlist)
|
|
|
|
|
{
|
|
|
|
|
//items = items.OfType<Playlist>();
|
|
|
|
|
isFolder = true;
|
|
|
|
|
}
|
|
|
|
|
else if (search.SearchType == SearchType.MusicAlbum)
|
|
|
|
|
{
|
|
|
|
|
//items = items.OfType<MusicAlbum>();
|
|
|
|
|
isFolder = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return folder.GetItems(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
Limit = limit,
|
|
|
|
|
StartIndex = startIndex,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
SortBy = sortOrders.ToArray(sortOrders.Count),
|
2016-10-29 22:22:20 +00:00
|
|
|
|
SortOrder = sort.SortOrder,
|
|
|
|
|
User = user,
|
|
|
|
|
Recursive = true,
|
|
|
|
|
IsMissing = false,
|
|
|
|
|
ExcludeItemTypes = new[] { typeof(Game).Name, typeof(Book).Name },
|
|
|
|
|
IsFolder = isFolder,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
MediaTypes = mediaTypes.ToArray(mediaTypes.Count),
|
2017-05-21 07:25:49 +00:00
|
|
|
|
DtoOptions = GetDtoOptions()
|
2016-10-29 22:22:20 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 07:25:49 +00:00
|
|
|
|
private DtoOptions GetDtoOptions()
|
|
|
|
|
{
|
|
|
|
|
return new DtoOptions(true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private QueryResult<ServerItem> GetUserItems(BaseItem item, StubType? stubType, User user, SortCriteria sort, int? startIndex, int? limit)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2016-12-20 19:59:25 +00:00
|
|
|
|
if (item is MusicGenre)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicGenreItems(item, null, user, sort, startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item is MusicArtist)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicArtistItems(item, null, user, sort, startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
if (item is Genre)
|
|
|
|
|
{
|
|
|
|
|
return GetGenreItems(item, null, user, sort, startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
var collectionFolder = item as ICollectionFolder;
|
|
|
|
|
if (collectionFolder != null && string.Equals(CollectionType.Music, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return GetMusicFolders(item, user, stubType, sort, startIndex, limit);
|
|
|
|
|
}
|
2017-08-02 07:30:17 +00:00
|
|
|
|
if (collectionFolder != null && string.Equals(CollectionType.Movies, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return GetMovieFolders(item, user, stubType, sort, startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
if (collectionFolder != null && string.Equals(CollectionType.TvShows, collectionFolder.CollectionType, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return GetTvFolders(item, user, stubType, sort, startIndex, limit);
|
|
|
|
|
}
|
2017-07-22 23:00:48 +00:00
|
|
|
|
|
2016-10-29 22:22:20 +00:00
|
|
|
|
if (stubType.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var person = item as Person;
|
|
|
|
|
if (person != null)
|
|
|
|
|
{
|
|
|
|
|
return GetItemsFromPerson(person, user, startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ApplyPaging(new QueryResult<ServerItem>(), startIndex, limit);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 07:31:30 +00:00
|
|
|
|
var folder = (Folder)item;
|
|
|
|
|
|
|
|
|
|
var query = new InternalItemsQuery
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
Limit = limit,
|
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
User = user,
|
2017-08-13 02:09:07 +00:00
|
|
|
|
IsVirtualItem = false,
|
|
|
|
|
PresetViews = new string[] { },
|
2017-05-26 06:48:54 +00:00
|
|
|
|
ExcludeItemTypes = new[] { typeof(Game).Name, typeof(Book).Name },
|
2017-05-21 07:25:49 +00:00
|
|
|
|
IsPlaceHolder = false,
|
|
|
|
|
DtoOptions = GetDtoOptions()
|
2016-12-20 07:31:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetSorting(query, sort, folder.IsPreSorted);
|
|
|
|
|
|
2017-05-26 06:48:54 +00:00
|
|
|
|
var queryResult = folder.GetItems(query);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2016-12-20 07:31:30 +00:00
|
|
|
|
return ToResult(queryResult);
|
|
|
|
|
}
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMusicFolders(BaseItem item, User user, StubType? stubType, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
Limit = limit
|
|
|
|
|
};
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Latest)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicLatest(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Playlists)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicPlaylists(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Albums)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicAlbums(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Artists)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicArtists(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.AlbumArtists)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicAlbumArtists(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.FavoriteAlbums)
|
|
|
|
|
{
|
|
|
|
|
return GetFavoriteAlbums(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.FavoriteArtists)
|
|
|
|
|
{
|
|
|
|
|
return GetFavoriteArtists(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.FavoriteSongs)
|
|
|
|
|
{
|
|
|
|
|
return GetFavoriteSongs(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Songs)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicSongs(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Genres)
|
|
|
|
|
{
|
|
|
|
|
return GetMusicGenres(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<ServerItem>();
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Latest
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Playlists
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Albums
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.AlbumArtists
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Artists
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Songs
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Genres
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.FavoriteArtists
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.FavoriteAlbums
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.FavoriteSongs
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = list.ToArray(list.Count),
|
2017-07-22 23:00:48 +00:00
|
|
|
|
TotalRecordCount = list.Count
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMovieFolders(BaseItem item, User user, StubType? stubType, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
Limit = limit
|
|
|
|
|
};
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.ContinueWatching)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieContinueWatching(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Latest)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieLatest(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Movies)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieMovies(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Collections)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieCollections(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Favorites)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieFavorites(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Genres)
|
|
|
|
|
{
|
|
|
|
|
return GetGenres(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<ServerItem>();
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.ContinueWatching
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Latest
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Movies
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Collections
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Favorites
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Genres
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = list.ToArray(list.Count),
|
2017-08-02 07:30:17 +00:00
|
|
|
|
TotalRecordCount = list.Count
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetTvFolders(BaseItem item, User user, StubType? stubType, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
Limit = limit
|
|
|
|
|
};
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.ContinueWatching)
|
|
|
|
|
{
|
|
|
|
|
return GetMovieContinueWatching(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.NextUp)
|
|
|
|
|
{
|
|
|
|
|
return GetNextUp(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Latest)
|
|
|
|
|
{
|
|
|
|
|
return GetTvLatest(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Series)
|
|
|
|
|
{
|
|
|
|
|
return GetSeries(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.FavoriteSeries)
|
|
|
|
|
{
|
|
|
|
|
return GetFavoriteSeries(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.FavoriteEpisodes)
|
|
|
|
|
{
|
|
|
|
|
return GetFavoriteEpisodes(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stubType.HasValue && stubType.Value == StubType.Genres)
|
|
|
|
|
{
|
|
|
|
|
return GetGenres(item, user, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = new List<ServerItem>();
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.ContinueWatching
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.NextUp
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Latest
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Series
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.FavoriteSeries
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.FavoriteEpisodes
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
list.Add(new ServerItem(item)
|
|
|
|
|
{
|
|
|
|
|
StubType = StubType.Genres
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = list.ToArray(list.Count),
|
2017-08-02 07:30:17 +00:00
|
|
|
|
TotalRecordCount = list.Count
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMovieContinueWatching(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.OrderBy = new List<Tuple<string, SortOrder>>
|
|
|
|
|
{
|
|
|
|
|
new Tuple<string, SortOrder> (ItemSortBy.DatePlayed, SortOrder.Descending),
|
|
|
|
|
new Tuple<string, SortOrder> (ItemSortBy.SortName, SortOrder.Ascending)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
query.IsResumable = true;
|
|
|
|
|
query.Limit = 10;
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetSeries(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMovieMovies(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMovieCollections(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
//query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(BoxSet).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMusicAlbums(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMusicSongs(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Audio).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetFavoriteSongs(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.IsFavorite = true;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Audio).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
private QueryResult<ServerItem> GetFavoriteSeries(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.IsFavorite = true;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Series).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetFavoriteEpisodes(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.IsFavorite = true;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Episode).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMovieFavorites(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.IsFavorite = true;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Movie).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
private QueryResult<ServerItem> GetFavoriteAlbums(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
query.Parent = parent;
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.IsFavorite = true;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(MusicAlbum).Name };
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
private QueryResult<ServerItem> GetGenres(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var genresResult = _libraryManager.GetGenres(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
AncestorIds = new[] { parent.Id.ToString("N") },
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
Limit = query.Limit
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = genresResult.TotalRecordCount,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = genresResult.Items.Select(i => i.Item1).ToArray(genresResult.Items.Length)
|
2017-08-02 07:30:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMusicGenres(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var genresResult = _libraryManager.GetMusicGenres(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
AncestorIds = new[] { parent.Id.ToString("N") },
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
Limit = query.Limit
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = genresResult.TotalRecordCount,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = genresResult.Items.Select(i => i.Item1).ToArray(genresResult.Items.Length)
|
2017-07-22 23:00:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMusicAlbumArtists(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var artists = _libraryManager.GetAlbumArtists(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
AncestorIds = new[] { parent.Id.ToString("N") },
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
Limit = query.Limit
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = artists.TotalRecordCount,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = artists.Items.Select(i => i.Item1).ToArray(artists.Items.Length)
|
2017-07-22 23:00:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMusicArtists(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var artists = _libraryManager.GetArtists(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
AncestorIds = new[] { parent.Id.ToString("N") },
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
Limit = query.Limit
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = artists.TotalRecordCount,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = artists.Items.Select(i => i.Item1).ToArray(artists.Items.Length)
|
2017-07-22 23:00:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetFavoriteArtists(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
var artists = _libraryManager.GetArtists(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
AncestorIds = new[] { parent.Id.ToString("N") },
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
IsFavorite = true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var result = new QueryResult<BaseItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = artists.TotalRecordCount,
|
2017-08-09 19:56:38 +00:00
|
|
|
|
Items = artists.Items.Select(i => i.Item1).ToArray(artists.Items.Length)
|
2017-07-22 23:00:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMusicPlaylists(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.Parent = null;
|
|
|
|
|
query.IncludeItemTypes = new[] { typeof(Playlist).Name };
|
|
|
|
|
query.SetUser(user);
|
|
|
|
|
query.Recursive = true;
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMusicLatest(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.SortBy = new string[] { };
|
|
|
|
|
|
|
|
|
|
var items = _userViewManager.GetLatestItems(new LatestItemsQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = user.Id.ToString("N"),
|
|
|
|
|
Limit = 50,
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Audio).Name },
|
|
|
|
|
ParentId = parent == null ? null : parent.Id.ToString("N"),
|
|
|
|
|
GroupItems = true
|
|
|
|
|
|
|
|
|
|
}, query.DtoOptions).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null).ToList();
|
|
|
|
|
|
|
|
|
|
return ToResult(items);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
private QueryResult<ServerItem> GetNextUp(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.SortBy = new string[] { };
|
|
|
|
|
|
|
|
|
|
var result = _tvSeriesManager.GetNextUp(new NextUpQuery
|
|
|
|
|
{
|
|
|
|
|
Limit = query.Limit,
|
|
|
|
|
StartIndex = query.StartIndex,
|
|
|
|
|
UserId = query.User.Id.ToString("N")
|
|
|
|
|
|
|
|
|
|
}, new List<Folder> { (Folder)parent }, query.DtoOptions);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetTvLatest(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.SortBy = new string[] { };
|
|
|
|
|
|
|
|
|
|
var items = _userViewManager.GetLatestItems(new LatestItemsQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = user.Id.ToString("N"),
|
|
|
|
|
Limit = 50,
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Episode).Name },
|
|
|
|
|
ParentId = parent == null ? null : parent.Id.ToString("N"),
|
2017-08-13 02:09:07 +00:00
|
|
|
|
GroupItems = false
|
2017-08-02 07:30:17 +00:00
|
|
|
|
|
|
|
|
|
}, query.DtoOptions).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null).ToList();
|
|
|
|
|
|
|
|
|
|
return ToResult(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> GetMovieLatest(BaseItem parent, User user, InternalItemsQuery query)
|
|
|
|
|
{
|
|
|
|
|
query.SortBy = new string[] { };
|
|
|
|
|
|
|
|
|
|
var items = _userViewManager.GetLatestItems(new LatestItemsQuery
|
|
|
|
|
{
|
|
|
|
|
UserId = user.Id.ToString("N"),
|
|
|
|
|
Limit = 50,
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Movie).Name },
|
|
|
|
|
ParentId = parent == null ? null : parent.Id.ToString("N"),
|
|
|
|
|
GroupItems = true
|
|
|
|
|
|
|
|
|
|
}, query.DtoOptions).Select(i => i.Item1 ?? i.Item2.FirstOrDefault()).Where(i => i != null).ToList();
|
|
|
|
|
|
|
|
|
|
return ToResult(items);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 19:59:25 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMusicArtistItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parentId,
|
|
|
|
|
ArtistIds = new[] { item.Id.ToString("N") },
|
|
|
|
|
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
|
|
|
|
Limit = limit,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
DtoOptions = GetDtoOptions()
|
2016-12-20 19:59:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
private QueryResult<ServerItem> GetGenreItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parentId,
|
|
|
|
|
GenreIds = new[] { item.Id.ToString("N") },
|
|
|
|
|
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name },
|
|
|
|
|
Limit = limit,
|
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
DtoOptions = GetDtoOptions()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 07:31:30 +00:00
|
|
|
|
private QueryResult<ServerItem> GetMusicGenreItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var query = new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = true,
|
|
|
|
|
ParentId = parentId,
|
2017-05-26 06:48:54 +00:00
|
|
|
|
GenreIds = new[] { item.Id.ToString("N") },
|
|
|
|
|
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
2016-12-20 07:31:30 +00:00
|
|
|
|
Limit = limit,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
DtoOptions = GetDtoOptions()
|
2016-12-20 07:31:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetSorting(query, sort, false);
|
|
|
|
|
|
|
|
|
|
var result = _libraryManager.GetItemsResult(query);
|
|
|
|
|
|
|
|
|
|
return ToResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 23:00:48 +00:00
|
|
|
|
private QueryResult<ServerItem> ToResult(List<BaseItem> result)
|
|
|
|
|
{
|
|
|
|
|
var serverItems = result
|
|
|
|
|
.Select(i => new ServerItem(i))
|
2017-08-09 19:56:38 +00:00
|
|
|
|
.ToArray(result.Count);
|
2017-07-22 23:00:48 +00:00
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = result.Count,
|
|
|
|
|
Items = serverItems
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 07:31:30 +00:00
|
|
|
|
private QueryResult<ServerItem> ToResult(QueryResult<BaseItem> result)
|
|
|
|
|
{
|
|
|
|
|
var serverItems = result
|
2016-10-29 22:22:20 +00:00
|
|
|
|
.Items
|
2016-12-20 19:59:25 +00:00
|
|
|
|
.Select(i => new ServerItem(i))
|
2017-08-09 19:56:38 +00:00
|
|
|
|
.ToArray(result.Items.Length);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
2016-12-20 07:31:30 +00:00
|
|
|
|
TotalRecordCount = result.TotalRecordCount,
|
2016-10-29 22:22:20 +00:00
|
|
|
|
Items = serverItems
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-20 07:31:30 +00:00
|
|
|
|
private void SetSorting(InternalItemsQuery query, SortCriteria sort, bool isPreSorted)
|
|
|
|
|
{
|
|
|
|
|
var sortOrders = new List<string>();
|
|
|
|
|
if (!isPreSorted)
|
|
|
|
|
{
|
|
|
|
|
sortOrders.Add(ItemSortBy.SortName);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
query.SortBy = sortOrders.ToArray(sortOrders.Count);
|
2016-12-20 07:31:30 +00:00
|
|
|
|
query.SortOrder = sort.SortOrder;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 22:22:20 +00:00
|
|
|
|
private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
|
|
|
|
{
|
2016-11-20 20:20:01 +00:00
|
|
|
|
PersonIds = new[] { person.Id.ToString("N") },
|
2016-10-29 22:22:20 +00:00
|
|
|
|
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name, typeof(Trailer).Name },
|
|
|
|
|
SortBy = new[] { ItemSortBy.SortName },
|
|
|
|
|
Limit = limit,
|
2017-05-21 07:25:49 +00:00
|
|
|
|
StartIndex = startIndex,
|
|
|
|
|
DtoOptions = GetDtoOptions()
|
2016-10-29 22:22:20 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
var serverItems = itemsResult.Items.Select(i => new ServerItem(i)).ToArray(itemsResult.Items.Length);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
return new QueryResult<ServerItem>
|
|
|
|
|
{
|
|
|
|
|
TotalRecordCount = itemsResult.TotalRecordCount,
|
|
|
|
|
Items = serverItems
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryResult<ServerItem> ApplyPaging(QueryResult<ServerItem> result, int? startIndex, int? limit)
|
|
|
|
|
{
|
|
|
|
|
result.Items = result.Items.Skip(startIndex ?? 0).Take(limit ?? int.MaxValue).ToArray();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ServerItem GetItemFromObjectId(string id, User user)
|
|
|
|
|
{
|
|
|
|
|
return DidlBuilder.IsIdRoot(id)
|
|
|
|
|
|
2016-12-20 19:59:25 +00:00
|
|
|
|
? new ServerItem(user.RootFolder)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
: ParseItemId(id, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ServerItem ParseItemId(string id, User user)
|
|
|
|
|
{
|
|
|
|
|
Guid itemId;
|
|
|
|
|
StubType? stubType = null;
|
|
|
|
|
|
|
|
|
|
// After using PlayTo, MediaMonkey sends a request to the server trying to get item info
|
|
|
|
|
const string paramsSrch = "Params=";
|
|
|
|
|
var paramsIndex = id.IndexOf(paramsSrch, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
if (paramsIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
id = id.Substring(paramsIndex + paramsSrch.Length);
|
|
|
|
|
|
|
|
|
|
var parts = id.Split(';');
|
|
|
|
|
id = parts[23];
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 07:30:17 +00:00
|
|
|
|
var enumNames = Enum.GetNames(typeof(StubType));
|
|
|
|
|
foreach (var name in enumNames)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
2017-08-02 07:30:17 +00:00
|
|
|
|
if (id.StartsWith(name + "_", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
stubType = (StubType)Enum.Parse(typeof(StubType), name, true);
|
|
|
|
|
id = id.Split(new[] { '_' }, 2)[1];
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-07-22 23:00:48 +00:00
|
|
|
|
}
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
|
|
if (Guid.TryParse(id, out itemId))
|
|
|
|
|
{
|
|
|
|
|
var item = _libraryManager.GetItemById(itemId);
|
|
|
|
|
|
2016-12-20 19:59:25 +00:00
|
|
|
|
return new ServerItem(item)
|
2016-10-29 22:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
StubType = stubType
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Error("Error parsing item Id: {0}. Returning user root folder.", id);
|
|
|
|
|
|
2016-12-20 19:59:25 +00:00
|
|
|
|
return new ServerItem(user.RootFolder);
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal class ServerItem
|
|
|
|
|
{
|
|
|
|
|
public BaseItem Item { get; set; }
|
|
|
|
|
public StubType? StubType { get; set; }
|
2016-12-20 19:59:25 +00:00
|
|
|
|
|
|
|
|
|
public ServerItem(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
Item = item;
|
|
|
|
|
|
|
|
|
|
if (item is IItemByName && !(item is Folder))
|
|
|
|
|
{
|
|
|
|
|
StubType = Dlna.ContentDirectory.StubType.Folder;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum StubType
|
|
|
|
|
{
|
|
|
|
|
Folder = 0,
|
2017-07-22 23:00:48 +00:00
|
|
|
|
Latest = 2,
|
|
|
|
|
Playlists = 3,
|
|
|
|
|
Albums = 4,
|
|
|
|
|
AlbumArtists = 5,
|
|
|
|
|
Artists = 6,
|
|
|
|
|
Songs = 7,
|
|
|
|
|
Genres = 8,
|
|
|
|
|
FavoriteSongs = 9,
|
|
|
|
|
FavoriteArtists = 10,
|
2017-08-02 07:30:17 +00:00
|
|
|
|
FavoriteAlbums = 11,
|
|
|
|
|
ContinueWatching = 12,
|
|
|
|
|
Movies = 13,
|
|
|
|
|
Collections = 14,
|
|
|
|
|
Favorites = 15,
|
|
|
|
|
NextUp = 16,
|
|
|
|
|
Series = 17,
|
|
|
|
|
FavoriteSeries = 18,
|
|
|
|
|
FavoriteEpisodes = 19
|
2016-10-29 22:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|