more cleanup

This commit is contained in:
Kilian von Pflugk 2024-04-20 12:58:29 +02:00
parent 8ca0212db7
commit 2eb6a873a8
13 changed files with 44 additions and 42 deletions

View File

@ -1,12 +1,13 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using ConfusedPolarBear.Plugin.IntroSkipper.Configuration;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Media file analyzer used to detect end credits that consist of text overlaid on a black background.
/// Bisects the end of the video file to perform an efficient search.
@ -76,7 +77,7 @@ public class BlackFrameAnalyzer : IMediaFileAnalyzer
/// <returns>Credits timestamp.</returns>
public Intro? AnalyzeMediaFile(QueuedEpisode episode, AnalysisMode mode, int minimum)
{
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
var config = Plugin.Instance?.Configuration ?? new PluginConfiguration();
// Start by analyzing the last N minutes of the file.
var start = TimeSpan.FromSeconds(config.MaximumCreditsDuration);

View File

@ -1,5 +1,3 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -7,9 +5,12 @@ using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using ConfusedPolarBear.Plugin.IntroSkipper.Configuration;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Chapter name analyzer.
/// </summary>
@ -89,7 +90,7 @@ public class ChapterAnalyzer : IMediaFileAnalyzer
{
Intro? matchingChapter = null;
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
var config = Plugin.Instance?.Configuration ?? new PluginConfiguration();
var minDuration = config.MinimumIntroDuration;
int maxDuration = mode == AnalysisMode.Introduction ?

View File

@ -1,12 +1,13 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Numerics;
using System.Threading;
using ConfusedPolarBear.Plugin.IntroSkipper.Configuration;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Chromaprint audio analyzer.
/// </summary>
@ -38,7 +39,7 @@ public class ChromaprintAnalyzer : IMediaFileAnalyzer
/// <param name="logger">Logger.</param>
public ChromaprintAnalyzer(ILogger<ChromaprintAnalyzer> logger)
{
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
var config = Plugin.Instance?.Configuration ?? new PluginConfiguration();
maximumDifferences = config.MaximumFingerprintPointDifferences;
invertedIndexShift = config.InvertedIndexShift;
maximumTimeSkip = config.MaximumTimeSkip;
@ -277,8 +278,8 @@ public class ChromaprintAnalyzer : IMediaFileAnalyzer
if (rhsIndex.TryGetValue(modifiedPoint, out var rhsModifiedPoint))
{
var lhsFirst = (int)lhsIndex[originalPoint];
var rhsFirst = (int)rhsModifiedPoint;
var lhsFirst = lhsIndex[originalPoint];
var rhsFirst = rhsModifiedPoint;
indexShifts.Add(rhsFirst - lhsFirst);
}
}

View File

@ -1,8 +1,8 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System.Collections.ObjectModel;
using System.Threading;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Media file analyzer interface.
/// </summary>

View File

@ -1,9 +1,9 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System.Collections.ObjectModel;
using System.Threading;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Chapter name analyzer.
/// </summary>

View File

@ -12,6 +12,7 @@ using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Session;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Timer = System.Timers.Timer;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
@ -26,7 +27,7 @@ public class AutoSkip : IHostedService, IDisposable
private ILogger<AutoSkip> _logger;
private IUserDataManager _userDataManager;
private ISessionManager _sessionManager;
private System.Timers.Timer _playbackTimer = new(1000);
private Timer _playbackTimer = new(1000);
private Dictionary<string, bool> _sentSeekCommand;
/// <summary>
@ -152,7 +153,7 @@ public class AutoSkip : IHostedService, IDisposable
_sessionManager.SendMessageCommand(
session.Id,
session.Id,
new MessageCommand()
new MessageCommand
{
Header = string.Empty, // some clients require header to be a string instead of null
Text = notificationText,

View File

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text.Json.Serialization;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
@ -102,7 +103,7 @@ public class Intro
var start = Math.Round(IntroStart, 2);
var end = Math.Round(IntroEnd, 2);
return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} {1} {2}", start, end, (int)action);
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}", start, end, (int)action);
}
}

