First Commit

This commit is contained in:
Mister Rajoy
2020-11-08 02:19:22 +01:00
parent 41c13bb80c
commit 09b3c26df0
11 changed files with 842 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using System;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Branding;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Api;
namespace Jellyfin.Plugin.Css.Api
{
[Route("/Css/Set", "POST", Summary = "Downloads theme songs")]
[Authenticated]
public class DownloadRequest : IReturnVoid
{
public string css {get;set;}
}
public class cssService : IService
{
private readonly CssManager _themeSongsManager;
private readonly ILogger<BrandingService> _logger;
public cssService(
ILogger<BrandingService> logger, IServerConfigurationManager serverConfigurationManager, IHttpResultFactory httpResultFactory)
{
_themeSongsManager = new CssManager(logger, serverConfigurationManager, httpResultFactory);
_logger = logger;
}
public void Post(DownloadRequest request)
{
_logger.LogInformation(request.css + "Will be setted");
_themeSongsManager.setCss();
_logger.LogInformation("Completed");
}
}
}

View File

@@ -0,0 +1,14 @@
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.Css.Configuration
{
public class PluginConfiguration : BasePluginConfiguration
{
public string selectedCss { get; set; }
public PluginConfiguration()
{
selectedCss = "";
}
}
}

View File

@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html>
<head>
<title>Css</title>
</head>
<body>
<div data-role="page" class="page type-interior pluginConfigurationPage tbsConfigurationPage"
data-require="emby-input,emby-button">
<div data-role="content">
<div class="content-primary">
<form class="tbsConfigurationPage">
<div class="sectionTitleContainer flex align-items-center">
<h2 class="sectionTitle">Theme Songs</h2>
<a is="emby-linkbutton" class="raised button-alt headerHelpButton emby-button" target="_blank"
href="https://github.com/danieladov/jellyfin-plugin-themesongs">Help</a>
</div>
<div class="verticalSection">
<p>
This plugin relies on the TVDB provider
Please make sure it is enabled!
</p>
<br />
</div>
<div class="selectContainer">
<label for="css">css</label>
<select is="emby-select" id="cssOptions">
<!--<option value='@import url("https://prayag17.github.io/JellyFlix/default.css");'>Netflix</option>
<option value='@import url("https://ctalvio.github.io/Kaleidochromic/default_style.css");'>otra</option>-->
</select>
<br />
<button is="emby-button" type="button" class="raised block" id="refresh-library"
onclick=setSkin()>
<span>Set Skin</span>
</button>
<div>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
<span>Save</span>
</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
function setSkin() {
var request = {
url: ApiClient.getUrl('/Css/Set'),
type: 'POST'
};
ApiClient.getPluginConfiguration(plugin.guid).then(function (config) {
config.selectedCss = $('#cssOptions').val();
ApiClient.updatePluginConfiguration(plugin.guid, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
Dashboard.alert("Changing skin...");
ApiClient.fetch(request).then(function () {
window.location.reload(true);
}).catch(function () {
Dashboard.alert({
message: "Unexpected error occurred!"
});
});
});
});
}
</script>
<script type="text/javascript">
var plugin = {
guid: 'e9ca8b8e-ca6d-40e7-85dc-58e536df8eb3'
};
$('#configPage').on('pageshow', function () {
Dashboard.showLoadingMsg();
loadSavedConfig();
ApiClient.getPluginConfiguration(plugin.guid).then(function (config) {
$('#cssOptions').val(config.selectedCss).change();
Dashboard.hideLoadingMsg();
});
});
$('#configForm').on('submit', function () {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(plugin.guid).then(function (config) {
config.selectedCss = $('#cssOptions').val();
ApiClient.updatePluginConfiguration(plugin.guid, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
});
return false;
});
function loadSavedConfig(){
ApiClient.getPluginConfiguration(plugin.guid).then(function (config) {
var obj = getParsedJson();
var count = 0;
obj.forEach(element => {
if(element.css == config.selectedCss){
document.getElementById("cssOptions").selectIndex=count;
}else{
count ++;
}
});
});
}
function getParsedJson(){
return JSON.parse('[{"name":"Netflix","author":"prayagprajapati17","css": "@import url(\\"https://prayag17.github.io/JellyFlix/default.css\\");"},{"name":"Kaleidochromic","author":"EdgeMentality","css": "@import url(\\"https://ctalvio.github.io/Kaleidochromic/default_style.css\\");"}]');
}
</script>
<script>
var cssOptions = document.getElementById("cssOptions");
var obj = getParsedJson();
obj.forEach(element => {
var opt = document.createElement("option");
opt.appendChild(document.createTextNode(element.name));
opt.value=element.css;
cssOptions.appendChild(opt);
});
</script>
</div>
</body>
</html>

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Branding;
using MediaBrowser.Api;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
namespace Jellyfin.Plugin.Css
{
public class CssManager : IServerEntryPoint
{
private readonly Timer _timer;
private readonly BrandingOptions _branding;
private readonly ILogger<BrandingService> _logger;
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly IHttpResultFactory _httpResultFactory;
private readonly BrandingOptions brandingOptions;
public CssManager(ILogger<BrandingService> logger, IServerConfigurationManager serverConfigurationManager, IHttpResultFactory httpResultFactory)
{
_logger = logger;
_timer = new Timer(_ => OnTimerElapsed(), null, Timeout.Infinite, Timeout.Infinite);
_serverConfigurationManager = serverConfigurationManager;
_httpResultFactory = httpResultFactory;
BrandingService brandingService = new BrandingService(_logger, _serverConfigurationManager, _httpResultFactory);
brandingOptions = (BrandingOptions) brandingService.Get(new GetBrandingOptions());
}
public void setCss()
{
string css = Plugin.Instance.Configuration.selectedCss;
brandingOptions.CustomCss = css;
}
public void removeCss()
{
brandingOptions.CustomCss = "";
}
private void OnTimerElapsed()
{
// Stop the timer until next update
_timer.Change(Timeout.Infinite, Timeout.Infinite);
}
public Task RunAsync()
{
return Task.CompletedTask;
}
public void Dispose()
{
}
}
}

View File

@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<IsPackable>true</IsPackable>
<AssemblyVersion>1.3.0</AssemblyVersion>
<FileVersion>1.3.0</FileVersion>
<Authors />
<Company />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jellyfin.Controller" Version="10.6.0" />
</ItemGroup>
<ItemGroup>
<None Remove="Configuration\configurationpage.html" />
<EmbeddedResource Include="Configuration\configurationpage.html" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Reference Include="MediaBrowser.Api">
<HintPath>..\..\..\..\..\..\Program Files\Jellyfin\Server\MediaBrowser.Api.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using Jellyfin.Plugin.Css.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.Css
{
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
public Plugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer)
: base(appPaths, xmlSerializer)
{
Instance = this;
}
public override string Name => "Css";
public static Plugin Instance { get; private set; }
public override string Description
=> "Css";
private readonly Guid _id = new Guid("e9ca8b8e-ca6d-40e7-85dc-58e536df8eb3");
public override Guid Id => _id;
public IEnumerable<PluginPageInfo> GetPages()
{
return new[]
{
new PluginPageInfo
{
Name = "Css",
EmbeddedResourcePath = GetType().Namespace + ".Configuration.configurationpage.html"
}
};
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Branding;
using MediaBrowser.Api;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
namespace Jellyfin.Plugin.Css.ScheduledTasks
{
public class SetCssTask : IScheduledTask
{
private readonly CssManager _themeSongsManager;
private readonly ILogger<BrandingService> _logger;
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly IHttpResultFactory _httpResultFactory;
private readonly BrandingOptions _branding;
public SetCssTask(ILogger<BrandingService> logger, IServerConfigurationManager serverConfigurationManager, IHttpResultFactory httpResultFactory)
{
_serverConfigurationManager = serverConfigurationManager;
_httpResultFactory = httpResultFactory;
_themeSongsManager = new CssManager(logger,serverConfigurationManager,httpResultFactory);
}
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
_logger.LogInformation("Starting plugin, Setting css");
_themeSongsManager.setCss();
_logger.LogInformation("Done");
return Task.CompletedTask;
}
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Run this task every 24 hours
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval,
IntervalTicks = TimeSpan.FromHours(24).Ticks
};
}
public string Name => "SetCss";
public string Key => "css";
public string Description => "Scans all libraries to download Theme Songs";
public string Category => "css";
}
public class RemoveCss : IScheduledTask
{
private readonly CssManager _themeSongsManager;
private readonly ILogger<BrandingService> _logger;
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly IHttpResultFactory _httpResultFactory;
private readonly BrandingOptions _branding;
public RemoveCss(ILogger<BrandingService> logger, BrandingOptions branding, IServerConfigurationManager serverConfigurationManager, IHttpResultFactory httpResultFactory)
{
// _logger = logger;
//_themeSongsManager = new CssManager(logger, branding);
}
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
_logger.LogInformation("Starting plugin, Downloading Theme Songs...");
_themeSongsManager.removeCss();
_logger.LogInformation("All theme songs downloaded");
return Task.CompletedTask;
}
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Run this task every 24 hours
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval,
IntervalTicks = TimeSpan.FromHours(24).Ticks
};
}
public string Name => "Css2";
public string Key => "removeCss";
public string Description => "Scans all libraries to download Movies Theme Songs";
public string Category => "Css";
}
}