From abd5a4889e6e0239968eebc99b5840473b0ba410 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 2 Aug 2017 14:29:11 +0100 Subject: [PATCH] #1458 #865 More work on landing --- src/Build/publish windows.bat | 6 -- src/Build/publish.bat | 9 --- .../landingpage/landingpage.component.html | 32 +++++++--- .../app/landingpage/landingpage.component.ts | 2 +- src/Ombi/Config/LandingPageBackground.cs | 10 +++ src/Ombi/Controllers/ImagesController.cs | 63 ++++++++++++++----- src/Ombi/Program.cs | 4 +- src/Ombi/Startup.cs | 1 + src/Ombi/appsettings.json | 19 ++++++ 9 files changed, 104 insertions(+), 42 deletions(-) delete mode 100644 src/Build/publish windows.bat delete mode 100644 src/Build/publish.bat create mode 100644 src/Ombi/Config/LandingPageBackground.cs diff --git a/src/Build/publish windows.bat b/src/Build/publish windows.bat deleted file mode 100644 index f984ee1ba..000000000 --- a/src/Build/publish windows.bat +++ /dev/null @@ -1,6 +0,0 @@ -;https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/ -cd .. -dotnet restore -dotnet publish -c Release /p:AppRuntimeIdentifier=win10-x64 - -exit \ No newline at end of file diff --git a/src/Build/publish.bat b/src/Build/publish.bat deleted file mode 100644 index e9af4b38c..000000000 --- a/src/Build/publish.bat +++ /dev/null @@ -1,9 +0,0 @@ -;https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/ -cd .. -dotnet restore -dotnet publish -c Release /p:AppRuntimeIdentifier=win10-x64 -dotnet publish -c Release /p:AppRuntimeIdentifier=osx.10.12-x64 -dotnet publish -c Release /p:AppRuntimeIdentifier=ubuntu.16.10-x64 -dotnet publish -c Release /p:AppRuntimeIdentifier=debian.8-x64 - -exit \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html index deb35032e..b14b36abd 100644 --- a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html +++ b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html @@ -1,12 +1,22 @@ 
- + + + +
+

Notice

+
diff --git a/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts b/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts index d12de8cdd..5bf482bb8 100644 --- a/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts +++ b/src/Ombi/ClientApp/app/landingpage/landingpage.component.ts @@ -29,7 +29,7 @@ export class LandingPageComponent implements OnInit { this.settingsService.getLandingPage().subscribe(x => this.landingPageSettings = x); this.requestService.getRequestsCount().subscribe(x => this.requestCount = x); this.images.getRandomBackground().subscribe(x => { - this.background = this.sanitizer.bypassSecurityTrustStyle('url(' + x.url + ')'); + this.background = this.sanitizer.bypassSecurityTrustStyle('linear-gradient(-10deg, transparent 20%, rgba(0,0,0,0.3) 20.1%, rgba(0,0,0,0.3) 80.1%, transparent 80%), url(' + x.url + ')'); }); this.mediaServerStatus = true; diff --git a/src/Ombi/Config/LandingPageBackground.cs b/src/Ombi/Config/LandingPageBackground.cs new file mode 100644 index 000000000..869772c41 --- /dev/null +++ b/src/Ombi/Config/LandingPageBackground.cs @@ -0,0 +1,10 @@ +namespace Ombi.Config +{ + public class LandingPageBackground + { + public int[] Movies { get; set; } + public int[] TvShows { get; set; } + } + + +} \ No newline at end of file diff --git a/src/Ombi/Controllers/ImagesController.cs b/src/Ombi/Controllers/ImagesController.cs index d0ec27de9..f1e35ae9f 100644 --- a/src/Ombi/Controllers/ImagesController.cs +++ b/src/Ombi/Controllers/ImagesController.cs @@ -5,43 +5,74 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Ombi.Config; namespace Ombi.Controllers { [ApiV1] public class ImagesController : Controller { - public ImagesController(IFanartTvApi api, IApplicationConfigRepository config) + public ImagesController(IFanartTvApi api, IApplicationConfigRepository config, IOptions options) { Api = api; Config = config; + Options = options.Value; } private IFanartTvApi Api { get; } private IApplicationConfigRepository Config { get; } + private LandingPageBackground Options { get; } [HttpGet("background")] public async Task GetBackgroundImage() { - var moviesArray = new[]{ - 278, - 238, - 431483, - 372058, - 244786, - 680, - 155, - 13, - 1891, - 399106 - }; + var moviesArray = Options.Movies; + var tvArray = Options.TvShows; - var key = await Config.Get(Store.Entities.ConfigurationTypes.FanartTv); + var rand = new Random(); + var movieUrl = string.Empty; + var tvUrl = string.Empty; - var result = await Api.GetMovieImages(155, key.Value); + if (moviesArray.Any()) + { + var item = rand.Next(moviesArray.Length); + var key = await Config.Get(Store.Entities.ConfigurationTypes.FanartTv); + var result = await Api.GetMovieImages(moviesArray[item], key.Value); - return new { url = result.moviebackground[0].url }; + while (!result.moviebackground.Any()) + { + result = await Api.GetMovieImages(moviesArray[item], key.Value); + } + movieUrl = result.moviebackground[0].url; + } + if(tvArray.Any()) + { + var item = rand.Next(tvArray.Length); + var key = await Config.Get(Store.Entities.ConfigurationTypes.FanartTv); + var result = await Api.GetTvImages(tvArray[item], key.Value); + + while (!result.showbackground.Any()) + { + result = await Api.GetTvImages(tvArray[item], key.Value); + } + + tvUrl = result.showbackground[0].url; + } + + if (!string.IsNullOrEmpty(movieUrl) && !string.IsNullOrEmpty(tvUrl)) + { + var result = rand.Next(2); + if (result == 0) return new { url = movieUrl }; + if (result == 1) return new { url = tvUrl }; + } + + if (!string.IsNullOrEmpty(movieUrl)) + { + return new { url = movieUrl }; + } + return new { url = tvUrl }; } } } diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index d0ba609ff..6c5a3f737 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -14,7 +14,7 @@ namespace Ombi public static void Main(string[] args) { Console.Title = "Ombi"; - var options = new Options(); + int port = 0; string host = string.Empty; Parser.Default.ParseArguments(args) @@ -86,7 +86,7 @@ namespace Ombi [Option('h', "host", Required = false, HelpText = "The Hostname default is http://*", Default ="http://*")] public string Host { get; set; } - [Option('p', "port", Required = false, HelpText = "The port, default is 5000", Default =5000)] + [Option('p', "port", Required = false, HelpText = "The port, default is 5000", Default = 5000)] public int Port { get; set; } } } diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index fa2100924..246b91f58 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -155,6 +155,7 @@ namespace Ombi //services.Configure(Configuration.GetSection("TokenAuthentication")); services.Configure(Configuration.GetSection("ApplicationSettings")); services.Configure(Configuration.GetSection("UserSettings")); + services.Configure(Configuration.GetSection("LandingPageBackground")); services.AddHangfire(x => { diff --git a/src/Ombi/appsettings.json b/src/Ombi/appsettings.json index 14aaf8125..c0aa63206 100644 --- a/src/Ombi/appsettings.json +++ b/src/Ombi/appsettings.json @@ -21,5 +21,24 @@ "Audience": "OmbiAudience", "TokenPath": "/api/v1/token/", "CookieName": "access_token" + }, + "LandingPageBackground": { + "Movies": [ + 278, + 244786, + 680, + 155, + 13, + 1891, + 399106 + ], + "TvShows": [ + 121361, + 74205, + 81189, + 79126, + 79349, + 275274 + ] } }