Merge pull request #2884 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2017-09-16 00:14:47 -04:00 committed by GitHub
commit f1fcc6e9c4
25 changed files with 44 additions and 2704 deletions

View File

@ -23,6 +23,19 @@ namespace Emby.Server.Implementations.Services
public SwaggerTag[] tags { get; set; }
public IDictionary<string, Dictionary<string, SwaggerMethod>> paths { get; set; }
public Dictionary<string, SwaggerDefinition> definitions { get; set; }
public SwaggerComponents components { get; set; }
}
public class SwaggerComponents
{
public Dictionary<string, SwaggerSecurityScheme> securitySchemes { get; set; }
}
public class SwaggerSecurityScheme
{
public string name { get; set; }
public string type { get; set; }
public string @in { get; set; }
}
public class SwaggerInfo
@ -38,6 +51,8 @@ namespace Emby.Server.Implementations.Services
public class SwaggerConcactInfo
{
public string email { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class SwaggerTag
@ -56,6 +71,7 @@ namespace Emby.Server.Implementations.Services
public string[] produces { get; set; }
public SwaggerParam[] parameters { get; set; }
public Dictionary<string, SwaggerResponse> responses { get; set; }
public Dictionary<string, string[]>[] security { get; set; }
}
public class SwaggerParam
@ -111,6 +127,15 @@ namespace Emby.Server.Implementations.Services
host = uri.Host;
}
var securitySchemes = new Dictionary<string, SwaggerSecurityScheme>();
securitySchemes["api_key"] = new SwaggerSecurityScheme
{
name = "api_key",
type = "apiKey",
@in = "query"
};
var spec = new SwaggerSpec
{
schemes = new[] { "http" },
@ -123,14 +148,20 @@ namespace Emby.Server.Implementations.Services
description = "Explore the Emby Server API",
contact = new SwaggerConcactInfo
{
email = "api@emby.media"
name = "Emby Developer Community",
url = "https://emby.media/community/index.php?/forum/47-developer-api"
},
termsOfService = "https://emby.media/terms"
},
paths = GetPaths(),
definitions = GetDefinitions(),
basePath = "/emby",
host = host
host = host,
components = new SwaggerComponents
{
securitySchemes = securitySchemes
}
};
return spec;
@ -193,6 +224,13 @@ namespace Emby.Server.Implementations.Services
description = "OK"
};
var security = new List<Dictionary<string, string[]>>();
var apiKeySecurity = new Dictionary<string, string[]>();
apiKeySecurity["api_key"] = new string[] { };
security.Add(apiKeySecurity);
result[verb.ToLower()] = new SwaggerMethod
{
summary = info.Summary,
@ -210,7 +248,9 @@ namespace Emby.Server.Implementations.Services
parameters = new SwaggerParam[] { },
responses = responses
responses = responses,
security = security.ToArray()
};
}

View File

@ -50,28 +50,6 @@
<Compile Include="IHasDtoOptions.cs" />
<Compile Include="LiveTv\ProgressiveFileCopier.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" />
<Compile Include="Reports\Common\ReportDisplayType.cs" />
<Compile Include="Reports\Common\ReportExportType.cs" />
<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\ReportOptions.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="Social\SharingService.cs" />
<Compile Include="StartupWizardService.cs" />
<Compile Include="Subtitles\SubtitleService.cs" />

View File

@ -1,256 +0,0 @@
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Querying;
using System.Collections.Generic;
using System.Linq;
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)
{
ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType);
List<ReportOptions<ActivityLogEntry>> options = this.GetReportOptions<ActivityLogEntry>(request,
() => this.GetDefaultHeaderMetadata(),
(hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).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.UserPrimaryImage,
HeaderMetadata.Date,
HeaderMetadata.User,
HeaderMetadata.Type,
HeaderMetadata.Severity,
HeaderMetadata.Name,
HeaderMetadata.ShortOverview,
HeaderMetadata.Overview,
//HeaderMetadata.UserId
//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.Name:
option.Column = (i, r) => i.Name;
option.Header.SortField = "";
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.UserPrimaryImage:
//option.Column = (i, r) => i.UserPrimaryImageTag;
option.Header.DisplayType = ReportDisplayType.Screen;
option.Header.ItemViewType = ItemViewType.UserPrimaryImage;
option.Header.ShowHeaderLabel = false;
internalHeader = HeaderMetadata.User;
option.Header.CanGroup = false;
option.Column = (i, r) =>
{
if (!string.IsNullOrEmpty(i.UserId))
{
MediaBrowser.Controller.Entities.User user = _userManager.GetUserById(i.UserId);
if (user != null)
{
var dto = _userManager.GetUserDto(user);
return dto.PrimaryImageTag;
}
}
return string.Empty;
};
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;
case HeaderMetadata.UserId:
option.Column = (i, r) => i.UserId;
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,
UserId = item.UserId
};
return rRow;
}
#endregion
}
}

View File

@ -1,16 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum HeaderActivitiesMetadata
{
None,
Name,
Overview,
ShortOverview,
Type,
Date,
UserPrimaryImageTag,
Severity,
Item,
User
}
}

View File

