Reports - Add Users activities

pull/702/head
Tavares André 10 years ago
parent ff26b09583
commit 1e07dbec63

@ -84,6 +84,8 @@
<Compile Include="Playback\MediaInfoService.cs" />
<Compile Include="Playback\TranscodingThrottler.cs" />
<Compile Include="PlaylistService.cs" />
<Compile Include="Reports\Activities\ReportActivitiesBuilder.cs" />
<Compile Include="Reports\Common\HeaderActivitiesMetadata.cs" />
<Compile Include="Reports\Common\HeaderMetadata.cs" />
<Compile Include="Reports\Common\ItemViewType.cs" />
<Compile Include="Reports\Common\ReportBuilderBase.cs" />
@ -91,15 +93,16 @@
<Compile Include="Reports\Common\ReportFieldType.cs" />
<Compile Include="Reports\Common\ReportHeaderIdType.cs" />
<Compile Include="Reports\Common\ReportHelper.cs" />
<Compile Include="Reports\Common\ReportIncludeItemTypes.cs" />
<Compile Include="Reports\Common\ReportViewType.cs" />
<Compile Include="Reports\Data\ReportBuilder.cs" />
<Compile Include="Reports\Data\ReportExport.cs" />
<Compile Include="Reports\Data\ReportGroup.cs" />
<Compile Include="Reports\Data\ReportHeader.cs" />
<Compile Include="Reports\Data\ReportItem.cs" />
<Compile Include="Reports\Data\ReportOptions.cs" />
<Compile Include="Reports\Data\ReportResult.cs" />
<Compile Include="Reports\Data\ReportRow.cs" />
<Compile Include="Reports\Model\ReportGroup.cs" />
<Compile Include="Reports\Model\ReportHeader.cs" />
<Compile Include="Reports\Model\ReportItem.cs" />
<Compile Include="Reports\Model\ReportResult.cs" />
<Compile Include="Reports\Model\ReportRow.cs" />
<Compile Include="Reports\ReportRequests.cs" />
<Compile Include="Reports\ReportsService.cs" />
<Compile Include="Reports\Stat\ReportStatBuilder.cs" />
@ -204,6 +207,13 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

@ -0,0 +1,240 @@
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Querying;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report activities builder. </summary>
/// <seealso cref="T:MediaBrowser.Api.Reports.ReportBuilderBase"/>
public class ReportActivitiesBuilder : ReportBuilderBase
{
#region [Constructors]
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportActivitiesBuilder class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
/// <param name="userManager"> Manager for user. </param>
public ReportActivitiesBuilder(ILibraryManager libraryManager, IUserManager userManager)
: base(libraryManager)
{
_userManager = userManager;
}
#endregion
#region [Private Fields]
private readonly IUserManager _userManager; ///< Manager for user
#endregion
#region [Public Methods]
/// <summary> Gets a result. </summary>
/// <param name="queryResult"> The query result. </param>
/// <param name="request"> The request. </param>
/// <returns> The result. </returns>
public ReportResult GetResult(QueryResult<ActivityLogEntry> queryResult, IReportsQuery request)
{
List<ReportOptions<ActivityLogEntry>> options = this.GetReportOptions<ActivityLogEntry>(request,
() => this.GetDefaultHeaderMetadata(),
(hm) => this.GetOption(hm)).Where(x => x.Header.Visible == true).ToList();
var headers = GetHeaders<ActivityLogEntry>(options);
var rows = GetReportRows(queryResult.Items, options);
ReportResult result = new ReportResult { Headers = headers };
HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
int i = headers.FindIndex(x => x.FieldName == groupBy);
if (groupBy != HeaderMetadata.None && i >= 0)
{
var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x })
.GroupBy(x => x.Group)
.OrderBy(x => x.Key)
.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });
result.Groups = rowsGroup.ToList();
result.IsGrouped = true;
}
else
{
result.Rows = rows;
result.IsGrouped = false;
}
return result;
}
#endregion
#region [Protected Internal Methods]
/// <summary> Gets the headers. </summary>
/// <typeparam name="H"> Type of the header. </typeparam>
/// <param name="request"> The request. </param>
/// <returns> The headers. </returns>
/// <seealso cref="M:MediaBrowser.Api.Reports.ReportBuilderBase.GetHeaders{H}(H)"/>
protected internal override List<ReportHeader> GetHeaders<H>(H request)
{
return this.GetHeaders<ActivityLogEntry>(request, () => this.GetDefaultHeaderMetadata(), (hm) => this.GetOption(hm));
}
#endregion
#region [Private Methods]
/// <summary> Gets default header metadata. </summary>
/// <returns> The default header metadata. </returns>
private List<HeaderMetadata> GetDefaultHeaderMetadata()
{
return new List<HeaderMetadata>
{
HeaderMetadata.Date,
HeaderMetadata.User,
HeaderMetadata.Type,
HeaderMetadata.Severity,
HeaderMetadata.Name,
HeaderMetadata.ShortOverview,
HeaderMetadata.Overview,
//HeaderMetadata.UserPrimaryImageTag,
//HeaderMetadata.Item,
};
}
/// <summary> Gets an option. </summary>
/// <param name="header"> The header. </param>
/// <param name="sortField"> The sort field. </param>
/// <returns> The option. </returns>
private ReportOptions<ActivityLogEntry> GetOption(HeaderMetadata header, string sortField = "")
{
HeaderMetadata internalHeader = header;
ReportOptions<ActivityLogEntry> option = new ReportOptions<ActivityLogEntry>()
{
Header = new ReportHeader
{
HeaderFieldType = ReportFieldType.String,
SortField = sortField,
Type = "",
ItemViewType = ItemViewType.None
}
};
switch (header)
{
case HeaderMetadata.StatusImage:
option.Header.ItemViewType = ItemViewType.StatusImage;
internalHeader = HeaderMetadata.Status;
option.Header.CanGroup = false;
break;
case HeaderMetadata.Name:
option.Column = (i, r) => i.Name;
break;
case HeaderMetadata.Overview:
option.Column = (i, r) => i.Overview;
option.Header.SortField = "";
option.Header.CanGroup = false;
break;
case HeaderMetadata.ShortOverview:
option.Column = (i, r) => i.ShortOverview;
option.Header.SortField = "";
option.Header.CanGroup = false;
break;
case HeaderMetadata.Type:
option.Column = (i, r) => i.Type;
option.Header.SortField = "";
break;
case HeaderMetadata.Date:
option.Column = (i, r) => i.Date;
option.Header.SortField = "";
option.Header.HeaderFieldType = ReportFieldType.DateTime;
option.Header.Type = "";
break;
case HeaderMetadata.UserPrimaryImageTag:
option.Column = (i, r) => i.UserPrimaryImageTag;
option.Header.SortField = "";
break;
case HeaderMetadata.Severity:
option.Column = (i, r) => i.Severity;
option.Header.SortField = "";
break;
case HeaderMetadata.Item:
option.Column = (i, r) => i.ItemId;
option.Header.SortField = "";
break;
case HeaderMetadata.User:
option.Column = (i, r) =>
{
if (!string.IsNullOrEmpty(i.UserId))
{
MediaBrowser.Controller.Entities.User user = _userManager.GetUserById(i.UserId);
if (user != null)
return user.Name;
}
return string.Empty;
};
option.Header.SortField = "";
break;
}
option.Header.Name = GetLocalizedHeader(internalHeader);
option.Header.FieldName = header;
return option;
}
/// <summary> Gets report rows. </summary>
/// <param name="items"> The items. </param>
/// <param name="options"> Options for controlling the operation. </param>
/// <returns> The report rows. </returns>
private List<ReportRow> GetReportRows(IEnumerable<ActivityLogEntry> items, List<ReportOptions<ActivityLogEntry>> options)
{
var rows = new List<ReportRow>();
foreach (ActivityLogEntry item in items)
{
ReportRow rRow = GetRow(item);
foreach (ReportOptions<ActivityLogEntry> option in options)
{
object itemColumn = option.Column != null ? option.Column(item, rRow) : "";
object itemId = option.ItemID != null ? option.ItemID(item) : "";
ReportItem rItem = new ReportItem
{
Name = ReportHelper.ConvertToString(itemColumn, option.Header.HeaderFieldType),
Id = ReportHelper.ConvertToString(itemId, ReportFieldType.Object)
};
rRow.Columns.Add(rItem);
}
rows.Add(rRow);
}
return rows;
}
/// <summary> Gets a row. </summary>
/// <param name="item"> The item. </param>
/// <returns> The row. </returns>
private ReportRow GetRow(ActivityLogEntry item)
{
ReportRow rRow = new ReportRow
{
Id = item.Id,
};
return rRow;
}
#endregion
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Reports
{
public enum HeaderActivitiesMetadata
{
None,
Name,
Overview,
ShortOverview,
Type,
Date,
UserPrimaryImageTag,
Severity,
Item,
User
}
}

@ -42,6 +42,15 @@ namespace MediaBrowser.Api.Reports
AudioAlbumArtist,
MusicArtist,
AudioAlbum,
Status
Status,
//Activity logs
Overview,
ShortOverview,
Type,
Date,
UserPrimaryImageTag,
Severity,
Item,
User
}
}

