Skip to content

Commit

Permalink
Use reversed fingerprints for credits
Browse files Browse the repository at this point in the history
  • Loading branch information
rlauuzo authored and AbandonedCart committed May 1, 2024
1 parent f2eae80 commit 8053ed6
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public ChromaprintAnalyzer(ILogger<ChromaprintAnalyzer> logger)
{
fingerprintCache[episode.EpisodeId] = FFmpegWrapper.Fingerprint(episode, mode);

// Use reversed fingerprints for credits
if (_analysisMode == AnalysisMode.Credits)
{
Array.Reverse(fingerprintCache[episode.EpisodeId]);
}

if (cancellationToken.IsCancellationRequested)
{
return analysisQueue;
Expand Down Expand Up @@ -123,14 +129,20 @@ public ChromaprintAnalyzer(ILogger<ChromaprintAnalyzer> logger)
* While this is desired behavior for detecting introductions, it breaks credit
* detection, as the audio we're analyzing was extracted from some point into the file.
*
* To fix this, add the starting time of the fingerprint to the reported time range.
* To fix this, the starting and ending times need to be switched, as they were previously reversed
* and subtracted from the episode duration to get the reported time range.
*/
if (this._analysisMode == AnalysisMode.Credits)
{
currentIntro.IntroStart += currentEpisode.CreditsFingerprintStart;
currentIntro.IntroEnd += currentEpisode.CreditsFingerprintStart;
remainingIntro.IntroStart += remainingEpisode.CreditsFingerprintStart;
remainingIntro.IntroEnd += remainingEpisode.CreditsFingerprintStart;
// Calculate new values for the current intro
double currentOriginalIntroStart = currentIntro.IntroStart;
currentIntro.IntroStart = currentEpisode.Duration - currentIntro.IntroEnd;
currentIntro.IntroEnd = currentEpisode.Duration - currentOriginalIntroStart;

// Calculate new values for the remaining intro
double remainingIntroOriginalStart = remainingIntro.IntroStart;
remainingIntro.IntroStart = remainingEpisode.Duration - remainingIntro.IntroEnd;
remainingIntro.IntroEnd = remainingEpisode.Duration - remainingIntroOriginalStart;
}

// Only save the discovered intro if it is:
Expand Down

0 comments on commit 8053ed6

Please sign in to comment.