Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for regional, alternate, altdvd orders (Alt implementation) #141

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Jellyfin.Plugin.Tvdb/Configuration/more-display-order-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**Setup Event Listeners */
document.addEventListener('viewshow', viewShowEvent)

// Mutation Observer
const observer = new MutationObserver(injectDisplayOrderOptions);
// Only observe when on tv.html, details, home.html, or search.html
observer.disconnect();

function viewShowEvent(){
const location = window.location.hash;
console.debug("Current: " + location);
if (location.startsWith('#/tv.html') || location.startsWith('#/details') || location.startsWith('#/home.html') || location.startsWith('#/search.html')){
console.debug('Connecting Observer');
observer.observe(document.body, {childList: true, subtree: true});
}
else{
console.debug('Disconnecting Observer');
observer.disconnect();
}
}

function injectDisplayOrderOptions(MutationList, observer){
console.debug("Mutation Observer Triggered");
const selectDisplayOrder = document.getElementById('selectDisplayOrder');

if (!selectDisplayOrder){
console.debug('selectDisplayOrder not found');
return;
}
console.debug('selectDisplayOrder found');
console.debug('Injecting Options')
observer.disconnect();
const options = [
{value: 'alternate', text: 'Alternate'},
{value: 'regional', text: 'Regional'},
{value: 'altdvd', text: 'Alternate DVD'}
]
//check if options already exist
if (selectDisplayOrder.options.length > 8){
console.debug('Options already exist');
observer.observe(document.body, {childList: true, subtree: true});
return;
}
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option.value;
optionElement.text = option.text;
selectDisplayOrder.appendChild(optionElement);
});
observer.observe(document.body, {childList: true, subtree: true});
}
2 changes: 2 additions & 0 deletions Jellyfin.Plugin.Tvdb/Jellyfin.Plugin.Tvdb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

<ItemGroup>
<None Remove="Configuration\config.html" />
<None Remove="Configuration\more-display-order-options.js" />
<EmbeddedResource Include="Configuration\config.html" />
<EmbeddedResource Include="Configuration\more-display-order-options.js" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Jellyfin.Plugin.Tvdb/TvdbClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
{
switch (searchInfo.SeriesDisplayOrder)
{
case "regional":
case "alternate":
case "altdvd":
case "dvd":
episodeNumber = searchInfo.IndexNumber.Value;
seasonNumber = searchInfo.ParentIndexNumber.Value;
Expand Down Expand Up @@ -493,6 +496,9 @@ public async Task<IReadOnlyList<ArtworkType>> GetArtworkTypeAsync(CancellationTo
{
switch (searchInfo.SeriesDisplayOrder)
{
case "regional":
case "alternate":
case "altdvd":
case "dvd":
case "absolute":
seriesResponse = await seriesClient.GetSeriesEpisodesAsync(page: 0, id: seriesTvdbId, season_type: searchInfo.SeriesDisplayOrder, season: seasonNumber, episodeNumber: episodeNumber, airDate: airDate, cancellationToken: cancellationToken).ConfigureAwait(false);
Expand Down
53 changes: 47 additions & 6 deletions Jellyfin.Plugin.Tvdb/TvdbPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Jellyfin.Plugin.Tvdb.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Plugin.Tvdb
{
Expand All @@ -13,6 +16,8 @@
/// </summary>
public class TvdbPlugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
private readonly ILogger<TvdbPlugin> _logger;

/// <summary>
/// Gets the provider name.
/// </summary>
Expand All @@ -28,10 +33,21 @@
/// </summary>
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
public TvdbPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
/// <param name="logger">Instance of the <see cref="ILogger{TvdbPlugin}"/> interface.</param>
public TvdbPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, ILogger<TvdbPlugin> logger)
: base(applicationPaths, xmlSerializer)
{
Instance = this;
_logger = logger;
var path = Path.Join(applicationPaths.WebPath, "index.html");
try
{
InjectDisplayOrderOptions(path);
}
catch (Exception e)
{
_logger.LogError(e, "Failed to inject display order options script.");
}
Comment on lines +47 to +50

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

/// <summary>
Expand All @@ -48,11 +64,36 @@
/// <inheritdoc />
public IEnumerable<PluginPageInfo> GetPages()
{
yield return new PluginPageInfo
return new[]
{
Name = Name,
EmbeddedResourcePath = $"{GetType().Namespace}.Configuration.config.html"
new PluginPageInfo
{
Name = Name,
EmbeddedResourcePath = $"{GetType().Namespace}.Configuration.config.html"
},
new PluginPageInfo
{
Name = "more-display-order-options.js",
EmbeddedResourcePath = $"{GetType().Namespace}.Configuration.more-display-order-options.js"
}
};
}

private void InjectDisplayOrderOptions(string path)
{
var content = File.ReadAllText(path);

var script = "<script src=\"configurationpage?name=more-display-order-options.js\"></script>";
if (content.Contains(script, StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation("Display order options script already injected.");
return;
}

var headEnd = new Regex("</head>", RegexOptions.IgnoreCase);
content = headEnd.Replace(content, script + "</head>", 1);
File.WriteAllText(path, content);
_logger.LogInformation("Display order options script injected.");
}
}
}
}