@ -13,217 +13,330 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report builder base. </summary>
public class ReportBuilderBase
{
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportBuilderBase class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportBuilderBase(ILibraryManager libraryManager)
{
_libraryManager = libraryManager;
}
/// <summary> Manager for library. </summary>
protected readonly ILibraryManager _libraryManager;
/// <summary> Gets audio stream. </summary>
/// <param name="item"> The item. </param>
/// <returns> The audio stream. </returns>
protected string GetAudioStream(BaseItem item)
{
var stream = GetStream(item, MediaStreamType.Audio);
if (stream != null)
return stream.Codec.ToUpper() == "DCA" ? stream.Profile : stream.Codec.
ToUpper();
return string.Empty;
}
/// <summary> Gets an episode. </summary>
/// <param name="item"> The item. </param>
/// <returns> The episode. </returns>
protected string GetEpisode(BaseItem item)
{
if (item.GetClientTypeName() == ChannelMediaContentType.Episode.ToString() && item.ParentIndexNumber != null)
return "Season " + item.ParentIndexNumber;
else
return item.Name;
}
/// <summary> Gets a genre. </summary>
/// <param name="name"> The name. </param>
/// <returns> The genre. </returns>
protected Genre GetGenre(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetGenre(name);
}
/// <summary> Gets genre identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The genre identifier. </returns>
protected string GetGenreID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetGenre(name).Id);
}
/// <summary> Gets list as string. </summary>
/// <param name="items"> The items. </param>
/// <returns> The list as string. </returns>
protected string GetListAsString(List<string> items)
{
return String.Join("; ", items);
}
/// <summary> Gets media source information. </summary>
/// <param name="item"> The item. </param>
/// <returns> The media source information. </returns>
protected MediaSourceInfo GetMediaSourceInfo(BaseItem item)
{
var mediaSource = item as IHasMediaSources;
if (mediaSource != null)
return mediaSource.GetMediaSources(false).FirstOrDefault(n => n.Type == MediaSourceType.Default);
return null;
}
/// <summary> Gets an object. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <typeparam name="R"> Type of the r. </typeparam>
/// <param name="item"> The item. </param>
/// <param name="function"> The function. </param>
/// <param name="defaultValue"> The default value. </param>
/// <returns> The object. </returns>
protected R GetObject<T, R>(BaseItem item, Func<T, R> function, R defaultValue = default(R)) where T : class
{
var value = item as T;
if (value != null && function != null)
return function(value);
else
return defaultValue;
}
/// <summary> Gets a person. </summary>
/// <param name="name"> The name. </param>
/// <returns> The person. </returns>
protected Person GetPerson(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetPerson(name);
}
/// <summary> Gets person identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The person identifier. </returns>
protected string GetPersonID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetPerson(name).Id);
}
/// <summary> Gets runtime date time. </summary>
/// <param name="runtime"> The runtime. </param>
/// <returns> The runtime date time. </returns>
protected double? GetRuntimeDateTime(long? runtime)
{
if (runtime.HasValue)
/// <summary> A report builder base. </summary>
public abstract class ReportBuilderBase
{
#region [Constructors]
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportBuilderBase class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportBuilderBase(ILibraryManager libraryManager)
{
_libraryManager = libraryManager;
}
#endregion
#region [Protected Fields]
/// <summary> Manager for library. </summary>
protected readonly ILibraryManager _libraryManager; ///< Manager for library
protected Func<bool, string> GetBoolString = s => s == true ? "x" : ""; ///< .
#endregion
#region [Protected Internal Methods]
/// <summary> Gets the headers. </summary>
/// <typeparam name="H"> Type of the header. </typeparam>
/// <param name="request"> The request. </param>
/// <returns> The headers. </returns>
protected internal abstract List<ReportHeader> GetHeaders<H>(H request) where H : IReportsHeader;
#endregion
#region [Protected Methods]
/// <summary> Gets active headers. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="options"> Options for controlling the operation. </param>
/// <returns> The active headers. </returns>
protected List<ReportHeader> GetActiveHeaders<T>(List<ReportOptions<T>> options)
{
List<ReportHeader> headers = new List<ReportHeader>();
foreach (ReportOptions<T> option in options.Where(x => x.Header.Visible == true))
{
headers.Add(option.Header);
}
return headers;
}
/// <summary> Gets audio stream. </summary>
/// <param name="item"> The item. </param>
/// <returns> The audio stream. </returns>
protected string GetAudioStream(BaseItem item)
{
var stream = GetStream(item, MediaStreamType.Audio);
if (stream != null)
return stream.Codec.ToUpper() == "DCA" ? stream.Profile : stream.Codec.
ToUpper();
return string.Empty;
}
/// <summary> Gets an episode. </summary>
/// <param name="item"> The item. </param>
/// <returns> The episode. </returns>
protected string GetEpisode(BaseItem item)
{
if (item.GetClientTypeName() == ChannelMediaContentType.Episode.ToString() && item.ParentIndexNumber != null)
return "Season " + item.ParentIndexNumber;
else
return item.Name;
}
/// <summary> Gets a genre. </summary>
/// <param name="name"> The name. </param>
/// <returns> The genre. </returns>
protected Genre GetGenre(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetGenre(name);
}
/// <summary> Gets genre identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The genre identifier. </returns>
protected string GetGenreID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetGenre(name).Id);
}
/// <summary> Gets the headers. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="options"> Options for controlling the operation. </param>
/// <returns> The headers. </returns>
protected List<ReportHeader> GetHeaders<T>(List<ReportOptions<T>> options)
{
List<ReportHeader> headers = new List<ReportHeader>();
foreach (ReportOptions<T> option in options)
{
headers.Add(option.Header);
}
return headers;
}
/// <summary> Gets the headers. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="request"> The request. </param>
/// <param name="getHeadersMetadata"> The get headers metadata. </param>
/// <param name="getOptions"> Options for controlling the get. </param>
/// <returns> The headers. </returns>
protected List<ReportHeader> GetHeaders<T>(IReportsHeader request, Func<List<HeaderMetadata>> getHeadersMetadata, Func<HeaderMetadata, ReportOptions<T>> getOptions)
{
List<ReportOptions<T>> options = this.GetReportOptions(request, getHeadersMetadata, getOptions);
return this.GetHeaders(options);
}
/// <summary> Gets list as string. </summary>
/// <param name="items"> The items. </param>
/// <returns> The list as string. </returns>
protected string GetListAsString(List<string> items)
{
return String.Join("; ", items);
}
/// <summary> Gets localized header. </summary>
/// <param name="internalHeader"> The internal header. </param>
/// <returns> The localized header. </returns>
protected static string GetLocalizedHeader(HeaderMetadata internalHeader)
{
string headerName = "";
if (internalHeader != HeaderMetadata.None)
{
string localHeader = "Header" + internalHeader.ToString();
headerName = internalHeader != HeaderMetadata.None ? ReportHelper.GetJavaScriptLocalizedString(localHeader) : "";
if (string.Compare(localHeader, headerName, StringComparison.CurrentCultureIgnoreCase) == 0)
headerName = ReportHelper.GetServerLocalizedString(localHeader);
}
return headerName;
}
/// <summary> Gets media source information. </summary>
/// <param name="item"> The item. </param>
/// <returns> The media source information. </returns>
protected MediaSourceInfo GetMediaSourceInfo(BaseItem item)
{
var mediaSource = item as IHasMediaSources;
if (mediaSource != null)
return mediaSource.GetMediaSources(false).FirstOrDefault(n => n.Type == MediaSourceType.Default);
return null;
}
/// <summary> Gets an object. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <typeparam name="R"> Type of the r. </typeparam>
/// <param name="item"> The item. </param>
/// <param name="function"> The function. </param>
/// <param name="defaultValue"> The default value. </param>
/// <returns> The object. </returns>
protected R GetObject<T, R>(BaseItem item, Func<T, R> function, R defaultValue = default(R)) where T : class
{
var value = item as T;
if (value != null && function != null)
return function(value);
else
return defaultValue;
}
/// <summary> Gets a person. </summary>
/// <param name="name"> The name. </param>
/// <returns> The person. </returns>
protected Person GetPerson(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetPerson(name);
}
/// <summary> Gets person identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The person identifier. </returns>
protected string GetPersonID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetPerson(name).Id);
}
/// <summary> Gets report options. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="request"> The request. </param>
/// <param name="getHeadersMetadata"> The get headers metadata. </param>
/// <param name="getOptions"> Options for controlling the get. </param>
/// <returns> The report options. </returns>
protected List<ReportOptions<T>> GetReportOptions<T>(IReportsHeader request, Func<List<HeaderMetadata>> getHeadersMetadata, Func<HeaderMetadata, ReportOptions<T>> getOptions)
{
List<HeaderMetadata> headersMetadata = getHeadersMetadata();
List<ReportOptions<T>> options = new List<ReportOptions<T>>();
foreach (HeaderMetadata header in headersMetadata)
{
options.Add(getOptions(header));
}
if (request != null && !string.IsNullOrEmpty(request.ReportColumns))
{
List<HeaderMetadata> headersMetadataFiltered = ReportHelper.GetFilteredReportHeaderMetadata(request.ReportColumns, () => headersMetadata);
foreach (ReportHeader header in options.Select(x => x.Header))
{
if (!headersMetadataFiltered.Contains(header.FieldName))
{
header.Visible = false;
}
}
}
return options;
}
/// <summary> Gets runtime date time. </summary>
/// <param name="runtime"> The runtime. </param>
/// <returns> The runtime date time. </returns>
protected double? GetRuntimeDateTime(long? runtime)
{
if (runtime.HasValue)
return Math.Ceiling(new TimeSpan(runtime.Value).TotalMinutes);
return null;
}
/// <summary> Gets series production year. </summary>
/// <param name="item"> The item. </param>
/// <returns> The series production year. </returns>
protected string GetSeriesProductionYear(BaseItem item)
{
string productionYear = item.ProductionYear.ToString();
var series = item as Series;
if (series == null)
{
if (item.ProductionYear == null || item.ProductionYear == 0)
return string.Empty;
return productionYear;
}
if (series.Status == SeriesStatus.Continuing)
return productionYear += "-Present";
if (series.EndDate != null && series.EndDate.Value.Year != series.ProductionYear)
return productionYear += "-" + series.EndDate.Value.Year;
return productionYear;
}
/// <summary> Gets a stream. </summary>
/// <param name="item"> The item. </param>
/// <param name="streamType"> Type of the stream. </param>
/// <returns> The stream. </returns>
protected MediaStream GetStream(BaseItem item, MediaStreamType streamType)
{
var itemInfo = GetMediaSourceInfo(item);
if (itemInfo != null)
return itemInfo.MediaStreams.FirstOrDefault(n => n.Type == streamType);
return null;
}
/// <summary> Gets a studio. </summary>
/// <param name="name"> The name. </param>
/// <returns> The studio. </returns>
protected Studio GetStudio(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetStudio(name);
}
/// <summary> Gets studio identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The studio identifier. </returns>
protected string GetStudioID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetStudio(name).Id);
}
/// <summary> Gets video resolution. </summary>
/// <param name="item"> The item. </param>
/// <returns> The video resolution. </returns>
protected string GetVideoResolution(BaseItem item)
{
var stream = GetStream(item,
MediaStreamType.Video);
if (stream != null && stream.Width != null)
return string.Format("{0} * {1}",
stream.Width,
(stream.Height != null ? stream.Height.ToString() : "-"));
return string.Empty;
}
/// <summary> Gets video stream. </summary>
/// <param name="item"> The item. </param>
/// <returns> The video stream. </returns>
protected string GetVideoStream(BaseItem item)
{
var stream = GetStream(item, MediaStreamType.Video);
if (stream != null)
return stream.Codec.ToUpper();
return string.Empty;
}
}
return null;
}
/// <summary> Gets series production year. </summary>
/// <param name="item"> The item. </param>
/// <returns> The series production year. </returns>
protected string GetSeriesProductionYear(BaseItem item)
{
string productionYear = item.ProductionYear.ToString();
var series = item as Series;
if (series == null)
{
if (item.ProductionYear == null || item.ProductionYear == 0)
return string.Empty;
return productionYear;
}
if (series.Status == SeriesStatus.Continuing)
return productionYear += "-Present";
if (series.EndDate != null && series.EndDate.Value.Year != series.ProductionYear)
return productionYear += "-" + series.EndDate.Value.Year;
return productionYear;
}
/// <summary> Gets a stream. </summary>
/// <param name="item"> The item. </param>
/// <param name="streamType"> Type of the stream. </param>
/// <returns> The stream. </returns>
protected MediaStream GetStream(BaseItem item, MediaStreamType streamType)
{
var itemInfo = GetMediaSourceInfo(item);
if (itemInfo != null)
return itemInfo.MediaStreams.FirstOrDefault(n => n.Type == streamType);
return null;
}
/// <summary> Gets a studio. </summary>
/// <param name="name"> The name. </param>
/// <returns> The studio. </returns>
protected Studio GetStudio(string name)
{
if (string.IsNullOrEmpty(name))
return null;
return _libraryManager.GetStudio(name);
}
/// <summary> Gets studio identifier. </summary>
/// <param name="name"> The name. </param>
/// <returns> The studio identifier. </returns>
protected string GetStudioID(string name)
{
if (string.IsNullOrEmpty(name))
return string.Empty;
return string.Format("{0:N}",
GetStudio(name).Id);
}
/// <summary> Gets video resolution. </summary>
/// <param name="item"> The item. </param>
/// <returns> The video resolution. </returns>
protected string GetVideoResolution(BaseItem item)
{
var stream = GetStream(item,
MediaStreamType.Video);
if (stream != null && stream.Width != null)
return string.Format("{0} * {1}",
stream.Width,
(stream.Height != null ? stream.Height.ToString() : "-"));
return string.Empty;
}
/// <summary> Gets video stream. </summary>
/// <param name="item"> The item. </param>
/// <returns> The video stream. </returns>
protected string GetVideoStream(BaseItem item)
{
var stream = GetStream(item, MediaStreamType.Video);
if (stream != null)
return stream.Codec.ToUpper();
return string.Empty;
}
#endregion
}
}

