diff options
Diffstat (limited to 'MediaBrowser.Api/Reports/Common')
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/HeaderMetadata.cs | 47 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ItemViewType.cs | 20 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs | 229 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportExportType.cs | 12 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportFieldType.cs | 19 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportHeaderIdType.cs | 12 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportHelper.cs | 101 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/Common/ReportViewType.cs | 25 |
8 files changed, 465 insertions, 0 deletions
diff --git a/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs b/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs new file mode 100644 index 000000000..3cb8f722d --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/HeaderMetadata.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +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, + StatusImage, + Tracks, + EpisodeSeries, + EpisodeSeason, + AudioAlbumArtist, + MusicArtist, + AudioAlbum, + Status + } +} diff --git a/MediaBrowser.Api/Reports/Common/ItemViewType.cs b/MediaBrowser.Api/Reports/Common/ItemViewType.cs new file mode 100644 index 000000000..3e09a290d --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ItemViewType.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ItemViewType + { + None, + Detail, + Edit, + List, + ItemByNameDetails, + StatusImage, + EmbeddedImage, + SubtitleImage, + TrailersImage, + SpecialsImage + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs b/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs new file mode 100644 index 000000000..af6dc997c --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportBuilderBase.cs @@ -0,0 +1,229 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +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; +using System.Text; +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) + 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; + } + + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportExportType.cs b/MediaBrowser.Api/Reports/Common/ReportExportType.cs new file mode 100644 index 000000000..05f27f72e --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportExportType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ReportExportType + { + CSV, + Excel + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportFieldType.cs b/MediaBrowser.Api/Reports/Common/ReportFieldType.cs new file mode 100644 index 000000000..58523657a --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportFieldType.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ReportFieldType + { + String, + Boolean, + Date, + Time, + DateTime, + Int, + Image, + Object, + Minutes + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportHeaderIdType.cs b/MediaBrowser.Api/Reports/Common/ReportHeaderIdType.cs new file mode 100644 index 000000000..58c118151 --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportHeaderIdType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ReportHeaderIdType + { + Row, + Item + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportHelper.cs b/MediaBrowser.Api/Reports/Common/ReportHelper.cs new file mode 100644 index 000000000..a557248c6 --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportHelper.cs @@ -0,0 +1,101 @@ +using MediaBrowser.Controller.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +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); + 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(); + } + } + } +} diff --git a/MediaBrowser.Api/Reports/Common/ReportViewType.cs b/MediaBrowser.Api/Reports/Common/ReportViewType.cs new file mode 100644 index 000000000..efdfcb0e7 --- /dev/null +++ b/MediaBrowser.Api/Reports/Common/ReportViewType.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.Api.Reports +{ + public enum ReportViewType + { + MusicArtist, + MusicAlbum, + Book, + BoxSet, + Episode, + Game, + Video, + Movie, + MusicVideo, + Trailer, + Season, + Series, + Audio, + BaseItem, + Artist + } +} |
