Showing preview only (372K chars total). Download the full file or copy to clipboard to get everything.
Repository: endrl/jellyfin-plugin-media-analyzer
Branch: master
Commit: 6bb1c3e8182f
Files: 91
Total size: 345.1 KB
Directory structure:
gitextract_z9ywbwcb/
├── .editorconfig
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.yml
│ │ └── feature_request.md
│ ├── dependabot.yml
│ └── workflows/
│ ├── build.yml
│ ├── package.sh
│ └── publish.yml
├── .gitignore
├── .vscode/
│ ├── launch.json
│ ├── settings.json
│ └── tasks.json
├── ACKNOWLEDGEMENTS.md
├── CHANGELOG.md
├── Jellyfin.Plugin.MediaAnalyzer/
│ ├── Analyzers/
│ │ ├── BlackFrameAnalyzer.cs
│ │ ├── ChapterAnalyzer.cs
│ │ ├── ChromaprintAnalyzer.cs
│ │ └── IMediaFileAnalyzer.cs
│ ├── Configuration/
│ │ ├── PluginConfiguration.cs
│ │ ├── configPage.html
│ │ ├── version.txt
│ │ └── visualizer.js
│ ├── Controllers/
│ │ ├── MediaAnalyzerController.cs
│ │ ├── TroubleshootingController.cs
│ │ └── VisualizationController.cs
│ ├── Data/
│ │ ├── AnalyzerType.cs
│ │ ├── BlackFrame.cs
│ │ ├── EpisodeVisualization.cs
│ │ ├── FingerprintException.cs
│ │ ├── IntroWithMetadata.cs
│ │ ├── MediaSegmentsDb.cs
│ │ ├── QueuedMedia.cs
│ │ ├── Segment.cs
│ │ ├── TimeRange.cs
│ │ ├── TimeRangeHelpers.cs
│ │ └── WarningManager.cs
│ ├── Db/
│ │ ├── MediaAnalyzerDbContext.cs
│ │ ├── MediaAnalyzerDbFactory.cs
│ │ ├── SegmentMetadata.cs
│ │ └── SegmentMetadataDb.cs
│ ├── Entrypoint/
│ │ └── LibraryChangedEntrypoint.cs
│ ├── FFmpegWrapper.cs
│ ├── Helper/
│ │ └── Utils.cs
│ ├── Jellyfin.Plugin.MediaAnalyzer.csproj
│ ├── Migrations/
│ │ ├── 20230525091047_CreateBlacklistSegment.Designer.cs
│ │ ├── 20230525091047_CreateBlacklistSegment.cs
│ │ ├── 20240903114429_CreateSegmentMetadata.Designer.cs
│ │ ├── 20240903114429_CreateSegmentMetadata.cs
│ │ └── MediaAnalyzerDbContextModelSnapshot.cs
│ ├── Plugin.cs
│ ├── QueueManager.cs
│ └── ScheduledTasks/
│ ├── AnalyzeMedia.cs
│ └── BaseItemAnalyzerTask.cs
├── Jellyfin.Plugin.MediaAnalyzer.Tests/
│ ├── Jellyfin.Plugin.MediaAnalyzer.Tests.csproj
│ ├── TestAudioFingerprinting.cs
│ ├── TestBlackFrames.cs
│ ├── TestChapterAnalyzer.cs
│ ├── TestContiguous.cs
│ ├── TestWarnings.cs
│ ├── audio/
│ │ └── README.txt
│ └── e2e_tests/
│ ├── .gitignore
│ ├── README.md
│ ├── build.sh
│ ├── config_sample.jsonc
│ ├── docker-compose.yml
│ ├── selenium/
│ │ ├── main.py
│ │ └── requirements.txt
│ ├── verifier/
│ │ ├── go.mod
│ │ ├── http.go
│ │ ├── main.go
│ │ ├── report.html
│ │ ├── report_comparison.go
│ │ ├── report_comparison_util.go
│ │ ├── report_generator.go
│ │ ├── schema_validation.go
│ │ └── structs/
│ │ ├── intro.go
│ │ ├── plugin_configuration.go
│ │ ├── public_info.go
│ │ └── report.go
│ └── wrapper/
│ ├── exec.go
│ ├── exec_test.go
│ ├── go.mod
│ ├── library.json
│ ├── main.go
│ ├── setup.go
│ └── structs.go
├── Jellyfin.Plugin.MediaAnalyzer.sln
├── LICENSE
├── README.md
├── build.yaml
├── docs/
│ └── release.md
└── jellyfin.ruleset
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# With more recent updates Visual Studio 2017 supports EditorConfig files out of the box
# Visual Studio Code needs an extension: https://github.com/editorconfig/editorconfig-vscode
# For emacs, vim, np++ and other editors, see here: https://github.com/editorconfig
###############################
# Core EditorConfig Options #
###############################
root = true
# All files
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = off
# YAML indentation
[*.{yml,yaml}]
indent_size = 2
# XML indentation
[*.{csproj,xml}]
indent_size = 2
###############################
# .NET Coding Conventions #
###############################
[*.{cs,vb}]
# Organize usings
dotnet_sort_system_directives_first = true
# this. preferences
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_readonly_field = true:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
###############################
# Naming Conventions #
###############################
# Style Definitions (From Roslyn)
# Non-private static fields are PascalCase
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.symbols = non_private_static_fields
dotnet_naming_rule.non_private_static_fields_should_be_pascal_case.style = non_private_static_field_style
dotnet_naming_symbols.non_private_static_fields.applicable_kinds = field
dotnet_naming_symbols.non_private_static_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
dotnet_naming_symbols.non_private_static_fields.required_modifiers = static
dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case
# Constants are PascalCase
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.constant_style.capitalization = pascal_case
# Static fields are camelCase and start with s_
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix = _
# Instance fields are camelCase and start with _
dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.instance_fields_should_be_camel_case.symbols = instance_fields
dotnet_naming_rule.instance_fields_should_be_camel_case.style = instance_field_style
dotnet_naming_symbols.instance_fields.applicable_kinds = field
dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
# Locals and parameters are camelCase
dotnet_naming_rule.locals_should_be_camel_case.severity = suggestion
dotnet_naming_rule.locals_should_be_camel_case.symbols = locals_and_parameters
dotnet_naming_rule.locals_should_be_camel_case.style = camel_case_style
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
dotnet_naming_style.camel_case_style.capitalization = camel_case
# Local functions are PascalCase
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_style.local_function_style.capitalization = pascal_case
# By default, name items with PascalCase
dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.all_members.applicable_kinds = *
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
###############################
# C# Coding Conventions #
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
# Pattern matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
# Expression-level preferences
csharp_prefer_braces = true:silent
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
###############################
# C# Formatting Rules #
###############################
# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.yml
================================================
name: "Bug report"
description: "Create a report to help us improve"
labels: [bug]
body:
- type: textarea
attributes:
label: Describe the bug
description: Also tell us, what did you expect to happen?
placeholder: |
The more information that you are able to provide, the better. Did you do anything before this happened? Did you upgrade or change anything? Any screenshots or logs you can provide will be helpful.
This is my issue.
Steps to Reproduce
1. In this environment...
2. With this config...
3. Run '...'
4. See error...
validations:
required: true
- type: input
attributes:
label: Operating system
placeholder: Debian 11, Windows 11, etc.
validations:
required: true
- type: input
attributes:
label: Jellyfin installation method
placeholder: Docker, Windows installer, etc.
validations:
required: true
- type: textarea
attributes:
label: Support Bundle
placeholder: go to Dashboard -> Plugins -> Media Analyzer -> Support Bundle (at the bottom of the page) and paste the contents of the textbox here
validations:
required: true
- type: textarea
attributes:
label: Jellyfin logs
placeholder: Paste any relevant logs here
render: shell
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for this project
labels: enhancement
assignees: ''
---
**Describe the feature you'd like added**
A clear and concise description of what you would like to see added.
**Additional context**
Add any other context or screenshots about the feature request here.
================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
# Fetch and update latest `nuget` pkgs
- package-ecosystem: nuget
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- chore
- dependency
- nuget
commit-message:
prefix: chore
include: scope
# Fetch and update latest `github-actions` pkgs
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
open-pull-requests-limit: 10
labels:
- ci
- dependency
- github_actions
commit-message:
prefix: ci
include: scope
================================================
FILE: .github/workflows/build.yml
================================================
name: "Build Plugin"
on:
push:
branches: ["master", "analyzers"]
pull_request:
branches: ["master"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Embed version info
run: echo "${{ github.sha }}" > Jellyfin.Plugin.MediaAnalyzer/Configuration/version.txt
- name: Build
run: dotnet build --no-restore
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Jellyfin.Plugin.MediaAnalyzer-${{ github.sha }}.dll
path: Jellyfin.Plugin.MediaAnalyzer/bin/Debug/net8.0/Jellyfin.Plugin.MediaAnalyzer.dll
if-no-files-found: error
================================================
FILE: .github/workflows/package.sh
================================================
#!/bin/bash
# Check argument count
if [[ $# -ne 1 ]]; then
echo "Usage: $0 VERSION"
exit 1
fi
# Use provided tag to derive archive filename and short tag
version="$1"
zip="jellyfin-plugin-mediaanalyzer-$version.zip"
short="$(echo "$version" | sed "s/^v//")"
# Get the assembly version
CSPROJ="Jellyfin.Plugin.MediaAnalyzer/Jellyfin.Plugin.MediaAnalyzer.csproj"
assemblyVersion="$(grep -m1 -oE "([0-9]\.){3}[0-9]" "$CSPROJ")"
# Get the date
date="$(date --utc -Iseconds | sed "s/\+00:00/Z/")"
# Debug
echo "Version: $version ($short)"
echo "Archive: $zip"
echo
echo "Running unit tests"
dotnet test -p:DefineConstants=SKIP_FFMPEG_TESTS || exit 1
echo
echo "Building plugin in Release mode"
dotnet build -c Release || exit 1
echo
# Create packaging directory
mkdir package
cd package || exit 1
# Copy the freshly built plugin DLL to the packaging directory and archive
cp "../Jellyfin.Plugin.MediaAnalyzer/bin/Release/net8.0/Jellyfin.Plugin.MediaAnalyzer.dll" ./ || exit 1
zip "$zip" Jellyfin.Plugin.MediaAnalyzer.dll || exit 1
# Calculate the checksum of the archive
checksum="$(md5sum "$zip" | cut -f 1 -d " ")"
# Generate the manifest entry for this plugin
cat > manifest.json <<'EOF'
{
"version": "ASSEMBLY",
"changelog": "- See the full changelog at [GitHub](https://github.com/Endrl/jellyfin-plugin-media-analyzer/blob/master/CHANGELOG.md)\n",
"targetAbi": "10.9.0.0",
"sourceUrl": "https://github.com/Endrl/jellyfin-plugin-media-analyzer/releases/download/VERSION/ZIP",
"checksum": "CHECKSUM",
"timestamp": "DATE"
}
EOF
sed -i "s/ASSEMBLY/$assemblyVersion/" manifest.json
sed -i "s/VERSION/$version/" manifest.json
sed -i "s/ZIP/$zip/" manifest.json
sed -i "s/CHECKSUM/$checksum/" manifest.json
sed -i "s/DATE/$date/" manifest.json
================================================
FILE: .github/workflows/publish.yml
================================================
name: "Package plugin"
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# set fetch-depth to 0 in order to clone all tags instead of just the current commit
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout latest tag
id: tag
run: |
tag="$(git tag --sort=committerdate | tail -n 1)"
git checkout "$tag"
echo "tag=$tag" >> $GITHUB_OUTPUT
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Package
run: .github/workflows/package.sh ${{ steps.tag.outputs.tag }}
- name: Upload plugin archive
uses: actions/upload-artifact@v4
with:
name: jellyfin-plugin-mediaanalyzer-bundle-${{ steps.tag.outputs.tag }}.zip
path: |
package/*.zip
package/*.json
if-no-files-found: error
================================================
FILE: .gitignore
================================================
bin/
obj/
BenchmarkDotNet.Artifacts/
/package/
# Ignore pre compiled web interface
docker/dist
================================================
FILE: .vscode/launch.json
================================================
{
// Paths and plugin names are configured in settings.json
"version": "0.2.0",
"configurations": [
{
"type": "coreclr",
"name": "Launch",
"request": "launch",
"preLaunchTask": "build-and-copy",
"program": "${config:jellyfinDir}/bin/Debug/net8.0/jellyfin.dll",
"args": [
//"--nowebclient"
"--webdir",
"${config:jellyfinWebDir}/dist/"
],
"cwd": "${config:jellyfinDir}",
}
]
}
================================================
FILE: .vscode/settings.json
================================================
{
// jellyfinDir : The directory of the cloned jellyfin server project
// This needs to be built once before it can be used
"jellyfinDir": "${workspaceFolder}/../jellyfin/Jellyfin.Server",
// jellyfinWebDir : The directory of the cloned jellyfin-web project
// This needs to be built once before it can be used
"jellyfinWebDir": "${workspaceFolder}/../jellyfin-web",
// jellyfinDataDir : the root data directory for a running jellyfin instance
// This is where jellyfin stores its configs, plugins, metadata etc
// This is platform specific by default, but on Windows defaults to
// ${env:LOCALAPPDATA}/jellyfin
"jellyfinDataDir": "${env:LOCALAPPDATA}/jellyfin",
"jellyfinDataDirWin": "${env:LOCALAPPDATA}\\jellyfin",
// The name of the plugin
"pluginName": "Jellyfin.Plugin.MediaAnalyzer",
"cmake.configureOnOpen": false
}
================================================
FILE: .vscode/tasks.json
================================================
{
// Paths and plugin name are configured in settings.json
"version": "2.0.0",
"tasks": [
{
// A chain task - build the plugin, then copy it to your
// jellyfin server's plugin directory
"label": "build-and-copy",
"dependsOrder": "sequence",
"dependsOn": ["build","copy-dll-win"],
"windows": {
"dependsOn": ["build","copy-dll-win"]
}
},
{
// Build the plugin
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"publish",
"${workspaceFolder}/${config:pluginName}.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
// Ensure the plugin directory exists before trying to use it
"label": "make-plugin-dir",
"type": "shell",
"command": "mkdir",
"args": [
"-Force",
"-Path",
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
]
},
{
// Copy the plugin dll to the jellyfin plugin install path
// This command copies every .dll from the build directory to the plugin dir
// Usually, you probablly only need ${config:pluginName}.dll
// But some plugins may bundle extra requirements
"label": "copy-dll-win",
"type": "shell",
"command": "xcopy",
"args": [
"/I",
"/y",
".\\${config:pluginName}\\bin\\Debug\\net8.0\\publish",
"${config:jellyfinDataDirWin}\\plugins\\${config:pluginName}\\"
]
},
{
// Copy the plugin dll to the jellyfin plugin install path
// This command copies every .dll from the build directory to the plugin dir
// Usually, you probablly only need ${config:pluginName}.dll
// But some plugins may bundle extra requirements
"label": "copy-dll",
"type": "shell",
"command": "cp",
"args": [
"./${config:pluginName}/bin/Debug/net8.0/publish/*",
"${config:jellyfinDataDir}/plugins/${config:pluginName}/"
]
},
]
}
================================================
FILE: ACKNOWLEDGEMENTS.md
================================================
Intro Skipper is made possible by the following open source projects:
* [acoustid-match](https://github.com/dnknth/acoustid-match) (MIT)
* [chromaprint](https://github.com/acoustid/chromaprint) (LGPL 2.1)
* [JellyScrub](https://github.com/nicknsy/jellyscrub) (MIT)
* [Jellyfin](https://github.com/jellyfin/jellyfin) (GPL)
================================================
FILE: CHANGELOG.md
================================================
# Changelog
## Unreleased
### Changed
* Task Timer is no longer configured by deafult. We listen for MediaLibrary changes instead. (Change back in options)
### Fixed
* Prevents a crash during save when start >= end time
## v0.4.0.0 (2023-11-02)
* Remove creatorId (sync with server implementation)
## v0.3.0.0 (2023-09-25)
* Add options to control listener
* Round to two decimal places
* Improve log messages
## v0.2.0.0 (2023-05-28)
* Blacklisting with db
* Enable movies credits detection
## v0.1.0.0 (2023-05-04)
* Outdated, removed from repository!
* Initial release
* New features
* Detect ending credits in television episodes
* Add support for using chapter names to locate introductions and ending credits
* Add support for using black frames to locate ending credits
* Internal changes
* Move Chromaprint analysis code out of the episode analysis task
* Add support for multiple analysis techinques
* Breaking Change
* Removed all server and frontend influencing mods
* Removed EDL handling
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/BlackFrameAnalyzer.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Microsoft.Extensions.Logging;
/// <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.
/// </summary>
public class BlackFrameAnalyzer : IMediaFileAnalyzer
{
private readonly TimeSpan _maximumError = new(0, 0, 4);
private readonly ILogger<BlackFrameAnalyzer> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="BlackFrameAnalyzer"/> class.
/// </summary>
/// <param name="logger">Logger.</param>
public BlackFrameAnalyzer(ILogger<BlackFrameAnalyzer> logger)
{
_logger = logger;
}
/// <inheritdoc />
public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOnlyDictionary<Guid, Segment> Analyzed, ReadOnlyDictionary<Guid, SegmentMetadata> SegmentMetadata)> AnalyzeMediaFilesAsync(
ReadOnlyCollection<QueuedMedia> analysisQueue,
MediaSegmentType mode,
CancellationToken cancellationToken)
{
if (mode != MediaSegmentType.Outro)
{
throw new NotImplementedException("Blackframe analyzing is just suitable for Credits/Outro");
}
var creditTimes = new Dictionary<Guid, Segment>();
var metadata = new Dictionary<Guid, SegmentMetadata>();
foreach (var episode in analysisQueue)
{
if (cancellationToken.IsCancellationRequested)
{
break;
}
var meta = await Plugin.Instance!.GetMetadataDb().GetSegments(episode.ItemId, mode, AnalyzerType.BlackFrameAnalyzer);
var intro = AnalyzeMediaFile(
episode,
mode,
Plugin.Instance!.Configuration.BlackFrameMinimumPercentage);
if (intro is null)
{
continue;
}
// protect against broken timestamps
if (intro.Start >= intro.End)
{
continue;
}
creditTimes[episode.ItemId] = intro;
if (meta is null)
{
metadata[episode.ItemId] = new SegmentMetadata(episode, mode, AnalyzerType.BlackFrameAnalyzer);
}
}
return (analysisQueue
.Where(x => !creditTimes.ContainsKey(x.ItemId))
.ToList()
.AsReadOnly(), creditTimes.AsReadOnly(), metadata.AsReadOnly());
}
/// <summary>
/// Analyzes an individual media file. Only public because of unit tests.
/// </summary>
/// <param name="episode">Media file to analyze.</param>
/// <param name="mode">Analysis mode.</param>
/// <param name="minimum">Percentage of the frame that must be black.</param>
/// <returns>Credits timestamp.</returns>
public Segment? AnalyzeMediaFile(QueuedMedia episode, MediaSegmentType mode, int minimum)
{
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
// Start by analyzing the last N minutes of the file.
var start = TimeSpan.FromSeconds(config.MaximumEpisodeCreditsDuration);
var end = TimeSpan.FromSeconds(config.MinimumCreditsDuration);
var firstFrameTime = 0.0;
// Continue bisecting the end of the file until the range that contains the first black
// frame is smaller than the maximum permitted error.
while (start - end > _maximumError)
{
// Analyze the middle two seconds from the current bisected range
var midpoint = (start + end) / 2;
var scanTime = episode.Duration - midpoint.TotalSeconds;
var tr = new TimeRange(scanTime, scanTime + 2);
_logger.LogTrace(
"{Episode}, dur {Duration}, bisect [{BStart}, {BEnd}], time [{Start}, {End}]",
episode.Name,
episode.Duration,
start,
end,
tr.Start,
tr.End);
var frames = FFmpegWrapper.DetectBlackFrames(episode, tr, minimum);
_logger.LogTrace(
"{Episode} at {Start} has {Count} black frames",
episode.Name,
tr.Start,
frames.Length);
if (frames.Length == 0)
{
// Since no black frames were found, slide the range closer to the end
start = midpoint;
}
else
{
// Some black frames were found, slide the range closer to the start
end = midpoint;
firstFrameTime = frames[0].Time + scanTime;
}
}
if (firstFrameTime > 0)
{
return new(episode.ItemId, episode.IsEpisode(), new TimeRange(firstFrameTime, episode.Duration));
}
return null;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChapterAnalyzer.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
/// <summary>
/// Chapter name analyzer.
/// </summary>
public class ChapterAnalyzer : IMediaFileAnalyzer
{
private ILogger<ChapterAnalyzer> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="ChapterAnalyzer"/> class.
/// </summary>
/// <param name="logger">Logger.</param>
public ChapterAnalyzer(ILogger<ChapterAnalyzer> logger)
{
_logger = logger;
}
/// <inheritdoc />
public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOnlyDictionary<Guid, Segment> Analyzed, ReadOnlyDictionary<Guid, SegmentMetadata> SegmentMetadata)> AnalyzeMediaFilesAsync(
ReadOnlyCollection<QueuedMedia> analysisQueue,
MediaSegmentType mode,
CancellationToken cancellationToken)
{
var skippableRanges = new Dictionary<Guid, Segment>();
var metadata = new Dictionary<Guid, SegmentMetadata>();
var expression = mode == MediaSegmentType.Intro ?
Plugin.Instance!.Configuration.ChapterAnalyzerIntroductionPattern :
Plugin.Instance!.Configuration.ChapterAnalyzerEndCreditsPattern;
if (string.IsNullOrWhiteSpace(expression))
{
return (analysisQueue, skippableRanges.AsReadOnly(), metadata.AsReadOnly());
}
foreach (var episode in analysisQueue)
{
if (cancellationToken.IsCancellationRequested)
{
break;
}
var meta = await Plugin.Instance!.GetMetadataDb().GetSegments(episode.ItemId, mode, AnalyzerType.ChapterAnalyzer);
var skipRange = FindMatchingChapter(
episode,
new(Plugin.Instance!.GetChapters(episode.ItemId)),
expression,
mode);
if (skipRange is null)
{
continue;
}
// protect against broken timestamps
if (skipRange.Start >= skipRange.End)
{
continue;
}
skippableRanges.Add(episode.ItemId, skipRange);
if (meta is null)
{
metadata[episode.ItemId] = new SegmentMetadata(episode, mode, AnalyzerType.ChapterAnalyzer);
}
}
return (analysisQueue
.Where(x => !skippableRanges.ContainsKey(x.ItemId))
.ToList()
.AsReadOnly(), skippableRanges.AsReadOnly(), metadata.AsReadOnly());
}
/// <summary>
/// Searches a list of chapter names for one that matches the provided regular expression.
/// Only public to allow for unit testing.
/// </summary>
/// <param name="episode">Episode.</param>
/// <param name="chapters">Media item chapters.</param>
/// <param name="expression">Regular expression pattern.</param>
/// <param name="mode">Analysis mode.</param>
/// <returns>Intro object containing skippable time range, or null if no chapter matched.</returns>
public Segment? FindMatchingChapter(
QueuedMedia episode,
Collection<ChapterInfo> chapters,
string expression,
MediaSegmentType mode)
{
Segment? matchingChapter = null;
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
var minDuration = config.MinimumIntroDuration;
int maxDuration = mode == MediaSegmentType.Intro ?
config.MaximumIntroDuration :
config.MaximumEpisodeCreditsDuration;
if (mode == MediaSegmentType.Outro)
{
// Since the ending credits chapter may be the last chapter in the file, append a virtual
// chapter at the very end of the file.
chapters.Add(new()
{
StartPositionTicks = TimeSpan.FromSeconds(episode.Duration).Ticks
});
}
// Check all chapters
for (int i = 0; i < chapters.Count - 1; i++)
{
var current = chapters[i];
var next = chapters[i + 1];
if (string.IsNullOrWhiteSpace(current.Name))
{
continue;
}
var currentRange = new TimeRange(
TimeSpan.FromTicks(current.StartPositionTicks).TotalSeconds,
TimeSpan.FromTicks(next.StartPositionTicks).TotalSeconds);
var baseMessage = string.Format(
CultureInfo.InvariantCulture,
"{0}: Chapter \"{1}\" ({2} - {3})",
episode.Path,
current.Name,
currentRange.Start,
currentRange.End);
if (currentRange.Duration < minDuration || currentRange.Duration > maxDuration)
{
_logger.LogTrace("{Base}: ignoring (invalid duration)", baseMessage);
continue;
}
// Regex.IsMatch() is used here in order to allow the runtime to cache the compiled regex
// between function invocations.
var match = Regex.IsMatch(
current.Name,
expression,
RegexOptions.None,
TimeSpan.FromSeconds(1));
if (!match)
{
_logger.LogTrace("{Base}: ignoring (does not match regular expression)", baseMessage);
continue;
}
matchingChapter = new(episode.ItemId, episode.IsEpisode(), currentRange);
_logger.LogTrace("{Base}: okay", baseMessage);
break;
}
return matchingChapter;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChromaprintAnalyzer.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Microsoft.Extensions.Logging;
/// <summary>
/// Chromaprint audio analyzer.
/// </summary>
public class ChromaprintAnalyzer : IMediaFileAnalyzer
{
/// <summary>
/// Seconds of audio in one fingerprint point.
/// This value is defined by the Chromaprint library and should not be changed.
/// </summary>
private const double SamplesToSeconds = 0.128;
private int minimumIntroDuration;
private int maximumDifferences;
private int invertedIndexShift;
private double maximumTimeSkip;
private double silenceDetectionMinimumDuration;
private ILogger<ChromaprintAnalyzer> _logger;
private MediaSegmentType _analyzingType;
/// <summary>
/// Initializes a new instance of the <see cref="ChromaprintAnalyzer"/> class.
/// </summary>
/// <param name="logger">Logger.</param>
public ChromaprintAnalyzer(ILogger<ChromaprintAnalyzer> logger)
{
var config = Plugin.Instance?.Configuration ?? new Configuration.PluginConfiguration();
maximumDifferences = config.MaximumFingerprintPointDifferences;
invertedIndexShift = config.InvertedIndexShift;
maximumTimeSkip = config.MaximumTimeSkip;
silenceDetectionMinimumDuration = config.SilenceDetectionMinimumDuration;
minimumIntroDuration = config.MinimumIntroDuration;
_logger = logger;
}
/// <inheritdoc />
public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOnlyDictionary<Guid, Segment> Analyzed, ReadOnlyDictionary<Guid, SegmentMetadata> SegmentMetadata)> AnalyzeMediaFilesAsync(
ReadOnlyCollection<QueuedMedia> analysisQueue,
MediaSegmentType mode,
CancellationToken cancellationToken)
{
// All segments for this season.
var seasonSegments = new Dictionary<Guid, Segment>();
// Cache of all fingerprints for this season.
var fingerprintCache = new Dictionary<Guid, uint[]>();
// Episode analysis queue based on not analyzed episodes
var episodeAnalysisQueue = analysisQueue.ToList().Where(m => !m.IsAnalyzed).ToList();
// Episodes that were analyzed and do not have an introduction.
var episodesWithoutSegments = new List<QueuedMedia>();
var metadata = new Dictionary<Guid, SegmentMetadata>();
this._analyzingType = mode;
// we need at least two episodes, it's possible to use an already analzyed one as reference
if (episodeAnalysisQueue.Count == 1 && analysisQueue.Count > 1)
{
var item = analysisQueue.Where(i => !episodeAnalysisQueue.Contains(i)).FirstOrDefault();
if (item is not null)
{
episodeAnalysisQueue.Add(item);
}
}
// If we have just one episode, we can abort and flag the episode to skip blacklisting
if (episodeAnalysisQueue.Count == 1)
{
var item = episodeAnalysisQueue.First();
_logger.LogInformation("Found just one episode for {Series}: S{Season}. Skipping as we need at least two.", item.SeriesName, item.SeasonNumber);
item.SkipPreventAnalyzing = true;
episodesWithoutSegments.Add(item);
return (episodesWithoutSegments.AsReadOnly(), seasonSegments.AsReadOnly(), metadata.AsReadOnly());
}
// Compute fingerprints for all episodes in the season
foreach (var episode in episodeAnalysisQueue)
{
try
{
fingerprintCache[episode.ItemId] = FFmpegWrapper.Fingerprint(episode, mode);
if (cancellationToken.IsCancellationRequested)
{
return (analysisQueue, seasonSegments.AsReadOnly(), metadata.AsReadOnly());
}
}
catch (FingerprintException ex)
{
_logger.LogDebug("Caught fingerprint error: {Ex}", ex);
WarningManager.SetFlag(PluginWarning.InvalidChromaprintFingerprint);
// Fallback to an empty fingerprint on any error
fingerprintCache[episode.ItemId] = Array.Empty<uint>();
}
}
// While there are still episodes in the queue
while (episodeAnalysisQueue.Count > 0)
{
// Pop the first episode from the queue
var currentEpisode = episodeAnalysisQueue[0];
episodeAnalysisQueue.RemoveAt(0);
// Search through all remaining episodes.
foreach (var remainingEpisode in episodeAnalysisQueue)
{
// Compare the current episode to all remaining episodes in the queue.
var (currentIntro, remainingIntro) = CompareEpisodes(
currentEpisode.ItemId,
fingerprintCache[currentEpisode.ItemId],
remainingEpisode.ItemId,
fingerprintCache[remainingEpisode.ItemId]);
// Ignore this comparison result if:
// - one of the intros isn't valid, or
// - the introduction exceeds the configured limit
if (
!remainingIntro.Valid ||
remainingIntro.Duration > Plugin.Instance!.Configuration.MaximumIntroDuration)
{
continue;
}
/* Since the Fingerprint() function returns an array of Chromaprint points without time
* information, the times reported from the index search function start from 0.
*
* 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.
*/
if (this._analyzingType == MediaSegmentType.Outro)
{
currentIntro.Start += currentEpisode.CreditsFingerprintStart;
currentIntro.End += currentEpisode.CreditsFingerprintStart;
remainingIntro.Start += remainingEpisode.CreditsFingerprintStart;
remainingIntro.End += remainingEpisode.CreditsFingerprintStart;
}
// Only save the discovered intro if it is:
// - the first intro discovered for this episode
// - longer than the previously discovered intro
if (
!seasonSegments.TryGetValue(currentIntro.ItemId, out var savedCurrentIntro) ||
currentIntro.Duration > savedCurrentIntro.Duration)
{
if (ValidateTime(currentIntro))
{
var meta = await Plugin.Instance!.GetMetadataDb().GetSegments(currentEpisode.ItemId, mode, AnalyzerType.ChromaprintAnalyzer);
if (meta is null)
{
metadata[currentIntro.ItemId] = new SegmentMetadata(currentEpisode, mode, AnalyzerType.ChromaprintAnalyzer);
}
seasonSegments[currentIntro.ItemId] = currentIntro;
}
}
if (
!seasonSegments.TryGetValue(remainingIntro.ItemId, out var savedRemainingIntro) ||
remainingIntro.Duration > savedRemainingIntro.Duration)
{
if (ValidateTime(currentIntro))
{
var meta = await Plugin.Instance!.GetMetadataDb().GetSegments(remainingEpisode.ItemId, mode, AnalyzerType.ChromaprintAnalyzer);
if (meta is null)
{
metadata[remainingIntro.ItemId] = new SegmentMetadata(remainingEpisode, mode, AnalyzerType.ChromaprintAnalyzer);
}
seasonSegments[remainingIntro.ItemId] = remainingIntro;
}
}
break;
}
// If no intro is found at this point, the popped episode is not reinserted into the queue.
episodesWithoutSegments.Add(currentEpisode);
}
if (this._analyzingType == MediaSegmentType.Intro)
{
// Adjust all introduction end times so that they end at silence.
seasonSegments = AdjustIntroEndTimes(analysisQueue, seasonSegments);
}
// If cancellation was requested, report that no episodes were analyzed.
if (cancellationToken.IsCancellationRequested)
{
seasonSegments.Clear();
metadata.Clear();
return (analysisQueue, seasonSegments.AsReadOnly(), metadata.AsReadOnly());
}
return (episodesWithoutSegments.AsReadOnly(), seasonSegments.AsReadOnly(), metadata.AsReadOnly());
}
/// <summary>
/// Analyze two episodes to find an introduction sequence shared between them.
/// </summary>
/// <param name="lhsId">First episode id.</param>
/// <param name="lhsPoints">First episode fingerprint points.</param>
/// <param name="rhsId">Second episode id.</param>
/// <param name="rhsPoints">Second episode fingerprint points.</param>
/// <returns>Intros for the first and second episodes.</returns>
public (Segment Lhs, Segment Rhs) CompareEpisodes(
Guid lhsId,
uint[] lhsPoints,
Guid rhsId,
uint[] rhsPoints)
{
// Creates an inverted fingerprint point index for both episodes.
// For every point which is a 100% match, search for an introduction at that point.
var (lhsRanges, rhsRanges) = SearchInvertedIndex(lhsId, lhsPoints, rhsId, rhsPoints);
if (lhsRanges.Count > 0)
{
_logger.LogTrace("Index search successful");
return GetLongestTimeRange(lhsId, lhsRanges, rhsId, rhsRanges);
}
_logger.LogTrace(
"Unable to find a shared introduction sequence between {LHS} and {RHS}",
lhsId,
rhsId);
return (new Segment(lhsId), new Segment(rhsId));
}
/// <summary>
/// Locates the longest range of similar audio and returns an Intro class for each range.
/// </summary>
/// <param name="lhsId">First episode id.</param>
/// <param name="lhsRanges">First episode shared timecodes.</param>
/// <param name="rhsId">Second episode id.</param>
/// <param name="rhsRanges">Second episode shared timecodes.</param>
/// <returns>Intros for the first and second episodes.</returns>
private (Segment Lhs, Segment Rhs) GetLongestTimeRange(
Guid lhsId,
List<TimeRange> lhsRanges,
Guid rhsId,
List<TimeRange> rhsRanges)
{
// Store the longest time range as the introduction.
lhsRanges.Sort();
rhsRanges.Sort();
var lhsIntro = lhsRanges[0];
var rhsIntro = rhsRanges[0];
// If the intro starts early in the episode, move it to the beginning.
if (lhsIntro.Start <= 5)
{
lhsIntro.Start = 0;
}
if (rhsIntro.Start <= 5)
{
rhsIntro.Start = 0;
}
// Create Intro classes for each time range.
return (new Segment(lhsId, lhsIntro), new Segment(rhsId, rhsIntro));
}
/// <summary>
/// Search for a shared introduction sequence using inverted indexes.
/// </summary>
/// <param name="lhsId">LHS ID.</param>
/// <param name="lhsPoints">Left episode fingerprint points.</param>
/// <param name="rhsId">RHS ID.</param>
/// <param name="rhsPoints">Right episode fingerprint points.</param>
/// <returns>List of shared TimeRanges between the left and right episodes.</returns>
private (List<TimeRange> Lhs, List<TimeRange> Rhs) SearchInvertedIndex(
Guid lhsId,
uint[] lhsPoints,
Guid rhsId,
uint[] rhsPoints)
{
var lhsRanges = new List<TimeRange>();
var rhsRanges = new List<TimeRange>();
// Generate inverted indexes for the left and right episodes.
var lhsIndex = FFmpegWrapper.CreateInvertedIndex(lhsId, lhsPoints);
var rhsIndex = FFmpegWrapper.CreateInvertedIndex(rhsId, rhsPoints);
var indexShifts = new HashSet<int>();
// For all audio points in the left episode, check if the right episode has a point which matches exactly.
// If an exact match is found, calculate the shift that must be used to align the points.
foreach (var kvp in lhsIndex)
{
var originalPoint = kvp.Key;
for (var i = -1 * invertedIndexShift; i <= invertedIndexShift; i++)
{
var modifiedPoint = (uint)(originalPoint + i);
if (rhsIndex.TryGetValue(modifiedPoint, out int modifiedPointValue))
{
var lhsFirst = (int)lhsIndex[originalPoint];
var rhsFirst = modifiedPointValue;
indexShifts.Add(rhsFirst - lhsFirst);
}
}
}
// Use all discovered shifts to compare the episodes.
foreach (var shift in indexShifts)
{
var (lhsIndexContiguous, rhsIndexContiguous) = FindContiguous(lhsPoints, rhsPoints, shift);
if (lhsIndexContiguous.End > 0 && rhsIndexContiguous.End > 0)
{
lhsRanges.Add(lhsIndexContiguous);
rhsRanges.Add(rhsIndexContiguous);
}
}
return (lhsRanges, rhsRanges);
}
/// <summary>
/// Finds the longest contiguous region of similar audio between two fingerprints using the provided shift amount.
/// </summary>
/// <param name="lhs">First fingerprint to compare.</param>
/// <param name="rhs">Second fingerprint to compare.</param>
/// <param name="shiftAmount">Amount to shift one fingerprint by.</param>
private (TimeRange Lhs, TimeRange Rhs) FindContiguous(
uint[] lhs,
uint[] rhs,
int shiftAmount)
{
var leftOffset = 0;
var rightOffset = 0;
// Calculate the offsets for the left and right hand sides.
if (shiftAmount < 0)
{
leftOffset -= shiftAmount;
}
else
{
rightOffset += shiftAmount;
}
// Store similar times for both LHS and RHS.
var lhsTimes = new List<double>();
var rhsTimes = new List<double>();
var upperLimit = Math.Min(lhs.Length, rhs.Length) - Math.Abs(shiftAmount);
// XOR all elements in LHS and RHS, using the shift amount from above.
for (var i = 0; i < upperLimit; i++)
{
// XOR both samples at the current position.
var lhsPosition = i + leftOffset;
var rhsPosition = i + rightOffset;
var diff = lhs[lhsPosition] ^ rhs[rhsPosition];
// If the difference between the samples is small, flag both times as similar.
if (CountBits(diff) > maximumDifferences)
{
continue;
}
var lhsTime = lhsPosition * SamplesToSeconds;
var rhsTime = rhsPosition * SamplesToSeconds;
lhsTimes.Add(lhsTime);
rhsTimes.Add(rhsTime);
}
// Ensure the last timestamp is checked
lhsTimes.Add(double.MaxValue);
rhsTimes.Add(double.MaxValue);
// Now that both fingerprints have been compared at this shift, see if there's a contiguous time range.
var lContiguous = TimeRangeHelpers.FindContiguous(lhsTimes.ToArray(), maximumTimeSkip);
if (lContiguous is null || lContiguous.Duration < minimumIntroDuration)
{
return (new TimeRange(), new TimeRange());
}
// Since LHS had a contiguous time range, RHS must have one also.
var rContiguous = TimeRangeHelpers.FindContiguous(rhsTimes.ToArray(), maximumTimeSkip)!;
if (this._analyzingType == MediaSegmentType.Intro)
{
// Tweak the end timestamps just a bit to ensure as little content as possible is skipped over.
// TODO: remove this
if (lContiguous.Duration >= 90)
{
lContiguous.End -= 2 * maximumTimeSkip;
rContiguous.End -= 2 * maximumTimeSkip;
}
else if (lContiguous.Duration >= 30)
{
lContiguous.End -= maximumTimeSkip;
rContiguous.End -= maximumTimeSkip;
}
}
return (lContiguous, rContiguous);
}
/// <summary>
/// Adjusts the end timestamps of all intros so that they end at silence.
/// </summary>
/// <param name="episodes">QueuedEpisodes to adjust.</param>
/// <param name="originalIntros">Original introductions.</param>
private Dictionary<Guid, Segment> AdjustIntroEndTimes(
ReadOnlyCollection<QueuedMedia> episodes,
Dictionary<Guid, Segment> originalIntros)
{
// The minimum duration of audio that must be silent before adjusting the intro's end.
var minimumSilence = Plugin.Instance!.Configuration.SilenceDetectionMinimumDuration;
Dictionary<Guid, Segment> modifiedIntros = new();
// For all episodes
foreach (var episode in episodes)
{
_logger.LogTrace(
"Adjusting introduction end time for {Name} ({Id})",
episode.Name,
episode.ItemId);
// If no intro was found for this episode, skip it.
if (!originalIntros.TryGetValue(episode.ItemId, out var originalIntro))
{
_logger.LogTrace("{Name} does not have an intro", episode.Name);
continue;
}
// Only adjust the end timestamp of the intro
var originalIntroEnd = new TimeRange(originalIntro.End - 15, originalIntro.End);
_logger.LogTrace(
"{Name} original intro: {Start} - {End}",
episode.Name,
originalIntro.Start,
originalIntro.End);
// Detect silence in the media file up to the end of the intro.
var silence = FFmpegWrapper.DetectSilence(episode, (int)originalIntro.End + 2);
// For all periods of silence
foreach (var currentRange in silence)
{
_logger.LogTrace(
"{Name} silence: {Start} - {End}",
episode.Name,
currentRange.Start,
currentRange.End);
// Ignore any silence that:
// * doesn't intersect the ending of the intro, or
// * is shorter than the user defined minimum duration, or
// * starts before the introduction does
if (
!originalIntroEnd.Intersects(currentRange) ||
currentRange.Duration < silenceDetectionMinimumDuration ||
currentRange.Start < originalIntro.Start)
{
continue;
}
// Adjust the end timestamp of the intro to match the start of the silence region.
originalIntro.End = currentRange.Start;
break;
}
_logger.LogTrace(
"{Name} adjusted intro: {Start} - {End}",
episode.Name,
originalIntro.Start,
originalIntro.End);
// Add the (potentially) modified intro back.
modifiedIntros[episode.ItemId] = originalIntro;
}
return modifiedIntros;
}
/// <summary>
/// Count the number of bits that are set in the provided number.
/// </summary>
/// <param name="number">Number to count bits in.</param>
/// <returns>Number of bits that are equal to 1.</returns>
public int CountBits(uint number)
{
return BitOperations.PopCount(number);
}
/// <summary>
/// Be sure the segment have a valid time.
/// </summary>
/// <param name="seg">Segment.</param>
/// <returns>True is valid.</returns>
private bool ValidateTime(Segment seg)
{
return seg.End > seg.Start;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/IMediaFileAnalyzer.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
using System;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
/// <summary>
/// Media file analyzer interface.
/// </summary>
public interface IMediaFileAnalyzer
{
/// <summary>
/// Analyze media files for shared introductions or credits, returning all media files that were not analyzed, analyzed and optional metadata for both.
/// </summary>
/// <param name="analysisQueue">Collection of unanalyzed media files.</param>
/// <param name="mode">Analysis mode.</param>
/// <param name="cancellationToken">Cancellation token from scheduled task.</param>
/// <returns>Collection of media files that were **unsuccessfully analyzed** and successfull.</returns>
public Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOnlyDictionary<Guid, Segment> Analyzed, ReadOnlyDictionary<Guid, SegmentMetadata> SegmentMetadata)> AnalyzeMediaFilesAsync(
ReadOnlyCollection<QueuedMedia> analysisQueue,
MediaSegmentType mode,
CancellationToken cancellationToken);
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/PluginConfiguration.cs
================================================
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.MediaAnalyzer.Configuration;
/// <summary>
/// Plugin configuration.
/// </summary>
public class PluginConfiguration : BasePluginConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
/// </summary>
public PluginConfiguration()
{
}
// ===== General settings =====
/// <summary>
/// Gets or sets a value indicating whether we run after a library scan.
/// </summary>
public bool RunAfterLibraryScan { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether we run after library item added or updated events.
/// </summary>
public bool RunAfterAddOrUpdateEvent { get; set; } = true;
// ===== Analysis settings =====
/// <summary>
/// Gets or sets a value indicating whether the episode's fingerprint should be cached to the filesystem.
/// </summary>
public bool CacheFingerprints { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the Blacklist should be resetted.
/// </summary>
public bool ResetBlacklist { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the Blacklist should be created or used.
/// </summary>
public bool EnableBlacklist { get; set; } = true;
/// <summary>
/// Gets or sets the max degree of parallelism used when analyzing episodes.
/// </summary>
public int MaxParallelism { get; set; } = 2;
/// <summary>
/// Gets or sets the comma separated list of library names to analyze. If empty, all libraries will be analyzed.
/// </summary>
public string SelectedLibraries { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the comma separated list of tv shows and seasons to skip the analyze. Format: "My Show;S01;S02, Another Show".
/// </summary>
public string SkippedTvShows { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the comma separated list of movies to skip the analyze.".
/// </summary>
public string SkippedMovies { get; set; } = string.Empty;
/// <summary>
/// Gets or sets a value indicating whether to analyze season 0.
/// </summary>
public bool AnalyzeSeasonZero { get; set; } = false;
// ===== Custom analysis settings =====
/// <summary>
/// Gets or sets the percentage of each episode's audio track to analyze.
/// </summary>
public int AnalysisPercent { get; set; } = 30;
/// <summary>
/// Gets or sets the upper limit (in minutes) on the length of each episode's audio track that will be analyzed.
/// </summary>
public int AnalysisLengthLimit { get; set; } = 15;
/// <summary>
/// Gets or sets the minimum length of similar audio that will be considered an introduction.
/// </summary>
public int MinimumIntroDuration { get; set; } = 15;
/// <summary>
/// Gets or sets the maximum length of similar audio that will be considered an introduction.
/// </summary>
public int MaximumIntroDuration { get; set; } = 120;
/// <summary>
/// Gets or sets the minimum length of similar audio that will be considered ending credits.
/// </summary>
public int MinimumCreditsDuration { get; set; } = 15;
/// <summary>
/// Gets or sets the upper limit (in seconds) on the length of each episode's audio track that will be analyzed when searching for ending credits.
/// </summary>
public int MaximumEpisodeCreditsDuration { get; set; } = 240;
/// <summary>
/// Gets or sets the upper limit (in seconds) on the length of each movie's audio track that will be analyzed when searching for ending credits.
/// </summary>
public int MaximumMovieCreditsDuration { get; set; } = 900;
/// <summary>
/// Gets or sets the minimum percentage of a frame that must consist of black pixels before it is considered a black frame.
/// </summary>
public int BlackFrameMinimumPercentage { get; set; } = 85;
/// <summary>
/// Gets or sets the regular expression used to detect introduction chapters.
/// </summary>
public string ChapterAnalyzerIntroductionPattern { get; set; } =
@"(^|\s)(Intro|Introduction|OP|Opening)(\s|$)";
/// <summary>
/// Gets or sets the regular expression used to detect ending credit chapters.
/// </summary>
public string ChapterAnalyzerEndCreditsPattern { get; set; } =
@"(^|\s)(Credits?|Ending|End|Outro)(\s|$)";
// ===== Internal algorithm settings =====
/// <summary>
/// Gets or sets the maximum number of bits (out of 32 total) that can be different between two Chromaprint points before they are considered dissimilar.
/// Defaults to 6 (81% similar).
/// </summary>
public int MaximumFingerprintPointDifferences { get; set; } = 6;
/// <summary>
/// Gets or sets the maximum number of seconds that can pass between two similar fingerprint points before a new time range is started.
/// </summary>
public double MaximumTimeSkip { get; set; } = 3.5;
/// <summary>
/// Gets or sets the amount to shift inverted indexes by.
/// </summary>
public int InvertedIndexShift { get; set; } = 2;
/// <summary>
/// Gets or sets the maximum amount of noise (in dB) that is considered silent.
/// Lowering this number will increase the filter's sensitivity to noise.
/// </summary>
public int SilenceDetectionMaximumNoise { get; set; } = -50;
/// <summary>
/// Gets or sets the minimum duration of audio (in seconds) that is considered silent.
/// </summary>
public double SilenceDetectionMinimumDuration { get; set; } = 0.33;
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/configPage.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<div id="TemplateConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<form id="FingerprintConfigForm">
<fieldset class="verticalSection-extrabottompadding">
<legend>General</legend>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="RunAfterLibraryScan" type="checkbox" is="emby-checkbox" />
<span>Run after Library Scan</span>
</label>
<div class="fieldDescription">Whenever the media library scan task ends, run the analyzer.</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="RunAfterAddOrUpdateEvent" type="checkbox" is="emby-checkbox" />
<span>Run after Library update events</span>
</label>
<div class="fieldDescription">When media folder watch is enabled the library will push events we can also listen for.</div>
</div>
<legend>Analysis</legend>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="AnalyzeSeasonZero" type="checkbox" is="emby-checkbox" />
<span>Analyze show extras</span>
</label>
<div class="fieldDescription">Analyze show extras (specials), listed as season 0.</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="CacheFingerprints" type="checkbox" is="emby-checkbox" />
<span>Cache Fringerprints</span>
</label>
<div class="fieldDescription">Requires lot's of disk space. Should be just enabled for development or when you play around with intro/credits options (Also disable blacklisting!).</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="EnableBlacklist" type="checkbox" is="emby-checkbox" />
<span>Enable Blacklisting</span>
</label>
<div class="fieldDescription">If we can't find an Intro/Outro Segment for an episode or movie it is blacklisted to prevent repeated analysis.</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="ResetBlacklist" type="checkbox" is="emby-checkbox" />
<span>Delete Blacklist</span>
</label>
<div class="fieldDescription">Delete the blacklist of segments.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MaxParallelism"> Maximum degree of parallelism </label>
<input id="MaxParallelism" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Maximum degree of parallelism to use when analyzing.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SelectedLibraries"> Limit analysis to the following libraries </label>
<input id="SelectedLibraries" type="text" is="emby-input" />
<div class="fieldDescription">Enter the names of libraries to analyze, separated by commas. If this field is left blank, all libraries on the server containing movies or television episodes will be analyzed.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SkippedTvShows"> Skip TV Shows </label>
<input id="SkippedTvShows" type="text" is="emby-input" />
<div class="fieldDescription">Enter the names of tv shows to skip the analyze, separated by commas. You can also skip seasons. Format: "My Show;S01;S02, Another Show, Third Show;S03;S05"</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SkippedMovies"> Skip Movies </label>
<input id="SkippedMovies" type="text" is="emby-input" />
<div class="fieldDescription">Enter the names of Movies to skip the analyze, separated by commas. Format: "The Godfather, Spiderman, Matrix"</div>
</div>
<details id="intro_reqs">
<summary>Modify introduction requirements</summary>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="AnalysisPercent"> Percent of audio to analyze </label>
<input id="AnalysisPercent" type="number" is="emby-input" min="1" max="90" />
<div class="fieldDescription">Analysis will be limited to this percentage of each episode's audio. For example, a value of 25 (the default) will limit analysis to the first quarter of each episode.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="AnalysisLengthLimit"> Maximum runtime of audio to analyze (in minutes) </label>
<input id="AnalysisLengthLimit" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Analysis will be limited to this amount of each episode's audio. For example, a value of 10 (the default) will limit analysis to the first 10 minutes of each episode.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MinimumIntroDuration"> Minimum introduction duration (in seconds) </label>
<input id="MinimumIntroDuration" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Similar sounding audio which is shorter than this duration will not be considered an introduction.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MaximumIntroDuration"> Maximum introduction duration (in seconds) </label>
<input id="MaximumIntroDuration" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Similar sounding audio which is longer than this duration will not be considered an introduction.</div>
</div>
<p>The amount of each episode's audio that will be analyzed is determined using both the percentage of audio and maximum runtime of audio to analyze. The minimum of (episode duration * percent, maximum runtime) is the amount of audio that will be analyzed.</p>
<p>
If the audio percentage or maximum runtime settings are modified, the cached fingerprints and introduction timestamps for each season you want to analyze with the modified settings <strong>will have to be deleted.</strong>
Increasing either of these settings will cause episode analysis to take much longer.
</p>
</details>
<details id="outros_reqs">
<summary>Modify Credits requirements</summary>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="BlackFrameMinimumPercentage"> Black frame (in percent) </label>
<input id="BlackFrameMinimumPercentage" type="number" is="emby-input" min="60" max="99" />
<div class="fieldDescription">Sets the minimum percentage of a frame that must consist of black pixels before it is considered a black frame.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MinimumCreditsDuration"> Minimum credits duration (in seconds) </label>
<input id="MinimumCreditsDuration" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Sets the minimum length of similar audio that will be considered ending credits.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MaximumEpisodeCreditsDuration"> Maximum episode credits duration (in seconds) </label>
<input id="MaximumEpisodeCreditsDuration" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Sets the upper limit on the length of each episode that will be analyzed when searching for ending credits.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="MaximumMovieCreditsDuration"> Maximum movie credits duration (in seconds) </label>
<input id="MaximumMovieCreditsDuration" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Sets the upper limit on the length of each movie that will be analyzed when searching for ending credits.</div>
</div>
</details>
<details id="silence">
<summary>Silence detection options</summary>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SilenceDetectionMaximumNoise"> Noise tolerance </label>
<input id="SilenceDetectionMaximumNoise" type="number" is="emby-input" min="-90" max="0" />
<div class="fieldDescription">Noise tolerance in negative decibels.</div>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="SilenceDetectionMinimumDuration"> Minimum silence duration </label>
<input id="SilenceDetectionMinimumDuration" type="number" is="emby-input" min="0" step="0.01" />
<div class="fieldDescription">Minimum silence duration in seconds before adjusting introduction end time.</div>
</div>
</details>
</fieldset>
<div>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
<span>Save</span>
</button>
<br />
</div>
</form>
</div>
<details id="support">
<summary>Support Bundle</summary>
<textarea id="supportBundle" rows="20" cols="75" readonly></textarea>
</details>
<details id="visualizer">
<summary>Advanced</summary>
<h3 style="margin: 0">Select episodes to manage</h3>
<select id="troubleshooterShow"></select>
<select id="troubleshooterSeason"></select>
<br />
<select id="troubleshooterEpisode1"></select>
<select id="troubleshooterEpisode2"></select>
<br />
<br />
<div id="timestampEditor" style="display: none">
<h3 style="margin: 0">Introduction timestamp editor</h3>
<p style="margin: 0">All times are in seconds.</p>
<p id="editLeftEpisodeTitle" style="margin-bottom: 0"></p>
<input style="width: 4em" type="number" min="0" id="editLeftEpisodeStart" /> to
<input style="width: 4em; margin-bottom: 10px" type="number" min="0" id="editLeftEpisodeEnd" />
<p id="editRightEpisodeTitle" style="margin-top: 0; margin-bottom: 0"></p>
<input style="width: 4em" type="number" min="0" id="editRightEpisodeStart" /> to
<input style="width: 4em; margin-bottom: 10px" type="number" min="0" id="editRightEpisodeEnd" />
<br />
<button id="btnUpdateTimestamps" type="button">Update timestamps</button>
<br />
<br />
<button id="btnEraseSeasonTimestamps" type="button">Erase all timestamps for this season</button>
<hr />
</div>
<button id="btnEraseIntroTimestamps">Erase all introduction timestamps (globally)</button>
<br />
<button id="btnEraseCreditTimestamps">Erase all end credits timestamps (globally)</button>
<br />
<br />
<h3>Fingerprint Visualizer</h3>
<p>
Interactively compare the audio fingerprints of two episodes. <br />
The blue and red bar to the right of the fingerprint diff turns blue when the corresponding fingerprint points are at least 80% similar.
</p>
<table>
<thead>
<td style="min-width: 100px; font-weight: bold">Key</td>
<td style="font-weight: bold">Function</td>
</thead>
<tbody>
<tr>
<td>Up arrow</td>
<td>Shift the left episode up by 0.128 seconds. Holding control will shift the episode by 10 seconds.</td>
</tr>
<tr>
<td>Down arrow</td>
<td>Shift the left episode down by 0.128 seconds. Holding control will shift the episode by 10 seconds.</td>
</tr>
<tr>
<td>Right arrow</td>
<td>Advance to the next pair of episodes.</td>
</tr>
<tr>
<td>Left arrow</td>
<td>Go back to the previous pair of episodes.</td>
</tr>
</tbody>
</table>
<br />
<span>Shift amount:</span>
<input type="number" min="-3000" max="3000" value="0" id="offset" />
<br />
<span id="suggestedShifts">Suggested shifts:</span>
<br />
<br />
<canvas id="troubleshooter"></canvas>
<span id="timestampContainer">
<span id="timestamps"></span> <br />
<span id="intros"></span>
</span>
</details>
</div>
<script src="configurationpage?name=visualizer.js"></script>
<script>
// first and second episodes to fingerprint & compare
var lhs = [];
var rhs = [];
// fingerprint point comparison & miminum similarity threshold (at most 6 bits out of 32 can be different)
var fprDiffs = [];
var fprDiffMinimum = (1 - 6 / 32) * 100;
// seasons grouped by show
var shows = {};
// settings elements
var visualizer = document.querySelector("details#visualizer");
var support = document.querySelector("details#support");
var btnEraseIntroTimestamps = document.querySelector("button#btnEraseIntroTimestamps");
var btnEraseCreditTimestamps = document.querySelector("button#btnEraseCreditTimestamps");
// all plugin configuration fields that can be get or set with .value (i.e. strings or numbers).
var configurationFields = [
// General
// analysis
"MaxParallelism",
"SelectedLibraries",
"SkippedTvShows",
"SkippedMovies",
"AnalysisPercent",
"AnalysisLengthLimit",
"MinimumIntroDuration",
"MaximumIntroDuration",
"MinimumCreditsDuration",
"MaximumEpisodeCreditsDuration",
"MaximumMovieCreditsDuration",
"BlackFrameMinimumPercentage",
// internals
"SilenceDetectionMaximumNoise",
"SilenceDetectionMinimumDuration",
];
var booleanConfigurationFields = ["AnalyzeSeasonZero","RunAfterLibraryScan","RunAfterAddOrUpdateEvent","CacheFingerprints","ResetBlacklist","EnableBlacklist"];
// visualizer elements
var canvas = document.querySelector("canvas#troubleshooter");
var selectShow = document.querySelector("select#troubleshooterShow");
var selectSeason = document.querySelector("select#troubleshooterSeason");
var selectEpisode1 = document.querySelector("select#troubleshooterEpisode1");
var selectEpisode2 = document.querySelector("select#troubleshooterEpisode2");
var txtOffset = document.querySelector("input#offset");
var txtSuggested = document.querySelector("span#suggestedShifts");
var btnUpdateTimestamps = document.querySelector("button#btnUpdateTimestamps");
var timeContainer = document.querySelector("span#timestampContainer");
var windowHashInterval = 0;
// when the fingerprint visualizer opens, populate show names
async function visualizerToggled() {
if (!visualizer.open) {
return;
}
// ensure the series select is empty
while (selectShow.options.length > 0) {
selectShow.remove(0);
}
Dashboard.showLoadingMsg();
shows = await getJson("JellyfinPluginIntroSkip/Shows");
var sorted = [];
for (var series in shows) {
sorted.push(series);
}
sorted.sort();
for (var show of sorted) {
addItem(selectShow, show, show);
}
selectShow.value = "";
Dashboard.hideLoadingMsg();
}
// fetch the support bundle whenever the detail section is opened.
async function supportToggled() {
if (!support.open) {
return;
}
// Fetch the support bundle
const bundle = await fetchWithAuth("JellyfinPluginIntroSkipSupport/SupportBundle", "GET", null);
const bundleText = await bundle.text();
// Display it to the user and select all
const ta = document.querySelector("textarea#supportBundle");
ta.value = bundleText;
ta.focus();
ta.setSelectionRange(0, ta.value.length);
// Attempt to copy it to the clipboard automatically, falling back
// to prompting the user to press Ctrl + C.
try {
navigator.clipboard.writeText(bundleText);
Dashboard.alert("Support bundle copied to clipboard");
} catch {
Dashboard.alert("Press Ctrl+C to copy support bundle");
}
}
// show changed, populate seasons
async function showChanged() {
clearSelect(selectSeason);
// add all seasons from this show to the season select
for (var season of shows[selectShow.value]) {
addItem(selectSeason, season, season);
}
selectSeason.value = "";
}
// season changed, reload all episodes
async function seasonChanged() {
const url = "JellyfinPluginIntroSkip/Show/" + encodeURI(selectShow.value) + "/" + selectSeason.value;
const episodes = await getJson(url);
clearSelect(selectEpisode1);
clearSelect(selectEpisode2);
let i = 1;
for (let episode of episodes) {
const strI = i.toLocaleString("en", { minimumIntegerDigits: 2, maximumFractionDigits: 0 });
addItem(selectEpisode1, strI + ": " + episode.Name, episode.Id);
addItem(selectEpisode2, strI + ": " + episode.Name, episode.Id);
i++;
}
setTimeout(() => {
selectEpisode1.selectedIndex = 0;
selectEpisode2.selectedIndex = 1;
episodeChanged();
}, 100);
}
// episode changed, get fingerprints & calculate diff
async function episodeChanged() {
if (!selectEpisode1.value || !selectEpisode2.value) {
return;
}
Dashboard.showLoadingMsg();
lhs = await getJson("JellyfinPluginIntroSkip/Episode/" + selectEpisode1.value + "/Chromaprint");
rhs = await getJson("JellyfinPluginIntroSkip/Episode/" + selectEpisode2.value + "/Chromaprint");
Dashboard.hideLoadingMsg();
txtOffset.value = "0";
refreshBounds();
renderTroubleshooter();
findExactMatches();
updateTimestampEditor();
}
// updates the timestamp editor
async function updateTimestampEditor() {
// Get the title and ID of the left and right episodes
const leftEpisode = selectEpisode1.options[selectEpisode1.selectedIndex];
const rightEpisode = selectEpisode2.options[selectEpisode2.selectedIndex];
// Try to get the timestamps of each intro, falling back a default value of zero if no intro was found
let leftEpisodeIntro = await getJson(`MediaSegments/${leftEpisode.value}?includeSegmentTypes=[Intro]`);
if (!leftEpisodeIntro.Items.length) {
leftEpisodeIntro = { StartTicks: 0, EndTicks: 0 };
} else {
leftEpisodeIntro = { StartTicks: ticksToSeconds(leftEpisodeIntro.Items[0].StartTicks), EndTicks: ticksToSeconds(leftEpisodeIntro.Items[0].EndTicks) };
}
let rightEpisodeIntro = await getJson(`MediaSegments/${rightEpisode.value}?includeSegmentTypes=[Intro]`);
if (!rightEpisodeIntro.Items.length) {
rightEpisodeIntro = { StartTicks: 0, EndTicks: 0 };
} else {
rightEpisodeIntro = { StartTicks: ticksToSeconds(rightEpisodeIntro.Items[0].StartTicks), EndTicks: ticksToSeconds(rightEpisodeIntro.Items[0].EndTicks) };
}
// Update the editor for the first and second episodes
document.querySelector("#timestampEditor").style.display = "unset";
document.querySelector("#editLeftEpisodeTitle").textContent = leftEpisode.text;
document.querySelector("#editLeftEpisodeStart").value = Math.round(leftEpisodeIntro.StartTicks);
document.querySelector("#editLeftEpisodeEnd").value = Math.round(leftEpisodeIntro.EndTicks);
document.querySelector("#editRightEpisodeTitle").textContent = rightEpisode.text;
document.querySelector("#editRightEpisodeStart").value = Math.round(rightEpisodeIntro.StartTicks);
document.querySelector("#editRightEpisodeEnd").value = Math.round(rightEpisodeIntro.EndTicks);
}
// adds an item to a dropdown
function addItem(select, text, value) {
let item = new Option(text, value);
select.add(item);
}
// clear a select of items
function clearSelect(select) {
let i,
L = select.options.length - 1;
for (i = L; i >= 0; i--) {
select.remove(i);
}
}
// convert between seconds and ticks
function ticksToSeconds(ticks) {
return ticks / 10_000_000
}
// convert between seconds and ticks
function secondsToTicks(seconds) {
return 10_000_000 * seconds
}
// make an authenticated GET to the server and parse the response as JSON
async function getJson(url) {
return await fetchWithAuth(url, "GET").then((r) => {
return r.json();
});
}
// make an authenticated fetch to the server
async function fetchWithAuth(url, method, body) {
url = ApiClient.serverAddress() + "/" + url;
const reqInit = {
method: method,
headers: {
Authorization: "MediaBrowser Token=" + ApiClient.accessToken(),
},
body: body,
};
if (method === "POST") {
reqInit.headers["Content-Type"] = "application/json";
}
return await fetch(url, reqInit);
}
// key pressed
function keyDown(e) {
let episodeDelta = 0;
let offsetDelta = 0;
switch (e.key) {
case "ArrowDown":
// if the control key is pressed, shift LHS by 10s. Otherwise, shift by 1.
offsetDelta = e.ctrlKey ? 10 / 0.128 : 1;
break;
case "ArrowUp":
offsetDelta = e.ctrlKey ? -10 / 0.128 : -1;
break;
case "ArrowRight":
episodeDelta = 2;
break;
case "ArrowLeft":
episodeDelta = -2;
break;
default:
return;
}
if (offsetDelta != 0) {
txtOffset.value = Number(txtOffset.value) + Math.floor(offsetDelta);
}
if (episodeDelta != 0) {
// calculate the number of episodes remaining in the LHS and RHS episode pickers
const lhsRemaining = selectEpisode1.selectedIndex;
const rhsRemaining = selectEpisode2.length - selectEpisode2.selectedIndex - 1;
// if we're moving forward and the right episode picker is close to the end, don't move.
if (episodeDelta > 0 && rhsRemaining <= 1) {
return;
} else if (episodeDelta < 0 && lhsRemaining <= 1) {
return;
}
selectEpisode1.selectedIndex += episodeDelta;
selectEpisode2.selectedIndex += episodeDelta;
episodeChanged();
}
renderTroubleshooter();
e.preventDefault();
}
// check that the user is still on the configuration page
function checkWindowHash() {
const h = location.hash;
if (h === "#!/configurationpage?name=Media%20Analyzer" || h.includes("#!/dialog")) {
return;
}
console.debug("navigated away from media analyzer configuration page");
document.removeEventListener("keydown", keyDown);
clearInterval(windowHashInterval);
}
// converts seconds to a readable timestamp (i.e. 127 becomes "02:07").
function secondsToString(seconds) {
return new Date(seconds * 1000).toISOString().substr(14, 5);
}
// erase all intro/credits timestamps
function eraseTimestamps(mode) {
const lower = mode.toLocaleLowerCase();
const title = "Confirm timestamp erasure";
const body = "Are you sure you want to erase all previously discovered " + mode.toLocaleLowerCase() + " timestamps?";
Dashboard.confirm(body, title, (result) => {
if (!result) {
return;
}
// FIXME: Can't implement, no upstream support
// fetchWithAuth("MediaSegment?type="+mode, "DELETE", null);
// Dashboard.alert(mode + " timestamps erased");
Dashboard.alert("Can't erase 'all' timestamps, there is no api in jellyfin");
});
}
document.querySelector("#TemplateConfigPage").addEventListener("pageshow", function () {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration("80885677-DACB-461B-AC97-EE7E971288AA").then(function (config) {
for (const field of configurationFields) {
document.querySelector("#" + field).value = config[field];
}
for (const field of booleanConfigurationFields) {
document.querySelector("#" + field).checked = config[field];
}
Dashboard.hideLoadingMsg();
});
});
document.querySelector("#FingerprintConfigForm").addEventListener("submit", function (e) {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration("80885677-DACB-461B-AC97-EE7E971288AA").then(function (config) {
for (const field of configurationFields) {
config[field] = document.querySelector("#" + field).value;
}
for (const field of booleanConfigurationFields) {
config[field] = document.querySelector("#" + field).checked;
}
ApiClient.updatePluginConfiguration("80885677-DACB-461B-AC97-EE7E971288AA", config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
});
e.preventDefault();
return false;
});
visualizer.addEventListener("toggle", visualizerToggled);
support.addEventListener("toggle", supportToggled);
txtOffset.addEventListener("change", renderTroubleshooter);
selectShow.addEventListener("change", showChanged);
selectSeason.addEventListener("change", seasonChanged);
selectEpisode1.addEventListener("change", episodeChanged);
selectEpisode2.addEventListener("change", episodeChanged);
btnEraseIntroTimestamps.addEventListener("click", (e) => {
eraseTimestamps("Intro");
e.preventDefault();
});
btnEraseCreditTimestamps.addEventListener("click", (e) => {
eraseTimestamps("Outro");
e.preventDefault();
});
btnUpdateTimestamps.addEventListener("click", () => {
const lhsId = selectEpisode1.options[selectEpisode1.selectedIndex].value;
const newLhsIntro = {
StartTicks: secondsToTicks(document.querySelector("#editLeftEpisodeStart").value),
EndTicks: secondsToTicks(document.querySelector("#editLeftEpisodeEnd").value),
ItemId: lhsId,
Type: 'Intro'
};
const rhsId = selectEpisode2.options[selectEpisode2.selectedIndex].value;
const newRhsIntro = {
StartTicks: secondsToTicks(document.querySelector("#editRightEpisodeStart").value),
EndTicks: secondsToTicks(document.querySelector("#editRightEpisodeEnd").value),
ItemId: rhsId,
Type: 'Intro'
};
// TODO: create new endpoint that can handle an update
fetchWithAuth("JellyfinPluginIntroSkip/Episode/" + lhsId + "/UpdateIntroTimestamps", "POST", JSON.stringify(newLhsIntro));
fetchWithAuth("JellyfinPluginIntroSkip/Episode/" + rhsId + "/UpdateIntroTimestamps", "POST", JSON.stringify(newRhsIntro));
Dashboard.alert("New introduction timestamps saved");
});
document.addEventListener("keydown", keyDown);
windowHashInterval = setInterval(checkWindowHash, 2500);
canvas.addEventListener("mousemove", (e) => {
const rect = e.currentTarget.getBoundingClientRect();
const y = e.clientY - rect.top;
const shift = Number(txtOffset.value);
let lTime, rTime, diffPos;
if (shift < 0) {
lTime = y * 0.128;
rTime = (y + shift) * 0.128;
diffPos = y + shift;
} else {
lTime = (y - shift) * 0.128;
rTime = y * 0.128;
diffPos = y - shift;
}
const diff = fprDiffs[Math.floor(diffPos)];
if (!diff) {
timeContainer.style.display = "none";
return;
} else {
timeContainer.style.display = "unset";
}
const times = document.querySelector("span#timestamps");
// LHS timestamp, RHS timestamp, percent similarity
times.textContent = secondsToString(lTime) + ", " + secondsToString(rTime) + ", " + Math.round(diff) + "%";
timeContainer.style.position = "relative";
timeContainer.style.left = "25px";
timeContainer.style.top = (-1 * rect.height + y).toString() + "px";
});
</script>
</div>
</body>
</html>
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/version.txt
================================================
unknown
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/visualizer.js
================================================
// re-render the troubleshooter with the latest offset
function renderTroubleshooter() {
paintFingerprintDiff(canvas, lhs, rhs, Number(offset.value));
findIntros();
}
// refresh the upper & lower bounds for the offset
function refreshBounds() {
const len = Math.min(lhs.length, rhs.length) - 1;
offset.min = -1 * len;
offset.max = len;
}
function findIntros() {
let times = [];
// get the times of all similar fingerprint points
for (let i in fprDiffs) {
if (fprDiffs[i] > fprDiffMinimum) {
times.push(i * 0.128);
}
}
// always close the last range
times.push(Number.MAX_VALUE);
let last = times[0];
let start = last;
let end = last;
let ranges = [];
for (let t of times) {
const diff = t - last;
if (diff <= 3.5) {
end = t;
last = t;
continue;
}
const dur = Math.round(end - start);
if (dur >= 15) {
ranges.push({
"start": start,
"end": end,
"duration": dur
});
}
start = t;
end = t;
last = t;
}
const introsLog = document.querySelector("span#intros");
introsLog.style.position = "relative";
introsLog.style.left = "115px";
introsLog.innerHTML = "";
const offset = Number(txtOffset.value) * 0.128;
for (let r of ranges) {
let lStart, lEnd, rStart, rEnd;
if (offset < 0) {
// negative offset, the diff is aligned with the RHS
lStart = r.start - offset;
lEnd = r.end - offset;
rStart = r.start;
rEnd = r.end;
} else {
// positive offset, the diff is aligned with the LHS
lStart = r.start;
lEnd = r.end;
rStart = r.start + offset;
rEnd = r.end + offset;
}
const lTitle = selectEpisode1.options[selectEpisode1.selectedIndex].text;
const rTitle = selectEpisode2.options[selectEpisode2.selectedIndex].text;
introsLog.innerHTML += "<span>" + lTitle + ": " +
secondsToString(lStart) + " - " + secondsToString(lEnd) + "</span> <br />";
introsLog.innerHTML += "<span>" + rTitle + ": " +
secondsToString(rStart) + " - " + secondsToString(rEnd) + "</span> <br />";
}
}
// find all shifts which align exact matches of audio.
function findExactMatches() {
let shifts = [];
for (let lhsIndex in lhs) {
let lhsPoint = lhs[lhsIndex];
let rhsIndex = rhs.findIndex((x) => x === lhsPoint);
if (rhsIndex === -1) {
continue;
}
let shift = rhsIndex - lhsIndex;
if (shifts.includes(shift)) {
continue;
}
shifts.push(shift);
}
// Only suggest up to 20 shifts
shifts = shifts.slice(0, 20);
txtSuggested.textContent = "Suggested shifts: ";
if (shifts.length === 0) {
txtSuggested.textContent += "none available";
} else {
shifts.sort((a, b) => { return a - b });
txtSuggested.textContent += shifts.join(", ");
}
}
// The below two functions were modified from https://github.com/dnknth/acoustid-match/blob/ffbf21d8c53c40d3b3b4c92238c35846545d3cd7/fingerprints/static/fingerprints/fputils.js
// Originally licensed as MIT.
function renderFingerprintData(ctx, fp, xor = false) {
const pixels = ctx.createImageData(32, fp.length);
let idx = 0;
for (let i = 0; i < fp.length; i++) {
for (let j = 0; j < 32; j++) {
if (fp[i] & (1 << j)) {
pixels.data[idx + 0] = 255;
pixels.data[idx + 1] = 255;
pixels.data[idx + 2] = 255;
} else {
pixels.data[idx + 0] = 0;
pixels.data[idx + 1] = 0;
pixels.data[idx + 2] = 0;
}
pixels.data[idx + 3] = 255;
idx += 4;
}
}
if (!xor) {
return pixels;
}
// if rendering the XOR of the fingerprints, count how many bits are different at each timecode
fprDiffs = [];
for (let i = 0; i < fp.length; i++) {
let count = 0;
for (let j = 0; j < 32; j++) {
if (fp[i] & (1 << j)) {
count++;
}
}
// push the percentage similarity
fprDiffs[i] = 100 - (count * 100) / 32;
}
return pixels;
}
function paintFingerprintDiff(canvas, fp1, fp2, offset) {
if (fp1.length == 0) {
return;
}
let leftOffset = 0, rightOffset = 0;
if (offset < 0) {
leftOffset -= offset;
} else {
rightOffset += offset;
}
let fpDiff = [];
fpDiff.length = Math.min(fp1.length, fp2.length) - Math.abs(offset);
for (let i = 0; i < fpDiff.length; i++) {
fpDiff[i] = fp1[i + leftOffset] ^ fp2[i + rightOffset];
}
const ctx = canvas.getContext('2d');
const pixels1 = renderFingerprintData(ctx, fp1);
const pixels2 = renderFingerprintData(ctx, fp2);
const pixelsDiff = renderFingerprintData(ctx, fpDiff, true);
const border = 4;
canvas.width = pixels1.width + border + // left fingerprint
pixels2.width + border + // right fingerprint
pixelsDiff.width + border // fingerprint diff
+ 4; // if diff[x] >= fprDiffMinimum
canvas.height = Math.max(pixels1.height, pixels2.height) + Math.abs(offset);
ctx.rect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#C5C5C5";
ctx.fill();
// draw left fingerprint
let dx = 0;
ctx.putImageData(pixels1, dx, rightOffset);
dx += pixels1.width + border;
// draw right fingerprint
ctx.putImageData(pixels2, dx, leftOffset);
dx += pixels2.width + border;
// draw fingerprint diff
ctx.putImageData(pixelsDiff, dx, Math.abs(offset));
dx += pixelsDiff.width + border;
// draw the fingerprint diff similarity indicator
// https://davidmathlogic.com/colorblind/#%23EA3535-%232C92EF
for (let i in fprDiffs) {
const j = Number(i);
const y = Math.abs(offset) + j;
const point = fprDiffs[j];
if (point >= 100) {
ctx.fillStyle = "#002FFF"
} else if (point >= fprDiffMinimum) {
ctx.fillStyle = "#2C92EF";
} else {
ctx.fillStyle = "#EA3535";
}
ctx.fillRect(dx, y, 4, 1);
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/MediaAnalyzerController.cs
================================================
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Mime;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer.Controllers;
/// <summary>
/// PluginEdl controller.
/// </summary>
[Authorize(Policy = "RequiresElevation")]
[ApiController]
[Produces(MediaTypeNames.Application.Json)]
[Route("PluginMediaAnalyzer")]
public class MediaAnalyzerController : ControllerBase
{
private readonly ILoggerFactory _loggerFactory;
private readonly ILibraryManager _libraryManager;
private readonly IMediaSegmentManager _mediaSegmentManager;
/// <summary>
/// Initializes a new instance of the <see cref="MediaAnalyzerController"/> class.
/// </summary>
/// <param name="loggerFactory">Logger factory.</param>
/// <param name="libraryManager">LibraryManager.</param>
/// <param name="mediaSegmentManager">MediaSegmentsManager.</param>
public MediaAnalyzerController(
ILoggerFactory loggerFactory,
ILibraryManager libraryManager,
IMediaSegmentManager mediaSegmentManager)
{
_loggerFactory = loggerFactory;
_libraryManager = libraryManager;
_mediaSegmentManager = mediaSegmentManager;
}
/// <summary>
/// Plugin meta endpoint.
/// </summary>
/// <returns>The version info.</returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public JsonResult GetPluginMetadata()
{
var json = new
{
version = Plugin.Instance!.Version.ToString(3),
};
return new JsonResult(json);
}
/// <summary>
/// Run analyzer based on itemIds and params and returns the segments + metadata.
/// </summary>
/// <param name="itemIds">ItemIds.</param>
/// <param name="analyzerTypes">Analyzers to use.</param>
/// <param name="mode">Segment Type to search for.</param>
/// <returns>The found segments.</returns>
[HttpGet("Analyzers")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<JsonResult> AnalyzeIds(
[FromQuery, Required] Guid[] itemIds,
[FromQuery, Required] AnalyzerType[] analyzerTypes,
[FromQuery, Required] MediaSegmentType mode)
{
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager, MediaSegmentType.Intro);
var errors = new JsonArray();
var analyzedItems = new Dictionary<Guid, Segment>();
var metadatas = new Dictionary<Guid, SegmentMetadata>();
var jsonObject = new JsonObject();
// get ItemIds
var mediaItems = queueManager.GetMediaItemsById(itemIds);
// setup analyzers
foreach (var (key, media) in mediaItems)
{
var items = media.AsReadOnly();
var totalItems = mediaItems.Count;
var first = items[0];
var analyzers = new Collection<IMediaFileAnalyzer>();
if (analyzerTypes.Contains(AnalyzerType.ChapterAnalyzer))
{
analyzers.Add(new ChapterAnalyzer(_loggerFactory.CreateLogger<ChapterAnalyzer>()));
}
// Movies don't use chromparint analyzer
if (first.IsEpisode() && analyzerTypes.Contains(AnalyzerType.ChromaprintAnalyzer))
{
if (items.Count == 1)
{
errors.Add($"Chromaprint needs at least two media files to compare, one provided: {first.GetFullName}");
}
else
{
analyzers.Add(new ChromaprintAnalyzer(_loggerFactory.CreateLogger<ChromaprintAnalyzer>()));
}
}
if (mode == MediaSegmentType.Outro && analyzerTypes.Contains(AnalyzerType.BlackFrameAnalyzer))
{
analyzers.Add(new BlackFrameAnalyzer(_loggerFactory.CreateLogger<BlackFrameAnalyzer>()));
}
// Use each analyzer to find skippable ranges in all media files, removing successfully
// analyzed items from the queue.
foreach (var analyzer in analyzers)
{
var cancellationToken = default(CancellationToken);
var (notAnalyzed, analyzed, metadata) = await analyzer.AnalyzeMediaFilesAsync(items, mode, cancellationToken);
var atype = analyzer is BlackFrameAnalyzer ? "BlackFrameAnalyzer" : analyzer is ChromaprintAnalyzer ? "ChromaprintAnalyzer" : analyzer is ChapterAnalyzer ? "ChapterAnalyzer" : throw new NotImplementedException("Unknown Analyzer type");
jsonObject.Add(atype, BuildAnalyzerOutput(analyzed, metadata));
}
}
jsonObject.Add("Errors", errors);
return new JsonResult(jsonObject);
}
/// <summary>
/// Fingerprint the provided episode and returns the uncompressed fingerprint data points.
/// </summary>
/// <param name="id">Episode id.</param>
/// <param name="mode">Type Intro or Outro.</param>
/// <returns>Read only collection of fingerprint points.</returns>
[HttpGet("Chromaprint/{Id}")]
public ActionResult<uint[]> GetMediaFingerprint(
[FromRoute, Required] Guid id,
[FromQuery, Required] MediaSegmentType mode)
{
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager, mode);
var queuedMedia = queueManager.GetMediaItemsById([id]);
// Search through all queued episodes to find the requested id
foreach (var season in queuedMedia)
{
foreach (var needle in season.Value)
{
if (needle.ItemId == id)
{
return FFmpegWrapper.Fingerprint(needle, mode);
}
}
}
return NotFound();
}
private static JsonObject BuildAnalyzerOutput(ReadOnlyDictionary<Guid, Segment> segments, ReadOnlyDictionary<Guid, SegmentMetadata> metadatas)
{
var itemsObject = new JsonObject();
Dictionary<Guid, SegmentMetadata> metadataLocal = metadatas.ToDictionary();
foreach (var item in segments)
{
if (metadatas.TryGetValue(item.Key, out var metadata))
{
metadataLocal.Remove(item.Key);
var json = new
{
Segment = item.Value,
Metadata = metadata
};
itemsObject.Add(item.Key.ToString(), json.ToString());
}
}
// we may have more metadata
foreach (var item in metadataLocal)
{
var json = new
{
Metadata = item.Value
};
itemsObject.Add(item.Key.ToString(), json.ToString());
}
return itemsObject;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/TroubleshootingController.cs
================================================
using System.Net.Mime;
using System.Text;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer.Controllers;
/// <summary>
/// Troubleshooting controller.
/// </summary>
[Authorize(Policy = "RequiresElevation")]
[ApiController]
[Produces(MediaTypeNames.Application.Json)]
[Route("JellyfinPluginIntroSkipSupport")]
public class TroubleshootingController : ControllerBase
{
// private readonly IApplicationHost _applicationHost;
private readonly ILogger<TroubleshootingController> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="TroubleshootingController"/> class.
/// </summary>
/// <param name="logger">Logger.</param>
public TroubleshootingController(
ILogger<TroubleshootingController> logger)
{
_logger = logger;
}
/// <summary>
/// Gets a Markdown formatted support bundle.
/// </summary>
/// <response code="200">Support bundle created.</response>
/// <returns>Support bundle.</returns>
[HttpGet("SupportBundle")]
[Produces(MediaTypeNames.Text.Plain)]
public ActionResult<string> GetSupportBundle()
{
var bundle = new StringBuilder();
// bundle.Append("* Jellyfin version: ");
// bundle.Append(_applicationHost.ApplicationVersionString);
// bundle.Append('\n');
var version = Plugin.Instance!.Version.ToString(3);
bundle.Append("* Plugin version: ");
bundle.Append(version);
bundle.Append('\n');
bundle.Append("* Warnings: `");
bundle.Append(WarningManager.GetWarnings());
bundle.Append("`\n");
bundle.Append(FFmpegWrapper.GetChromaprintLogs());
return bundle.ToString();
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/VisualizationController.cs
================================================
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Mime;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer.Controllers;
/// <summary>
/// Audio fingerprint visualization controller. Allows browsing fingerprints on a per episode basis.
/// </summary>
[Authorize(Policy = "RequiresElevation")]
[ApiController]
[Produces(MediaTypeNames.Application.Json)]
[Route("JellyfinPluginIntroSkip")]
public class VisualizationController : ControllerBase
{
private readonly ILoggerFactory _loggerFactory;
private readonly ILibraryManager _libraryManager;
private readonly ILogger<VisualizationController> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="VisualizationController"/> class.
/// </summary>
/// <param name="logger">Logger.</param>
/// <param name="loggerFactory">loggerFactory.</param>
/// <param name="libraryManager">libraryManager.</param>
public VisualizationController(
ILogger<VisualizationController> logger,
ILoggerFactory loggerFactory,
ILibraryManager libraryManager)
{
_loggerFactory = loggerFactory;
_libraryManager = libraryManager;
_logger = logger;
}
/// <summary>
/// Returns all show names and seasons.
/// </summary>
/// <returns>Dictionary of show names to a list of season names.</returns>
[HttpGet("Shows")]
public ActionResult<Dictionary<string, HashSet<string>>> GetShowSeasons()
{
_logger.LogDebug("Returning season names by series");
var showSeasons = new Dictionary<string, HashSet<string>>();
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager, MediaSegmentType.Intro);
var queuedMedia = queueManager.GetMediaItems();
// Loop through all seasons in the analysis queue
foreach (var kvp in queuedMedia)
{
// Check that this season contains at least one episode.
var episodes = kvp.Value;
if (episodes is null || episodes.Count == 0)
{
_logger.LogDebug("Skipping season {Id} (null or empty)", kvp.Key);
continue;
}
// Peek at the top episode from this season and store the series name and season number.
var first = episodes[0];
var series = first.SeriesName;
var season = GetSeasonName(first);
// Validate the series and season before attempting to store it.
if (string.IsNullOrWhiteSpace(series) || string.IsNullOrWhiteSpace(season))
{
_logger.LogDebug("Skipping season {Id} (no name or number)", kvp.Key);
continue;
}
// TryAdd is used when adding the HashSet since it is a no-op if one was already created for this series.
showSeasons.TryAdd(series, new HashSet<string>());
showSeasons[series].Add(season);
}
return showSeasons;
}
/// <summary>
/// Returns the names and unique identifiers of all episodes in the provided season.
/// </summary>
/// <param name="series">Show name.</param>
/// <param name="season">Season name.</param>
/// <returns>List of episode titles.</returns>
[HttpGet("Show/{Series}/{Season}")]
public ActionResult<List<EpisodeVisualization>> GetSeasonEpisodes(
[FromRoute] string series,
[FromRoute] string season)
{
var visualEpisodes = new List<EpisodeVisualization>();
if (!LookupSeasonByName(series, season, out var episodes))
{
return NotFound();
}
foreach (var e in episodes)
{
visualEpisodes.Add(new EpisodeVisualization(e.ItemId, e.Name));
}
return visualEpisodes;
}
/// <summary>
/// Fingerprint the provided episode and returns the uncompressed fingerprint data points.
/// </summary>
/// <param name="id">Episode id.</param>
/// <returns>Read only collection of fingerprint points.</returns>
[HttpGet("Episode/{Id}/Chromaprint")]
public ActionResult<uint[]> GetEpisodeFingerprint([FromRoute] Guid id)
{
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager, MediaSegmentType.Intro);
var queuedMedia = queueManager.GetMediaItems();
// Search through all queued episodes to find the requested id
foreach (var season in queuedMedia)
{
foreach (var needle in season.Value)
{
if (needle.ItemId == id)
{
return FFmpegWrapper.Fingerprint(needle, MediaSegmentType.Intro);
}
}
}
return NotFound();
}
private string GetSeasonName(QueuedMedia episode)
{
return "Season " + episode.SeasonNumber.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
/// Lookup a named season of a series and return all queued episodes.
/// </summary>
/// <param name="series">Series name.</param>
/// <param name="season">Season name.</param>
/// <param name="episodes">Episodes.</param>
/// <returns>Boolean indicating if the requested season was found.</returns>
private bool LookupSeasonByName(string series, string season, out List<QueuedMedia> episodes)
{
var queueManager = new QueueManager(_loggerFactory.CreateLogger<QueueManager>(), _libraryManager, MediaSegmentType.Intro);
var queuedMedia = queueManager.GetMediaItems();
foreach (var queuedEpisodes in queuedMedia)
{
var first = queuedEpisodes.Value[0];
var firstSeasonName = GetSeasonName(first);
// Assert that the queued episode series and season are equal to what was requested
if (
!string.Equals(first.SeriesName, series, StringComparison.OrdinalIgnoreCase) ||
!string.Equals(firstSeasonName, season, StringComparison.OrdinalIgnoreCase))
{
continue;
}
episodes = queuedEpisodes.Value;
return true;
}
episodes = new List<QueuedMedia>();
return false;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/AnalyzerType.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Analyzer Type.
/// </summary>
public enum AnalyzerType
{
/// <summary>
/// No Analyzer.
/// </summary>
NotSet,
/// <summary>
/// Blackframe Analyzer.
/// </summary>
BlackFrameAnalyzer,
/// <summary>
/// Chapter Analyzer.
/// </summary>
ChapterAnalyzer,
/// <summary>
/// Chromaprint Analyzer.
/// </summary>
ChromaprintAnalyzer,
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/BlackFrame.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// A frame of video that partially (or entirely) consists of black pixels.
/// </summary>
public class BlackFrame
{
/// <summary>
/// Initializes a new instance of the <see cref="BlackFrame"/> class.
/// </summary>
/// <param name="percent">Percentage of the frame that is black.</param>
/// <param name="time">Time this frame appears at.</param>
public BlackFrame(int percent, double time)
{
Percentage = percent;
Time = time;
}
/// <summary>
/// Gets or sets the percentage of the frame that is black.
/// </summary>
public int Percentage { get; set; }
/// <summary>
/// Gets or sets the time (in seconds) this frame appeared at.
/// </summary>
public double Time { get; set; }
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/EpisodeVisualization.cs
================================================
using System;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Episode name and internal ID as returned by the visualization controller.
/// </summary>
public class EpisodeVisualization
{
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeVisualization"/> class.
/// </summary>
/// <param name="id">Episode id.</param>
/// <param name="name">Episode name.</param>
public EpisodeVisualization(Guid id, string name)
{
Id = id;
Name = name;
}
/// <summary>
/// Gets the id.
/// </summary>
public Guid Id { get; private set; }
/// <summary>
/// Gets the name.
/// </summary>
public string Name { get; private set; } = string.Empty;
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/FingerprintException.cs
================================================
using System;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Exception raised when an error is encountered analyzing audio.
/// </summary>
public class FingerprintException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="FingerprintException"/> class.
/// </summary>
public FingerprintException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FingerprintException"/> class.
/// </summary>
/// <param name="message">Exception message.</param>
public FingerprintException(string message) : base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FingerprintException"/> class.
/// </summary>
/// <param name="message">Exception message.</param>
/// <param name="inner">Inner exception.</param>
public FingerprintException(string message, Exception inner) : base(message, inner)
{
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/IntroWithMetadata.cs
================================================
using System;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// An Segment class with episode metadata. Only used in end to end testing programs.
/// </summary>
public class IntroWithMetadata : Segment
{
/// <summary>
/// Initializes a new instance of the <see cref="IntroWithMetadata"/> class.
/// </summary>
/// <param name="series">Series name.</param>
/// <param name="season">Season number.</param>
/// <param name="title">Episode title.</param>
/// <param name="intro">Intro timestamps.</param>
public IntroWithMetadata(string series, int season, string title, Segment intro)
{
Series = series;
Season = season;
Title = title;
ItemId = intro.ItemId;
Start = intro.Start;
End = intro.End;
}
/// <summary>
/// Gets or sets the series name of the TV episode associated with this intro.
/// </summary>
public string Series { get; set; }
/// <summary>
/// Gets or sets the season number of the TV episode associated with this intro.
/// </summary>
public int Season { get; set; }
/// <summary>
/// Gets or sets the title of the TV episode associated with this intro.
/// </summary>
public string Title { get; set; }
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/MediaSegmentsDb.cs
================================================
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller;
using MediaBrowser.Model.MediaSegments;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Small abstraction over MediaSegmentsManager.
/// </summary>
public class MediaSegmentsDb
{
private readonly IMediaSegmentManager _segmentsManager;
/// <summary>
/// Initializes a new instance of the <see cref="MediaSegmentsDb"/> class.
/// </summary>
/// <param name="segmentsManager">MediaSegmentsManager.</param>
public MediaSegmentsDb(IMediaSegmentManager segmentsManager)
{
_segmentsManager = segmentsManager;
}
/// <summary>
/// Test if we can find segments.
/// </summary>
/// <param name="itemId">ItemId.</param>
/// <param name="type">Mode.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
public async Task<bool> HasSegments(Guid itemId, MediaSegmentType type)
{
var list = await _segmentsManager.GetSegmentsAsync(itemId, [type]).ConfigureAwait(false);
return list.Any();
}
/// <summary>
/// Create new media segment together with metadata. Can also handle additional metadata without segment.
/// </summary>
/// <param name="segments">segments to add.</param>
/// <param name="metadata">Metadata for a segment.</param>
/// <param name="mode">Mode.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
public async Task CreateMediaSegments(ReadOnlyDictionary<Guid, Segment> segments, ReadOnlyDictionary<Guid, SegmentMetadata> metadata, MediaSegmentType mode)
{
var metaDBb = Plugin.Instance!.GetMetadataDb();
Dictionary<Guid, SegmentMetadata> metadataLocal = metadata.ToDictionary();
if (metaDBb == null)
{
throw new InvalidOperationException("Meta database was null");
}
foreach (var (key, seg) in segments)
{
var newGuid = Guid.NewGuid();
var newSeg = new MediaSegmentDto()
{
Id = newGuid,
ItemId = seg.ItemId,
Type = mode,
StartTicks = Utils.SToTicks(seg.Start),
EndTicks = Utils.SToTicks(seg.End),
};
await _segmentsManager.CreateSegmentAsync(newSeg, Plugin.Instance!.Name).ConfigureAwait(false);
if (metadata.TryGetValue(key, out var meta))
{
metadataLocal.Remove(key);
meta.SegmentId = newGuid;
metaDBb.SaveSegment(meta);
}
}
// we may have more metadata
foreach (var meta in metadataLocal)
{
metaDBb.SaveSegment(meta.Value);
}
}
/// <summary>
/// Get segments from db by mode and id.
/// </summary>
/// <param name="itemId">Item Id.</param>
/// <param name="mode">Mode of analysis.</param>
/// <returns>Dictionary of guid,segments.</returns>
public async Task<Dictionary<Guid, Segment>> GetMediaSegmentsByIdAsync(Guid itemId, MediaSegmentType mode)
{
var segments = await _segmentsManager.GetSegmentsAsync(itemId, [mode]).ConfigureAwait(false);
var intros = new Dictionary<Guid, Segment>();
foreach (var item in segments)
{
intros.TryAdd(item.ItemId, new Segment()
{
ItemId = item.ItemId,
Start = Utils.TicksToS(item.StartTicks),
End = Utils.TicksToS(item.EndTicks),
});
}
return intros;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/QueuedMedia.cs
================================================
using System;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Media queued for analysis.
/// </summary>
public class QueuedMedia
{
/// <summary>
/// Gets or sets the Series name.
/// </summary>
public string SeriesName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the season number.
/// </summary>
public int SeasonNumber { get; set; }
/// <summary>
/// Gets or sets the media id.
/// </summary>
public Guid ItemId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this media has been already analyzed.
/// </summary>
public bool IsAnalyzed { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this media should be skipped for blacklisting.
/// This will happen when a Season has just one episode, which can't be Chromaprint compared analyzed but maybe at a later run.
/// </summary>
public bool SkipPreventAnalyzing { get; set; }
/// <summary>
/// Gets or sets the full path to episode/movie.
/// </summary>
public string Path { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name of the media, episode or movie.
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the name of the source like quality (1080p, 4k, ...).
/// </summary>
public string SourceName { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the timestamp (in seconds) to stop searching for an introduction at.
/// </summary>
public int IntroFingerprintEnd { get; set; }
/// <summary>
/// Gets or sets the timestamp (in seconds) to start looking for end credits at.
/// </summary>
public int CreditsFingerprintStart { get; set; }
/// <summary>
/// Gets or sets the total duration of this media file (in seconds).
/// </summary>
public int Duration { get; set; }
/// <inheritdoc/>
public override bool Equals(object? obj)
{
return (obj as QueuedMedia)?.ItemId == this.ItemId;
}
/// <inheritdoc/>
public override int GetHashCode()
{
return ItemId.GetHashCode();
}
/// <summary>
/// Gets the full name of the media, episode or movie with source name/quality.
/// </summary>
/// <returns>The full name of the media.</returns>
public string GetFullName()
{
if (IsEpisode())
{
return $"{SeriesName} S{SeasonNumber} - {Name}";
}
else
{
return $"{Name} ({SourceName})";
}
}
/// <summary>
/// Gets or sets a value indicating whether this media is an episode, part of a tv show.
/// </summary>
/// <returns>Is an episode or not.</returns>
public bool IsEpisode()
{
return !string.IsNullOrEmpty(SeriesName);
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/Segment.cs
================================================
using System;
using System.Text.Json.Serialization;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Result of fingerprinting and analyzing two episodes in a season.
/// All times are measured in seconds relative to the beginning of the media file.
/// </summary>
public class Segment
{
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
/// </summary>
/// <param name="episode">Episode.</param>
/// <param name="isEpisode">is episode.</param>
/// <param name="intro">Introduction time range.</param>
public Segment(Guid episode, bool isEpisode, TimeRange intro)
{
ItemId = episode;
Start = intro.Start;
End = intro.End;
IsEpisode = isEpisode;
}
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
/// </summary>
/// <param name="episode">Episode.</param>
/// <param name="intro">Introduction time range.</param>
public Segment(Guid episode, TimeRange intro)
{
ItemId = episode;
Start = intro.Start;
End = intro.End;
}
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
/// </summary>
/// <param name="episode">Episode.</param>
public Segment(Guid episode)
{
ItemId = episode;
Start = 0;
End = 0;
}
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
/// </summary>
/// <param name="intro">intro.</param>
public Segment(Segment intro)
{
ItemId = intro.ItemId;
Start = intro.Start;
End = intro.End;
}
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
/// </summary>
public Segment()
{
}
/// <summary>
/// Gets or sets the item ID of db.
/// </summary>
public Guid ItemId { get; set; }
/// <summary>
/// Gets a value indicating whether this introduction is valid or not.
/// Invalid results must not be returned through the API.
/// </summary>
public bool Valid => End > 0;
/// <summary>
/// Gets the duration of this intro.
/// </summary>
[JsonIgnore]
public double Duration => End - Start;
/// <summary>
/// Gets or sets the segment sequence start time.
/// </summary>
public double Start { get; set; }
/// <summary>
/// Gets or sets the segment sequence end time.
/// </summary>
public double End { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this is an episode (not a movie).
/// </summary>
public bool IsEpisode { get; set; } = true;
/// <summary>
/// Gets or sets which analyzer created this segment.
/// </summary>
public AnalyzerType? AnalyzerType { get; set; }
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/TimeRange.cs
================================================
using System;
namespace Jellyfin.Plugin.MediaAnalyzer;
#pragma warning disable CA1036 // Override methods on comparable types
/// <summary>
/// Range of contiguous time.
/// </summary>
public class TimeRange : IComparable
{
/// <summary>
/// Initializes a new instance of the <see cref="TimeRange"/> class.
/// </summary>
public TimeRange()
{
Start = 0;
End = 0;
}
/// <summary>
/// Initializes a new instance of the <see cref="TimeRange"/> class.
/// </summary>
/// <param name="start">Time range start.</param>
/// <param name="end">Time range end.</param>
public TimeRange(double start, double end)
{
Start = start;
End = end;
}
/// <summary>
/// Initializes a new instance of the <see cref="TimeRange"/> class.
/// </summary>
/// <param name="original">Original TimeRange.</param>
public TimeRange(TimeRange original)
{
Start = original.Start;
End = original.End;
}
/// <summary>
/// Gets or sets the time range start (in seconds).
/// </summary>
public double Start { get; set; }
/// <summary>
/// Gets or sets the time range end (in seconds).
/// </summary>
public double End { get; set; }
/// <summary>
/// Gets the duration of this time range (in seconds).
/// </summary>
public double Duration => End - Start;
/// <summary>
/// Compare TimeRange durations.
/// </summary>
/// <param name="obj">Object to compare with.</param>
/// <returns>int.</returns>
public int CompareTo(object? obj)
{
if (!(obj is TimeRange tr))
{
throw new ArgumentException("obj must be a TimeRange");
}
return tr.Duration.CompareTo(Duration);
}
/// <summary>
/// Tests if this TimeRange object intersects the provided TimeRange.
/// </summary>
/// <param name="tr">Second TimeRange object to test.</param>
/// <returns>true if tr intersects the current TimeRange, false otherwise.</returns>
public bool Intersects(TimeRange tr)
{
return
(Start < tr.Start && tr.Start < End) ||
(Start < tr.End && tr.End < End);
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/TimeRangeHelpers.cs
================================================
using System;
using System.Collections.Generic;
namespace Jellyfin.Plugin.MediaAnalyzer;
#pragma warning restore CA1036
/// <summary>
/// Time range helpers.
/// </summary>
public static class TimeRangeHelpers
{
/// <summary>
/// Finds the longest contiguous time range.
/// </summary>
/// <param name="times">Sorted timestamps to search.</param>
/// <param name="maximumDistance">Maximum distance permitted between contiguous timestamps.</param>
/// <returns>The longest contiguous time range (if one was found), or null (if none was found).</returns>
public static TimeRange? FindContiguous(double[] times, double maximumDistance)
{
if (times.Length == 0)
{
return null;
}
Array.Sort(times);
var ranges = new List<TimeRange>();
var currentRange = new TimeRange(times[0], times[0]);
// For all provided timestamps, check if it is contiguous with its neighbor.
for (var i = 0; i < times.Length - 1; i++)
{
var current = times[i];
var next = times[i + 1];
if (next - current <= maximumDistance)
{
currentRange.End = next;
continue;
}
ranges.Add(new TimeRange(currentRange));
currentRange = new TimeRange(next, next);
}
// Find and return the longest contiguous range.
ranges.Sort();
return (ranges.Count > 0) ? ranges[0] : null;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/WarningManager.cs
================================================
namespace Jellyfin.Plugin.MediaAnalyzer;
using System;
/// <summary>
/// Support bundle warning.
/// </summary>
[Flags]
public enum PluginWarning
{
/// <summary>
/// No warnings have been added.
/// </summary>
None = 0,
/// <summary>
/// Attempted to add skip button to web interface, but was unable to.
/// </summary>
UnableToAddSkipButton = 1,
/// <summary>
/// At least one media file on the server was unable to be fingerprinted by Chromaprint.
/// </summary>
InvalidChromaprintFingerprint = 2,
/// <summary>
/// The version of ffmpeg installed on the system is not compatible with the plugin.
/// </summary>
IncompatibleFFmpegBuild = 4,
}
/// <summary>
/// Warning manager.
/// </summary>
public static class WarningManager
{
private static PluginWarning warnings;
/// <summary>
/// Set warning.
/// </summary>
/// <param name="warning">Warning.</param>
public static void SetFlag(PluginWarning warning)
{
warnings |= warning;
}
/// <summary>
/// Clear warnings.
/// </summary>
public static void Clear()
{
warnings = PluginWarning.None;
}
/// <summary>
/// Get warnings.
/// </summary>
/// <returns>Warnings.</returns>
public static string GetWarnings()
{
return warnings.ToString();
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbContext.cs
================================================
using System;
using Microsoft.EntityFrameworkCore;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Plugin database.
/// </summary>
public class MediaAnalyzerDbContext : DbContext
{
private string dbPath;
/// <summary>
/// Initializes a new instance of the <see cref="MediaAnalyzerDbContext"/> class.
/// </summary>
/// <param name="path">Path to db.</param>
public MediaAnalyzerDbContext(string path)
{
dbPath = path;
}
/// <summary>
/// Initializes a new instance of the <see cref="MediaAnalyzerDbContext"/> class.
/// </summary>
/// <param name="options">The options.</param>
public MediaAnalyzerDbContext(DbContextOptions options) : base(options)
{
var folder = Environment.SpecialFolder.LocalApplicationData;
var path = Environment.GetFolderPath(folder);
dbPath = System.IO.Path.Join(path, "mediaanalyzer.db");
}
/// <summary>
/// Gets the <see cref="DbSet{TEntity}"/> containing the blacklisted segments.
/// </summary>
public DbSet<SegmentMetadata> SegmentMetadata => Set<SegmentMetadata>();
/// <inheritdoc/>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite($"Data Source={dbPath}");
/// <inheritdoc/>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SegmentMetadata>()
.HasKey(s => s.Id);
modelBuilder.Entity<SegmentMetadata>()
.Property(s => s.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<SegmentMetadata>()
.HasIndex(s => s.ItemId);
}
/// <summary>
/// Apply migrations. Needs to be called before any actions are executed.
/// </summary>
public void ApplyMigrations()
{
this.Database.Migrate();
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbFactory.cs
================================================
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Plugin database factory.
/// </summary>
public class MediaAnalyzerDbFactory : IDesignTimeDbContextFactory<MediaAnalyzerDbContext>
{
/// <inheritdoc/>
public MediaAnalyzerDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<MediaAnalyzerDbContext>();
optionsBuilder.UseSqlite("Data Source=jfpmediaanalyzer.db");
return new MediaAnalyzerDbContext(optionsBuilder.Options);
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadata.cs
================================================
using System;
using Jellyfin.Data.Enums;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Metadata for MediaSegments. Metadata is also created for non segments (e.g. analyze blocking).
/// </summary>
public class SegmentMetadata
{
/// <summary>
/// Initializes a new instance of the <see cref="SegmentMetadata"/> class.
/// </summary>
/// <param name="media">Media item.</param>
/// <param name="mode">The mode it ran.</param>
/// <param name="analyzer">Analyzer who created it.</param>
public SegmentMetadata(QueuedMedia media, MediaSegmentType mode, AnalyzerType analyzer)
{
ItemId = media.ItemId;
Type = mode;
AnalyzerType = analyzer;
Name = media.GetFullName();
}
/// <summary>
/// Initializes a new instance of the <see cref="SegmentMetadata"/> class.
/// </summary>
public SegmentMetadata()
{
}
/// <summary>
/// Gets or sets the Id. Database generated.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the "full" name for the Media (Series + Season + Episode or Movie + Source).
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the segment Id of Jellyfin.
/// </summary>
public Guid SegmentId { get; set; }
/// <summary>
/// Gets or sets the item ID of Jellyfin.
/// </summary>
public Guid ItemId { get; set; }
/// <summary>
/// Gets or sets the segment type.
/// </summary>
public MediaSegmentType Type { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the segment is blocked for future analysis.
/// </summary>
public bool PreventAnalyzing { get; set; }
/// <summary>
/// Gets or sets which analyzer created this segment.
/// </summary>
public AnalyzerType AnalyzerType { get; set; } = AnalyzerType.NotSet;
/// <summary>
/// Gets or sets the analyzer note. Data that an analyzer might provide as additional info.
/// </summary>
public string AnalyzerNote { get; set; } = string.Empty;
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadataDb.cs
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using Microsoft.EntityFrameworkCore;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Database api for segment metadata.
/// </summary>
public class SegmentMetadataDb
{
private string _pluginDbPath;
/// <summary>
/// Initializes a new instance of the <see cref="SegmentMetadataDb"/> class.
/// </summary>
/// <param name="pluginDbPath">Plugin db path.</param>
public SegmentMetadataDb(string pluginDbPath)
{
_pluginDbPath = pluginDbPath;
}
/// <summary>
/// Create or update a segment.
/// </summary>
/// <param name="seg">Segment.</param>
public async void SaveSegment(SegmentMetadata seg)
{
using var db = GetPluginDb();
await CreateOrUpdate(db, seg).ConfigureAwait(false);
await db.SaveChangesAsync().ConfigureAwait(false);
}
/// <summary>
/// Create prevent analyze segments from QueuedMedia.
/// </summary>
/// <param name="media">Queued Media.</param>
/// <param name="mode">Mode.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task CreatePreventAnalyzeSegments(IReadOnlyCollection<QueuedMedia> media, MediaSegmentType mode)
{
using var db = GetPluginDb();
foreach (var seg in media)
{
var newseg = new SegmentMetadata
{
Name = seg.GetFullName(),
Type = mode,
PreventAnalyzing = true,
ItemId = seg.ItemId,
};
await CreateOrUpdate(db, newseg).ConfigureAwait(false);
}
await db.SaveChangesAsync().ConfigureAwait(false);
}
/// <summary>
/// Get metadata for segmentId.
/// </summary>
/// <param name="segmentId">Media ItemId.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task<SegmentMetadata> GetSegment(Guid segmentId)
{
using var db = GetPluginDb();
return await db.SegmentMetadata.AsNoTracking().FirstAsync(s => s.SegmentId == segmentId).ConfigureAwait(false);
}
/// <summary>
/// Get metadata for itemId and type. We also store metadata for media that have no segmentId in jellyfin.
/// </summary>
/// <param name="itemId">Media ItemId.</param>
/// <param name="type">Segment Type.</param>
/// <param name="analyzer">Optional: type of ananlyzer.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task<IEnumerable<SegmentMetadata>> GetSegments(Guid itemId, MediaSegmentType type, AnalyzerType? analyzer)
{
using var db = GetPluginDb();
var query = db.SegmentMetadata.Where(s => s.ItemId == itemId && s.Type == type);
if (analyzer is not null)
{
query = query.Where(s => s.AnalyzerType == analyzer);
}
return await query.AsNoTracking().ToListAsync().ConfigureAwait(false);
}
/// <summary>
/// Check if itemId and type should be prevented to analyze. AnalyzerType of these segments is NotSet.
/// </summary>
/// <param name="itemId">Media ItemId.</param>
/// <param name="type">Segment Type.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task<bool> PreventAnalyze(Guid itemId, MediaSegmentType type)
{
using var db = GetPluginDb();
var seg = await db.SegmentMetadata.FirstAsync(s => s.ItemId == itemId && s.Type == type && s.AnalyzerType == AnalyzerType.NotSet).ConfigureAwait(false);
// we may have multiple metadata for the same type+itemId. Search in all of them
return seg is not null && seg.PreventAnalyzing;
}
/// <summary>
/// Delete all metadata for itemId with prevent analyze set to true. Without itemId deletes them all.
/// </summary>
/// <param name="itemId">Media ItemId.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task DeletePreventAnalyzeSegments(Guid? itemId)
{
using var db = GetPluginDb();
var query = db.SegmentMetadata.Where(s => s.PreventAnalyzing);
if (!itemId.IsNullOrEmpty())
{
query = db.SegmentMetadata.Where(s => s.ItemId == itemId);
}
await query.ExecuteDeleteAsync().ConfigureAwait(false);
}
/// <summary>
/// Delete all metadata for itemId and optional type.
/// </summary>
/// <param name="itemId">Media ItemId.</param>
/// <param name="type">Segment Type.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task DeleteSegments(Guid itemId, MediaSegmentType? type)
{
using var db = GetPluginDb();
var query = db.SegmentMetadata.Where(s => s.ItemId == itemId);
if (type is not null)
{
query = query.Where(s => s.Type == type);
}
await query.ExecuteDeleteAsync().ConfigureAwait(false);
}
/// <summary>
/// Create or update a segment.
/// </summary>
/// <param name="db">Database.</param>
/// <param name="seg">SegmentMetadata.</param>
/// <returns>Task.</returns>
private async Task CreateOrUpdate(MediaAnalyzerDbContext db, SegmentMetadata seg)
{
var found = await db.SegmentMetadata.FirstAsync(s => s.Id.Equals(seg.Id)).ConfigureAwait(false);
if (found is not null)
{
found.Name = seg.Name;
found.SegmentId = seg.SegmentId;
found.Type = seg.Type;
found.ItemId = seg.ItemId;
found.PreventAnalyzing = seg.PreventAnalyzing;
found.AnalyzerType = seg.AnalyzerType;
found.AnalyzerNote = seg.AnalyzerNote;
}
else
{
db.SegmentMetadata.Add(seg);
}
}
/// <summary>
/// Get context of plugin database.
/// </summary>
/// <returns>Instance of db.</returns>
public MediaAnalyzerDbContext GetPluginDb()
{
return new MediaAnalyzerDbContext(_pluginDbPath);
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Entrypoint/LibraryChangedEntrypoint.cs
================================================
using System;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Act on changes of the jellyfin library.
/// </summary>
public sealed class LibraryChangedEntrypoint : IHostedService, IDisposable
{
private readonly ILibraryManager _libraryManager;
private readonly ITaskManager _taskManager;
private readonly ILogger<LibraryChangedEntrypoint> _logger;
private readonly ILoggerFactory _loggerFactory;
private Timer _queueTimer;
private bool _analyzeAgain;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryChangedEntrypoint"/> class.
/// </summary>
/// <param name="libraryManager">Library manager.</param>
/// <param name="taskManager">Task manager.</param>
/// <param name="logger">Logger.</param>
/// <param name="loggerFactory">Logger factory.</param>
public LibraryChangedEntrypoint(
ILibraryManager libraryManager,
ITaskManager taskManager,
ILogger<LibraryChangedEntrypoint> logger,
ILoggerFactory loggerFactory)
{
_libraryManager = libraryManager;
_taskManager = taskManager;
_logger = logger;
_loggerFactory = loggerFactory;
_queueTimer = new Timer(
OnQueueTimerCallback,
null,
Timeout.InfiniteTimeSpan,
Timeout.InfiniteTimeSpan);
}
/// <inheritdoc/>
public Task StartAsync(CancellationToken cancellationToken)
{
_libraryManager.ItemAdded += LibraryManagerItemAdded;
_libraryManager.ItemUpdated += LibraryManagerItemUpdated;
_libraryManager.ItemRemoved += LibraryManagerItemRemoved;
FFmpegWrapper.Logger = _logger;
return Task.CompletedTask;
}
/// <inheritdoc/>
public Task StopAsync(CancellationToken cancellationToken)
{
_libraryManager.ItemAdded -= LibraryManagerItemAdded;
_libraryManager.ItemUpdated -= LibraryManagerItemUpdated;
_libraryManager.ItemRemoved -= LibraryManagerItemRemoved;
return Task.CompletedTask;
}
/// <summary>
/// Delete segments for itemid when library removed it.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
private void LibraryManagerItemRemoved(object? sender, ItemChangeEventArgs itemChangeEventArgs)
{
if (itemChangeEventArgs.Item is not Movie and not Episode)
{
return;
}
if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual)
{
return;
}
_ = Plugin.Instance!.GetMetadataDb().DeleteSegments(itemChangeEventArgs.Item.Id, null);
}
/// <summary>
/// Library item was added.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
private void LibraryManagerItemAdded(object? sender, ItemChangeEventArgs itemChangeEventArgs)
{
if (!Plugin.Instance!.Configuration.RunAfterAddOrUpdateEvent)
{
return;
}
// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Movie and not Episode)
{
return;
}
if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual)
{
return;
}
StartTimer();
}
/// <summary>
/// TaskManager task ended.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="eventArgs">The <see cref="TaskCompletionEventArgs"/>.</param>
private void TaskManagerTaskCompleted(object? sender, TaskCompletionEventArgs eventArgs)
{
var result = eventArgs.Result;
if (!Plugin.Instance!.Configuration.RunAfterLibraryScan)
{
return;
}
if (result.Key != "RefreshLibrary")
{
return;
}
if (result.Status != TaskCompletionStatus.Completed)
{
return;
}
StartTimer();
}
/// <summary>
/// Library item was updated.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
private void LibraryManagerItemUpdated(object? sender, ItemChangeEventArgs itemChangeEventArgs)
{
if (!Plugin.Instance!.Configuration.RunAfterAddOrUpdateEvent)
{
return;
}
// Don't do anything if it's not a supported media type
if (itemChangeEventArgs.Item is not Movie and not Episode)
{
return;
}
if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual)
{
return;
}
StartTimer();
}
/// <summary>
/// Start or restart timer to debounce analyzing.
/// </summary>
private void StartTimer()
{
if (Plugin.Instance!.AnalysisRunning)
{
_analyzeAgain = true;
}
else
{
_logger.LogInformation("Media Library changed, analyzis will start soon!");
_queueTimer.Change(TimeSpan.FromMilliseconds(15000), Timeout.InfiniteTimeSpan);
}
}
/// <summary>
/// Wait for timer callback to be completed.
/// </summary>
private void OnQueueTimerCallback(object? state)
{
try
{
OnQueueTimerCallbackInternal();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in OnQueueTimerCallbackInternal");
}
}
/// <summary>
/// Wait for timer to be completed.
/// </summary>
private void OnQueueTimerCallbackInternal()
{
_logger.LogInformation("Timer elapsed - start analyzing");
Plugin.Instance!.AnalysisRunning = true;
var progress = new Progress<double>();
var cancellationToken = new CancellationToken(false);
// intro
var introBaseAnalyzer = new BaseItemAnalyzerTask(
MediaSegmentType.Intro,
_loggerFactory.CreateLogger<AnalyzeMedia>(),
_loggerFactory,
_libraryManager);
introBaseAnalyzer.AnalyzeItems(progress, cancellationToken);
// outro
var outroBaseAnalyzer = new BaseItemAnalyzerTask(
MediaSegmentType.Outro,
_loggerFactory.CreateLogger<AnalyzeMedia>(),
_loggerFactory,
_libraryManager);
outroBaseAnalyzer.AnalyzeItems(progress, cancellationToken);
Plugin.Instance!.AnalysisRunning = false;
// we might need to analyze again
if (_analyzeAgain)
{
_logger.LogInformation("Analyzing ended, but we need to analyze again!");
_analyzeAgain = false;
StartTimer();
}
}
/// <inheritdoc/>
public void Dispose()
{
_queueTimer.Dispose();
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/FFmpegWrapper.cs
================================================
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Jellyfin.Data.Enums;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Wrapper for libchromaprint and the silencedetect filter.
/// </summary>
public static class FFmpegWrapper
{
private static readonly object InvertedIndexCacheLock = new();
/// <summary>
/// Used with FFmpeg's silencedetect filter to extract the start and end times of silence.
/// </summary>
private static readonly Regex SilenceDetectionExpression = new(
"silence_(?<type>start|end): (?<time>[0-9\\.]+)");
/// <summary>
/// Used with FFmpeg's blackframe filter to extract the time and percentage of black pixels.
/// </summary>
private static readonly Regex BlackFrameRegex = new("(pblack|t):[0-9.]+");
/// <summary>
/// Gets or sets the logger.
/// </summary>
public static ILogger? Logger { get; set; }
private static Dictionary<string, string> ChromaprintLogs { get; set; } = new();
private static Dictionary<Guid, Dictionary<uint, int>> InvertedIndexCache { get; set; } = new();
/// <summary>
/// Check that the installed version of ffmpeg supports chromaprint.
/// </summary>
/// <returns>true if a compatible version of ffmpeg is installed, false on any error.</returns>
public static bool CheckFFmpegVersion()
{
try
{
// Always log ffmpeg's version information.
if (!CheckFFmpegRequirement(
"-version",
"ffmpeg",
"version",
"Unknown error with FFmpeg version"))
{
ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
// First, validate that the installed version of ffmpeg supports chromaprint at all.
if (!CheckFFmpegRequirement(
"-muxers",
"chromaprint",
"muxer list",
"The installed version of ffmpeg does not support chromaprint"))
{
ChromaprintLogs["error"] = "chromaprint_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
// Second, validate that the Chromaprint muxer understands the "-fp_format raw" option.
if (!CheckFFmpegRequirement(
"-h muxer=chromaprint",
"binary raw fingerprint",
"chromaprint options",
"The installed version of ffmpeg does not support raw binary fingerprints"))
{
ChromaprintLogs["error"] = "fp_format_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
// Third, validate that ffmpeg supports of the all required silencedetect options.
if (!CheckFFmpegRequirement(
"-h filter=silencedetect",
"noise tolerance",
"silencedetect options",
"The installed version of ffmpeg does not support the silencedetect filter"))
{
ChromaprintLogs["error"] = "silencedetect_not_supported";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
Logger?.LogDebug("Installed version of ffmpeg meets fingerprinting requirements");
ChromaprintLogs["error"] = "okay";
return true;
}
catch
{
ChromaprintLogs["error"] = "unknown_error";
WarningManager.SetFlag(PluginWarning.IncompatibleFFmpegBuild);
return false;
}
}
/// <summary>
/// Fingerprint a queued episode.
/// </summary>
/// <param name="episode">Queued episode to fingerprint.</param>
/// <param name="mode">Portion of media file to fingerprint. Introduction = first 25% / 10 minutes and Credits = last 4 minutes.</param>
/// <returns>Numerical fingerprint points.</returns>
public static uint[] Fingerprint(QueuedMedia episode, MediaSegmentType mode)
{
int start, end;
if (mode == MediaSegmentType.Intro)
{
start = 0;
end = episode.IntroFingerprintEnd;
}
else if (mode == MediaSegmentType.Outro)
{
start = episode.CreditsFingerprintStart;
end = episode.Duration;
}
else
{
throw new ArgumentException("Unknown analysis mode " + mode.ToString());
}
return Fingerprint(episode, mode, start, end);
}
/// <summary>
/// Transforms a Chromaprint into an inverted index of fingerprint points to the last index it appeared at.
/// </summary>
/// <param name="id">Episode ID.</param>
/// <param name="fingerprint">Chromaprint fingerprint.</param>
/// <returns>Inverted index.</returns>
public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[] fingerprint)
{
lock (InvertedIndexCacheLock)
{
if (InvertedIndexCache.TryGetValue(id, out var cached))
{
return cached;
}
}
var invIndex = new Dictionary<uint, int>();
for (int i = 0; i < fingerprint.Length; i++)
{
// Get the current point.
var point = fingerprint[i];
// Append the current sample's timecode to the collection for this point.
invIndex[point] = i;
}
lock (InvertedIndexCacheLock)
{
InvertedIndexCache[id] = invIndex;
}
return invIndex;
}
/// <summary>
/// Detect ranges of silence in the provided episode.
/// </summary>
/// <param name="episode">Queued episode.</param>
/// <param name="limit">Maximum amount of audio (in seconds) to detect silence in.</param>
/// <returns>Array of TimeRange objects that are silent in the queued episode.</returns>
public static TimeRange[] DetectSilence(QueuedMedia episode, int limit)
{
Logger?.LogTrace(
"Detecting silence in \"{File}\" (limit {Limit}, id {Id})",
episode.Path,
limit,
episode.ItemId);
// -vn, -sn, -dn: ignore video, subtitle, and data tracks
var args = string.Format(
CultureInfo.InvariantCulture,
"-vn -sn -dn " +
"-i \"{0}\" -to {1} -af \"silencedetect=noise={2}dB:duration=0.1\" -f null -",
episode.Path,
limit,
Plugin.Instance?.Configuration.SilenceDetectionMaximumNoise ?? -50);
// Cache the output of this command to "GUID-intro-silence-v1"
var cacheKey = episode.ItemId.ToString("N") + "-intro-silence-v1";
var currentRange = new TimeRange();
var silenceRanges = new List<TimeRange>();
/* Each match will have a type (either "start" or "end") and a timecode (a double).
*
* Sample output:
* [silencedetect @ 0x000000000000] silence_start: 12.34
* [silencedetect @ 0x000000000000] silence_end: 56.123 | silence_duration: 43.783
*/
var raw = Encoding.UTF8.GetString(GetOutput(args, cacheKey, true));
foreach (Match match in SilenceDetectionExpression.Matches(raw))
{
var isStart = match.Groups["type"].Value == "start";
var time = Convert.ToDouble(match.Groups["time"].Value, CultureInfo.InvariantCulture);
if (isStart)
{
currentRange.Start = time;
}
else
{
currentRange.End = time;
silenceRanges.Add(new TimeRange(currentRange));
}
}
return silenceRanges.ToArray();
}
/// <summary>
/// Finds the location of all black frames in a media file within a time range.
/// </summary>
/// <param name="episode">Media file to analyze.</param>
/// <param name="range">Time range to search.</param>
/// <param name="minimum">Percentage of the frame that must be black.</param>
/// <returns>Array of frames that are mostly black.</returns>
public static BlackFrame[] DetectBlackFrames(
QueuedMedia episode,
TimeRange range,
int minimum)
{
// Seek to the start of the time range and find frames that are at least 50% black.
var args = string.Format(
CultureInfo.InvariantCulture,
"-ss {0} -i \"{1}\" -to {2} -an -dn -sn -vf \"blackframe=amount=50\" -f null -",
range.Start,
episode.Path,
range.End - range.Start);
// Cache the results to GUID-blackframes-START-END-v1.
var cacheKey = string.Format(
CultureInfo.InvariantCulture,
"{0}-blackframes-{1}-{2}-v1",
episode.ItemId.ToString("N"),
range.Start,
range.End);
var blackFrames = new List<BlackFrame>();
/* Run the blackframe filter.
*
* Sample output:
* [Parsed_blackframe_0 @ 0x0000000] frame:1 pblack:99 pts:43 t:0.043000 type:B last_keyframe:0
* [Parsed_blackframe_0 @ 0x0000000] frame:2 pblack:99 pts:85 t:0.085000 type:B last_keyframe:0
*/
var raw = Encoding.UTF8.GetString(GetOutput(args, cacheKey, true));
foreach (var line in raw.Split('\n'))
{
var matches = BlackFrameRegex.Matches(line);
if (matches.Count != 2)
{
continue;
}
var (strPercent, strTime) = (
matches[0].Value.Split(':')[1],
matches[1].Value.Split(':')[1]
);
var bf = new BlackFrame(
Convert.ToInt32(strPercent, CultureInfo.InvariantCulture),
Convert.ToDouble(strTime, CultureInfo.InvariantCulture));
if (bf.Percentage > minimum)
{
blackFrames.Add(bf);
}
}
return blackFrames.ToArray();
}
/// <summary>
/// Gets Chromaprint debugging logs.
/// </summary>
/// <returns>Markdown formatted logs.</returns>
public static string GetChromaprintLogs()
{
// Print the FFmpeg detection status at the top.
// Format: "* FFmpeg: `error`"
// Append two newlines to separate the bulleted list from the logs
var logs = string.Format(
CultureInfo.InvariantCulture,
"* FFmpeg: `{0}`\n\n",
ChromaprintLogs["error"]);
// Always include ffmpeg version information
logs += FormatFFmpegLog("version");
// Don't print feature detection logs if the plugin started up okay
if (ChromaprintLogs["error"] == "okay")
{
return logs;
}
// Print all remaining logs
foreach (var kvp in ChromaprintLogs)
{
if (kvp.Key == "error" || kvp.Key == "version")
{
continue;
}
logs += FormatFFmpegLog(kvp.Key);
}
return logs;
}
/// <summary>
/// Run an FFmpeg command with the provided arguments and validate that the output contains
/// the provided string.
/// </summary>
/// <param name="arguments">Arguments to pass to FFmpeg.</param>
/// <param name="mustContain">String that the output must contain. Case insensitive.</param>
/// <param name="bundleName">Support bundle key to store FFmpeg's output under.</param>
/// <param name="errorMessage">Error message to log if this requirement is not met.</param>
/// <returns>true on success, false on error.</returns>
private static bool CheckFFmpegRequirement(
string arguments,
string mustContain,
string bundleName,
string errorMessage)
{
Logger?.LogDebug("Checking FFmpeg requirement {Arguments}", arguments);
var output = Encoding.UTF8.GetString(GetOutput(arguments, string.Empty, false, 2000));
Logger?.LogTrace("Output of ffmpeg {Arguments}: {Output}", arguments, output);
ChromaprintLogs[bundleName] = output;
if (!output.Contains(mustContain, StringComparison.OrdinalIgnoreCase))
{
Logger?.LogError("{ErrorMessage}", errorMessage);
return false;
}
Logger?.LogDebug("FFmpeg requirement {Arguments} met", arguments);
return true;
}
/// <summary>
/// Runs ffmpeg and returns standard output (or error).
/// If caching is enabled, will use cacheFilename to cache the output of this command.
/// </summary>
/// <param name="args">Arguments to pass to ffmpeg.</param>
/// <param name="cacheFilename">Filename to cache the output of this command to, or string.Empty if this command should not be cached.</param>
/// <param name="stderr">If standard error should be returned.</param>
/// <param name="timeout">Timeout (in miliseconds) to wait for ffmpeg to exit.</param>
private static ReadOnlySpan<byte> GetOutput(
string args,
string cacheFilename,
bool stderr = false,
int timeout = 60 * 1000)
{
var ffmpegPath = Plugin.Instance?.FFmpegPath ?? "ffmpeg";
// The silencedetect and blackframe filters output data at the info log level.
var useInfoLevel = args.Contains("silencedetect", StringComparison.OrdinalIgnoreCase) ||
args.Contains("blackframe", StringComparison.OrdinalIgnoreCase);
var logLevel = useInfoLevel ? "info" : "warning";
var cacheOutput =
(Plugin.Instance?.Configuration.CacheFingerprints ?? false) &&
!string.IsNullOrEmpty(cacheFilename);
// If caching is enabled, try to load the output of this command from the cached file.
if (cacheOutput)
{
// Calculate the absolute path to the cached file.
cacheFilename = Path.Join(Plugin.Instance!.FingerprintCachePath, cacheFilename);
// If the cached file exists, return whatever it holds.
if (File.Exists(cacheFilename))
{
Logger?.LogTrace("Returning contents of cache {Cache}", cacheFilename);
return File.ReadAllBytes(cacheFilename);
}
Logger?.LogTrace("Not returning contents of cache {Cache} (not found)", cacheFilename);
}
// Prepend some flags to prevent FFmpeg from logging it's banner and progress information
// for each file that is fingerprinted.
var prependArgument = string.Format(
CultureInfo.InvariantCulture,
"-hide_banner -loglevel {0} ",
logLevel);
var info = new ProcessStartInfo(ffmpegPath, args.Insert(0, prependArgument))
{
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = false,
ErrorDialog = false,
RedirectStandardOutput = !stderr,
RedirectStandardError = stderr
};
var ffmpeg = new Process
{
StartInfo = info
};
Logger?.LogDebug(
"Starting ffmpeg with the following arguments: {Arguments}",
ffmpeg.StartInfo.Arguments);
ffmpeg.Start();
using (MemoryStream ms = new MemoryStream())
{
var buf = new byte[4096];
var bytesRead = 0;
do
{
var streamReader = stderr ? ffmpeg.StandardError : ffmpeg.StandardOutput;
bytesRead = streamReader.BaseStream.Read(buf, 0, buf.Length);
ms.Write(buf, 0, bytesRead);
}
while (bytesRead > 0);
ffmpeg.WaitForExit(timeout);
var output = ms.ToArray();
// If caching is enabled, cache the output of this command.
if (cacheOutput)
{
File.WriteAllBytes(cacheFilename, output);
}
return output;
}
}
/// <summary>
/// Fingerprint a queued episode.
/// </summary>
/// <param name="episode">Queued episode to fingerprint.</param>
/// <param name="mode">Portion of media file to fingerprint.</param>
/// <param name="start">Time (in seconds) relative to the start of the file to start fingerprinting from.</param>
/// <param name="end">Time (in seconds) relative to the start of the file to stop fingerprinting at.</param>
/// <returns>Numerical fingerprint points.</returns>
private static uint[] Fingerprint(QueuedMedia episode, MediaSegmentType mode, int start, int end)
{
// Try to load this episode from cache before running ffmpeg.
if (LoadCachedFingerprint(episode, mode, out uint[] cachedFingerprint))
{
Logger?.LogTrace("Fingerprint cache hit on {File}", episode.Path);
return cachedFingerprint;
}
Logger?.LogDebug(
"Fingerprinting [{Start}, {End}] from \"{File}\" (id {Id})",
start,
end,
episode.Path,
episode.ItemId);
var args = string.Format(
CultureInfo.InvariantCulture,
"-ss {0} -i \"{1}\" -to {2} -ac 2 -f chromaprint -fp_format raw -",
start,
episode.Path,
end - start);
// Returns all fingerprint points as raw 32 bit unsigned integers (little endian).
var rawPoints = GetOutput(args, string.Empty);
if (rawPoints.Length == 0 || rawPoints.Length % 4 != 0)
{
Logger?.LogWarning("Chromaprint returned {Count} points for \"{Path}\"", rawPoints.Length, episode.Path);
throw new FingerprintException("chromaprint output for \"" + episode.Path + "\" was malformed");
}
var results = new List<uint>();
for (var i = 0; i < rawPoints.Length; i += 4)
{
var rawPoint = rawPoints.Slice(i, 4);
results.Add(BitConverter.ToUInt32(rawPoint));
}
// Try to cache this fingerprint.
CacheFingerprint(episode, mode, results);
return results.ToArray();
}
/// <summary>
/// Tries to load an episode's fingerprint from cache. If caching is not enabled, calling this function is a no-op.
/// This function was created before the unified caching mechanism was introduced (in v0.1.7).
/// </summary>
/// <param name="episode">Episode to try to load from cache.</param>
/// <param name="mode">Analysis mode.</param>
/// <param name="fingerprint">Array to store the fingerprint in.</param>
/// <returns>true if the episode was successfully loaded from cache, false on any other error.</returns>
private static bool LoadCachedFingerprint(
QueuedMedia episode,
MediaSegmentType mode,
out uint[] fingerprint)
{
fingerprint = Array.Empty<uint>();
// If fingerprint caching isn't enabled, don't try to load anything.
if (!(Plugin.Instance?.Configuration.CacheFingerprints ?? false))
{
return false;
}
var path = GetFingerprintCachePath(episode, mode);
// If this episode isn't cached, bail out.
if (!File.Exists(path))
{
return false;
}
var raw = File.ReadAllLines(path, Encoding.UTF8);
var result = new List<uint>();
// Read each stringified uint.
result.EnsureCapacity(raw.Length);
try
{
foreach (var rawNumber in raw)
{
result.Add(Convert.ToUInt32(rawNumber, CultureInfo.InvariantCulture));
}
}
catch (FormatException)
{
// Occurs when the cached fingerprint is corrupt.
Logger?.LogDebug(
"Cached fingerprint for {Path} ({Id}) is corrupt, ignoring cache",
episode.Path,
episode.ItemId);
return false;
}
fingerprint = result.ToArray();
return true;
}
/// <summary>
/// Cache an episode's fingerprint to disk. If caching is not enabled, calling this function is a no-op.
/// This function was created before the unified caching mechanism was introduced (in v0.1.7).
/// </summary>
/// <param name="episode">Episode to store in cache.</param>
/// <param name="mode">Analysis mode.</param>
/// <param name="fingerprint">Fingerprint of the episode to store.</param>
private static void CacheFingerprint(
QueuedMedia episode,
MediaSegmentType mode,
List<uint> fingerprint)
{
// Bail out if caching isn't enabled.
if (!(Plugin.Instance?.Configuration.CacheFingerprints ?? false))
{
return;
}
// Stringify each data point.
var lines = new List<string>();
foreach (var number in fingerprint)
{
lines.Add(number.ToString(CultureInfo.InvariantCulture));
}
// Cache the episode.
File.WriteAllLinesAsync(
GetFingerprintCachePath(episode, mode),
lines,
Encoding.UTF8).ConfigureAwait(false);
}
/// <summary>
/// Determines the path an episode should be cached at.
/// This function was created before the unified caching mechanism was introduced (in v0.1.7).
/// </summary>
/// <param name="episode">Episode.</param>
/// <param name="mode">Analysis mode.</param>
private static string GetFingerprintCachePath(QueuedMedia episode, MediaSegmentType mode)
{
var basePath = Path.Join(
Plugin.Instance!.FingerprintCachePath,
episode.ItemId.ToString("N"));
if (mode == MediaSegmentType.Intro)
{
return basePath;
}
else if (mode == MediaSegmentType.Outro)
{
return basePath + "-credits";
}
else
{
throw new ArgumentException("Unknown analysis mode " + mode.ToString());
}
}
private static string FormatFFmpegLog(string key)
{
/* Format:
* FFmpeg NAME:
* ```
* LOGS
* ```
*/
var formatted = string.Format(CultureInfo.InvariantCulture, "FFmpeg {0}:\n```\n", key);
formatted += ChromaprintLogs[key];
// Ensure the closing triple backtick is on a separate line
if (!formatted.EndsWith('\n'))
{
formatted += "\n";
}
formatted += "```\n\n";
return formatted;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Helper/Utils.cs
================================================
using System;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// Convert between Ticks and other time representations.
/// </summary>
public static class Utils
{
/// <summary>
/// Convert Seconds to Ticks.
/// </summary>
/// <param name="value">seconds.</param>
/// <returns>Time in ticks.</returns>
public static long SToTicks(double value)
{
return TimeSpan.FromSeconds(value).Ticks;
}
/// <summary>
/// Convert Ticks to Seconds.
/// </summary>
/// <param name="value">ticks.</param>
/// <returns>Time in seconds.</returns>
public static double TicksToS(long value)
{
return TimeSpan.FromTicks(value).Seconds;
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Jellyfin.Plugin.MediaAnalyzer.csproj
================================================
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.MediaAnalyzer</RootNamespace>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.4.0.0</FileVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<MediaSegmentType>AllEnabledByDefault</MediaSegmentType>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<!--
<PackageReference Include="Jellyfin.Controller" Version="10.10.*" />
<PackageReference Include="Jellyfin.Model" Version="10.10.*" />
-->
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>
<!-- REMOVE AND USE NUGET PUBLISHED PACKAGES -->
<ItemGroup>
<ProjectReference Include="../../jellyfin/Jellyfin.Data/Jellyfin.Data.csproj" />
<ProjectReference Include="../../jellyfin/MediaBrowser.Model/MediaBrowser.Model.csproj" />
<ProjectReference Include="../../jellyfin/MediaBrowser.Controller/MediaBrowser.Controller.csproj" />
<ProjectReference Include="../../jellyfin/MediaBrowser.Common/MediaBrowser.Common.csproj" />
<ProjectReference Include="../../jellyfin/src/Jellyfin.Extensions/Jellyfin.Extensions.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\visualizer.js" />
<EmbeddedResource Include="Configuration\version.txt" />
</ItemGroup>
</Project>
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.Designer.cs
================================================
// <auto-generated />
using System;
using Jellyfin.Plugin.MediaAnalyzer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Jellyfin.Plugin.MediaAnalyzer.Migrations
{
[DbContext(typeof(MediaAnalyzerDbContext))]
[Migration("20230525091047_CreateBlacklistSegment")]
partial class CreateBlacklistSegment
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.5");
modelBuilder.Entity("Jellyfin.Plugin.MediaAnalyzer.BlacklistSegment", b =>
{
b.Property<Guid>("ItemId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ItemId", "Type");
b.ToTable("BlacklistSegment");
});
#pragma warning restore 612, 618
}
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.cs
================================================
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jellyfin.Plugin.MediaAnalyzer.Migrations
{
/// <inheritdoc />
public partial class CreateBlacklistSegment : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BlacklistSegment",
columns: table => new
{
ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BlacklistSegment", x => new { x.ItemId, x.Type });
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BlacklistSegment");
}
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.Designer.cs
================================================
// <auto-generated />
using System;
using Jellyfin.Plugin.MediaAnalyzer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Jellyfin.Plugin.MediaAnalyzer.Migrations
{
[DbContext(typeof(MediaAnalyzerDbContext))]
[Migration("20240903114429_CreateSegmentMetadata")]
partial class CreateSegmentMetadata
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.3");
modelBuilder.Entity("Jellyfin.Plugin.MediaAnalyzer.SegmentMetadata", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AnalyzerNote")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("AnalyzerType")
.HasColumnType("INTEGER");
b.Property<Guid>("ItemId")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("PreventAnalyzing")
.HasColumnType("INTEGER");
b.Property<Guid>("SegmentId")
.HasColumnType("TEXT");
b.Property<string>("SeriesName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ItemId");
b.ToTable("SegmentMetadata");
});
#pragma warning restore 612, 618
}
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.cs
================================================
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jellyfin.Plugin.MediaAnalyzer.Migrations
{
/// <inheritdoc />
public partial class CreateSegmentMetadata : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BlacklistSegment");
migrationBuilder.CreateTable(
name: "SegmentMetadata",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
SeriesName = table.Column<string>(type: "TEXT", nullable: false),
SegmentId = table.Column<Guid>(type: "TEXT", nullable: false),
ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
PreventAnalyzing = table.Column<bool>(type: "INTEGER", nullable: false),
AnalyzerType = table.Column<int>(type: "INTEGER", nullable: true),
AnalyzerNote = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SegmentMetadata", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_SegmentMetadata_ItemId",
table: "SegmentMetadata",
column: "ItemId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SegmentMetadata");
migrationBuilder.CreateTable(
name: "BlacklistSegment",
columns: table => new
{
ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BlacklistSegment", x => new { x.ItemId, x.Type });
});
}
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/MediaAnalyzerDbContextModelSnapshot.cs
================================================
// <auto-generated />
using System;
using Jellyfin.Plugin.MediaAnalyzer;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Jellyfin.Plugin.MediaAnalyzer.Migrations
{
[DbContext(typeof(MediaAnalyzerDbContext))]
partial class MediaAnalyzerDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.3");
modelBuilder.Entity("Jellyfin.Plugin.MediaAnalyzer.SegmentMetadata", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AnalyzerNote")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("AnalyzerType")
.HasColumnType("INTEGER");
b.Property<Guid>("ItemId")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("PreventAnalyzing")
.HasColumnType("INTEGER");
b.Property<Guid>("SegmentId")
.HasColumnType("TEXT");
b.Property<string>("SeriesName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ItemId");
b.ToTable("SegmentMetadata");
});
#pragma warning restore 612, 618
}
}
}
================================================
FILE: Jellyfin.Plugin.MediaAnalyzer/Plugin.cs
================================================
using System;
using System.Collections.Generic;
using System.IO;
using Jellyfin.Plugin.MediaAnalyzer.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaAnalyzer;
/// <summary>
/// TV Show Intro Skip plugin. Uses audio analysis to find common sequences of audio shared between episodes.
/// </summary>
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
{
private IXmlSerializer _xmlSerializer;
private ILibraryManager _
gitextract_z9ywbwcb/ ├── .editorconfig ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.yml │ │ └── feature_request.md │ ├── dependabot.yml │ └── workflows/ │ ├── build.yml │ ├── package.sh │ └── publish.yml ├── .gitignore ├── .vscode/ │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── ACKNOWLEDGEMENTS.md ├── CHANGELOG.md ├── Jellyfin.Plugin.MediaAnalyzer/ │ ├── Analyzers/ │ │ ├── BlackFrameAnalyzer.cs │ │ ├── ChapterAnalyzer.cs │ │ ├── ChromaprintAnalyzer.cs │ │ └── IMediaFileAnalyzer.cs │ ├── Configuration/ │ │ ├── PluginConfiguration.cs │ │ ├── configPage.html │ │ ├── version.txt │ │ └── visualizer.js │ ├── Controllers/ │ │ ├── MediaAnalyzerController.cs │ │ ├── TroubleshootingController.cs │ │ └── VisualizationController.cs │ ├── Data/ │ │ ├── AnalyzerType.cs │ │ ├── BlackFrame.cs │ │ ├── EpisodeVisualization.cs │ │ ├── FingerprintException.cs │ │ ├── IntroWithMetadata.cs │ │ ├── MediaSegmentsDb.cs │ │ ├── QueuedMedia.cs │ │ ├── Segment.cs │ │ ├── TimeRange.cs │ │ ├── TimeRangeHelpers.cs │ │ └── WarningManager.cs │ ├── Db/ │ │ ├── MediaAnalyzerDbContext.cs │ │ ├── MediaAnalyzerDbFactory.cs │ │ ├── SegmentMetadata.cs │ │ └── SegmentMetadataDb.cs │ ├── Entrypoint/ │ │ └── LibraryChangedEntrypoint.cs │ ├── FFmpegWrapper.cs │ ├── Helper/ │ │ └── Utils.cs │ ├── Jellyfin.Plugin.MediaAnalyzer.csproj │ ├── Migrations/ │ │ ├── 20230525091047_CreateBlacklistSegment.Designer.cs │ │ ├── 20230525091047_CreateBlacklistSegment.cs │ │ ├── 20240903114429_CreateSegmentMetadata.Designer.cs │ │ ├── 20240903114429_CreateSegmentMetadata.cs │ │ └── MediaAnalyzerDbContextModelSnapshot.cs │ ├── Plugin.cs │ ├── QueueManager.cs │ └── ScheduledTasks/ │ ├── AnalyzeMedia.cs │ └── BaseItemAnalyzerTask.cs ├── Jellyfin.Plugin.MediaAnalyzer.Tests/ │ ├── Jellyfin.Plugin.MediaAnalyzer.Tests.csproj │ ├── TestAudioFingerprinting.cs │ ├── TestBlackFrames.cs │ ├── TestChapterAnalyzer.cs │ ├── TestContiguous.cs │ ├── TestWarnings.cs │ ├── audio/ │ │ └── README.txt │ └── e2e_tests/ │ ├── .gitignore │ ├── README.md │ ├── build.sh │ ├── config_sample.jsonc │ ├── docker-compose.yml │ ├── selenium/ │ │ ├── main.py │ │ └── requirements.txt │ ├── verifier/ │ │ ├── go.mod │ │ ├── http.go │ │ ├── main.go │ │ ├── report.html │ │ ├── report_comparison.go │ │ ├── report_comparison_util.go │ │ ├── report_generator.go │ │ ├── schema_validation.go │ │ └── structs/ │ │ ├── intro.go │ │ ├── plugin_configuration.go │ │ ├── public_info.go │ │ └── report.go │ └── wrapper/ │ ├── exec.go │ ├── exec_test.go │ ├── go.mod │ ├── library.json │ ├── main.go │ ├── setup.go │ └── structs.go ├── Jellyfin.Plugin.MediaAnalyzer.sln ├── LICENSE ├── README.md ├── build.yaml ├── docs/ │ └── release.md └── jellyfin.ruleset
SYMBOL INDEX (253 symbols across 57 files)
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/TestAudioFingerprinting.cs
class TestAudioFingerprinting (line 13) | public class TestAudioFingerprinting
method TestInstallationCheck (line 15) | [FactSkipFFmpegTests]
method TestBitCounting (line 21) | [Theory]
method TestFingerprinting (line 34) | [FactSkipFFmpegTests]
method TestIndexGeneration (line 70) | [Fact]
method TestIntroDetection (line 90) | [FactSkipFFmpegTests]
method TestSilenceDetection (line 118) | [FactSkipFFmpegTests]
method queueEpisode (line 138) | private QueuedMedia queueEpisode(string path)
method CreateChromaprintAnalyzer (line 148) | private ChromaprintAnalyzer CreateChromaprintAnalyzer()
class FactSkipFFmpegTests (line 155) | public class FactSkipFFmpegTests : FactAttribute
method FactSkipFFmpegTests (line 158) | public FactSkipFFmpegTests() {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/TestBlackFrames.cs
class TestBlackFrames (line 9) | public class TestBlackFrames
method TestBlackFrameDetection (line 11) | [FactSkipFFmpegTests]
method TestEndCreditDetection (line 31) | [FactSkipFFmpegTests]
method queueFile (line 46) | private QueuedMedia queueFile(string path)
method CreateFrameSequence (line 56) | private BlackFrame[] CreateFrameSequence(double start, double end)
method CreateBlackFrameAnalyzer (line 68) | private BlackFrameAnalyzer CreateBlackFrameAnalyzer()
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/TestChapterAnalyzer.cs
class TestChapterAnalyzer (line 11) | public class TestChapterAnalyzer
method TestIntroductionExpression (line 13) | [Theory]
method TestEndCreditsExpression (line 29) | [Theory]
method FindChapter (line 45) | private Segment? FindChapter(Collection<ChapterInfo> chapters, MediaSe...
method CreateChapters (line 58) | private Collection<ChapterInfo> CreateChapters(string name, MediaSegme...
method CreateChapter (line 76) | private ChapterInfo CreateChapter(string name, int position)
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/TestContiguous.cs
class TestTimeRanges (line 5) | public class TestTimeRanges
method TestSmallRange (line 7) | [Fact]
method TestLargeRange (line 21) | [Fact]
method TestFuturama (line 37) | [Fact]
method TestTimeRangeIntersection (line 79) | [Theory]
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/TestWarnings.cs
class TestFlags (line 5) | public class TestFlags
method TestEmptyFlagSerialization (line 7) | [Fact]
method TestSingleFlagSerialization (line 14) | [Fact]
method TestDoubleFlagSerialization (line 22) | [Fact]
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/selenium/main.py
function main (line 9) | def main():
function test_server (line 65) | def test_server(server, executor, driver_type):
function login (line 102) | def login(driver, server):
function test_skip_button (line 112) | def test_skip_button(driver, server):
function make_url (line 171) | def make_url(server, url):
function screenshot (line 177) | def screenshot(driver, filename):
function assert_video_playing (line 184) | def assert_video_playing(driver):
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/http.go
function SendRequest (line 15) | func SendRequest(method, url, apiKey string) []byte {
function GetServerInfo (line 54) | func GetServerInfo(hostAddress, apiKey string) structs.PublicInfo {
function GetPluginConfiguration (line 67) | func GetPluginConfiguration(hostAddress, apiKey string) structs.PluginCo...
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/main.go
function flags (line 8) | func flags() {
function main (line 61) | func main() {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_comparison.go
function compareReports (line 18) | func compareReports(oldReportPath, newReportPath, destination string) {
function unmarshalReport (line 87) | func unmarshalReport(path string) structs.Report {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_comparison_util.go
function templateSortShows (line 14) | func templateSortShows(shows map[string]structs.Seasons) []string {
function templateSortSeason (line 27) | func templateSortSeason(show structs.Seasons) []int {
function templateCompareEpisodes (line 40) | func templateCompareEpisodes(id string, reports structs.TemplateReportDa...
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_generator.go
function generateReport (line 17) | func generateReport(hostAddress, apiKey, reportDestination string, keepT...
function runAnalysisAndWait (line 104) | func runAnalysisAndWait(hostAddress, apiKey string, pollInterval time.Du...
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/schema_validation.go
function validateApiSchema (line 13) | func validateApiSchema(hostAddress, apiKey, rawIds string) {
function validateV1Intro (line 49) | func validateV1Intro(id string, intro structs.Intro, schema map[string]i...
function getTimestampsV1 (line 90) | func getTimestampsV1(hostAddress, apiKey, id, version string) (structs.I...
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/intro.go
type Intro (line 3) | type Intro struct
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/plugin_configuration.go
type PluginConfiguration (line 8) | type PluginConfiguration struct
method AnalysisSettings (line 18) | func (c PluginConfiguration) AnalysisSettings() string {
method IntroductionRequirements (line 38) | func (c PluginConfiguration) IntroductionRequirements() string {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/public_info.go
type PublicInfo (line 3) | type PublicInfo struct
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/report.go
type Seasons (line 5) | type Seasons
type Report (line 7) | type Report struct
type TemplateReportData (line 27) | type TemplateReportData struct
type IntroPair (line 36) | type IntroPair struct
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/exec.go
function RunProgram (line 15) | func RunProgram(program string, args []string, timeout time.Duration) {
function redactString (line 61) | func redactString(raw string) string {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/exec_test.go
function TestStringRedaction (line 5) | func TestStringRedaction(t *testing.T) {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/main.go
function flags (line 28) | func flags() {
function main (line 42) | func main() {
function login (line 224) | func login(server Server) string {
function waitForServerStartup (line 277) | func waitForServerStartup(address string) {
function loadConfiguration (line 303) | func loadConfiguration() Configuration {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/setup.go
function SetupServer (line 13) | func SetupServer(server, password string) {
function sendRequest (line 52) | func sendRequest(url string, method string, body string) {
FILE: Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/structs.go
type Configuration (line 3) | type Configuration struct
type Common (line 8) | type Common struct
type Server (line 13) | type Server struct
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/BlackFrameAnalyzer.cs
class BlackFrameAnalyzer (line 16) | public class BlackFrameAnalyzer : IMediaFileAnalyzer
method BlackFrameAnalyzer (line 26) | public BlackFrameAnalyzer(ILogger<BlackFrameAnalyzer> logger)
method AnalyzeMediaFilesAsync (line 32) | public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOn...
method AnalyzeMediaFile (line 90) | public Segment? AnalyzeMediaFile(QueuedMedia episode, MediaSegmentType...
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChapterAnalyzer.cs
class ChapterAnalyzer (line 18) | public class ChapterAnalyzer : IMediaFileAnalyzer
method ChapterAnalyzer (line 26) | public ChapterAnalyzer(ILogger<ChapterAnalyzer> logger)
method AnalyzeMediaFilesAsync (line 32) | public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOn...
method FindMatchingChapter (line 97) | public Segment? FindMatchingChapter(
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChromaprintAnalyzer.cs
class ChromaprintAnalyzer (line 16) | public class ChromaprintAnalyzer : IMediaFileAnalyzer
method ChromaprintAnalyzer (line 42) | public ChromaprintAnalyzer(ILogger<ChromaprintAnalyzer> logger)
method AnalyzeMediaFilesAsync (line 55) | public async Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOn...
method CompareEpisodes (line 231) | public (Segment Lhs, Segment Rhs) CompareEpisodes(
method GetLongestTimeRange (line 264) | private (Segment Lhs, Segment Rhs) GetLongestTimeRange(
method SearchInvertedIndex (line 300) | private (List<TimeRange> Lhs, List<TimeRange> Rhs) SearchInvertedIndex(
method FindContiguous (line 353) | private (TimeRange Lhs, TimeRange Rhs) FindContiguous(
method AdjustIntroEndTimes (line 435) | private Dictionary<Guid, Segment> AdjustIntroEndTimes(
method CountBits (line 515) | public int CountBits(uint number)
method ValidateTime (line 525) | private bool ValidateTime(Segment seg)
FILE: Jellyfin.Plugin.MediaAnalyzer/Analyzers/IMediaFileAnalyzer.cs
type IMediaFileAnalyzer (line 12) | public interface IMediaFileAnalyzer
method AnalyzeMediaFilesAsync (line 21) | public Task<(ReadOnlyCollection<QueuedMedia> NotAnalyzed, ReadOnlyDict...
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/PluginConfiguration.cs
class PluginConfiguration (line 8) | public class PluginConfiguration : BasePluginConfiguration
method PluginConfiguration (line 13) | public PluginConfiguration()
FILE: Jellyfin.Plugin.MediaAnalyzer/Configuration/visualizer.js
function renderTroubleshooter (line 2) | function renderTroubleshooter() {
function refreshBounds (line 8) | function refreshBounds() {
function findIntros (line 14) | function findIntros() {
function findExactMatches (line 89) | function findExactMatches() {
function renderFingerprintData (line 122) | function renderFingerprintData(ctx, fp, xor = false) {
function paintFingerprintDiff (line 167) | function paintFingerprintDiff(canvas, fp1, fp2, offset) {
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/MediaAnalyzerController.cs
class MediaAnalyzerController (line 23) | [Authorize(Policy = "RequiresElevation")]
method MediaAnalyzerController (line 39) | public MediaAnalyzerController(
method GetPluginMetadata (line 53) | [HttpGet]
method AnalyzeIds (line 72) | [HttpGet("Analyzers")]
method GetMediaFingerprint (line 143) | [HttpGet("Chromaprint/{Id}")]
method BuildAnalyzerOutput (line 166) | private static JsonObject BuildAnalyzerOutput(ReadOnlyDictionary<Guid,...
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/TroubleshootingController.cs
class TroubleshootingController (line 12) | [Authorize(Policy = "RequiresElevation")]
method TroubleshootingController (line 25) | public TroubleshootingController(
method GetSupportBundle (line 36) | [HttpGet("SupportBundle")]
FILE: Jellyfin.Plugin.MediaAnalyzer/Controllers/VisualizationController.cs
class VisualizationController (line 16) | [Authorize(Policy = "RequiresElevation")]
method VisualizationController (line 32) | public VisualizationController(
method GetShowSeasons (line 46) | [HttpGet("Shows")]
method GetSeasonEpisodes (line 92) | [HttpGet("Show/{Series}/{Season}")]
method GetEpisodeFingerprint (line 117) | [HttpGet("Episode/{Id}/Chromaprint")]
method GetSeasonName (line 138) | private string GetSeasonName(QueuedMedia episode)
method LookupSeasonByName (line 150) | private bool LookupSeasonByName(string series, string season, out List...
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/AnalyzerType.cs
type AnalyzerType (line 6) | public enum AnalyzerType
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/BlackFrame.cs
class BlackFrame (line 6) | public class BlackFrame
method BlackFrame (line 13) | public BlackFrame(int percent, double time)
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/EpisodeVisualization.cs
class EpisodeVisualization (line 8) | public class EpisodeVisualization
method EpisodeVisualization (line 15) | public EpisodeVisualization(Guid id, string name)
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/FingerprintException.cs
class FingerprintException (line 8) | public class FingerprintException : Exception
method FingerprintException (line 13) | public FingerprintException()
method FingerprintException (line 21) | public FingerprintException(string message) : base(message)
method FingerprintException (line 30) | public FingerprintException(string message, Exception inner) : base(me...
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/IntroWithMetadata.cs
class IntroWithMetadata (line 9) | public class IntroWithMetadata : Segment
method IntroWithMetadata (line 18) | public IntroWithMetadata(string series, int season, string title, Segm...
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/MediaSegmentsDb.cs
class MediaSegmentsDb (line 15) | public class MediaSegmentsDb
method MediaSegmentsDb (line 23) | public MediaSegmentsDb(IMediaSegmentManager segmentsManager)
method HasSegments (line 34) | public async Task<bool> HasSegments(Guid itemId, MediaSegmentType type)
method CreateMediaSegments (line 47) | public async Task CreateMediaSegments(ReadOnlyDictionary<Guid, Segment...
method GetMediaSegmentsByIdAsync (line 94) | public async Task<Dictionary<Guid, Segment>> GetMediaSegmentsByIdAsync...
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/QueuedMedia.cs
class QueuedMedia (line 8) | public class QueuedMedia
method Equals (line 67) | public override bool Equals(object? obj)
method GetHashCode (line 73) | public override int GetHashCode()
method GetFullName (line 82) | public string GetFullName()
method IsEpisode (line 98) | public bool IsEpisode()
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/Segment.cs
class Segment (line 10) | public class Segment
method Segment (line 18) | public Segment(Guid episode, bool isEpisode, TimeRange intro)
method Segment (line 31) | public Segment(Guid episode, TimeRange intro)
method Segment (line 42) | public Segment(Guid episode)
method Segment (line 53) | public Segment(Segment intro)
method Segment (line 63) | public Segment()
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/TimeRange.cs
class TimeRange (line 10) | public class TimeRange : IComparable
method TimeRange (line 15) | public TimeRange()
method TimeRange (line 26) | public TimeRange(double start, double end)
method TimeRange (line 36) | public TimeRange(TimeRange original)
method CompareTo (line 62) | public int CompareTo(object? obj)
method Intersects (line 77) | public bool Intersects(TimeRange tr)
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/TimeRangeHelpers.cs
class TimeRangeHelpers (line 11) | public static class TimeRangeHelpers
method FindContiguous (line 19) | public static TimeRange? FindContiguous(double[] times, double maximum...
FILE: Jellyfin.Plugin.MediaAnalyzer/Data/WarningManager.cs
type PluginWarning (line 8) | [Flags]
class WarningManager (line 35) | public static class WarningManager
method SetFlag (line 43) | public static void SetFlag(PluginWarning warning)
method Clear (line 51) | public static void Clear()
method GetWarnings (line 60) | public static string GetWarnings()
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbContext.cs
class MediaAnalyzerDbContext (line 9) | public class MediaAnalyzerDbContext : DbContext
method MediaAnalyzerDbContext (line 17) | public MediaAnalyzerDbContext(string path)
method MediaAnalyzerDbContext (line 26) | public MediaAnalyzerDbContext(DbContextOptions options) : base(options)
method OnConfiguring (line 39) | protected override void OnConfiguring(DbContextOptionsBuilder optionsB...
method OnModelCreating (line 43) | protected override void OnModelCreating(ModelBuilder modelBuilder)
method ApplyMigrations (line 59) | public void ApplyMigrations()
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbFactory.cs
class MediaAnalyzerDbFactory (line 9) | public class MediaAnalyzerDbFactory : IDesignTimeDbContextFactory<MediaA...
method CreateDbContext (line 12) | public MediaAnalyzerDbContext CreateDbContext(string[] args)
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadata.cs
class SegmentMetadata (line 9) | public class SegmentMetadata
method SegmentMetadata (line 17) | public SegmentMetadata(QueuedMedia media, MediaSegmentType mode, Analy...
method SegmentMetadata (line 28) | public SegmentMetadata()
FILE: Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadataDb.cs
class SegmentMetadataDb (line 14) | public class SegmentMetadataDb
method SegmentMetadataDb (line 22) | public SegmentMetadataDb(string pluginDbPath)
method SaveSegment (line 31) | public async void SaveSegment(SegmentMetadata seg)
method CreatePreventAnalyzeSegments (line 44) | public async Task CreatePreventAnalyzeSegments(IReadOnlyCollection<Que...
method GetSegment (line 69) | public async Task<SegmentMetadata> GetSegment(Guid segmentId)
method GetSegments (line 82) | public async Task<IEnumerable<SegmentMetadata>> GetSegments(Guid itemI...
method PreventAnalyze (line 100) | public async Task<bool> PreventAnalyze(Guid itemId, MediaSegmentType t...
method DeletePreventAnalyzeSegments (line 113) | public async Task DeletePreventAnalyzeSegments(Guid? itemId)
method DeleteSegments (line 132) | public async Task DeleteSegments(Guid itemId, MediaSegmentType? type)
method CreateOrUpdate (line 151) | private async Task CreateOrUpdate(MediaAnalyzerDbContext db, SegmentMe...
method GetPluginDb (line 175) | public MediaAnalyzerDbContext GetPluginDb()
FILE: Jellyfin.Plugin.MediaAnalyzer/Entrypoint/LibraryChangedEntrypoint.cs
class LibraryChangedEntrypoint (line 18) | public sealed class LibraryChangedEntrypoint : IHostedService, IDisposable
method LibraryChangedEntrypoint (line 34) | public LibraryChangedEntrypoint(
method StartAsync (line 53) | public Task StartAsync(CancellationToken cancellationToken)
method StopAsync (line 64) | public Task StopAsync(CancellationToken cancellationToken)
method LibraryManagerItemRemoved (line 77) | private void LibraryManagerItemRemoved(object? sender, ItemChangeEvent...
method LibraryManagerItemAdded (line 97) | private void LibraryManagerItemAdded(object? sender, ItemChangeEventAr...
method TaskManagerTaskCompleted (line 123) | private void TaskManagerTaskCompleted(object? sender, TaskCompletionEv...
method LibraryManagerItemUpdated (line 150) | private void LibraryManagerItemUpdated(object? sender, ItemChangeEvent...
method StartTimer (line 174) | private void StartTimer()
method OnQueueTimerCallback (line 190) | private void OnQueueTimerCallback(object? state)
method OnQueueTimerCallbackInternal (line 205) | private void OnQueueTimerCallbackInternal()
method Dispose (line 242) | public void Dispose()
FILE: Jellyfin.Plugin.MediaAnalyzer/FFmpegWrapper.cs
class FFmpegWrapper (line 16) | public static class FFmpegWrapper
method CheckFFmpegVersion (line 44) | public static bool CheckFFmpegVersion()
method Fingerprint (line 114) | public static uint[] Fingerprint(QueuedMedia episode, MediaSegmentType...
method CreateInvertedIndex (line 142) | public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[...
method DetectSilence (line 177) | public static TimeRange[] DetectSilence(QueuedMedia episode, int limit)
method DetectBlackFrames (line 233) | public static BlackFrame[] DetectBlackFrames(
method GetChromaprintLogs (line 293) | public static string GetChromaprintLogs()
method CheckFFmpegRequirement (line 335) | private static bool CheckFFmpegRequirement(
method GetOutput (line 366) | private static ReadOnlySpan<byte> GetOutput(
method Fingerprint (line 464) | private static uint[] Fingerprint(QueuedMedia episode, MediaSegmentTyp...
method LoadCachedFingerprint (line 516) | private static bool LoadCachedFingerprint(
method CacheFingerprint (line 572) | private static void CacheFingerprint(
method GetFingerprintCachePath (line 603) | private static string GetFingerprintCachePath(QueuedMedia episode, Med...
method FormatFFmpegLog (line 623) | private static string FormatFFmpegLog(string key)
FILE: Jellyfin.Plugin.MediaAnalyzer/Helper/Utils.cs
class Utils (line 8) | public static class Utils
method SToTicks (line 15) | public static long SToTicks(double value)
method TicksToS (line 25) | public static double TicksToS(long value)
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.Designer.cs
class CreateBlacklistSegment (line 13) | [DbContext(typeof(MediaAnalyzerDbContext))]
method BuildTargetModel (line 18) | protected override void BuildTargetModel(ModelBuilder modelBuilder)
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.cs
class CreateBlacklistSegment (line 9) | public partial class CreateBlacklistSegment : Migration
method Up (line 12) | protected override void Up(MigrationBuilder migrationBuilder)
method Down (line 29) | protected override void Down(MigrationBuilder migrationBuilder)
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.Designer.cs
class CreateSegmentMetadata (line 13) | [DbContext(typeof(MediaAnalyzerDbContext))]
method BuildTargetModel (line 18) | protected override void BuildTargetModel(ModelBuilder modelBuilder)
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.cs
class CreateSegmentMetadata (line 9) | public partial class CreateSegmentMetadata : Migration
method Up (line 12) | protected override void Up(MigrationBuilder migrationBuilder)
method Down (line 43) | protected override void Down(MigrationBuilder migrationBuilder)
FILE: Jellyfin.Plugin.MediaAnalyzer/Migrations/MediaAnalyzerDbContextModelSnapshot.cs
class MediaAnalyzerDbContextModelSnapshot (line 12) | [DbContext(typeof(MediaAnalyzerDbContext))]
method BuildModel (line 15) | protected override void BuildModel(ModelBuilder modelBuilder)
FILE: Jellyfin.Plugin.MediaAnalyzer/Plugin.cs
class Plugin (line 22) | public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
method Plugin (line 44) | public Plugin(
method GetPages (line 115) | public IEnumerable<PluginPageInfo> GetPages()
method GetItem (line 132) | internal BaseItem? GetItem(Guid id)
method GetItemPath (line 142) | internal string GetItemPath(Guid id)
method GetChapters (line 160) | internal List<ChapterInfo> GetChapters(Guid id)
method GetMetadataDb (line 169) | public SegmentMetadataDb GetMetadataDb()
method GetMediaSegmentsDb (line 178) | public MediaSegmentsDb GetMediaSegmentsDb()
method OnConfigurationChanged (line 183) | private void OnConfigurationChanged(object? sender, BasePluginConfigur...
method OnUninstalling (line 196) | public override void OnUninstalling()
FILE: Jellyfin.Plugin.MediaAnalyzer/QueueManager.cs
class QueueManager (line 21) | public class QueueManager
method QueueManager (line 38) | public QueueManager(ILogger<QueueManager> logger, ILibraryManager libr...
method GetMediaItems (line 54) | public ReadOnlyDictionary<Guid, List<QueuedMedia>> GetMediaItems()
method GetMediaItemsById (line 100) | public ReadOnlyDictionary<Guid, List<QueuedMedia>> GetMediaItemsById(G...
method LoadAnalysisSettings (line 131) | private void LoadAnalysisSettings()
method QueueLibraryContents (line 205) | private void QueueLibraryContents(string rawId)
method SkipEpisode (line 283) | private bool SkipEpisode(Episode episode)
method QueueEpisode (line 293) | private void QueueEpisode(Episode episode)
method QueueMovie (line 352) | private void QueueMovie(Movie movie, MediaSourceInfo source)
method VerifyQueue (line 417) | public ReadOnlyCollection<QueuedMedia> VerifyQueue(ReadOnlyCollection<...
method FilterWithSegmentsAsync (line 452) | public async Task<(ReadOnlyCollection<QueuedMedia> FilteredItems, bool...
method FilterWithBlacklistAsync (line 495) | public async Task<ReadOnlyCollection<QueuedMedia>> FilterWithBlacklist...
FILE: Jellyfin.Plugin.MediaAnalyzer/ScheduledTasks/AnalyzeMedia.cs
class AnalyzeMedia (line 15) | public class AnalyzeMedia : IScheduledTask
method AnalyzeMedia (line 26) | public AnalyzeMedia(
method ExecuteAsync (line 60) | public Task ExecuteAsync(IProgress<double> progress, CancellationToken...
method GetDefaultTriggers (line 106) | public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
FILE: Jellyfin.Plugin.MediaAnalyzer/ScheduledTasks/BaseItemAnalyzerTask.cs
class BaseItemAnalyzerTask (line 15) | public class BaseItemAnalyzerTask
method BaseItemAnalyzerTask (line 32) | public BaseItemAnalyzerTask(
method AnalyzeItems (line 49) | public void AnalyzeItems(
method AnalyzeItems (line 156) | private async Task<int> AnalyzeItems(
Condensed preview — 91 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (376K chars).
[
{
"path": ".editorconfig",
"chars": 8749,
"preview": "# With more recent updates Visual Studio 2017 supports EditorConfig files out of the box\n# Visual Studio Code needs an e"
},
{
"path": ".github/ISSUE_TEMPLATE/bug_report.yml",
"chars": 1355,
"preview": "name: \"Bug report\"\ndescription: \"Create a report to help us improve\"\nlabels: [bug]\nbody:\n - type: textarea\n attribut"
},
{
"path": ".github/ISSUE_TEMPLATE/feature_request.md",
"chars": 310,
"preview": "---\nname: Feature request\nabout: Suggest an idea for this project\nlabels: enhancement\nassignees: ''\n\n---\n\n**Describe the"
},
{
"path": ".github/dependabot.yml",
"chars": 597,
"preview": "version: 2\nupdates:\n # Fetch and update latest `nuget` pkgs\n - package-ecosystem: nuget\n directory: /\n schedule:"
},
{
"path": ".github/workflows/build.yml",
"chars": 851,
"preview": "name: \"Build Plugin\"\n\non:\n push:\n branches: [\"master\", \"analyzers\"]\n pull_request:\n branches: [\"master\"]\n\njobs:\n"
},
{
"path": ".github/workflows/package.sh",
"chars": 1781,
"preview": "#!/bin/bash\n\n# Check argument count\nif [[ $# -ne 1 ]]; then\n echo \"Usage: $0 VERSION\"\n exit 1\nfi\n\n# Use provided t"
},
{
"path": ".github/workflows/publish.yml",
"chars": 1019,
"preview": "name: \"Package plugin\"\n\non:\n workflow_dispatch:\n\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n # set fetch"
},
{
"path": ".gitignore",
"chars": 96,
"preview": "bin/\nobj/\nBenchmarkDotNet.Artifacts/\n/package/\n\n# Ignore pre compiled web interface\ndocker/dist\n"
},
{
"path": ".vscode/launch.json",
"chars": 558,
"preview": " {\n // Paths and plugin names are configured in settings.json\n \"version\": \"0.2.0\",\n \"configurations\": [\n "
},
{
"path": ".vscode/settings.json",
"chars": 883,
"preview": "{\n // jellyfinDir : The directory of the cloned jellyfin server project\n // This needs to be built once before it "
},
{
"path": ".vscode/tasks.json",
"chars": 2558,
"preview": "{\n // Paths and plugin name are configured in settings.json\n \"version\": \"2.0.0\",\n \"tasks\": [\n {\n "
},
{
"path": "ACKNOWLEDGEMENTS.md",
"chars": 323,
"preview": "Intro Skipper is made possible by the following open source projects:\n\n* [acoustid-match](https://github.com/dnknth/acou"
},
{
"path": "CHANGELOG.md",
"chars": 1028,
"preview": "# Changelog\n\n## Unreleased\n\n### Changed\n\n* Task Timer is no longer configured by deafult. We listen for MediaLibrary cha"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Analyzers/BlackFrameAnalyzer.cs",
"chars": 5111,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Objec"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChapterAnalyzer.cs",
"chars": 5921,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Objec"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Analyzers/ChromaprintAnalyzer.cs",
"chars": 20688,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Objec"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Analyzers/IMediaFileAnalyzer.cs",
"chars": 1123,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.ObjectModel;\nusing System.Threading;\nus"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Configuration/PluginConfiguration.cs",
"chars": 5769,
"preview": "using MediaBrowser.Model.Plugins;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer.Configuration;\n\n/// <summary>\n/// Plugin conf"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Configuration/configPage.html",
"chars": 38751,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n </head>\n\n <body>\n <div id=\"Te"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Configuration/version.txt",
"chars": 8,
"preview": "unknown\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Configuration/visualizer.js",
"chars": 6499,
"preview": "// re-render the troubleshooter with the latest offset\nfunction renderTroubleshooter() {\n paintFingerprintDiff(canvas"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Controllers/MediaAnalyzerController.cs",
"chars": 7215,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Collections.ObjectModel;\nusing System.ComponentModel.DataAn"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Controllers/TroubleshootingController.cs",
"chars": 1807,
"preview": "using System.Net.Mime;\nusing System.Text;\nusing Microsoft.AspNetCore.Authorization;\nusing Microsoft.AspNetCore.Mvc;\nusin"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Controllers/VisualizationController.cs",
"chars": 6455,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Net.Mime;\nusing Jellyfin.Data.E"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/AnalyzerType.cs",
"chars": 458,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Analyzer Type.\n/// </summary>\npublic enum AnalyzerType\n{\n "
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/BlackFrame.cs",
"chars": 821,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// A frame of video that partially (or entirely) consists of bl"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/EpisodeVisualization.cs",
"chars": 743,
"preview": "using System;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Episode name and internal ID as returned by t"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/FingerprintException.cs",
"chars": 957,
"preview": "using System;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Exception raised when an error is encountered"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/IntroWithMetadata.cs",
"chars": 1308,
"preview": "using System;\nusing System.Text.Json.Serialization;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// An Segm"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/MediaSegmentsDb.cs",
"chars": 3790,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Collections.ObjectModel;\nusing System.Linq;\nusing System.Th"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/QueuedMedia.cs",
"chars": 2887,
"preview": "using System;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Media queued for analysis.\n/// </summary>\npub"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/Segment.cs",
"chars": 2840,
"preview": "using System;\nusing System.Text.Json.Serialization;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Result "
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/TimeRange.cs",
"chars": 2230,
"preview": "using System;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n#pragma warning disable CA1036 // Override methods on comparabl"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/TimeRangeHelpers.cs",
"chars": 1510,
"preview": "using System;\nusing System.Collections.Generic;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n#pragma warning restore CA103"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Data/WarningManager.cs",
"chars": 1375,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\n\n/// <summary>\n/// Support bundle warning.\n/// </summary>\n[Flags"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbContext.cs",
"chars": 1874,
"preview": "using System;\nusing Microsoft.EntityFrameworkCore;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Plugin d"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Db/MediaAnalyzerDbFactory.cs",
"chars": 596,
"preview": "using Microsoft.EntityFrameworkCore;\nusing Microsoft.EntityFrameworkCore.Design;\n\nnamespace Jellyfin.Plugin.MediaAnalyze"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadata.cs",
"chars": 2131,
"preview": "using System;\nusing Jellyfin.Data.Enums;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Metadata for Media"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Db/SegmentMetadataDb.cs",
"chars": 6325,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing Jellyfin.Data.Enu"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Entrypoint/LibraryChangedEntrypoint.cs",
"chars": 7370,
"preview": "using System;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Jellyfin.Data.Enums;\nusing MediaBrowser.Contro"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/FFmpegWrapper.cs",
"chars": 22946,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.IO;\nu"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Helper/Utils.cs",
"chars": 707,
"preview": "using System;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer;\n\n/// <summary>\n/// Convert between Ticks and other time represen"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Jellyfin.Plugin.MediaAnalyzer.csproj",
"chars": 2221,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <TargetFramework>net8.0</TargetFramework>\n <RootNamespace>Je"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.Designer.cs",
"chars": 1313,
"preview": "// <auto-generated />\nusing System;\nusing Jellyfin.Plugin.MediaAnalyzer;\nusing Microsoft.EntityFrameworkCore;\nusing Mic"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Migrations/20230525091047_CreateBlacklistSegment.cs",
"chars": 1119,
"preview": "using System;\nusing Microsoft.EntityFrameworkCore.Migrations;\n\n#nullable disable\n\nnamespace Jellyfin.Plugin.MediaAnalyz"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.Designer.cs",
"chars": 2074,
"preview": "// <auto-generated />\nusing System;\nusing Jellyfin.Plugin.MediaAnalyzer;\nusing Microsoft.EntityFrameworkCore;\nusing Mic"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Migrations/20240903114429_CreateSegmentMetadata.cs",
"chars": 2430,
"preview": "using System;\nusing Microsoft.EntityFrameworkCore.Migrations;\n\n#nullable disable\n\nnamespace Jellyfin.Plugin.MediaAnalyz"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Migrations/MediaAnalyzerDbContextModelSnapshot.cs",
"chars": 1967,
"preview": "// <auto-generated />\nusing System;\nusing Jellyfin.Plugin.MediaAnalyzer;\nusing Microsoft.EntityFrameworkCore;\nusing Mic"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/Plugin.cs",
"chars": 6502,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing Jellyfin.Plugin.MediaAnalyzer.Configuration;\nusin"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/QueueManager.cs",
"chars": 18582,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.Objec"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/ScheduledTasks/AnalyzeMedia.cs",
"chars": 3194,
"preview": "using System;\nusing System.Collections.Generic;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing Jellyfin.Dat"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer/ScheduledTasks/BaseItemAnalyzerTask.cs",
"chars": 7468,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer;\n\nusing System;\nusing System.Collections.ObjectModel;\nusing System.Linq;\nusing S"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/Jellyfin.Plugin.MediaAnalyzer.Tests.csproj",
"chars": 972,
"preview": "<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <TargetFramework>net8.0</TargetFramework>\n <Nullable>enable<"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/TestAudioFingerprinting.cs",
"chars": 6277,
"preview": "/* These tests require that the host system has a version of FFmpeg installed\n * which supports both chromaprint and the"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/TestBlackFrames.cs",
"chars": 1973,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer.Tests;\n\nusing System;\nusing System.Collections.Generic;\nusing Jellyfin.Data.Enum"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/TestChapterAnalyzer.cs",
"chars": 2789,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer.Tests;\n\nusing System;\nusing System.Collections.Generic;\nusing System.Collections"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/TestContiguous.cs",
"chars": 4511,
"preview": "using Xunit;\n\nnamespace Jellyfin.Plugin.MediaAnalyzer.Tests;\n\npublic class TestTimeRanges\n{\n [Fact]\n public void T"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/TestWarnings.cs",
"chars": 956,
"preview": "namespace Jellyfin.Plugin.MediaAnalyzer.Tests;\n\nusing Xunit;\n\npublic class TestFlags\n{\n [Fact]\n public void TestEm"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/audio/README.txt",
"chars": 541,
"preview": "The audio used in the fingerprinting unit tests is from Big Buck Bunny, attributed below.\n\nBoth big_buck_bunny_intro.mp3"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/.gitignore",
"chars": 211,
"preview": "# Binaries\n/verifier/verifier\n/run_tests\n/plugin_binaries/\n\n# Wrapper configuration and base configuration files\nconfig."
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/README.md",
"chars": 2073,
"preview": "# End to end testing framework\n\n## wrapper\n\nThe wrapper script (compiled as `run_tests`) runs multiple tests on Jellyfin"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/build.sh",
"chars": 251,
"preview": "#!/bin/bash\n\necho \"[+] Building timestamp verifier\"\n(cd verifier && go build -o verifier) || exit 1\n\necho \"[+] Building "
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/config_sample.jsonc",
"chars": 691,
"preview": "{\n \"common\": {\n \"library\": \"/full/path/to/test/library/on/host/TV\",\n \"episode\": \"Episode title to searc"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/docker-compose.yml",
"chars": 701,
"preview": "version: \"3\"\nservices:\n chrome:\n image: selenium/standalone-chrome:106.0\n shm_size: 2gb\n ports:\n - 4444:4"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/selenium/main.py",
"chars": 6582,
"preview": "import argparse, os, time\n\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webd"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/selenium/requirements.txt",
"chars": 18,
"preview": "selenium >= 4.3.0\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/go.mod",
"chars": 68,
"preview": "module github.com/confusedpolarbear/intro_skipper_verifier\n\ngo 1.17\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/http.go",
"chars": 1772,
"preview": "package main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/confusedpolarbear/intr"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/main.go",
"chars": 2078,
"preview": "package main\n\nimport (\n\t\"flag\"\n\t\"time\"\n)\n\nfunc flags() {\n\t// Report generation\n\thostAddress := flag.String(\"address\", \"\""
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report.html",
"chars": 13490,
"preview": "<!DOCTYPE html>\n<html>\n\n<!-- TODO: when templating this, pre-populate the ignored shows value with something pulled from"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_comparison.go",
"chars": 3849,
"preview": "package main\n\nimport (\n\t_ \"embed\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"html/template\"\n\t\"math\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/confusedp"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_comparison_util.go",
"chars": 2195,
"preview": "package main\n\nimport (\n\t\"fmt\"\n\t\"math\"\n\t\"sort\"\n\n\t\"github.com/confusedpolarbear/intro_skipper_verifier/structs\"\n)\n\n// repo"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/report_generator.go",
"chars": 4919,
"preview": "package main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/confusedpolarbear/intro"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/schema_validation.go",
"chars": 3241,
"preview": "package main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/confusedpolarbear/intro_skipper_verifier"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/intro.go",
"chars": 225,
"preview": "package structs\n\ntype Intro struct {\n\tEpisodeId string\n\n\tSeries string\n\tSeason int\n\tTitle string\n\n\tIntroStart float32\n\t"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/plugin_configuration.go",
"chars": 931,
"preview": "package structs\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\ntype PluginConfiguration struct {\n\tCacheFingerprints bool\n\tMaxParallelism"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/public_info.go",
"chars": 92,
"preview": "package structs\n\ntype PublicInfo struct {\n\tVersion string\n\tOperatingSystem string\n}\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/verifier/structs/report.go",
"chars": 1053,
"preview": "package structs\n\nimport \"time\"\n\ntype Seasons map[int][]Intro\n\ntype Report struct {\n\tPath string `json:\"-\"`\n\n\tStartedAt "
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/exec.go",
"chars": 1372,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\t\"os/exec\"\n\t\"regexp\"\n\t\"strings\"\n\t\"time\"\n)\n\n// Run an external pr"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/exec_test.go",
"chars": 358,
"preview": "package main\n\nimport \"testing\"\n\nfunc TestStringRedaction(t *testing.T) {\n\traw := \"-key deadbeef -first second -user admi"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/go.mod",
"chars": 67,
"preview": "module github.com/confusedpolarbear/intro_skipper_wrapper\n\ngo 1.17\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/library.json",
"chars": 2362,
"preview": "{\n \"LibraryOptions\": {\n \"EnableArchiveMediaFiles\": false,\n \"EnablePhotos\": false,\n \"EnableRealtimeMonitor\": fa"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/main.go",
"chars": 9917,
"preview": "package main\n\nimport (\n\t\"bufio\"\n\t\"bytes\"\n\t\"crypto/rand\"\n\t\"encoding/hex\"\n\t\"encoding/json\"\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/setup.go",
"chars": 1802,
"preview": "package main\n\nimport (\n\t\"bytes\"\n\t_ \"embed\"\n\t\"fmt\"\n\t\"net/http\"\n)\n\n//go:embed library.json\nvar librarySetupPayload string\n"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.Tests/e2e_tests/wrapper/structs.go",
"chars": 644,
"preview": "package main\n\ntype Configuration struct {\n\tCommon Common `json:\"common\"`\n\tServers []Server `json:\"servers\"`\n}\n\ntype C"
},
{
"path": "Jellyfin.Plugin.MediaAnalyzer.sln",
"chars": 1394,
"preview": "Microsoft Visual Studio Solution File, Format Version 12.00\n#\nProject(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Jell"
},
{
"path": "LICENSE",
"chars": 35149,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "README.md",
"chars": 3153,
"preview": "# Jellyfin Media Analyzer\n\n## Archived\n\n⚠️\nThis project is no longer in development. Please move on to [intro-skipper](h"
},
{
"path": "build.yaml",
"chars": 397,
"preview": "---\nname: \"Media Analyzer\"\nguid: \"80885677-DACB-461B-AC97-EE7E971288AA\"\nversion: \"0.1.0.0\"\ntargetAbi: \"10.10.0.0\"\nframew"
},
{
"path": "docs/release.md",
"chars": 526,
"preview": "# Release procedure\n\n## Run tests\n\n1. Run unit tests with `dotnet test`\n2. Run end to end tests with `JELLYFIN_TOKEN=api"
},
{
"path": "jellyfin.ruleset",
"chars": 6613,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RuleSet Name=\"Rules for Jellyfin.Server\" Description=\"Code analysis rules for Je"
}
]
About this extraction
This page contains the full source code of the endrl/jellyfin-plugin-media-analyzer GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 91 files (345.1 KB), approximately 80.6k tokens, and a symbol index with 253 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.