@ -7,95 +7,135 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
public class ReportHelper
{
/// <summary> Gets java script localized string. </summary>
/// <param name="phrase"> The phrase. </param>
/// <returns> The java script localized string. </returns>
public static string GetJavaScriptLocalizedString(string phrase)
{
var dictionary = BaseItem.LocalizationManager.GetJavaScriptLocalizationDictionary(BaseItem.ConfigurationManager.Configuration.UICulture);
string value;
if (dictionary.TryGetValue(phrase, out value))
{
return value;
}
return phrase;
}
/// <summary> Gets server localized string. </summary>
/// <param name="phrase"> The phrase. </param>
/// <returns> The server localized string. </returns>
public static string GetServerLocalizedString(string phrase)
{
return BaseItem.LocalizationManager.GetLocalizedString(phrase, BaseItem.ConfigurationManager.Configuration.UICulture);
}
/// <summary> Gets row type. </summary>
/// <param name="rowType"> The type. </param>
/// <returns> The row type. </returns>
public static ReportViewType GetRowType(string rowType)
{
if (string.IsNullOrEmpty(rowType))
return ReportViewType.BaseItem;
ReportViewType rType;
if (!Enum.TryParse<ReportViewType>(rowType, out rType))
return ReportViewType.BaseItem;
return rType;
}
/// <summary> Gets header metadata type. </summary>
/// <param name="header"> The header. </param>
/// <returns> The header metadata type. </returns>
public static HeaderMetadata GetHeaderMetadataType(string header)
{
if (string.IsNullOrEmpty(header))
return HeaderMetadata.None;
HeaderMetadata rType;
if (!Enum.TryParse<HeaderMetadata>(header, out rType))
return HeaderMetadata.None;
return rType;
}
/// <summary> Convert field to string. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="value"> The value. </param>
/// <param name="fieldType"> Type of the field. </param>
/// <returns> The field converted to string. </returns>
public static string ConvertToString<T>(T value, ReportFieldType fieldType)
{
if (value == null)
return "";
switch (fieldType)
{
case ReportFieldType.String:
return value.ToString();
case ReportFieldType.Boolean:
return value.ToString();
case ReportFieldType.Date:
return string.Format("{0:d}", value);
case ReportFieldType.Time:
return string.Format("{0:t}", value);
case ReportFieldType.DateTime:
return string.Format("{0:d}", value);
/// <summary> A report helper. </summary>
public class ReportHelper
{
#region [Public Methods]
/// <summary> Convert field to string. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="value"> The value. </param>
/// <param name="fieldType"> Type of the field. </param>
/// <returns> The field converted to string. </returns>
public static string ConvertToString<T>(T value, ReportFieldType fieldType)
{
if (value == null)
return "";
switch (fieldType)
{
case ReportFieldType.String:
return value.ToString();
case ReportFieldType.Boolean:
return value.ToString();
case ReportFieldType.Date:
return string.Format("{0:d}", value);
case ReportFieldType.Time:
return string.Format("{0:t}", value);
case ReportFieldType.DateTime:
return string.Format("{0:d}", value);
case ReportFieldType.Minutes:
return string.Format("{0}mn", value);
case ReportFieldType.Int:
return string.Format("", value);
default:
if (value is Guid)
return string.Format("{0:N}", value);
return value.ToString();
}
}
}
case ReportFieldType.Int:
return string.Format("", value);
default:
if (value is Guid)
return string.Format("{0:N}", value);
return value.ToString();
}
}
/// <summary> Gets filtered report header metadata. </summary>
/// <param name="reportColumns"> The report columns. </param>
/// <param name="defaultReturnValue"> The default return value. </param>
/// <returns> The filtered report header metadata. </returns>
public static List<HeaderMetadata> GetFilteredReportHeaderMetadata(string reportColumns, Func<List<HeaderMetadata>> defaultReturnValue = null)
{
if (!string.IsNullOrEmpty(reportColumns))
{
var s = reportColumns.Split('|').Select(x => ReportHelper.GetHeaderMetadataType(x)).Where(x => x != HeaderMetadata.None);
return s.ToList();
}
else
if (defaultReturnValue != null)
return defaultReturnValue();
else
return new List<HeaderMetadata>();
}
/// <summary> Gets header metadata type. </summary>
/// <param name="header"> The header. </param>
/// <returns> The header metadata type. </returns>
public static HeaderMetadata GetHeaderMetadataType(string header)
{
if (string.IsNullOrEmpty(header))
return HeaderMetadata.None;
HeaderMetadata rType;
if (!Enum.TryParse<HeaderMetadata>(header, out rType))
return HeaderMetadata.None;
return rType;
}
/// <summary> Gets java script localized string. </summary>
/// <param name="phrase"> The phrase. </param>
/// <returns> The java script localized string. </returns>
public static string GetJavaScriptLocalizedString(string phrase)
{
var dictionary = BaseItem.LocalizationManager.GetJavaScriptLocalizationDictionary(BaseItem.ConfigurationManager.Configuration.UICulture);
string value;
if (dictionary.TryGetValue(phrase, out value))
{
return value;
}
return phrase;
}
/// <summary> Gets report view type. </summary>
/// <param name="rowType"> The type. </param>
/// <returns> The report view type. </returns>
public static ReportViewType GetReportViewType(string rowType)
{
if (string.IsNullOrEmpty(rowType))
return ReportViewType.ReportData;
ReportViewType rType;
if (!Enum.TryParse<ReportViewType>(rowType, out rType))
return ReportViewType.ReportData;
return rType;
}
/// <summary> Gets row type. </summary>
/// <param name="rowType"> The type. </param>
/// <returns> The row type. </returns>
public static ReportIncludeItemTypes GetRowType(string rowType)
{
if (string.IsNullOrEmpty(rowType))
return ReportIncludeItemTypes.BaseItem;
ReportIncludeItemTypes rType;
if (!Enum.TryParse<ReportIncludeItemTypes>(rowType, out rType))
return ReportIncludeItemTypes.BaseItem;
return rType;
}
/// <summary> Gets server localized string. </summary>
/// <param name="phrase"> The phrase. </param>
/// <returns> The server localized string. </returns>
public static string GetServerLocalizedString(string phrase)
{
return BaseItem.LocalizationManager.GetLocalizedString(phrase, BaseItem.ConfigurationManager.Configuration.UICulture);
}
#endregion
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Reports
{
public enum ReportIncludeItemTypes
{
MusicArtist,
MusicAlbum,
Book,
BoxSet,
Episode,
Game,
Video,
Movie,
MusicVideo,
Trailer,
Season,
Series,
Audio,
BaseItem,
Artist
}
}

@ -6,20 +6,9 @@ namespace MediaBrowser.Api.Reports
{
public enum ReportViewType
{
MusicArtist,
MusicAlbum,
Book,
BoxSet,
Episode,
Game,
Video,
Movie,
MusicVideo,
Trailer,
Season,
Series,
Audio,
BaseItem,
Artist
ReportData,
ReportStatistics,
ReportActivities
}
}

@ -17,162 +17,89 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report builder. </summary>
/// <seealso cref="T:MediaBrowser.Api.Reports.ReportBuilderBase"/>
public class ReportBuilder : ReportBuilderBase
{
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportBuilder class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportBuilder(ILibraryManager libraryManager)
: base(libraryManager)
{
}
private Func<bool, string> GetBoolString = s => s == true ? "x" : "";
public ReportResult GetReportResult(BaseItem[] items, ReportViewType reportRowType, BaseReportRequest request)
{
List<HeaderMetadata> headersMetadata = this.GetFilteredReportHeaderMetadata(reportRowType, request);
var headers = GetReportHeaders(reportRowType, headersMetadata);
var rows = GetReportRows(items, headersMetadata);
ReportResult result = new ReportResult { Headers = headers };
HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
int i = headers.FindIndex(x => x.FieldName == groupBy);
if (groupBy != HeaderMetadata.None && i > 0)
{
var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Genre = g.Trim(), Rows = x })
.GroupBy(x => x.Genre)
.OrderBy(x => x.Key)
.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });
result.Groups = rowsGroup.ToList();
result.IsGrouped = true;
}
else
{
result.Rows = rows;
result.IsGrouped = false;
}
return result;
}
public List<ReportHeader> GetReportHeaders(ReportViewType reportRowType, BaseReportRequest request)
{
List<ReportHeader> headersMetadata = this.GetReportHeaders(reportRowType);
if (request != null && !string.IsNullOrEmpty(request.ReportColumns))
{
List<HeaderMetadata> headersMetadataFiltered = this.GetFilteredReportHeaderMetadata(reportRowType, request);
foreach (ReportHeader reportHeader in headersMetadata)
{
if (!headersMetadataFiltered.Contains(reportHeader.FieldName))
{
reportHeader.Visible = false;
}
}
}
return headersMetadata;
}
public List<ReportHeader> GetReportHeaders(ReportViewType reportRowType, List<HeaderMetadata> headersMetadata = null)
{
if (headersMetadata == null)
headersMetadata = this.GetDefaultReportHeaderMetadata(reportRowType);
List<ReportOptions<BaseItem>> options = new List<ReportOptions<BaseItem>>();
foreach (HeaderMetadata header in headersMetadata)
{
options.Add(GetReportOption(header));
}
List<ReportHeader> headers = new List<ReportHeader>();
foreach (ReportOptions<BaseItem> option in options)
{
headers.Add(option.Header);
}
return headers;
}
private List<ReportRow> GetReportRows(IEnumerable<BaseItem> items, List<HeaderMetadata> headersMetadata)
{
List<ReportOptions<BaseItem>> options = new List<ReportOptions<BaseItem>>();
foreach (HeaderMetadata header in headersMetadata)
{
options.Add(GetReportOption(header));
}
var rows = new List<ReportRow>();
foreach (BaseItem item in items)
{
ReportRow rRow = GetRow(item);
foreach (ReportOptions<BaseItem> option in options)
{
object itemColumn = option.Column != null ? option.Column(item, rRow) : "";
object itemId = option.ItemID != null ? option.ItemID(item) : "";
ReportItem rItem = new ReportItem
{
Name = ReportHelper.ConvertToString(itemColumn, option.Header.HeaderFieldType),
Id = ReportHelper.ConvertToString(itemId, ReportFieldType.Object)
};
rRow.Columns.Add(rItem);
}
rows.Add(rRow);
}
return rows;
}
/// <summary> Gets a row. </summary>
/// <param name="item"> The item. </param>
/// <returns> The row. </returns>
private ReportRow GetRow(BaseItem item)
{
var hasTrailers = item as IHasTrailers;
var hasSpecialFeatures = item as IHasSpecialFeatures;
var video = item as Video;
ReportRow rRow = new ReportRow
{
Id = item.Id.ToString("N"),
HasLockData = item.IsLocked,
IsUnidentified = item.IsUnidentified,
HasLocalTrailer = hasTrailers != null ? hasTrailers.GetTrailerIds().Count() > 0 : false,
HasImageTagsPrimary = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Primary) > 0),
HasImageTagsBackdrop = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Backdrop) > 0),
HasImageTagsLogo = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Logo) > 0),
HasSpecials = hasSpecialFeatures != null ? hasSpecialFeatures.SpecialFeatureIds.Count > 0 : false,
HasSubtitles = video != null ? video.HasSubtitles : false,
RowType = ReportHelper.GetRowType(item.GetClientTypeName())
};
return rRow;
}
public List<HeaderMetadata> GetFilteredReportHeaderMetadata(ReportViewType reportRowType, BaseReportRequest request)
{
if (request != null && !string.IsNullOrEmpty(request.ReportColumns))
{
var s = request.ReportColumns.Split('|').Select(x => ReportHelper.GetHeaderMetadataType(x)).Where(x => x != HeaderMetadata.None);
return s.ToList();
}
else
return this.GetDefaultReportHeaderMetadata(reportRowType);
}
public List<HeaderMetadata> GetDefaultReportHeaderMetadata(ReportViewType reportRowType)
{
switch (reportRowType)
{
case ReportViewType.Season:
return new List<HeaderMetadata>
/// <summary> A report builder. </summary>
/// <seealso cref="T:MediaBrowser.Api.Reports.ReportBuilderBase"/>
public class ReportBuilder : ReportBuilderBase
{
#region [Constructors]
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportBuilder class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportBuilder(ILibraryManager libraryManager)
: base(libraryManager)
{
}
#endregion
#region [Public Methods]
/// <summary> Gets report result. </summary>
/// <param name="items"> The items. </param>
/// <param name="request"> The request. </param>
/// <returns> The report result. </returns>
public ReportResult GetResult(BaseItem[] items, IReportsQuery request)
{
ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
List<ReportOptions<BaseItem>> options = this.GetReportOptions<BaseItem>(request,
() => this.GetDefaultHeaderMetadata(reportRowType),
(hm) => this.GetOption(hm)).Where(x => x.Header.Visible == true).ToList();
var headers = GetHeaders<BaseItem>(options);
var rows = GetReportRows(items, options);
ReportResult result = new ReportResult { Headers = headers };
HeaderMetadata groupBy = ReportHelper.GetHeaderMetadataType(request.GroupBy);
int i = headers.FindIndex(x => x.FieldName == groupBy);
if (groupBy != HeaderMetadata.None && i >= 0)
{
var rowsGroup = rows.SelectMany(x => x.Columns[i].Name.Split(';'), (x, g) => new { Group = g.Trim(), Rows = x })
.GroupBy(x => x.Group)
.OrderBy(x => x.Key)
.Select(x => new ReportGroup { Name = x.Key, Rows = x.Select(r => r.Rows).ToList() });
result.Groups = rowsGroup.ToList();
result.IsGrouped = true;
}
else
{
result.Rows = rows;
result.IsGrouped = false;
}
return result;
}
#endregion
#region [Protected Internal Methods]
/// <summary> Gets the headers. </summary>
/// <typeparam name="H"> Type of the header. </typeparam>
/// <param name="request"> The request. </param>
/// <returns> The headers. </returns>
/// <seealso cref="M:MediaBrowser.Api.Reports.ReportBuilderBase.GetHeaders{H}(H)"/>
protected internal override List<ReportHeader> GetHeaders<H>(H request)
{
ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
return this.GetHeaders<BaseItem>(request, () => this.GetDefaultHeaderMetadata(reportRowType), (hm) => this.GetOption(hm));
}
#endregion
#region [Private Methods]
/// <summary> Gets default report header metadata. </summary>
/// <param name="reportIncludeItemTypes"> Type of the report row. </param>
/// <returns> The default report header metadata. </returns>
private List<HeaderMetadata> GetDefaultHeaderMetadata(ReportIncludeItemTypes reportIncludeItemTypes)
{
switch (reportIncludeItemTypes)
{
case ReportIncludeItemTypes.Season:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Series,
@ -183,8 +110,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Genres
};
case ReportViewType.Series:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Series:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -199,8 +126,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Specials
};
case ReportViewType.MusicAlbum:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.MusicAlbum:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -212,8 +139,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Genres
};
case ReportViewType.MusicArtist:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.MusicArtist:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.MusicArtist,
@ -223,8 +150,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Genres
};
case ReportViewType.Game:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Game:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -239,8 +166,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Trailers
};
case ReportViewType.Movie:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Movie:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -259,8 +186,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Specials
};
case ReportViewType.Book:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Book:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -272,8 +199,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.CommunityRating
};
case ReportViewType.BoxSet:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.BoxSet:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -286,8 +213,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Trailers
};
case ReportViewType.Audio:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Audio:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -305,8 +232,8 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Audio
};
case ReportViewType.Episode:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Episode:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -327,12 +254,12 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Specials
};
case ReportViewType.Video:
case ReportViewType.MusicVideo:
case ReportViewType.Trailer:
case ReportViewType.BaseItem:
default:
return new List<HeaderMetadata>
case ReportIncludeItemTypes.Video:
case ReportIncludeItemTypes.MusicVideo:
case ReportIncludeItemTypes.Trailer:
case ReportIncludeItemTypes.BaseItem:
default:
return new List<HeaderMetadata>
{
HeaderMetadata.StatusImage,
HeaderMetadata.Name,
@ -351,239 +278,282 @@ namespace MediaBrowser.Api.Reports
HeaderMetadata.Specials
};
}
}
/// <summary> Gets report option. </summary>
/// <param name="header"> The header. </param>
/// <param name="sortField"> The sort field. </param>
/// <returns> The report option. </returns>
private ReportOptions<BaseItem> GetReportOption(HeaderMetadata header, string sortField = "")
{
ReportHeader reportHeader = new ReportHeader
{
HeaderFieldType = ReportFieldType.String,
SortField = sortField,
Type = "",
ItemViewType = ItemViewType.None
};
Func<BaseItem, ReportRow, object> column = null;
Func<BaseItem, object> itemId = null;
HeaderMetadata internalHeader = header;
switch (header)
{
case HeaderMetadata.StatusImage:
reportHeader.ItemViewType = ItemViewType.StatusImage;
internalHeader = HeaderMetadata.Status;
reportHeader.CanGroup = false;
break;
case HeaderMetadata.Name:
column = (i, r) => i.Name;
reportHeader.ItemViewType = ItemViewType.Detail;
reportHeader.SortField = "SortName";
break;
case HeaderMetadata.DateAdded:
column = (i, r) => i.DateCreated;
reportHeader.SortField = "DateCreated,SortName";
reportHeader.HeaderFieldType = ReportFieldType.DateTime;
reportHeader.Type = "";
break;
case HeaderMetadata.PremiereDate:
case HeaderMetadata.ReleaseDate:
column = (i, r) => i.PremiereDate;
reportHeader.HeaderFieldType = ReportFieldType.DateTime;
reportHeader.SortField = "ProductionYear,PremiereDate,SortName";
break;
case HeaderMetadata.Runtime:
column = (i, r) => this.GetRuntimeDateTime(i.RunTimeTicks);
reportHeader.HeaderFieldType = ReportFieldType.Minutes;
reportHeader.SortField = "Runtime,SortName";
break;
case HeaderMetadata.PlayCount:
reportHeader.HeaderFieldType = ReportFieldType.Int;
break;
case HeaderMetadata.Season:
column = (i, r) => this.GetEpisode(i);
reportHeader.ItemViewType = ItemViewType.Detail;
reportHeader.SortField = "SortName";
break;
case HeaderMetadata.SeasonNumber:
column = (i, r) => this.GetObject<Season, string>(i, (x) => x.IndexNumber == null ? "" : x.IndexNumber.ToString());
reportHeader.SortField = "IndexNumber";
reportHeader.HeaderFieldType = ReportFieldType.Int;
break;
case HeaderMetadata.Series:
column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
reportHeader.ItemViewType = ItemViewType.Detail;
reportHeader.SortField = "SeriesSortName,SortName";
break;
case HeaderMetadata.EpisodeSeries:
column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
reportHeader.ItemViewType = ItemViewType.Detail;
itemId = (i) =>
{
Series series = this.GetObject<Episode, Series>(i, (x) => x.Series);
if (series == null)
return string.Empty;
return series.Id;
};
reportHeader.SortField = "SeriesSortName,SortName";
internalHeader = HeaderMetadata.Series;
break;
case HeaderMetadata.EpisodeSeason:
column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
reportHeader.ItemViewType = ItemViewType.Detail;
itemId = (i) =>
{
Season season = this.GetObject<Episode, Season>(i, (x) => x.Season);
if (season == null)
return string.Empty;
return season.Id;
};
reportHeader.SortField = "SortName";
internalHeader = HeaderMetadata.Season;
break;
case HeaderMetadata.Network:
column = (i, r) => this.GetListAsString(i.Studios);
itemId = (i) => this.GetStudioID(i.Studios.FirstOrDefault());
reportHeader.ItemViewType = ItemViewType.ItemByNameDetails;
reportHeader.SortField = "Studio,SortName";
break;
case HeaderMetadata.Year:
column = (i, r) => this.GetSeriesProductionYear(i);
reportHeader.SortField = "ProductionYear,PremiereDate,SortName";
break;
case HeaderMetadata.ParentalRating:
column = (i, r) => i.OfficialRating;
reportHeader.SortField = "OfficialRating,SortName";
break;
case HeaderMetadata.CommunityRating:
column = (i, r) => i.CommunityRating;
reportHeader.SortField = "CommunityRating,SortName";
break;
case HeaderMetadata.Trailers:
column = (i, r) => this.GetBoolString(r.HasLocalTrailer);
reportHeader.ItemViewType = ItemViewType.TrailersImage;
break;
case HeaderMetadata.Specials:
column = (i, r) => this.GetBoolString(r.HasSpecials);
reportHeader.ItemViewType = ItemViewType.SpecialsImage;
break;
case HeaderMetadata.GameSystem:
column = (i, r) => this.GetObject<Game, string>(i, (x) => x.GameSystem);
reportHeader.SortField = "GameSystem,SortName";
break;
case HeaderMetadata.Players:
column = (i, r) => this.GetObject<Game, int?>(i, (x) => x.PlayersSupported);
reportHeader.SortField = "Players,GameSystem,SortName";
break;
case HeaderMetadata.AlbumArtist:
column = (i, r) => this.GetObject<MusicAlbum, string>(i, (x) => x.AlbumArtist);
itemId = (i) => this.GetPersonID(this.GetObject<MusicAlbum, string>(i, (x) => x.AlbumArtist));
reportHeader.ItemViewType = ItemViewType.Detail;
reportHeader.SortField = "AlbumArtist,Album,SortName";
break;
case HeaderMetadata.MusicArtist:
column = (i, r) => this.GetObject<MusicArtist, string>(i, (x) => x.GetLookupInfo().Name);
reportHeader.ItemViewType = ItemViewType.Detail;
reportHeader.SortField = "AlbumArtist,Album,SortName";
internalHeader = HeaderMetadata.AlbumArtist;
break;
case HeaderMetadata.AudioAlbumArtist:
column = (i, r) => this.GetListAsString(this.GetObject<Audio, List<string>>(i, (x) => x.AlbumArtists));
reportHeader.SortField = "AlbumArtist,Album,SortName";
internalHeader = HeaderMetadata.AlbumArtist;
break;
case HeaderMetadata.AudioAlbum:
column = (i, r) => this.GetObject<Audio, string>(i, (x) => x.Album);
reportHeader.SortField = "Album,SortName";
internalHeader = HeaderMetadata.Album;
break;
case HeaderMetadata.Countries:
column = (i, r) => this.GetListAsString(this.GetObject<IHasProductionLocations, List<string>>(i, (x) => x.ProductionLocations));
break;
case HeaderMetadata.Disc:
column = (i, r) => i.ParentIndexNumber;
break;
case HeaderMetadata.Track:
column = (i, r) => i.IndexNumber;
break;
case HeaderMetadata.Tracks:
column = (i, r) => this.GetObject<MusicAlbum, List<Audio>>(i, (x) => x.Tracks.ToList(), new List<Audio>()).Count();
break;
case HeaderMetadata.Audio:
column = (i, r) => this.GetAudioStream(i);
break;
case HeaderMetadata.EmbeddedImage:
break;
case HeaderMetadata.Video:
column = (i, r) => this.GetVideoStream(i);
break;
case HeaderMetadata.Resolution:
column = (i, r) => this.GetVideoResolution(i);
break;
case HeaderMetadata.Subtitles:
column = (i, r) => this.GetBoolString(r.HasSubtitles);
reportHeader.ItemViewType = ItemViewType.SubtitleImage;
break;
case HeaderMetadata.Genres:
column = (i, r) => this.GetListAsString(i.Genres);
break;
}
string headerName = "";
if (internalHeader != HeaderMetadata.None)
{
string localHeader = "Header" + internalHeader.ToString();
headerName = internalHeader != HeaderMetadata.None ? ReportHelper.GetJavaScriptLocalizedString(localHeader) : "";
if (string.Compare(localHeader, headerName, StringComparison.CurrentCultureIgnoreCase) == 0)
headerName = ReportHelper.GetServerLocalizedString(localHeader);
}
reportHeader.Name = headerName;
reportHeader.FieldName = header;
ReportOptions<BaseItem> option = new ReportOptions<BaseItem>()
{
Header = reportHeader,
Column = column,
ItemID = itemId
};
return option;
}
}
}
}
/// <summary> Gets report option. </summary>
/// <param name="header"> The header. </param>
/// <param name="sortField"> The sort field. </param>
/// <returns> The report option. </returns>
private ReportOptions<BaseItem> GetOption(HeaderMetadata header, string sortField = "")
{
HeaderMetadata internalHeader = header;
ReportOptions<BaseItem> option = new ReportOptions<BaseItem>()
{
Header = new ReportHeader
{
HeaderFieldType = ReportFieldType.String,
SortField = sortField,
Type = "",
ItemViewType = ItemViewType.None
}
};
switch (header)
{
case HeaderMetadata.StatusImage:
option.Header.ItemViewType = ItemViewType.StatusImage;
internalHeader = HeaderMetadata.Status;
option.Header.CanGroup = false;
break;
case HeaderMetadata.Name:
option.Column = (i, r) => i.Name;
option.Header.ItemViewType = ItemViewType.Detail;
option.Header.SortField = "SortName";
break;
case HeaderMetadata.DateAdded:
option.Column = (i, r) => i.DateCreated;
option.Header.SortField = "DateCreated,SortName";
option.Header.HeaderFieldType = ReportFieldType.DateTime;
option.Header.Type = "";
break;
case HeaderMetadata.PremiereDate:
case HeaderMetadata.ReleaseDate:
option.Column = (i, r) => i.PremiereDate;
option.Header.HeaderFieldType = ReportFieldType.DateTime;
option.Header.SortField = "ProductionYear,PremiereDate,SortName";
break;
case HeaderMetadata.Runtime:
option.Column = (i, r) => this.GetRuntimeDateTime(i.RunTimeTicks);
option.Header.HeaderFieldType = ReportFieldType.Minutes;
option.Header.SortField = "Runtime,SortName";
break;
case HeaderMetadata.PlayCount:
option.Header.HeaderFieldType = ReportFieldType.Int;
break;
case HeaderMetadata.Season:
option.Column = (i, r) => this.GetEpisode(i);
option.Header.ItemViewType = ItemViewType.Detail;
option.Header.SortField = "SortName";
break;
case HeaderMetadata.SeasonNumber:
option.Column = (i, r) => this.GetObject<Season, string>(i, (x) => x.IndexNumber == null ? "" : x.IndexNumber.ToString());
option.Header.SortField = "IndexNumber";
option.Header.HeaderFieldType = ReportFieldType.Int;
break;
case HeaderMetadata.Series:
option.Column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
option.Header.ItemViewType = ItemViewType.Detail;
option.Header.SortField = "SeriesSortName,SortName";
break;
case HeaderMetadata.EpisodeSeries:
option.Column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
option.Header.ItemViewType = ItemViewType.Detail;
option.ItemID = (i) =>
{
Series series = this.GetObject<Episode, Series>(i, (x) => x.Series);
if (series == null)
return string.Empty;
return series.Id;
};
option.Header.SortField = "SeriesSortName,SortName";
internalHeader = HeaderMetadata.Series;
break;
case HeaderMetadata.EpisodeSeason:
option.Column = (i, r) => this.GetObject<IHasSeries, string>(i, (x) => x.SeriesName);
option.Header.ItemViewType = ItemViewType.Detail;
option.ItemID = (i) =>
{
Season season = this.GetObject<Episode, Season>(i, (x) => x.Season);
if (season == null)
return string.Empty;
return season.Id;
};
option.Header.SortField = "SortName";
internalHeader = HeaderMetadata.Season;
break;
case HeaderMetadata.Network:
option.Column = (i, r) => this.GetListAsString(i.Studios);
option.ItemID = (i) => this.GetStudioID(i.Studios.FirstOrDefault());
option.Header.ItemViewType = ItemViewType.ItemByNameDetails;
option.Header.SortField = "Studio,SortName";
break;
case HeaderMetadata.Year:
option.Column = (i, r) => this.GetSeriesProductionYear(i);
option.Header.SortField = "ProductionYear,PremiereDate,SortName";
break;
case HeaderMetadata.ParentalRating:
option.Column = (i, r) => i.OfficialRating;
option.Header.SortField = "OfficialRating,SortName";
break;
case HeaderMetadata.CommunityRating:
option.Column = (i, r) => i.CommunityRating;
option.Header.SortField = "CommunityRating,SortName";
break;
case HeaderMetadata.Trailers:
option.Column = (i, r) => this.GetBoolString(r.HasLocalTrailer);
option.Header.ItemViewType = ItemViewType.TrailersImage;
break;
case HeaderMetadata.Specials:
option.Column = (i, r) => this.GetBoolString(r.HasSpecials);
option.Header.ItemViewType = ItemViewType.SpecialsImage;
break;
case HeaderMetadata.GameSystem:
option.Column = (i, r) => this.GetObject<Game, string>(i, (x) => x.GameSystem);
option.Header.SortField = "GameSystem,SortName";
break;
case HeaderMetadata.Players:
option.Column = (i, r) => this.GetObject<Game, int?>(i, (x) => x.PlayersSupported);
option.Header.SortField = "Players,GameSystem,SortName";
break;
case HeaderMetadata.AlbumArtist:
option.Column = (i, r) => this.GetObject<MusicAlbum, string>(i, (x) => x.AlbumArtist);
option.ItemID = (i) => this.GetPersonID(this.GetObject<MusicAlbum, string>(i, (x) => x.AlbumArtist));
option.Header.ItemViewType = ItemViewType.Detail;
option.Header.SortField = "AlbumArtist,Album,SortName";
break;
case HeaderMetadata.MusicArtist:
option.Column = (i, r) => this.GetObject<MusicArtist, string>(i, (x) => x.GetLookupInfo().Name);
option.Header.ItemViewType = ItemViewType.Detail;
option.Header.SortField = "AlbumArtist,Album,SortName";
internalHeader = HeaderMetadata.AlbumArtist;
break;
case HeaderMetadata.AudioAlbumArtist:
option.Column = (i, r) => this.GetListAsString(this.GetObject<Audio, List<string>>(i, (x) => x.AlbumArtists));
option.Header.SortField = "AlbumArtist,Album,SortName";
internalHeader = HeaderMetadata.AlbumArtist;
break;
case HeaderMetadata.AudioAlbum:
option.Column = (i, r) => this.GetObject<Audio, string>(i, (x) => x.Album);
option.Header.SortField = "Album,SortName";
internalHeader = HeaderMetadata.Album;
break;
case HeaderMetadata.Countries:
option.Column = (i, r) => this.GetListAsString(this.GetObject<IHasProductionLocations, List<string>>(i, (x) => x.ProductionLocations));
break;
case HeaderMetadata.Disc:
option.Column = (i, r) => i.ParentIndexNumber;
break;
case HeaderMetadata.Track:
option.Column = (i, r) => i.IndexNumber;
break;
case HeaderMetadata.Tracks:
option.Column = (i, r) => this.GetObject<MusicAlbum, List<Audio>>(i, (x) => x.Tracks.ToList(), new List<Audio>()).Count();
break;
case HeaderMetadata.Audio:
option.Column = (i, r) => this.GetAudioStream(i);
break;
case HeaderMetadata.EmbeddedImage:
break;
case HeaderMetadata.Video:
option.Column = (i, r) => this.GetVideoStream(i);
break;
case HeaderMetadata.Resolution:
option.Column = (i, r) => this.GetVideoResolution(i);
break;
case HeaderMetadata.Subtitles:
option.Column = (i, r) => this.GetBoolString(r.HasSubtitles);
option.Header.ItemViewType = ItemViewType.SubtitleImage;
break;
case HeaderMetadata.Genres:
option.Column = (i, r) => this.GetListAsString(i.Genres);
break;
}
option.Header.Name = GetLocalizedHeader(internalHeader);
option.Header.FieldName = header;
return option;
}
/// <summary> Gets report rows. </summary>
/// <param name="items"> The items. </param>
/// <param name="options"> Options for controlling the operation. </param>
/// <returns> The report rows. </returns>
private List<ReportRow> GetReportRows(IEnumerable<BaseItem> items, List<ReportOptions<BaseItem>> options)
{
var rows = new List<ReportRow>();
foreach (BaseItem item in items)
{
ReportRow rRow = GetRow(item);
foreach (ReportOptions<BaseItem> option in options)
{
object itemColumn = option.Column != null ? option.Column(item, rRow) : "";
object itemId = option.ItemID != null ? option.ItemID(item) : "";
ReportItem rItem = new ReportItem
{
Name = ReportHelper.ConvertToString(itemColumn, option.Header.HeaderFieldType),
Id = ReportHelper.ConvertToString(itemId, ReportFieldType.Object)
};
rRow.Columns.Add(rItem);
}
rows.Add(rRow);
}
return rows;
}
/// <summary> Gets a row. </summary>
/// <param name="item"> The item. </param>
/// <returns> The row. </returns>
private ReportRow GetRow(BaseItem item)
{
var hasTrailers = item as IHasTrailers;
var hasSpecialFeatures = item as IHasSpecialFeatures;
var video = item as Video;
ReportRow rRow = new ReportRow
{
Id = item.Id.ToString("N"),
HasLockData = item.IsLocked,
IsUnidentified = item.IsUnidentified,
HasLocalTrailer = hasTrailers != null ? hasTrailers.GetTrailerIds().Count() > 0 : false,
HasImageTagsPrimary = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Primary) > 0),
HasImageTagsBackdrop = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Backdrop) > 0),
HasImageTagsLogo = (item.ImageInfos != null && item.ImageInfos.Count(n => n.Type == ImageType.Logo) > 0),
HasSpecials = hasSpecialFeatures != null ? hasSpecialFeatures.SpecialFeatureIds.Count > 0 : false,
HasSubtitles = video != null ? video.HasSubtitles : false,
RowType = ReportHelper.GetRowType(item.GetClientTypeName())
};
return rRow;
}
#endregion
}
}