@ -1,69 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum HeaderMetadata
{
None,
Name,
PremiereDate,
DateAdded,
ReleaseDate,
Runtime,
PlayCount,
Season,
SeasonNumber,
Series,
Network,
Year,
ParentalRating,
CommunityRating,
Trailers,
Specials,
GameSystem,
Players,
AlbumArtist,
Album,
Disc,
Track,
Audio,
EmbeddedImage,
Video,
Resolution,
Subtitles,
Genres,
Countries,
Status,
Tracks,
EpisodeSeries,
EpisodeSeason,
EpisodeNumber,
AudioAlbumArtist,
MusicArtist,
AudioAlbum,
Locked,
ImagePrimary,
ImageBackdrop,
ImageLogo,
Actor,
Studios,
Composer,
Director,
GuestStar,
Producer,
Writer,
Artist,
Years,
ParentalRatings,
CommunityRatings,
//Activity logs
Overview,
ShortOverview,
Type,
Date,
UserPrimaryImage,
Severity,
Item,
User,
UserId
}
}

View File

@ -1,21 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ItemViewType
{
None,
Detail,
Edit,
List,
ItemByNameDetails,
StatusImage,
EmbeddedImage,
SubtitleImage,
TrailersImage,
SpecialsImage,
LockDataImage,
TagsPrimaryImage,
TagsBackdropImage,
TagsLogoImage,
UserPrimaryImage
}
}

View File

@ -1,365 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Reports
{
/// <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, ReportDisplayType displayType)
{
List<ReportHeader> headers = new List<ReportHeader>();
foreach (ReportOptions<T> option in options.Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)))
{
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)
{
if (internalHeader == HeaderMetadata.EpisodeNumber)
{
return "Episode";
}
string headerName = "";
if (internalHeader != HeaderMetadata.None)
{
string localHeader = "Header" + internalHeader.ToString();
headerName = ReportHelper.GetCoreLocalizedString(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>>();
ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType);
foreach (HeaderMetadata header in headersMetadata)
{
ReportOptions<T> headerOptions = getOptions(header);
if (this.DisplayTypeVisible(headerOptions.Header.DisplayType, displayType))
options.Add(headerOptions);
}
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 (this.DisplayTypeVisible(header.DisplayType, displayType))
{
if (!headersMetadataFiltered.Contains(header.FieldName) && displayType != ReportDisplayType.Export)
{
header.DisplayType = ReportDisplayType.None;
}
}
else
header.DisplayType = ReportDisplayType.None;
}
}
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;
}
/// <summary> Displays a type visible. </summary>
/// <param name="headerDisplayType"> Type of the header display. </param>
/// <param name="displayType"> Type of the display. </param>
/// <returns> true if it succeeds, false if it fails. </returns>
protected bool DisplayTypeVisible(ReportDisplayType headerDisplayType, ReportDisplayType displayType)
{
if (headerDisplayType == ReportDisplayType.None)
return false;
bool rval = headerDisplayType == displayType || headerDisplayType == ReportDisplayType.ScreenExport && (displayType == ReportDisplayType.Screen || displayType == ReportDisplayType.Export);
return rval;
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportDisplayType
{
None,
Screen,
Export,
ScreenExport
}
}

View File

@ -1,8 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportExportType
{
CSV,
Excel
}
}

View File

@ -1,15 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportFieldType
{
String,
Boolean,
Date,
Time,
DateTime,
Int,
Image,
Object,
Minutes
}
}

View File

@ -1,8 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportHeaderIdType
{
Row,
Item
}
}

View File

@ -1,138 +0,0 @@
using MediaBrowser.Controller.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Reports
{
/// <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();
}
}
/// <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 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 report display type. </summary>
/// <param name="displayType"> Type of the display. </param>
/// <returns> The report display type. </returns>
public static ReportDisplayType GetReportDisplayType(string displayType)
{
if (string.IsNullOrEmpty(displayType))
return ReportDisplayType.ScreenExport;
ReportDisplayType rType;
if (!Enum.TryParse<ReportDisplayType>(displayType, out rType))
return ReportDisplayType.ScreenExport;
return rType;
}
/// <summary> Gets core localized string. </summary>
/// <param name="phrase"> The phrase. </param>
/// <returns> The core localized string. </returns>
public static string GetCoreLocalizedString(string phrase)
{
return BaseItem.LocalizationManager.GetLocalizedString(phrase);
}
#endregion
}
}

View File

@ -1,21 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportIncludeItemTypes
{
MusicArtist,
MusicAlbum,
Book,
BoxSet,
Episode,
Game,
Video,
Movie,
MusicVideo,
Trailer,
Season,
Series,
Audio,
BaseItem,
Artist
}
}

View File

@ -1,9 +0,0 @@
namespace MediaBrowser.Api.Reports
{
public enum ReportViewType
{
ReportData,
ReportActivities
}
}

View File