View File

@ -1,7 +1,7 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Support bundle warning.
/// </summary>

View File

@ -1,10 +1,10 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.ObjectModel;
using System.IO;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Update EDL files associated with a list of episodes.
/// </summary>
@ -68,7 +68,8 @@ public static class EdlManager
_logger?.LogDebug("Episode {Id} did not have an introduction, skipping", id);
continue;
}
else if (!intro.Valid)
if (!intro.Valid)
{
_logger?.LogDebug("Episode {Id} did not have a valid introduction, skipping", id);
continue;

View File

@ -206,7 +206,7 @@ public class Entrypoint : IHostedService, IDisposable
}
// Unless user initiated, this is likely an overlap
if (Entrypoint.AutomaticTaskState == TaskState.Running)
if (AutomaticTaskState == TaskState.Running)
{
return;
}
@ -219,7 +219,7 @@ public class Entrypoint : IHostedService, IDisposable
/// </summary>
private void StartTimer()
{
if (Entrypoint.AutomaticTaskState == TaskState.Running)
if (AutomaticTaskState == TaskState.Running)
{
_analyzeAgain = true; // Items added during a scan will be included later.
}
@ -347,8 +347,6 @@ public class Entrypoint : IHostedService, IDisposable
if (!dispose)
{
_queueTimer.Dispose();
return;
}
}
}

View File

@ -125,7 +125,7 @@ public static class FFmpegWrapper
}
else
{
throw new ArgumentException("Unknown analysis mode " + mode.ToString());
throw new ArgumentException("Unknown analysis mode " + mode);
}
return Fingerprint(episode, mode, start, end);
@ -642,14 +642,13 @@ public static class FFmpegWrapper
{
return basePath;
}
else if (mode == AnalysisMode.Credits)
if (mode == AnalysisMode.Credits)
{
return basePath + "-credits";
}
else
{
throw new ArgumentException("Unknown analysis mode " + mode.ToString());
}
throw new ArgumentException("Unknown analysis mode " + mode);
}
private static string FormatFFmpegLog(string key)

View File

@ -1,5 +1,3 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -9,9 +7,10 @@ using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Manages enqueuing library items for analysis.
/// </summary>
@ -124,7 +123,7 @@ public class QueueManager
{
_logger.LogDebug("Constructing anonymous internal query");
var query = new InternalItemsQuery()
var query = new InternalItemsQuery
{
// Order by series name, season, and then episode number so that status updates are logged in order
ParentId = id,
@ -203,7 +202,7 @@ public class QueueManager
// Queue the episode for analysis
var maxCreditsDuration = Plugin.Instance.Configuration.MaximumCreditsDuration;
_queuedEpisodes[episode.SeasonId].Add(new QueuedEpisode()
_queuedEpisodes[episode.SeasonId].Add(new QueuedEpisode
{
SeriesName = episode.SeriesName,
SeasonNumber = episode.AiredSeasonNumber ?? 0,

View File

@ -1,5 +1,3 @@
namespace ConfusedPolarBear.Plugin.IntroSkipper;
using System;
using System.Collections.ObjectModel;
using System.Threading;
@ -7,6 +5,8 @@ using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using Microsoft.Extensions.Logging;
namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// <summary>
/// Common code shared by all media item analyzer tasks.
/// </summary>
@ -85,12 +85,12 @@ public class BaseItemAnalyzerTask
}
var totalProcessed = 0;
var options = new ParallelOptions()
var options = new ParallelOptions
{
MaxDegreeOfParallelism = Plugin.Instance.Configuration.MaxParallelism
};
Parallel.ForEach(queue, options, (season) =>
Parallel.ForEach(queue, options, season =>
{
var writeEdl = false;