Start parallel rewrite
This commit is contained in:
parent
3370f1058d
commit
56fdbef0ec
@ -87,114 +87,126 @@ public class FingerprinterTask : IScheduledTask
|
|||||||
|
|
||||||
foreach (var season in queue)
|
foreach (var season in queue)
|
||||||
{
|
{
|
||||||
var first = season.Value[0];
|
AnalyzeSeason(season, cancellationToken);
|
||||||
|
|
||||||
/* Don't analyze specials or seasons with an insufficient number of episodes.
|
// TODO: report progress on a per episode basis
|
||||||
* A season with only 1 episode can't be analyzed as it would compare the episode to itself,
|
totalProcessed += season.Value.Count;
|
||||||
* which would result in the entire episode being marked as an introduction, as the audio is identical.
|
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
||||||
*/
|
}
|
||||||
if (season.Value.Count < 2 || first.SeasonNumber == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation(
|
return Task.CompletedTask;
|
||||||
"Analyzing {Count} episodes from {Name} season {Season}",
|
}
|
||||||
season.Value.Count,
|
|
||||||
first.SeriesName,
|
|
||||||
first.SeasonNumber);
|
|
||||||
|
|
||||||
// Ensure there are an even number of episodes
|
private void AnalyzeSeason(
|
||||||
var episodes = season.Value;
|
KeyValuePair<Guid, List<QueuedEpisode>> season,
|
||||||
if (episodes.Count % 2 != 0)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
episodes.Add(episodes[episodes.Count - 2]);
|
var first = season.Value[0];
|
||||||
}
|
|
||||||
|
|
||||||
// Analyze each pair of episodes in the current season
|
/* Don't analyze specials or seasons with an insufficient number of episodes.
|
||||||
var everFoundIntro = false;
|
* A season with only 1 episode can't be analyzed as it would compare the episode to itself,
|
||||||
var failures = 0;
|
* which would result in the entire episode being marked as an introduction, as the audio is identical.
|
||||||
for (var i = 0; i < episodes.Count; i += 2)
|
*/
|
||||||
{
|
if (season.Value.Count < 2 || first.SeasonNumber == 0)
|
||||||
if (cancellationToken.IsCancellationRequested)
|
{
|
||||||
{
|
return;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var lhs = episodes[i];
|
_logger.LogInformation(
|
||||||
var rhs = episodes[i + 1];
|
"Analyzing {Count} episodes from {Name} season {Season}",
|
||||||
|
season.Value.Count,
|
||||||
|
first.SeriesName,
|
||||||
|
first.SeasonNumber);
|
||||||
|
|
||||||
// TODO: make configurable
|
// Ensure there are an even number of episodes
|
||||||
if (!everFoundIntro && failures >= 6)
|
var episodes = season.Value;
|
||||||
{
|
if (episodes.Count % 2 != 0)
|
||||||
_logger.LogWarning(
|
{
|
||||||
"Failed to find an introduction in {Series} season {Season}",
|
episodes.Add(episodes[episodes.Count - 2]);
|
||||||
lhs.SeriesName,
|
}
|
||||||
lhs.SeasonNumber);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: add retry logic
|
|
||||||
var alreadyDone = Plugin.Instance!.Intros;
|
|
||||||
if (alreadyDone.ContainsKey(lhs.EpisodeId) && alreadyDone.ContainsKey(rhs.EpisodeId))
|
|
||||||
{
|
|
||||||
_logger.LogDebug(
|
|
||||||
"Episodes {LHS} and {RHS} have both already been fingerprinted",
|
|
||||||
lhs.EpisodeId,
|
|
||||||
rhs.EpisodeId);
|
|
||||||
|
|
||||||
totalProcessed += 2;
|
|
||||||
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogDebug("Analyzing {LHS} and {RHS}", lhs.Path, rhs.Path);
|
|
||||||
|
|
||||||
var (lhsIntro, rhsIntro) = FingerprintEpisodes(lhs, rhs);
|
|
||||||
|
|
||||||
Plugin.Instance.Intros![lhsIntro.EpisodeId] = lhsIntro;
|
|
||||||
Plugin.Instance.Intros![rhsIntro.EpisodeId] = rhsIntro;
|
|
||||||
|
|
||||||
if (!lhsIntro.Valid)
|
|
||||||
{
|
|
||||||
failures += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
everFoundIntro = true;
|
|
||||||
}
|
|
||||||
catch (FingerprintException ex)
|
|
||||||
{
|
|
||||||
_logger.LogError("Caught fingerprint error: {Ex}", ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
totalProcessed += 2;
|
|
||||||
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin.Instance!.SaveTimestamps();
|
|
||||||
|
|
||||||
|
// Analyze each pair of episodes in the current season
|
||||||
|
var everFoundIntro = false;
|
||||||
|
var failures = 0;
|
||||||
|
for (var i = 0; i < episodes.Count; i += 2)
|
||||||
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!everFoundIntro)
|
var lhs = episodes[i];
|
||||||
|
var rhs = episodes[i + 1];
|
||||||
|
|
||||||
|
// TODO: make configurable
|
||||||
|
if (!everFoundIntro && failures >= 6)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning(
|
||||||
|
"Failed to find an introduction in {Series} season {Season}",
|
||||||
|
lhs.SeriesName,
|
||||||
|
lhs.SeasonNumber);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: add retry logic
|
||||||
|
var alreadyDone = Plugin.Instance!.Intros;
|
||||||
|
if (alreadyDone.ContainsKey(lhs.EpisodeId) && alreadyDone.ContainsKey(rhs.EpisodeId))
|
||||||
|
{
|
||||||
|
_logger.LogDebug(
|
||||||
|
"Episodes {LHS} and {RHS} have both already been fingerprinted",
|
||||||
|
lhs.EpisodeId,
|
||||||
|
rhs.EpisodeId);
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: bring back
|
||||||
|
totalProcessed += 2;
|
||||||
|
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
||||||
|
*/
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reanalyze this season to check for (and hopefully correct) outliers and failed episodes.
|
try
|
||||||
CheckSeason(season.Value);
|
{
|
||||||
|
_logger.LogDebug("Analyzing {LHS} and {RHS}", lhs.Path, rhs.Path);
|
||||||
|
|
||||||
|
var (lhsIntro, rhsIntro) = FingerprintEpisodes(lhs, rhs);
|
||||||
|
|
||||||
|
Plugin.Instance.Intros![lhsIntro.EpisodeId] = lhsIntro;
|
||||||
|
Plugin.Instance.Intros![rhsIntro.EpisodeId] = rhsIntro;
|
||||||
|
|
||||||
|
if (!lhsIntro.Valid)
|
||||||
|
{
|
||||||
|
failures += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
everFoundIntro = true;
|
||||||
|
}
|
||||||
|
catch (FingerprintException ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Caught fingerprint error: {Ex}", ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
TODO: bring back
|
||||||
|
totalProcessed += 2;
|
||||||
|
progress.Report((totalProcessed * 100) / Plugin.Instance!.TotalQueued);
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
Plugin.Instance!.SaveTimestamps();
|
||||||
|
|
||||||
|
if (cancellationToken.IsCancellationRequested || !everFoundIntro)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reanalyze this season to check for (and hopefully correct) outliers and failed episodes.
|
||||||
|
CheckSeason(season.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user