@ -1,626 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api.Reports
{
/// <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);
ReportDisplayType displayType = ReportHelper.GetReportDisplayType(request.DisplayType);
List<ReportOptions<BaseItem>> options = this.GetReportOptions<BaseItem>(request,
() => this.GetDefaultHeaderMetadata(reportRowType),
(hm) => this.GetOption(hm)).Where(x => this.DisplayTypeVisible(x.Header.DisplayType, displayType)).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.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Series,
HeaderMetadata.Season,
HeaderMetadata.SeasonNumber,
HeaderMetadata.DateAdded,
HeaderMetadata.Year,
HeaderMetadata.Genres
};
case ReportIncludeItemTypes.Series:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.Network,
HeaderMetadata.DateAdded,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Runtime,
HeaderMetadata.Trailers,
HeaderMetadata.Specials
};
case ReportIncludeItemTypes.MusicAlbum:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.AlbumArtist,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Tracks,
HeaderMetadata.Year,
HeaderMetadata.Genres
};
case ReportIncludeItemTypes.MusicArtist:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.MusicArtist,
HeaderMetadata.Countries,
HeaderMetadata.DateAdded,
HeaderMetadata.Year,
HeaderMetadata.Genres
};
case ReportIncludeItemTypes.Game:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.GameSystem,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Players,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.Trailers
};
case ReportIncludeItemTypes.Movie:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Runtime,
HeaderMetadata.Video,
HeaderMetadata.Resolution,
HeaderMetadata.Audio,
HeaderMetadata.Subtitles,
HeaderMetadata.Trailers,
HeaderMetadata.Specials
};
case ReportIncludeItemTypes.Book:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating
};
case ReportIncludeItemTypes.BoxSet:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Trailers
};
case ReportIncludeItemTypes.Audio:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.AudioAlbumArtist,
HeaderMetadata.AudioAlbum,
HeaderMetadata.Disc,
HeaderMetadata.Track,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Runtime,
HeaderMetadata.Audio
};
case ReportIncludeItemTypes.Episode:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.EpisodeSeries,
HeaderMetadata.Season,
HeaderMetadata.EpisodeNumber,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Runtime,
HeaderMetadata.Video,
HeaderMetadata.Resolution,
HeaderMetadata.Audio,
HeaderMetadata.Subtitles,
HeaderMetadata.Trailers,
HeaderMetadata.Specials
};
case ReportIncludeItemTypes.Video:
case ReportIncludeItemTypes.MusicVideo:
case ReportIncludeItemTypes.Trailer:
case ReportIncludeItemTypes.BaseItem:
default:
return new List<HeaderMetadata>
{
HeaderMetadata.Status,
HeaderMetadata.Locked,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.ImagePrimary,
HeaderMetadata.ImageBackdrop,
HeaderMetadata.ImageLogo,
HeaderMetadata.Name,
HeaderMetadata.DateAdded,
HeaderMetadata.ReleaseDate,
HeaderMetadata.Year,
HeaderMetadata.Genres,
HeaderMetadata.ParentalRating,
HeaderMetadata.CommunityRating,
HeaderMetadata.Runtime,
HeaderMetadata.Video,
HeaderMetadata.Resolution,
HeaderMetadata.Audio,
HeaderMetadata.Subtitles,
HeaderMetadata.Trailers,
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> 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.Status:
option.Header.ItemViewType = ItemViewType.StatusImage;
internalHeader = HeaderMetadata.Status;
option.Header.CanGroup = false;
option.Header.DisplayType = ReportDisplayType.Screen;
break;
case HeaderMetadata.Locked:
option.Column = (i, r) => this.GetBoolString(r.HasLockData);
option.Header.ItemViewType = ItemViewType.LockDataImage;
option.Header.CanGroup = false;
option.Header.DisplayType = ReportDisplayType.Export;
break;
case HeaderMetadata.ImagePrimary:
option.Column = (i, r) => this.GetBoolString(r.HasImageTagsPrimary);
option.Header.ItemViewType = ItemViewType.TagsPrimaryImage;
option.Header.CanGroup = false;
option.Header.DisplayType = ReportDisplayType.Export;
break;
case HeaderMetadata.ImageBackdrop:
option.Column = (i, r) => this.GetBoolString(r.HasImageTagsBackdrop);
option.Header.ItemViewType = ItemViewType.TagsBackdropImage;
option.Header.CanGroup = false;
option.Header.DisplayType = ReportDisplayType.Export;
break;
case HeaderMetadata.ImageLogo:
option.Column = (i, r) => this.GetBoolString(r.HasImageTagsLogo);
option.Header.ItemViewType = ItemViewType.TagsLogoImage;
option.Header.CanGroup = false;
option.Header.DisplayType = ReportDisplayType.Export;
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.EpisodeNumber:
option.Column = (i, r) => this.GetObject<BaseItem, string>(i, (x) => x.IndexNumber == null ? "" : x.IndexNumber.ToString());
//option.Header.SortField = "IndexNumber";
//option.Header.HeaderFieldType = ReportFieldType.Int;
break;
case HeaderMetadata.Network:
option.Column = (i, r) => this.GetListAsString(i.Studios.ToList());
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.ToList()));
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.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.Cast<Audio>().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,
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.Length > 0 : false,
HasSubtitles = video != null ? video.HasSubtitles : false,
RowType = ReportHelper.GetRowType(item.GetClientTypeName())
};
return rRow;
}
#endregion
}
}

View File

