From 7dae0069d65883d8b2a5ba635991354eb395b7c6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 11:32:11 -0400 Subject: [PATCH] added new image params & GameSystem constants --- MediaBrowser.Api/Images/ImageRequest.cs | 8 ++-- MediaBrowser.Api/Images/ImageWriter.cs | 2 +- .../Drawing/ImageProcessingOptions.cs | 4 +- MediaBrowser.Controller/LiveTv/ChannelInfo.cs | 9 +++- .../MediaBrowser.Model.Portable.csproj | 9 ++-- .../MediaBrowser.Model.net35.csproj | 9 ++-- MediaBrowser.Model/Drawing/ImageOverlay.cs | 18 ------- MediaBrowser.Model/Dto/ImageOptions.cs | 27 ++++++++++- MediaBrowser.Model/Games/GameSystem.cs | 48 +++++++++++++++++++ MediaBrowser.Model/LiveTv/ChannelInfoDto.cs | 6 +++ MediaBrowser.Model/LiveTv/ChannelType.cs | 19 ++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 3 +- .../Drawing/ImageProcessor.cs | 33 ++++++++----- .../Drawing/PercentPlayedDrawer.cs | 6 +-- .../Drawing/WatchedIndicatorDrawer.cs | 5 +- .../LiveTv/LiveTvManager.cs | 3 +- 16 files changed, 155 insertions(+), 54 deletions(-) delete mode 100644 MediaBrowser.Model/Drawing/ImageOverlay.cs create mode 100644 MediaBrowser.Model/Games/GameSystem.cs create mode 100644 MediaBrowser.Model/LiveTv/ChannelType.cs diff --git a/MediaBrowser.Api/Images/ImageRequest.cs b/MediaBrowser.Api/Images/ImageRequest.cs index 210ee5b64e..288fd9ea63 100644 --- a/MediaBrowser.Api/Images/ImageRequest.cs +++ b/MediaBrowser.Api/Images/ImageRequest.cs @@ -56,11 +56,11 @@ namespace MediaBrowser.Api.Images [ApiMember(Name = "Format", Description = "Determines the output foramt of the image - original,gif,jpg,png", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public ImageOutputFormat Format { get; set; } - [ApiMember(Name = "Indicator", Description = "Determines what overlay to render, if any. none, watched.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public ImageOverlay? Indicator { get; set; } + [ApiMember(Name = "AddPlayedIndicator", Description = "Optional. Add a played indicator", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool AddPlayedIndicator { get; set; } - [ApiMember(Name = "PercentPlayed", Description = "Percent to render for the percent played overlay", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public int PercentPlayed { get; set; } + [ApiMember(Name = "PercentPlayed", Description = "Optional percent to render for the percent played overlay", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public int? PercentPlayed { get; set; } [ApiMember(Name = "BackgroundColor", Description = "Optional. Apply a background color for transparent images.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string BackgroundColor { get; set; } diff --git a/MediaBrowser.Api/Images/ImageWriter.cs b/MediaBrowser.Api/Images/ImageWriter.cs index 190d2ba473..4c61b68024 100644 --- a/MediaBrowser.Api/Images/ImageWriter.cs +++ b/MediaBrowser.Api/Images/ImageWriter.cs @@ -90,7 +90,7 @@ namespace MediaBrowser.Api.Images Quality = Request.Quality, Width = Request.Width, OutputFormat = Request.Format, - Indicator = Request.Indicator, + AddPlayedIndicator = Request.AddPlayedIndicator, PercentPlayed = Request.PercentPlayed, BackgroundColor = Request.BackgroundColor }; diff --git a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs index 5910601248..76a079c577 100644 --- a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs +++ b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs @@ -35,9 +35,9 @@ namespace MediaBrowser.Controller.Drawing public ImageOutputFormat OutputFormat { get; set; } - public ImageOverlay? Indicator { get; set; } + public bool AddPlayedIndicator { get; set; } - public int PercentPlayed { get; set; } + public int? PercentPlayed { get; set; } public string BackgroundColor { get; set; } } diff --git a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs index 5f40134482..7ad1ec6c9b 100644 --- a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs @@ -1,4 +1,5 @@ - +using MediaBrowser.Model.LiveTv; + namespace MediaBrowser.Controller.LiveTv { /// @@ -17,5 +18,11 @@ namespace MediaBrowser.Controller.LiveTv /// /// The name of the service. public string ServiceName { get; set; } + + /// + /// Gets or sets the type of the channel. + /// + /// The type of the channel. + public ChannelType ChannelType { get; set; } } } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 56e9c3f8e3..60eacd91ce 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -86,9 +86,6 @@ Drawing\ImageOutputFormat.cs - - Drawing\ImageOverlay.cs - Dto\BaseItemDto.cs @@ -203,6 +200,9 @@ Extensions\ModelExtensions.cs + + Games\GameSystem.cs + Globalization\CountryInfo.cs @@ -218,6 +218,9 @@ LiveTv\ChannelInfoDto.cs + + LiveTv\ChannelType.cs + LiveTv\LiveTvServiceInfo.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 92abac5cff..70cd4533dc 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -70,9 +70,6 @@ Drawing\ImageOutputFormat.cs - - Drawing\ImageOverlay.cs - Dto\BaseItemDto.cs @@ -187,6 +184,9 @@ Extensions\ModelExtensions.cs + + Games\GameSystem.cs + Globalization\CountryInfo.cs @@ -202,6 +202,9 @@ LiveTv\ChannelInfoDto.cs + + LiveTv\ChannelType.cs + LiveTv\LiveTvServiceInfo.cs diff --git a/MediaBrowser.Model/Drawing/ImageOverlay.cs b/MediaBrowser.Model/Drawing/ImageOverlay.cs deleted file mode 100644 index 8ae53746be..0000000000 --- a/MediaBrowser.Model/Drawing/ImageOverlay.cs +++ /dev/null @@ -1,18 +0,0 @@ - -namespace MediaBrowser.Model.Drawing -{ - /// - /// Enum ImageOverlay - /// - public enum ImageOverlay - { - /// - /// The watched - /// - Played, - /// - /// The percent played - /// - PercentPlayed - } -} diff --git a/MediaBrowser.Model/Dto/ImageOptions.cs b/MediaBrowser.Model/Dto/ImageOptions.cs index c5c89b0b23..7fe162ff99 100644 --- a/MediaBrowser.Model/Dto/ImageOptions.cs +++ b/MediaBrowser.Model/Dto/ImageOptions.cs @@ -70,10 +70,33 @@ namespace MediaBrowser.Model.Dto /// true if [enable image enhancers]; otherwise, false. public bool EnableImageEnhancers { get; set; } + /// + /// Gets or sets the format. + /// + /// The format. public ImageOutputFormat Format { get; set; } - public ImageOverlay? Indicator { get; set; } - + /// + /// Gets or sets a value indicating whether [add played indicator]. + /// + /// true if [add played indicator]; otherwise, false. + public bool AddPlayedIndicator { get; set; } + + /// + /// Gets or sets the percent played. + /// + /// The percent played. + public int? PercentPlayed { get; set; } + + /// + /// Gets or sets the color of the background. + /// + /// The color of the background. + public string BackgroundColor { get; set; } + + /// + /// Initializes a new instance of the class. + /// public ImageOptions() { EnableImageEnhancers = true; diff --git a/MediaBrowser.Model/Games/GameSystem.cs b/MediaBrowser.Model/Games/GameSystem.cs new file mode 100644 index 0000000000..ab8f1efa75 --- /dev/null +++ b/MediaBrowser.Model/Games/GameSystem.cs @@ -0,0 +1,48 @@ + +namespace MediaBrowser.Model.Games +{ + public class GameSystem + { + public const string Nintendo = "Nintendo"; + public const string SuperNintendo = "Super Nintendo"; + public const string Panasonic3DO = "3DO"; + public const string Amiga = "Amiga"; + public const string Arcade = "Arcade"; + public const string Atari2600 = "Atari 2600"; + public const string Atari5200 = "Atari 5200"; + public const string Atari7800 = "Atari 7800"; + public const string AtariXE = "Atari XE"; + public const string AtariJaguar = "Atari Jaguar"; + public const string AtariJaguarCD = "Atari Jaguar CD"; + public const string Colecovision = "Colecovision"; + public const string Commodore64 = "Commodore 64"; + public const string CommodoreVic20 = "Commodore Vic-20"; + public const string Intellivision = "Intellivision"; + public const string MicrosoftXBox = "Xbox"; + public const string NeoGeo = "Neo Geo"; + public const string Nintendo64 = "Nintendo 64"; + public const string NintendoDS = "Nintendo DS"; + public const string NintendoGameBoy = "Game Boy"; + public const string NintendoGameBoyAdvance = "Game Boy Advance"; + public const string NintendoGameBoyColor = "Game Boy Color"; + public const string NintendoGameCube = "Gamecube"; + public const string VirtualBoy = "Virtual Boy"; + public const string Wii = "Nintendo Wii"; + public const string DOS = "DOS"; + public const string Windows = "Windows"; + public const string Sega32X = "Sega 32X"; + public const string SegaCD = "Sega CD"; + public const string SegaDreamcast = "Dreamcast"; + public const string SegaGameGear = "Game Gear"; + public const string SegaGenesis = "Sega Genesis"; + public const string SegaMasterSystem = "Sega Master System"; + public const string SegaMegaDrive = "Sega Mega Drive"; + public const string SegaSaturn = "Sega Saturn"; + public const string SonyPlaystation = "Sony Playstation"; + public const string SonyPlaystation2 = "PS2"; + public const string SonyPSP = "PSP"; + public const string TurboGrafx16 = "TurboGrafx 16"; + public const string TurboGrafxCD = "TurboGrafx CD"; + public const string ZxSpectrum = "ZX Spectrum"; + } +} diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs index 5150897c3d..c77d7ed127 100644 --- a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs @@ -17,5 +17,11 @@ namespace MediaBrowser.Model.LiveTv /// /// The name of the service. public string ServiceName { get; set; } + + /// + /// Gets or sets the type of the channel. + /// + /// The type of the channel. + public ChannelType ChannelType { get; set; } } } diff --git a/MediaBrowser.Model/LiveTv/ChannelType.cs b/MediaBrowser.Model/LiveTv/ChannelType.cs new file mode 100644 index 0000000000..bca16f8396 --- /dev/null +++ b/MediaBrowser.Model/LiveTv/ChannelType.cs @@ -0,0 +1,19 @@ + +namespace MediaBrowser.Model.LiveTv +{ + /// + /// Enum ChannelType + /// + public enum ChannelType + { + /// + /// The TV + /// + TV, + + /// + /// The radio + /// + Radio + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index b317dbf0ee..1ee9b97a2e 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -48,7 +48,6 @@ - @@ -63,10 +62,12 @@ + + diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs index 7a16747fbe..d073521496 100644 --- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs +++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs @@ -109,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Drawing var quality = options.Quality ?? 90; - var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.Indicator, options.PercentPlayed, options.BackgroundColor); + var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.BackgroundColor); try { @@ -180,7 +180,7 @@ namespace MediaBrowser.Server.Implementations.Drawing thumbnailGraph.DrawImage(originalImage, 0, 0, newWidth, newHeight); - DrawIndicator(thumbnailGraph, newWidth, newHeight, options.Indicator, options.PercentPlayed); + DrawIndicator(thumbnailGraph, newWidth, newHeight, options); var outputFormat = GetOutputFormat(originalImage, options.OutputFormat); @@ -277,28 +277,31 @@ namespace MediaBrowser.Server.Implementations.Drawing /// The graphics. /// Width of the image. /// Height of the image. - /// The indicator. - /// The percent played. - private void DrawIndicator(Graphics graphics, int imageWidth, int imageHeight, ImageOverlay? indicator, int percentPlayed) + /// The options. + private void DrawIndicator(Graphics graphics, int imageWidth, int imageHeight, ImageProcessingOptions options) { - if (!indicator.HasValue) + if (!options.AddPlayedIndicator && !options.PercentPlayed.HasValue) { return; } try { - if (indicator.Value == ImageOverlay.Played) + var percentOffset = 0; + + if (options.AddPlayedIndicator) { var currentImageSize = new Size(imageWidth, imageHeight); new WatchedIndicatorDrawer().Process(graphics, currentImageSize); + + percentOffset = 0 - WatchedIndicatorDrawer.IndicatorWidth; } - if (indicator.Value == ImageOverlay.PercentPlayed) + if (options.PercentPlayed.HasValue) { var currentImageSize = new Size(imageWidth, imageHeight); - new PercentPlayedDrawer().Process(graphics, currentImageSize, percentPlayed); + new PercentPlayedDrawer().Process(graphics, currentImageSize, options.PercentPlayed.Value, percentOffset); } } catch (Exception ex) @@ -400,7 +403,7 @@ namespace MediaBrowser.Server.Implementations.Drawing /// /// Gets the cache file path based on a set of parameters /// - private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, ImageOverlay? overlay, int percentPlayed, string backgroundColor) + private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageOutputFormat format, bool addPlayedIndicator, int? percentPlayed, string backgroundColor) { var filename = originalPath; @@ -417,10 +420,14 @@ namespace MediaBrowser.Server.Implementations.Drawing filename += "f=" + format; } - if (overlay.HasValue) + if (addPlayedIndicator) { - filename += "o=" + overlay.Value; - filename += "p=" + percentPlayed; + filename += "pl=true"; + } + + if (percentPlayed.HasValue) + { + filename += "p=" + percentPlayed.Value; } if (!string.IsNullOrEmpty(backgroundColor)) diff --git a/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs b/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs index 3558244584..e2f5b6129c 100644 --- a/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs +++ b/MediaBrowser.Server.Implementations/Drawing/PercentPlayedDrawer.cs @@ -10,9 +10,9 @@ namespace MediaBrowser.Server.Implementations.Drawing private const int FontSize = 30; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public void Process(Graphics graphics, Size imageSize, int percent) + public void Process(Graphics graphics, Size imageSize, int percent, int rightOffset) { - var x = imageSize.Width - IndicatorWidth; + var x = imageSize.Width - IndicatorWidth + rightOffset; using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 102, 192, 16))) { @@ -20,7 +20,7 @@ namespace MediaBrowser.Server.Implementations.Drawing var text = string.Format("{0}%", percent.ToString(_usCulture)); - x = imageSize.Width - (percent < 10 ? 66 : 75); + x = imageSize.Width - (percent < 10 ? 66 : 75) + rightOffset; using (var font = new Font(FontFamily.GenericSansSerif, FontSize, FontStyle.Regular, GraphicsUnit.Pixel)) { diff --git a/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs b/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs index 921494dba6..c889db3044 100644 --- a/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs +++ b/MediaBrowser.Server.Implementations/Drawing/WatchedIndicatorDrawer.cs @@ -5,15 +5,16 @@ namespace MediaBrowser.Server.Implementations.Drawing public class WatchedIndicatorDrawer { private const int IndicatorHeight = 50; + public const int IndicatorWidth = 50; private const int FontSize = 50; public void Process(Graphics graphics, Size imageSize) { - var x = imageSize.Width - IndicatorHeight; + var x = imageSize.Width - IndicatorWidth; using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 204, 51, 51))) { - graphics.FillRectangle(backdroundBrush, x, 0, IndicatorHeight, IndicatorHeight); + graphics.FillRectangle(backdroundBrush, x, 0, IndicatorWidth, IndicatorHeight); const string text = "a"; diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 87b02816f7..34be46d726 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -38,7 +38,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv return new ChannelInfoDto { Name = info.Name, - ServiceName = info.ServiceName + ServiceName = info.ServiceName, + ChannelType = info.ChannelType }; } }