2019-02-21 01:57:43 -08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2021-12-13 16:58:05 -07:00
|
|
|
using System.Globalization;
|
2022-05-05 18:10:34 -05:00
|
|
|
using System.IO;
|
2022-04-29 23:52:50 -05:00
|
|
|
using ConfusedPolarBear.Plugin.IntroSkipper.Configuration;
|
2019-02-21 01:57:43 -08:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
using MediaBrowser.Model.Plugins;
|
|
|
|
using MediaBrowser.Model.Serialization;
|
|
|
|
|
2022-04-29 23:52:50 -05:00
|
|
|
namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
2021-12-13 16:58:05 -07:00
|
|
|
|
|
|
|
/// <summary>
|
2022-05-01 01:24:57 -05:00
|
|
|
/// Intro skipper plugin. Uses audio analysis to find common sequences of audio shared between episodes.
|
2021-12-13 16:58:05 -07:00
|
|
|
/// </summary>
|
|
|
|
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
2019-02-21 01:57:43 -08:00
|
|
|
{
|
2022-05-05 18:10:34 -05:00
|
|
|
private IXmlSerializer _xmlSerializer;
|
|
|
|
private string _introPath;
|
|
|
|
|
2022-05-01 01:24:57 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
|
|
|
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
|
|
|
|
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
|
|
|
: base(applicationPaths, xmlSerializer)
|
|
|
|
{
|
2022-05-05 18:10:34 -05:00
|
|
|
_xmlSerializer = xmlSerializer;
|
|
|
|
|
|
|
|
// Create the base & cache directories (if needed).
|
|
|
|
FingerprintCachePath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "cache");
|
|
|
|
if (!Directory.Exists(FingerprintCachePath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(FingerprintCachePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
_introPath = Path.Join(applicationPaths.PluginConfigurationsPath, "intros", "intros.xml");
|
|
|
|
|
2022-05-01 01:24:57 -05:00
|
|
|
Intros = new Dictionary<Guid, Intro>();
|
|
|
|
AnalysisQueue = new Dictionary<Guid, List<QueuedEpisode>>();
|
|
|
|
Instance = this;
|
|
|
|
|
2022-05-05 18:10:34 -05:00
|
|
|
RestoreTimestamps();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Save timestamps to disk.
|
|
|
|
/// </summary>
|
|
|
|
public void SaveTimestamps()
|
|
|
|
{
|
|
|
|
var introList = new List<Intro>();
|
|
|
|
|
|
|
|
foreach (var intro in Plugin.Instance!.Intros)
|
|
|
|
{
|
|
|
|
introList.Add(intro.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
_xmlSerializer.SerializeToFile(introList, _introPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Restore previous analysis results from disk.
|
|
|
|
/// </summary>
|
|
|
|
public void RestoreTimestamps()
|
|
|
|
{
|
|
|
|
if (!File.Exists(_introPath))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since dictionaries can't be easily serialized, analysis results are stored on disk as a list.
|
|
|
|
var introList = (List<Intro>)_xmlSerializer.DeserializeFromFile(typeof(List<Intro>), _introPath);
|
|
|
|
|
|
|
|
foreach (var intro in introList)
|
|
|
|
{
|
|
|
|
Plugin.Instance!.Intros[intro.EpisodeId] = intro;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IEnumerable<PluginPageInfo> GetPages()
|
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
|
|
|
new PluginPageInfo
|
|
|
|
{
|
|
|
|
Name = this.Name,
|
|
|
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
|
|
|
}
|
|
|
|
};
|
2022-05-01 01:24:57 -05:00
|
|
|
}
|
|
|
|
|
2022-05-01 00:33:22 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Results of fingerprinting all episodes.
|
|
|
|
/// </summary>
|
|
|
|
public Dictionary<Guid, Intro> Intros { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Map of season ids to episodes that have been queued for fingerprinting.
|
|
|
|
/// </summary>
|
|
|
|
public Dictionary<Guid, List<QueuedEpisode>> AnalysisQueue { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Total number of episodes in the queue.
|
|
|
|
/// </summary>
|
|
|
|
public int TotalQueued { get; set; }
|
|
|
|
|
2022-05-05 18:10:34 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Directory to cache fingerprints in.
|
|
|
|
/// </summary>
|
|
|
|
public string FingerprintCachePath { get; private set; }
|
|
|
|
|
2021-12-13 16:58:05 -07:00
|
|
|
/// <inheritdoc />
|
2022-04-29 23:52:50 -05:00
|
|
|
public override string Name => "Intro Skipper";
|
2019-11-27 03:13:09 +09:00
|
|
|
|
2021-12-13 16:58:05 -07:00
|
|
|
/// <inheritdoc />
|
2022-04-29 23:52:50 -05:00
|
|
|
public override Guid Id => Guid.Parse("c83d86bb-a1e0-4c35-a113-e2101cf4ee6b");
|
2019-02-21 01:57:43 -08:00
|
|
|
|
2022-05-01 01:24:57 -05:00
|
|
|
/// <inheritdoc />
|
2021-12-13 16:58:05 -07:00
|
|
|
public static Plugin? Instance { get; private set; }
|
2019-03-10 08:53:30 +09:00
|
|
|
}
|