@ -7,8 +7,9 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report options. </summary>
internal class ReportOptions<I>
public class ReportOptions<I>
{
/// <summary> Initializes a new instance of the ReportOptions class. </summary>
public ReportOptions()

@ -66,6 +66,6 @@ namespace MediaBrowser.Api.Reports
/// <summary> Gets or sets the type. </summary>
/// <value> The type. </value>
public ReportViewType RowType { get; set; }
public ReportIncludeItemTypes RowType { get; set; }
}
}

@ -7,8 +7,80 @@ using System.Linq;
namespace MediaBrowser.Api.Reports
{
public class BaseReportRequest : BaseItemsRequest
{
public interface IReportsDownload : IReportsQuery
{
/// <summary> Gets or sets the minimum date. </summary>
/// <value> The minimum date. </value>
string MinDate { get; set; }
}
/// <summary> Interface for reports query. </summary>
public interface IReportsQuery : IReportsHeader
{
/// <summary>
/// Gets or sets a value indicating whether this MediaBrowser.Api.Reports.GetActivityLogs has
/// query limit. </summary>
/// <value>
/// true if this MediaBrowser.Api.Reports.GetActivityLogs has query limit, false if not. </value>
bool HasQueryLimit { get; set; }
/// <summary> Gets or sets who group this MediaBrowser.Api.Reports.GetActivityLogs. </summary>
/// <value> Describes who group this MediaBrowser.Api.Reports.GetActivityLogs. </value>
string GroupBy { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
int? Limit { get; set; }
}
public interface IReportsHeader
{
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
string ReportView { get; set; }
/// <summary> Gets or sets the report columns. </summary>
/// <value> The report columns. </value>
string ReportColumns { get; set; }
/// <summary> Gets or sets a list of types of the include items. </summary>
/// <value> A list of types of the include items. </value>
string IncludeItemTypes { get; set; }
}
public class BaseReportRequest : BaseItemsRequest, IReportsQuery
{
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this MediaBrowser.Api.Reports.BaseReportRequest has
/// query limit. </summary>
/// <value>
/// true if this MediaBrowser.Api.Reports.BaseReportRequest has query limit, false if not. </value>
[ApiMember(Name = "HasQueryLimit", Description = "Optional. If specified, results will include all records.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool HasQueryLimit { get; set; }
/// <summary>
/// Gets or sets who group this MediaBrowser.Api.Reports.BaseReportRequest. </summary>
/// <value> Describes who group this MediaBrowser.Api.Reports.BaseReportRequest. </value>
[ApiMember(Name = "GroupBy", Description = "Optional. If specified, results will include grouped records.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string GroupBy { get; set; }
/// <summary> Gets or sets the report columns. </summary>
/// <value> The report columns. </value>
[ApiMember(Name = "ReportColumns", Description = "Optional. The columns to show.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportColumns { get; set; }
/// <summary>
/// Gets or sets the user id.
/// </summary>
@ -63,11 +135,6 @@ namespace MediaBrowser.Api.Reports
[ApiMember(Name = "Ids", Description = "Optional. If specific items are needed, specify a list of item id's to retrieve. This allows multiple, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Ids { get; set; }
public bool HasQueryLimit { get; set; }
public string GroupBy { get; set; }
public string ReportColumns { get; set; }
/// <summary>
/// Gets or sets the video types.
/// </summary>
@ -261,8 +328,22 @@ namespace MediaBrowser.Api.Reports
}
[Route("/Reports/Headers", "GET", Summary = "Gets reports headers based on library items")]
public class GetReportHeaders : BaseReportRequest, IReturn<List<ReportHeader>>
{
public class GetReportHeaders : IReturn<List<ReportHeader>>, IReportsHeader
{
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary> Gets or sets a list of types of the include items. </summary>
/// <value> A list of types of the include items. </value>
[ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string IncludeItemTypes { get; set; }
/// <summary> Gets or sets the report columns. </summary>
/// <value> The report columns. </value>
[ApiMember(Name = "ReportColumns", Description = "Optional. The columns to show.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportColumns { get; set; }
}
[Route("/Reports/Statistics", "GET", Summary = "Gets reports statistics based on library items")]
@ -273,7 +354,7 @@ namespace MediaBrowser.Api.Reports
}
[Route("/Reports/Items/Download", "GET", Summary = "Downloads report")]
public class GetReportDownload : BaseReportRequest
public class GetReportDownload : BaseReportRequest, IReportsDownload
{
public GetReportDownload()
{
@ -281,6 +362,61 @@ namespace MediaBrowser.Api.Reports
}
public ReportExportType ExportType { get; set; }
/// <summary> Gets or sets the minimum date. </summary>
/// <value> The minimum date. </value>
[ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MinDate { get; set; }
}
[Route("/Reports/Activities", "GET", Summary = "Gets activities entries")]
public class GetActivityLogs : IReturn<ReportResult>, IReportsQuery, IReportsDownload
{
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "ReportView", Description = "The report view. Values (ReportData, ReportStatistics, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this MediaBrowser.Api.Reports.GetActivityLogs has
/// query limit. </summary>
/// <value>
/// true if this MediaBrowser.Api.Reports.GetActivityLogs has query limit, false if not. </value>
[ApiMember(Name = "HasQueryLimit", Description = "Optional. If specified, results will include all records.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool HasQueryLimit { get; set; }
/// <summary> Gets or sets who group this MediaBrowser.Api.Reports.GetActivityLogs. </summary>
/// <value> Describes who group this MediaBrowser.Api.Reports.GetActivityLogs. </value>
[ApiMember(Name = "GroupBy", Description = "Optional. If specified, results will include grouped records.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string GroupBy { get; set; }
/// <summary> Gets or sets the report columns. </summary>
/// <value> The report columns. </value>
[ApiMember(Name = "ReportColumns", Description = "Optional. The columns to show.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportColumns { get; set; }
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
/// <summary> Gets or sets the minimum date. </summary>
/// <value> The minimum date. </value>
[ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MinDate { get; set; }
[ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string IncludeItemTypes { get; set; }
}
}

File diff suppressed because it is too large Load Diff

@ -9,206 +9,265 @@ using System.Threading.Tasks;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report stat builder. </summary>
/// <seealso cref="T:MediaBrowser.Api.Reports.ReportBuilderBase"/>
public class ReportStatBuilder : ReportBuilderBase
{
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportStatBuilder class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportStatBuilder(ILibraryManager libraryManager)
: base(libraryManager)
{
}
/// <summary> Gets report stat result. </summary>
/// <param name="items"> The items. </param>
/// <param name="reportRowType"> Type of the report row. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The report stat result. </returns>
public ReportStatResult GetReportStatResult(BaseItem[] items, ReportViewType reportRowType, int topItem = 5)
{
ReportStatResult result = new ReportStatResult();
result = this.GetResultGenres(result, items, topItem);
result = this.GetResultStudios(result, items, topItem);
result = this.GetResultPersons(result, items, topItem);
result = this.GetResultProductionYears(result, items, topItem);
result = this.GetResulProductionLocations(result, items, topItem);
result = this.GetResultCommunityRatings(result, items, topItem);
result = this.GetResultParentalRatings(result, items, topItem);
switch (reportRowType)
{
case ReportViewType.Season:
case ReportViewType.Series:
case ReportViewType.MusicAlbum:
case ReportViewType.MusicArtist:
case ReportViewType.Game:
break;
case ReportViewType.Movie:
case ReportViewType.BoxSet:
break;
case ReportViewType.Book:
case ReportViewType.Episode:
case ReportViewType.Video:
case ReportViewType.MusicVideo:
case ReportViewType.Trailer:
case ReportViewType.Audio:
case ReportViewType.BaseItem:
default:
break;
}
result.Groups = result.Groups.OrderByDescending(n => n.Items.Count()).ToList();
return result;
}
private ReportStatResult GetResultGenres(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderGenres"), topItem,
items.SelectMany(x => x.Genres)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetGenreID(x.Key)
}));
return result;
}
private ReportStatResult GetResultStudios(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderStudios"), topItem,
items.SelectMany(x => x.Studios)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetStudioID(x.Key)
})
);
return result;
}
private ReportStatResult GetResultPersons(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
List<string> t = new List<string> { PersonType.Actor, PersonType.Composer, PersonType.Director, PersonType.GuestStar, PersonType.Producer, PersonType.Writer, "Artist", "AlbumArtist" };
foreach (var item in t)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("Option" + item), topItem,
items.SelectMany(x => x.People)
.Where(n => n.Type == item)
.GroupBy(x => x.Name)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetPersonID(x.Key)
})
);
}
return result;
}
private ReportStatResult GetResultCommunityRatings(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("LabelCommunityRating"), topItem,
items.Where(x => x.CommunityRating != null && x.CommunityRating > 0)
.GroupBy(x => x.CommunityRating)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
private ReportStatResult GetResultParentalRatings(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderParentalRatings"), topItem,
items.Where(x => x.OfficialRating != null)
.GroupBy(x => x.OfficialRating)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
private ReportStatResult GetResultProductionYears(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderYears"), topItem,
items.Where(x => x.ProductionYear != null && x.ProductionYear > 0)
.GroupBy(x => x.ProductionYear)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
private ReportStatResult GetResulProductionLocations(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderCountries"), topItem,
items.OfType<IHasProductionLocations>()
.Where(x => x.ProductionLocations != null)
.SelectMany(x => x.ProductionLocations)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
/// <summary> Gets the groups. </summary>
/// <param name="result"> The result. </param>
/// <param name="header"> The header. </param>
/// <param name="topItem"> The top item. </param>
/// <param name="top"> The top. </param>
private void GetGroups(ReportStatResult result, string header, int topItem, IEnumerable<ReportStatItem> top)
{
if (top.Count() > 0)
{
var group = new ReportStatGroup { Header = ReportStatGroup.FormatedHeader(header, topItem) };
group.Items.AddRange(top);
result.Groups.Add(group);
}
}
}
/// <summary> A report stat builder. </summary>
/// <seealso cref="T:MediaBrowser.Api.Reports.ReportBuilderBase"/>
public class ReportStatBuilder : ReportBuilderBase
{
#region [Constructors]
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportStatBuilder class. </summary>
/// <param name="libraryManager"> Manager for library. </param>
public ReportStatBuilder(ILibraryManager libraryManager)
: base(libraryManager)
{
}
#endregion
#region [Public Methods]
/// <summary> Gets report stat result. </summary>
/// <param name="items"> The items. </param>
/// <param name="reportIncludeItemTypes"> List of types of the report include items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The report stat result. </returns>
public ReportStatResult GetResult(BaseItem[] items, ReportIncludeItemTypes reportIncludeItemTypes, int topItem = 5)
{
ReportStatResult result = new ReportStatResult();
result = this.GetResultGenres(result, items, topItem);
result = this.GetResultStudios(result, items, topItem);
result = this.GetResultPersons(result, items, topItem);
result = this.GetResultProductionYears(result, items, topItem);
result = this.GetResulProductionLocations(result, items, topItem);
result = this.GetResultCommunityRatings(result, items, topItem);
result = this.GetResultParentalRatings(result, items, topItem);
switch (reportIncludeItemTypes)
{
case ReportIncludeItemTypes.Season:
case ReportIncludeItemTypes.Series:
case ReportIncludeItemTypes.MusicAlbum:
case ReportIncludeItemTypes.MusicArtist:
case ReportIncludeItemTypes.Game:
break;
case ReportIncludeItemTypes.Movie:
case ReportIncludeItemTypes.BoxSet:
break;
case ReportIncludeItemTypes.Book:
case ReportIncludeItemTypes.Episode:
case ReportIncludeItemTypes.Video:
case ReportIncludeItemTypes.MusicVideo:
case ReportIncludeItemTypes.Trailer:
case ReportIncludeItemTypes.Audio:
case ReportIncludeItemTypes.BaseItem:
default:
break;
}
result.Groups = result.Groups.OrderByDescending(n => n.Items.Count()).ToList();
return result;
}
#endregion
#region [Protected Internal Methods]
/// <summary> Gets the headers. </summary>
/// <typeparam name="H"> Type of the header. </typeparam>
/// <param name="request"> The request. </param>
/// <returns> The headers. </returns>
/// <seealso cref="M:MediaBrowser.Api.Reports.ReportBuilderBase.GetHeaders{H}(H)"/>
protected internal override List<ReportHeader> GetHeaders<H>(H request)
{
throw new NotImplementedException();
}
#endregion
#region [Private Methods]
/// <summary> Gets the groups. </summary>
/// <param name="result"> The result. </param>
/// <param name="header"> The header. </param>
/// <param name="topItem"> The top item. </param>
/// <param name="top"> The top. </param>
private void GetGroups(ReportStatResult result, string header, int topItem, IEnumerable<ReportStatItem> top)
{
if (top.Count() > 0)
{
var group = new ReportStatGroup { Header = ReportStatGroup.FormatedHeader(header, topItem) };
group.Items.AddRange(top);
result.Groups.Add(group);
}
}
/// <summary> Gets resul production locations. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The resul production locations. </returns>
private ReportStatResult GetResulProductionLocations(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderCountries"), topItem,
items.OfType<IHasProductionLocations>()
.Where(x => x.ProductionLocations != null)
.SelectMany(x => x.ProductionLocations)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
/// <summary> Gets result community ratings. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result community ratings. </returns>
private ReportStatResult GetResultCommunityRatings(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("LabelCommunityRating"), topItem,
items.Where(x => x.CommunityRating != null && x.CommunityRating > 0)
.GroupBy(x => x.CommunityRating)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
/// <summary> Gets result genres. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result genres. </returns>
private ReportStatResult GetResultGenres(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderGenres"), topItem,
items.SelectMany(x => x.Genres)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetGenreID(x.Key)
}));
return result;
}
/// <summary> Gets result parental ratings. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result parental ratings. </returns>
private ReportStatResult GetResultParentalRatings(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderParentalRatings"), topItem,
items.Where(x => x.OfficialRating != null)
.GroupBy(x => x.OfficialRating)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
/// <summary> Gets result persons. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result persons. </returns>
private ReportStatResult GetResultPersons(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
List<string> t = new List<string> { PersonType.Actor, PersonType.Composer, PersonType.Director, PersonType.GuestStar, PersonType.Producer, PersonType.Writer, "Artist", "AlbumArtist" };
foreach (var item in t)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("Option" + item), topItem,
items.SelectMany(x => x.People)
.Where(n => n.Type == item)
.GroupBy(x => x.Name)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetPersonID(x.Key)
})
);
}
return result;
}
/// <summary> Gets result production years. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result production years. </returns>
private ReportStatResult GetResultProductionYears(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderYears"), topItem,
items.Where(x => x.ProductionYear != null && x.ProductionYear > 0)
.GroupBy(x => x.ProductionYear)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key.ToString(),
Value = x.Count().ToString()
})
);
return result;
}
/// <summary> Gets result studios. </summary>
/// <param name="result"> The result. </param>
/// <param name="items"> The items. </param>
/// <param name="topItem"> The top item. </param>
/// <returns> The result studios. </returns>
private ReportStatResult GetResultStudios(ReportStatResult result, BaseItem[] items, int topItem = 5)
{
this.GetGroups(result, ReportHelper.GetServerLocalizedString("HeaderStudios"), topItem,
items.SelectMany(x => x.Studios)
.GroupBy(x => x)
.OrderByDescending(x => x.Count())
.Take(topItem)
.Select(x => new ReportStatItem
{
Name = x.Key,
Value = x.Count().ToString(),
Id = GetStudioID(x.Key)
})
);
return result;
}
#endregion
}
}

@ -1448,6 +1448,7 @@
"OptionReportList": "List View",
"OptionReportStatistics": "Statistics",
"OptionReportGrouping": "Grouping",
"OptionReportActivities": "Activities Log",
"HeaderExport": "Export",
"HeaderColumns": "Columns",
"ButtonReset": "Reset",
@ -1455,5 +1456,9 @@
"ButtonUnlockGuide": "Unlock Guide",
"LabelEnableFullScreen": "Enable fullscreen mode",
"LabelEnableChromecastAc3Passthrough": "Enable Chromecast AC3 Passthrough",
"LabelSyncPath": "Synced content path:"
"LabelSyncPath": "Synced content path:",
"HeaderOverview": "Overview",
"HeaderShortOverview": "Short Overview",
"HeaderType": "Type",
"HeaderSeverity": "Severity"
}

Loading…
Cancel
Save