Skip to content

Commit

Permalink
Fixed MovieOrganizer
Browse files Browse the repository at this point in the history
  • Loading branch information
softworkz committed Nov 24, 2016
1 parent 8978d94 commit ea551c2
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 89 deletions.
69 changes: 69 additions & 0 deletions MovieOrganizer/Html/StaticFileServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Services;
using System.IO;
using System;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;

namespace MovieOrganizer.Html
{
[Route("/web/components/fileorganizer/fileorganizer.js", "GET")]
[Route("/web/components/fileorganizer/fileorganizer.template.html", "GET")]
public class GetStaticResource
{
}

public class StaticFileServer : IService, IRequiresRequest
{
private readonly ILogger _logger;

/// <summary>
/// Gets or sets the HTTP result factory.
/// </summary>
/// <value>The HTTP result factory.</value>
private readonly IHttpResultFactory _resultFactory;

/// <summary>
/// Gets or sets the request context.
/// </summary>
/// <value>The request context.</value>
public IRequest Request { get; set; }

public StaticFileServer(ILogManager logManager, IHttpResultFactory resultFactory)
{
_logger = logManager.GetLogger(GetType().Name);
_resultFactory = resultFactory;
}

/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public async Task<object> Get(GetStaticResource request)
{
var path = Request.PathInfo;

var contentType = MimeTypes.GetMimeType(path);

MemoryStream resultStream = null;

if (path.Contains("/components/fileorganizer/fileorganizer.js"))
{
resultStream = HtmlHelper.OrganizerScript;
}
else if (path.Contains("/components/fileorganizer/fileorganizer.template.html"))
{
resultStream = HtmlHelper.OrganizerTemplate;
}

if (resultStream != null)
{
resultStream = new MemoryStream(resultStream.GetBuffer());
}

return _resultFactory.GetResult(resultStream, contentType);
}
}
}
32 changes: 12 additions & 20 deletions MovieOrganizer/Html/fileorganizer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['dialogHelper', 'require', 'emby-checkbox', 'emby-input', 'emby-button', 'emby-select', 'formDialogStyle'], function (dialogHelper, require) {
define(['dialogHelper', 'require', 'emby-checkbox', 'emby-input', 'emby-button', 'emby-select', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, require) {

var extractedName;
var extractedYear;
Expand Down Expand Up @@ -137,10 +137,10 @@
var resultId = dlg.querySelector('#hfResultId').value;
var seriesId = dlg.querySelector('#selectSeries').value;

var targetFolder;
var newProviderIds;
var newSeriesName;
var newSeriesYear;
var targetFolder = null;
var newProviderIds = null;
var newSeriesName = null;
var newSeriesYear = null;

if (seriesId == "##NEW##" && currentNewItem != null) {
seriesId = null;
Expand Down Expand Up @@ -296,17 +296,15 @@
}
}

function selectTab(dlg, tabIndex) {
function selectType(dlg) {

if (tabIndex == 0) {
dlg.querySelector('#episode').classList.add('ui-btn-active');
dlg.querySelector('#movie').classList.remove('ui-btn-active');
var type = dlg.querySelector('#selectContentType').value;

if (type == 'episode') {
dlg.querySelector('#organizeSeries').classList.remove('hide');
dlg.querySelector('#organizeMovies').classList.add('hide');
}
else {
dlg.querySelector('#episode').classList.remove('ui-btn-active');
dlg.querySelector('#movie').classList.add('ui-btn-active');
dlg.querySelector('#organizeSeries').classList.add('hide');
dlg.querySelector('#organizeMovies').classList.remove('hide');
}
Expand Down Expand Up @@ -343,7 +341,6 @@
html += Globalize.translateDocument(template);

dlg.innerHTML = html;
document.body.appendChild(dlg);

dlg.querySelector('.formDialogHeaderTitle').innerHTML = Globalize.translate('FileOrganizeManually');

Expand Down Expand Up @@ -394,17 +391,12 @@
selectedSeriesChanged(dlg);
});

dlg.querySelector('#episode').addEventListener('click', function (e) {

selectTab(dlg, 0);
});

dlg.querySelector('#movie').addEventListener('click', function (e) {
dlg.querySelector('#selectContentType').addEventListener('change', function (e) {

selectTab(dlg, 1);
selectType(dlg);
});

selectTab(dlg, 0);
dlg.querySelector('#selectContentType').value = 'episode';

initForms(dlg, item);
};
Expand Down
54 changes: 31 additions & 23 deletions MovieOrganizer/Html/fileorganizer.template.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<div class="formDialogHeader">
<button is="emby-button" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>
<div class="formDialogHeaderTitle">
</div>
<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>
<h3 class="formDialogHeaderTitle"></h3>
</div>

<div class="formDialogContent smoothScrollY">
<div class="dialog-content-centered">
<div id="tabcontainer" class="readOnlyContent" style="margin:auto;">
<div data-role="controlgroup" data-type="horizontal" class="localnav" data-mini="true" style="margin-top: 1em">
<a id="episode" href="#" data-role="button" class="ui-btn-active">Series Episode</a>
<a id="movie" href="#" data-role="button">Organize Movie</a>
</div>
<div class="formDialogContent smoothScrollY" style="padding-top: 2em;">
<div class="dialogContentInner dialog-content-centered">
<div id="typeContainer" style="margin:auto;">
<h3 class="selectContainer fldSelectContentType">
<select is="emby-select" id="selectContentType" label="Organize Content Type" required>
<option value="episode" selected>Series Episode</option>
<option value="movie">Movie</option>
</select>
</h3>
</div>

<form id="organizeSeries" class="episodeCorrectionForm" style="margin:auto;">

<p><b>Filename:</b> <span class="inputFile"></span></p>
<p class="paraInputSeriesName"><b>Extracted Series Name:</b> <span class="inputSeriesName"></span></p>
<p class="paraInputYear"><b>Extracted Year::</b> <span class="inputYear"></span></p>
<p><span class="fieldDescription">Filename:</span> <span class="inputFile"></span></p>
<p class="paraInputSeriesName"><span class="fieldDescription">Extracted Series Name:</span> <span class="inputSeriesName"></span></p>
<p class="paraInputYear"><span class="fieldDescription">Extracted Year:</span> <span class="inputYear"></span></p>

<div class="selectContainer" style="margin: 2em 0 1em;">
<div style="margin: 2em 0 0;">
<div style="display:flex; align-items:center;">
<div style="flex-grow:1;">
<select is="emby-select" id="selectSeries" label="${LabelSeries}" required></select>
<select is="emby-select" id="selectSeries" label="${LabelSeries}" required style="margin-bottom: 0;"></select>
</div>
<button type="button" is="emby-button" id="btnNewSeries" class="autoSize" title="${ButtonNew}"><i class="md-icon">add</i></button>
<button type="button" is="emby-button" id="btnNewSeries" class="raised btnNewSeries submit mini" title="${ButtonNew}" style="margin-left:1em; margin-bottom: 1em;">
<i class="md-icon">add</i>
<span>${ButtonNew}</span>
</button>
</div>
</div>
<div class="selectContainer fldSelectSeriesFolder hide">
Expand Down Expand Up @@ -52,19 +56,23 @@
<span>${OptionRememberOrganizeCorrection} <span class="extractedName" style="font-weight: bold; font-style: italic" /></span>
</label>
</div>

<br />
<button is="emby-button" type="submit" class="raised submit block">
<i class="md-icon">check</i>
<span>${ButtonOk}</span>
</button>
<input id="hfResultId" type="hidden" />

<div class="formDialogFooter">
<button is="emby-button" type="submit" class="raised button-submit block formDialogFooterItem">
<span>${ButtonOk}</span>
</button>
</div>

</form>

<form class="organizeMovieForm hide" id="organizeMovies" style="margin:auto;">

<p><b>Filename:</b><br /><span class="inputFile2"></span></p>
<p class="paraInputSeriesName2"><b>Extracted Name:</b><br /><span class="inputSeriesName2"></span></p>
<p class="paraInputYear2"><b>Extracted Year::</b><br /><span class="inputYear2"></span></p>
<p><span class="fieldDescription">Filename:</span> <span class="inputFile2"></span></p>
<p class="paraInputSeriesName2"><span class="fieldDescription">Extracted Series Name:</span> <span class="inputSeriesName2"></span></p>
<p class="paraInputYear2"><span class="fieldDescription">Extracted Year:</span> <span class="inputYear2"></span></p>

<div style="margin: 2em 0 1em;">
<button is="emby-button" type="button" class="raised block" id="btnIdentifyMovie">
Expand Down
1 change: 1 addition & 0 deletions MovieOrganizer/MovieOrganizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Api\MovieOrganizerApi.cs" />
<Compile Include="Configuration\PluginConfiguration.cs" />
<Compile Include="HtmlHelper.cs" />
<Compile Include="Html\StaticFileServer.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerEntryPoint.cs" />
Expand Down
8 changes: 6 additions & 2 deletions MovieOrganizer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public Plugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer)
{
Instance = this;
_appPaths = appPaths;
HtmlHelper.InstallFiles(_appPaths, PluginConfiguration);
}

public override string Name
Expand Down Expand Up @@ -42,7 +41,12 @@ public override void OnUninstalling()
}

public static Plugin Instance { get; private set; }


public IApplicationPaths AppPaths
{
get { return _appPaths; }
}

public PluginConfiguration PluginConfiguration
{
get { return Configuration; }
Expand Down
4 changes: 2 additions & 2 deletions MovieOrganizer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MovieOrganizer Beta 5")]
[assembly: AssemblyDescription("Beta 5")]
[assembly: AssemblyTitle("MovieOrganizer Beta 6")]
[assembly: AssemblyDescription("Beta 6")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MovieOrganizer")]
Expand Down
51 changes: 9 additions & 42 deletions MovieOrganizer/ServerEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using MovieOrganizer;
using MovieOrganizer.Api;
using MovieOrganizer.Service;
using System.IO;
using System.Web;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using MovieOrganizer.Html;

namespace MovieOrganizer
{
Expand All @@ -27,7 +26,7 @@ public class ServerEntryPoint : IServerEntryPoint
private readonly ILogger _logger;
private readonly IServerApplicationHost _appHost;
private readonly IFileSystem _fileSystem;
private readonly IHttpServer _httpServer;
private readonly IHttpResultFactory _resultFactory;
private readonly IServerConfigurationManager _configurationManager;
private readonly ILocalizationManager _localizationManager;
private readonly IServerManager _serverManager;
Expand All @@ -36,6 +35,7 @@ public class ServerEntryPoint : IServerEntryPoint

private MovieOrganizerApi _api;
private MovieOrganizerService _service;
private StaticFileServer _staticFileServer;

public static ServerEntryPoint Instance { get; private set; }

Expand All @@ -55,8 +55,8 @@ public ServerEntryPoint(
ILibraryManager libraryManager,
ILibraryMonitor libraryMonitor,
ILogManager logger,
IServerApplicationHost appHost,
IHttpServer httpServer,
IServerApplicationHost appHost,
IHttpResultFactory resultFactory,
IFileSystem fileSystem,
ILocalizationManager localizationManager,
IServerManager serverManager,
Expand All @@ -70,14 +70,13 @@ public ServerEntryPoint(
_appHost = appHost;
_fileSystem = fileSystem;
_configurationManager = configurationManager;
_httpServer = httpServer;
_resultFactory = resultFactory;
_localizationManager = localizationManager;
_serverManager = serverManager;
_providerManager = providerManager;
_fileOrganizationService = fileOrganizationService;

var serviceStackHost = (IAppHost)httpServer;
serviceStackHost.RawHttpHandlers.Add(ProcessRequestRaw);
HtmlHelper.InstallFiles(Plugin.Instance.AppPaths, Plugin.Instance.PluginConfiguration);

_service = new MovieOrganizerService(
_configurationManager,
Expand All @@ -92,6 +91,8 @@ public ServerEntryPoint(
_fileOrganizationService);

_api = new MovieOrganizerApi(logger, _service, _libraryManager);

_staticFileServer = new StaticFileServer(logger, _resultFactory);
}

/// <summary>
Expand All @@ -108,39 +109,5 @@ public void Dispose()
{
}

public virtual HttpAsyncTaskHandler ProcessRequestRaw(IHttpRequest request)
{
MemoryStream resultStream = null;

if (request.PathInfo.Contains("/components/fileorganizer/fileorganizer.js"))
{
resultStream = HtmlHelper.OrganizerScript;
}
else if (request.PathInfo.Contains("/components/fileorganizer/fileorganizer.template.html"))
{
resultStream = HtmlHelper.OrganizerTemplate;
}

if (resultStream != null)
{
var handler = new CustomActionHandler((httpReq, httpRes) =>
{
httpRes.ContentType = "text/html";

lock (resultStream)
{
resultStream.Seek(0, SeekOrigin.Begin);
resultStream.WriteTo(httpRes.OutputStream);
httpRes.EndRequest();
}

httpRes.End();
});

return handler;
}

return null;
}
}
}

0 comments on commit ea551c2

Please sign in to comment.