@ -1,209 +0,0 @@
using System.Linq;
using System.Text;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report export. </summary>
public class ReportExport
{
/// <summary> Export to CSV. </summary>
/// <param name="reportResult"> The report result. </param>
/// <returns> A string. </returns>
public string ExportToCsv(ReportResult reportResult)
{
StringBuilder returnValue = new StringBuilder();
returnValue.AppendLine(string.Join(";", reportResult.Headers.Select(s => s.Name.Replace(',', ' ')).ToArray()));
if (reportResult.IsGrouped)
foreach (ReportGroup group in reportResult.Groups)
{
foreach (ReportRow row in reportResult.Rows)
{
returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
}
}
else
foreach (ReportRow row in reportResult.Rows)
{
returnValue.AppendLine(string.Join(";", row.Columns.Select(s => s.Name.Replace(',', ' ')).ToArray()));
}
return returnValue.ToString();
}
/// <summary> Export to excel. </summary>
/// <param name="reportResult"> The report result. </param>
/// <returns> A string. </returns>
public string ExportToExcel(ReportResult reportResult)
{
string style = @"<style type='text/css'>
BODY {
font-family: Arial;
font-size: 12px;
}
TABLE {
font-family: Arial;
font-size: 12px;
}
A {
font-family: Arial;
color: #144A86;
font-size: 12px;
cursor: pointer;
text-decoration: none;
font-weight: bold;
}
DIV {
font-family: Arial;
font-size: 12px;
margin-bottom: 0px;
}
P, LI, DIV {
font-size: 12px;
margin-bottom: 0px;
}
P, UL {
font-size: 12px;
margin-bottom: 6px;
margin-top: 0px;
}
H1 {
font-size: 18pt;
}
H2 {
font-weight: bold;
font-size: 14pt;
COLOR: #C0C0C0;
}
H3 {
font-weight: normal;
font-size: 14pt;
text-indent: +1em;
}
H4 {
font-size: 10pt;
font-weight: normal;
}
H5 {
font-size: 10pt;
font-weight: normal;
background: #A9A9A9;
COLOR: white;
display: inline;
}
H6 {
padding: 2 1 2 5;
font-size: 11px;
font-weight: bold;
text-decoration: none;
margin-bottom: 1px;
}
UL {
line-height: 1.5em;
list-style-type: disc;
}
OL {
line-height: 1.5em;
}
LI {
line-height: 1.5em;
}
A IMG {
border: 0;
}
table.gridtable {
color: #333333;
border-width: 0.1pt;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 0.1pt;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable tr {
background-color: #ffffff;
}
table.gridtable td {
border-width: 0.1pt;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>";
string Html = @"<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=8, IE=9, IE=10' />
<meta charset='utf-8'>
<title>Emby Reports Export</title>";
Html += "\n" + style + "\n";
Html += "</head>\n";
Html += "<body>\n";
StringBuilder returnValue = new StringBuilder();
returnValue.AppendLine("<table class='gridtable'>");
returnValue.AppendLine("<tr>");
returnValue.AppendLine(string.Join("", reportResult.Headers.Select(s => string.Format("<th>{0}</th>", s.Name)).ToArray()));
returnValue.AppendLine("</tr>");
if (reportResult.IsGrouped)
foreach (ReportGroup group in reportResult.Groups)
{
returnValue.AppendLine("<tr>");
returnValue.AppendLine("<th scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + (string.IsNullOrEmpty(group.Name) ? "&nbsp;" : group.Name) + "</th>");
returnValue.AppendLine("</tr>");
foreach (ReportRow row in group.Rows)
{
ExportToExcelRow(reportResult, returnValue, row);
}
returnValue.AppendLine("<tr>");
returnValue.AppendLine("<th style='background-color: #ffffff;' scope='rowgroup' colspan='" + reportResult.Headers.Count + "'>" + "&nbsp;" + "</th>");
returnValue.AppendLine("</tr>");
}
else
foreach (ReportRow row in reportResult.Rows)
{
ExportToExcelRow(reportResult, returnValue, row);
}
returnValue.AppendLine("</table>");
Html += returnValue.ToString();
Html += "</body>";
Html += "</html>";
return Html;
}
private static void ExportToExcelRow(ReportResult reportResult,
StringBuilder returnValue,
ReportRow row)
{
returnValue.AppendLine("<tr>");
returnValue.AppendLine(string.Join("", row.Columns.Select(s => string.Format("<td>{0}</td>", s.Name)).ToArray()));
returnValue.AppendLine("</tr>");
}
}
}

View File

@ -1,48 +0,0 @@
using System;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report options. </summary>
public class ReportOptions<I>
{
/// <summary> Initializes a new instance of the ReportOptions class. </summary>
public ReportOptions()
{
}
/// <summary> Initializes a new instance of the ReportOptions class. </summary>
/// <param name="header"> . </param>
/// <param name="row"> . </param>
public ReportOptions(ReportHeader header, Func<I, ReportRow, object> column)
{
Header = header;
Column = column;
}
/// <summary>
/// Initializes a new instance of the ReportOptions class.
/// </summary>
/// <param name="header"></param>
/// <param name="column"></param>
/// <param name="itemID"></param>
public ReportOptions(ReportHeader header, Func<I, ReportRow, object> column, Func<I, object> itemID)
{
Header = header;
Column = column;
ItemID = itemID;
}
/// <summary> Gets or sets the header. </summary>
/// <value> The header. </value>
public ReportHeader Header { get; set; }
/// <summary> Gets or sets the column. </summary>
/// <value> The column. </value>
public Func<I, ReportRow, object> Column { get; set; }
/// <summary> Gets or sets the identifier of the item. </summary>
/// <value> The identifier of the item. </value>
public Func<I, object> ItemID { get; set; }
}
}

View File

@ -1,40 +0,0 @@
using System.Collections.Generic;
namespace MediaBrowser.Api.Reports
{
/// <summary> A report group. </summary>
public class ReportGroup
{
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportGroup class. </summary>
public ReportGroup()
{
Rows = new List<ReportRow>();
}
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportGroup class. </summary>
/// <param name="rows"> The rows. </param>
public ReportGroup(List<ReportRow> rows)
{
Rows = rows;
}
/// <summary> Gets or sets the name. </summary>
/// <value> The name. </value>
public string Name { get; set; }
/// <summary> Gets or sets the rows. </summary>
/// <value> The rows. </value>
public List<ReportRow> Rows { get; set; }
/// <summary> Returns a string that represents the current object. </summary>
/// <returns> A string that represents the current object. </returns>
/// <seealso cref="M:System.Object.ToString()"/>
public override string ToString()
{
return Name;
}
}
}

View File

@ -1,57 +0,0 @@
namespace MediaBrowser.Api.Reports
{
/// <summary> A report header. </summary>
public class ReportHeader
{
/// <summary> Initializes a new instance of the ReportHeader class. </summary>
public ReportHeader()
{
ItemViewType = ItemViewType.None;
Visible = true;
CanGroup = true;
ShowHeaderLabel = true;
DisplayType = ReportDisplayType.ScreenExport;
}
/// <summary> Gets or sets the type of the header field. </summary>
/// <value> The type of the header field. </value>
public ReportFieldType HeaderFieldType { get; set; }
/// <summary> Gets or sets the name of the header. </summary>
/// <value> The name of the header. </value>
public string Name { get; set; }
/// <summary> Gets or sets the name of the field. </summary>
/// <value> The name of the field. </value>
public HeaderMetadata FieldName { get; set; }
/// <summary> Gets or sets the sort field. </summary>
/// <value> The sort field. </value>
public string SortField { get; set; }
/// <summary> Gets or sets the type. </summary>
/// <value> The type. </value>
public string Type { get; set; }
/// <summary> Gets or sets the type of the item view. </summary>
/// <value> The type of the item view. </value>
public ItemViewType ItemViewType { get; set; }
/// <summary> Gets or sets a value indicating whether this object is visible. </summary>
/// <value> true if visible, false if not. </value>
public bool Visible { get; set; }
/// <summary> Gets or sets the type of the display. </summary>
/// <value> The type of the display. </value>
public ReportDisplayType DisplayType { get; set; }
/// <summary> Gets or sets a value indicating whether the header label is shown. </summary>
/// <value> true if show header label, false if not. </value>
public bool ShowHeaderLabel { get; set; }
/// <summary> Gets or sets a value indicating whether we can group. </summary>
/// <value> true if we can group, false if not. </value>
public bool CanGroup { get; set; }
}
}

View File

@ -1,28 +0,0 @@
namespace MediaBrowser.Api.Reports
{
/// <summary> A report item. </summary>
public class ReportItem
{
/// <summary> Gets or sets the identifier. </summary>
/// <value> The identifier. </value>
public string Id { get; set; }
/// <summary> Gets or sets the name. </summary>
/// <value> The name. </value>
public string Name { get; set; }
public string Image { get; set; }
/// <summary> Gets or sets the custom tag. </summary>
/// <value> The custom tag. </value>
public string CustomTag { get; set; }
/// <summary> Returns a string that represents the current object. </summary>
/// <returns> A string that represents the current object. </returns>
/// <seealso cref="M:System.Object.ToString()"/>
public override string ToString()
{
return Name;
}
}
}

View File

@ -1,53 +0,0 @@
using System.Collections.Generic;
namespace MediaBrowser.Api.Reports
{
/// <summary> Encapsulates the result of a report. </summary>
public class ReportResult
{
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportResult class. </summary>
public ReportResult()
{
Rows = new List<ReportRow>();
Headers = new List<ReportHeader>();
Groups = new List<ReportGroup>();
TotalRecordCount = 0;
IsGrouped = false;
}
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportResult class. </summary>
/// <param name="headers"> The headers. </param>
/// <param name="rows"> The rows. </param>
public ReportResult(List<ReportHeader> headers, List<ReportRow> rows)
{
Rows = rows;
Headers = headers;
TotalRecordCount = 0;
}
/// <summary> Gets or sets the rows. </summary>
/// <value> The rows. </value>
public List<ReportRow> Rows { get; set; }
/// <summary> Gets or sets the headers. </summary>
/// <value> The headers. </value>
public List<ReportHeader> Headers { get; set; }
/// <summary> Gets or sets the groups. </summary>
/// <value> The groups. </value>
public List<ReportGroup> Groups { get; set; }
/// <summary> Gets or sets the number of total records. </summary>
/// <value> The total number of record count. </value>
public int TotalRecordCount { get; set; }
/// <summary> Gets or sets the is grouped. </summary>
/// <value> The is grouped. </value>
public bool IsGrouped { get; set; }
}
}

View File

@ -1,67 +0,0 @@
using System.Collections.Generic;
namespace MediaBrowser.Api.Reports
{
public class ReportRow
{
/// <summary>
/// Initializes a new instance of the ReportRow class.
/// </summary>
public ReportRow()
{
Columns = new List<ReportItem>();
}
/// <summary> Gets or sets the identifier. </summary>
/// <value> The identifier. </value>
public string Id { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this object has backdrop image. </summary>
/// <value> true if this object has backdrop image, false if not. </value>
public bool HasImageTagsBackdrop { get; set; }
/// <summary> Gets or sets a value indicating whether this object has image tags. </summary>
/// <value> true if this object has image tags, false if not. </value>
public bool HasImageTagsPrimary { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this object has image tags logo. </summary>
/// <value> true if this object has image tags logo, false if not. </value>
public bool HasImageTagsLogo { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this object has local trailer. </summary>
/// <value> true if this object has local trailer, false if not. </value>
public bool HasLocalTrailer { get; set; }
/// <summary> Gets or sets a value indicating whether this object has lock data. </summary>
/// <value> true if this object has lock data, false if not. </value>
public bool HasLockData { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this object has embedded image. </summary>
/// <value> true if this object has embedded image, false if not. </value>
public bool HasEmbeddedImage { get; set; }
/// <summary> Gets or sets a value indicating whether this object has subtitles. </summary>
/// <value> true if this object has subtitles, false if not. </value>
public bool HasSubtitles { get; set; }
/// <summary> Gets or sets a value indicating whether this object has specials. </summary>
/// <value> true if this object has specials, false if not. </value>
public bool HasSpecials { get; set; }
/// <summary> Gets or sets the columns. </summary>
/// <value> The columns. </value>
public List<ReportItem> Columns { get; set; }
/// <summary> Gets or sets the type. </summary>
/// <value> The type. </value>
public ReportIncludeItemTypes RowType { get; set; }
/// <summary> Gets or sets the identifier of the user. </summary>
/// <value> The identifier of the user. </value>
public string UserId { get; set; }
}
}

View File

@ -1,194 +0,0 @@
using MediaBrowser.Api.UserLibrary;
using System.Collections.Generic;
using MediaBrowser.Model.Services;
namespace MediaBrowser.Api.Reports
{
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; }
/// <summary> Gets or sets a list of types of the displays. </summary>
/// <value> A list of types of the displays. </value>
string DisplayType { 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, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string DisplayType { 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; }
}
[Route("/Reports/Items", "GET", Summary = "Gets reports based on library items")]
public class GetItemReport : BaseReportRequest, IReturn<ReportResult>
{
}
[Route("/Reports/Headers", "GET", Summary = "Gets reports headers based on library items")]
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, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string DisplayType { 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/Items/Download", "GET", Summary = "Downloads report")]
public class GetReportDownload : BaseReportRequest, IReportsDownload
{
public GetReportDownload()
{
ExportType = ReportExportType.CSV;
}
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, ReportActivities)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string ReportView { get; set; }
/// <summary> Gets or sets the report view. </summary>
/// <value> The report view. </value>
[ApiMember(Name = "DisplayType", Description = "The report display type. Values (None, Screen, Export, ScreenExport)", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string DisplayType { 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; }
}
}

View File

@ -1,420 +0,0 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Querying;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Globalization;
using System.Linq;
using System;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
namespace MediaBrowser.Api.Reports
{
/// <summary> The reports service. </summary>
/// <seealso cref="T:MediaBrowser.Api.BaseApiService"/>
public class ReportsService : BaseApiService
{
#region [Constructors]
/// <summary>
/// Initializes a new instance of the MediaBrowser.Api.Reports.ReportsService class. </summary>
/// <param name="userManager"> Manager for user. </param>
/// <param name="libraryManager"> Manager for library. </param>
/// <param name="localization"> The localization. </param>
/// <param name="activityManager"> Manager for activity. </param>
public ReportsService(IUserManager userManager, ILibraryManager libraryManager, ILocalizationManager localization, IActivityManager activityManager, IActivityRepository repo)
{
_userManager = userManager;
_libraryManager = libraryManager;
_localization = localization;
_activityManager = activityManager;
_repo = repo;
}
#endregion
#region [Private Fields]
private readonly IActivityManager _activityManager; ///< Manager for activity
/// <summary> Manager for library. </summary>
private readonly ILibraryManager _libraryManager; ///< Manager for library
/// <summary> The localization. </summary>
private readonly ILocalizationManager _localization; ///< The localization
private readonly IActivityRepository _repo;
/// <summary> Manager for user. </summary>
private readonly IUserManager _userManager; ///< Manager for user
#endregion
#region [Public Methods]
/// <summary> Gets the given request. </summary>
/// <param name="request"> The request. </param>
/// <returns> A Task&lt;object&gt; </returns>
public object Get(GetActivityLogs request)
{
request.DisplayType = "Screen";
ReportResult result = GetReportActivities(request);
return ToOptimizedResult(result);
}
/// <summary> Gets the given request. </summary>
/// <param name="request"> The request. </param>
/// <returns> A Task&lt;object&gt; </returns>
public object Get(GetReportHeaders request)
{
if (string.IsNullOrEmpty(request.IncludeItemTypes))
return null;
request.DisplayType = "Screen";
ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView);
List<ReportHeader> result = new List<ReportHeader>();
switch (reportViewType)
{
case ReportViewType.ReportData:
ReportBuilder dataBuilder = new ReportBuilder(_libraryManager);
result = dataBuilder.GetHeaders(request);
break;
case ReportViewType.ReportActivities:
ReportActivitiesBuilder activityBuilder = new ReportActivitiesBuilder(_libraryManager, _userManager);
result = activityBuilder.GetHeaders(request);
break;
}
return ToOptimizedResult(result);
}
/// <summary> Gets the given request. </summary>
/// <param name="request"> The request. </param>
/// <returns> A Task&lt;object&gt; </returns>
public object Get(GetItemReport request)
{
if (string.IsNullOrEmpty(request.IncludeItemTypes))
return null;
request.DisplayType = "Screen";
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
var reportResult = GetReportResult(request, user);
return ToOptimizedResult(reportResult);
}
/// <summary> Gets the given request. </summary>
/// <param name="request"> The request. </param>
/// <returns> A Task&lt;object&gt; </returns>
public object Get(GetReportDownload request)
{
if (string.IsNullOrEmpty(request.IncludeItemTypes))
return null;
request.DisplayType = "Export";
ReportViewType reportViewType = ReportHelper.GetReportViewType(request.ReportView);
var headers = new Dictionary<string, string>();
string fileExtension = "csv";
string contentType = "text/plain;charset='utf-8'";
switch (request.ExportType)
{
case ReportExportType.CSV:
break;
case ReportExportType.Excel:
contentType = "application/vnd.ms-excel";
fileExtension = "xls";
break;
}
var filename = "ReportExport." + fileExtension;
headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename);
headers["Content-Encoding"] = "UTF-8";
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
ReportResult result = null;
switch (reportViewType)
{
case ReportViewType.ReportData:
ReportIncludeItemTypes reportRowType = ReportHelper.GetRowType(request.IncludeItemTypes);
ReportBuilder dataBuilder = new ReportBuilder(_libraryManager);
QueryResult<BaseItem> queryResult = GetQueryResult(request, user);
result = dataBuilder.GetResult(queryResult.Items, request);
result.TotalRecordCount = queryResult.TotalRecordCount;
break;
case ReportViewType.ReportActivities:
result = GetReportActivities(request);
break;
}
string returnResult = string.Empty;
switch (request.ExportType)
{
case ReportExportType.CSV:
returnResult = new ReportExport().ExportToCsv(result);
break;
case ReportExportType.Excel:
returnResult = new ReportExport().ExportToExcel(result);
break;
}
return ResultFactory.GetResult(returnResult, contentType, headers);
}
#endregion
private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user)
{
var query = new InternalItemsQuery(user)
{
IsPlayed = request.IsPlayed,
MediaTypes = request.GetMediaTypes(),
IncludeItemTypes = request.GetIncludeItemTypes(),
ExcludeItemTypes = request.GetExcludeItemTypes(),
Recursive = request.Recursive,
OrderBy = request.GetOrderBy(),
IsFavorite = request.IsFavorite,
Limit = request.Limit,
StartIndex = request.StartIndex,
IsMissing = request.IsMissing,
IsUnaired = request.IsUnaired,
CollapseBoxSetItems = request.CollapseBoxSetItems,
NameLessThan = request.NameLessThan,
NameStartsWith = request.NameStartsWith,
NameStartsWithOrGreater = request.NameStartsWithOrGreater,
HasImdbId = request.HasImdbId,
IsPlaceHolder = request.IsPlaceHolder,
IsLocked = request.IsLocked,
IsInBoxSet = request.IsInBoxSet,
IsHD = request.IsHD,
Is3D = request.Is3D,
HasTvdbId = request.HasTvdbId,
HasTmdbId = request.HasTmdbId,
HasOverview = request.HasOverview,
HasOfficialRating = request.HasOfficialRating,
HasParentalRating = request.HasParentalRating,
HasSpecialFeature = request.HasSpecialFeature,
HasSubtitles = request.HasSubtitles,
HasThemeSong = request.HasThemeSong,
HasThemeVideo = request.HasThemeVideo,
HasTrailer = request.HasTrailer,
Tags = request.GetTags(),
OfficialRatings = request.GetOfficialRatings(),
Genres = request.GetGenres(),
GenreIds = request.GetGenreIds(),
StudioIds = request.GetStudioIds(),
Person = request.Person,
PersonIds = request.GetPersonIds(),
PersonTypes = request.GetPersonTypes(),
Years = request.GetYears(),
ImageTypes = request.GetImageTypes().ToArray(),
VideoTypes = request.GetVideoTypes().ToArray(),
AdjacentTo = request.AdjacentTo,
ItemIds = request.GetItemIds(),
MinPlayers = request.MinPlayers,
MaxPlayers = request.MaxPlayers,
MinCommunityRating = request.MinCommunityRating,
MinCriticRating = request.MinCriticRating,
ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId),
ParentIndexNumber = request.ParentIndexNumber,
AiredDuringSeason = request.AiredDuringSeason,
EnableTotalRecordCount = request.EnableTotalRecordCount
};
if (!string.IsNullOrWhiteSpace(request.Ids))
{
query.CollapseBoxSetItems = false;
}
foreach (var filter in request.GetFilters())
{
switch (filter)
{
case ItemFilter.Dislikes:
query.IsLiked = false;
break;
case ItemFilter.IsFavorite:
query.IsFavorite = true;
break;
case ItemFilter.IsFavoriteOrLikes:
query.IsFavoriteOrLiked = true;
break;
case ItemFilter.IsFolder:
query.IsFolder = true;
break;
case ItemFilter.IsNotFolder:
query.IsFolder = false;
break;
case ItemFilter.IsPlayed:
query.IsPlayed = true;
break;
case ItemFilter.IsResumable:
query.IsResumable = true;
break;
case ItemFilter.IsUnplayed:
query.IsPlayed = false;
break;
case ItemFilter.Likes:
query.IsLiked = true;
break;
}
}
if (!string.IsNullOrEmpty(request.MinPremiereDate))
{
query.MinPremiereDate = DateTime.Parse(request.MinPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
}
if (!string.IsNullOrEmpty(request.MaxPremiereDate))
{
query.MaxPremiereDate = DateTime.Parse(request.MaxPremiereDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
}
// Filter by Series Status
if (!string.IsNullOrEmpty(request.SeriesStatus))
{
query.SeriesStatuses = request.SeriesStatus.Split(',').Select(d => (SeriesStatus)Enum.Parse(typeof(SeriesStatus), d, true)).ToArray();
}
// ExcludeLocationTypes
if (!string.IsNullOrEmpty(request.ExcludeLocationTypes))
{
var excludeLocationTypes = request.ExcludeLocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
if (excludeLocationTypes.Contains(LocationType.Virtual))
{
query.IsVirtualItem = false;
}
}
// Min official rating
if (!string.IsNullOrWhiteSpace(request.MinOfficialRating))
{
query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
}
// Max official rating
if (!string.IsNullOrWhiteSpace(request.MaxOfficialRating))
{
query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating);
}
return query;
}
private QueryResult<BaseItem> GetQueryResult(BaseReportRequest request, User user)
{
// all report queries currently need this because it's not being specified
request.Recursive = true;
var item = string.IsNullOrEmpty(request.ParentId) ?
user == null ? _libraryManager.RootFolder : user.RootFolder :
_libraryManager.GetItemById(request.ParentId);
if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase))
{
//item = user == null ? _libraryManager.RootFolder : user.RootFolder;
}
else if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase))
{
item = user == null ? _libraryManager.RootFolder : user.RootFolder;
}
// Default list type = children
var folder = item as Folder;
if (folder == null)
{
folder = user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder();
}
if (!string.IsNullOrEmpty(request.Ids))
{
request.Recursive = true;
var query = GetItemsQuery(request, user);
var result = folder.GetItems(query);
if (string.IsNullOrWhiteSpace(request.SortBy))
{
var ids = query.ItemIds.ToList();
// Try to preserve order
result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id.ToString("N"))).ToArray();
}
return result;
}
if (request.Recursive)
{
return folder.GetItems(GetItemsQuery(request, user));
}
if (user == null)
{
return folder.GetItems(GetItemsQuery(request, null));
}
var userRoot = item as UserRootFolder;
if (userRoot == null)
{
return folder.GetItems(GetItemsQuery(request, user));
}
IEnumerable<BaseItem> items = folder.GetChildren(user, true);
var itemsArray = items.ToArray();
return new QueryResult<BaseItem>
{
Items = itemsArray,
TotalRecordCount = itemsArray.Length
};
}
#region [Private Methods]
/// <summary> Gets report activities. </summary>
/// <param name="request"> The request. </param>
/// <returns> The report activities. </returns>
private ReportResult GetReportActivities(IReportsDownload request)
{
DateTime? minDate = string.IsNullOrWhiteSpace(request.MinDate) ?
(DateTime?)null :
DateTime.Parse(request.MinDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
QueryResult<ActivityLogEntry> queryResult;
if (request.HasQueryLimit)
queryResult = _repo.GetActivityLogEntries(minDate, request.StartIndex, request.Limit);
else
queryResult = _repo.GetActivityLogEntries(minDate, request.StartIndex, null);
//var queryResult = _activityManager.GetActivityLogEntries(minDate, request.StartIndex, request.Limit);
ReportActivitiesBuilder builder = new ReportActivitiesBuilder(_libraryManager, _userManager);
var result = builder.GetResult(queryResult, request);
result.TotalRecordCount = queryResult.TotalRecordCount;
return result;
}
/// <summary> Gets report result. </summary>
/// <param name="request"> The request. </param>
/// <returns> The report result. </returns>
private ReportResult GetReportResult(GetItemReport request, User user)
{
ReportBuilder reportBuilder = new ReportBuilder(_libraryManager);
QueryResult<BaseItem> queryResult = GetQueryResult(request, user);
ReportResult reportResult = reportBuilder.GetResult(queryResult.Items, request);
reportResult.TotalRecordCount = queryResult.TotalRecordCount;
return reportResult;
}
#endregion
}
}

View File

@ -1,3 +1,3 @@
using System.Reflection;
[assembly: AssemblyVersion("3.2.30.22")]
[assembly: AssemblyVersion("3.2.30.23")]