Browse Source

add video stats to search index (#1033)

pull/1034/head
Jason Dove 3 years ago committed by GitHub
parent
commit
f0bea295c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 6
      ErsatzTV.FFmpeg/Format/AvailablePixelFormats.cs
  3. 3
      ErsatzTV.Infrastructure/Search/CustomQueryParser.cs
  4. 88
      ErsatzTV.Infrastructure/Search/SearchIndex.cs
  5. 12
      docs/user-guide/search.md

4
CHANGELOG.md

@ -46,6 +46,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -46,6 +46,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `isForced`: bool indicating whether the stream is flagged as forced
- `language`: the stream's language
- `title`: the stream's title
- Add new fields to search index
- `video_codec`: the video codec
- `video_bit_depth`: the number of bits in the video stream's pixel format, e.g. 8 or 10
- `video_dynamic_range`: the video's dynamic range, either `sdr` or `hdr`
### Changed
- Change `Multi-Episode Shuffle` scripting system to use Javascript instead of Lua

6
ErsatzTV.FFmpeg/Format/AvailablePixelFormats.cs

@ -4,7 +4,7 @@ namespace ErsatzTV.FFmpeg.Format; @@ -4,7 +4,7 @@ namespace ErsatzTV.FFmpeg.Format;
public static class AvailablePixelFormats
{
public static Option<IPixelFormat> ForPixelFormat(string pixelFormat, ILogger logger) =>
public static Option<IPixelFormat> ForPixelFormat(string pixelFormat, ILogger? logger) =>
pixelFormat switch
{
PixelFormat.YUV420P => new PixelFormatYuv420P(),
@ -15,9 +15,9 @@ public static class AvailablePixelFormats @@ -15,9 +15,9 @@ public static class AvailablePixelFormats
_ => LogUnknownPixelFormat(pixelFormat, logger)
};
private static Option<IPixelFormat> LogUnknownPixelFormat(string pixelFormat, ILogger logger)
private static Option<IPixelFormat> LogUnknownPixelFormat(string pixelFormat, ILogger? logger)
{
logger.LogWarning("Unexpected pixel format {PixelFormat} may have playback issues", pixelFormat);
logger?.LogWarning("Unexpected pixel format {PixelFormat} may have playback issues", pixelFormat);
return Option<IPixelFormat>.None;
}
}

3
ErsatzTV.Infrastructure/Search/CustomQueryParser.cs

@ -16,7 +16,8 @@ public class CustomQueryParser : QueryParser @@ -16,7 +16,8 @@ public class CustomQueryParser : QueryParser
SearchIndex.HeightField,
SearchIndex.WidthField,
SearchIndex.SeasonNumberField,
SearchIndex.EpisodeNumberField
SearchIndex.EpisodeNumberField,
SearchIndex.VideoBitDepthField
};
public CustomQueryParser(LuceneVersion matchVersion, string f, Analyzer a) : base(matchVersion, f, a)

88
ErsatzTV.Infrastructure/Search/SearchIndex.cs

@ -6,6 +6,8 @@ using ErsatzTV.Core.Interfaces.Repositories; @@ -6,6 +6,8 @@ using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Interfaces.Repositories.Caching;
using ErsatzTV.Core.Interfaces.Search;
using ErsatzTV.Core.Search;
using ErsatzTV.FFmpeg;
using ErsatzTV.FFmpeg.Format;
using LanguageExt.UnsafeValueAccess;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Core;
@ -20,6 +22,7 @@ using Lucene.Net.Store; @@ -20,6 +22,7 @@ using Lucene.Net.Store;
using Lucene.Net.Util;
using Microsoft.Extensions.Logging;
using Directory = System.IO.Directory;
using MediaStream = ErsatzTV.Core.Domain.MediaStream;
using Query = Lucene.Net.Search.Query;
namespace ErsatzTV.Infrastructure.Search;
@ -56,6 +59,8 @@ public sealed class SearchIndex : ISearchIndex @@ -56,6 +59,8 @@ public sealed class SearchIndex : ISearchIndex
private const string ShowGenreField = "show_genre";
private const string ShowTagField = "show_tag";
private const string MetadataKindField = "metadata_kind";
private const string VideoCodecField = "video_codec";
private const string VideoDynamicRange = "video_dynamic_range";
internal const string MinutesField = "minutes";
internal const string HeightField = "height";
@ -64,6 +69,7 @@ public sealed class SearchIndex : ISearchIndex @@ -64,6 +69,7 @@ public sealed class SearchIndex : ISearchIndex
internal const string EpisodeNumberField = "episode_number";
internal const string AddedDateField = "added_date";
internal const string ReleaseDateField = "release_date";
internal const string VideoBitDepthField = "video_bit_depth";
public const string MovieType = "movie";
public const string ShowType = "show";
@ -73,7 +79,7 @@ public sealed class SearchIndex : ISearchIndex @@ -73,7 +79,7 @@ public sealed class SearchIndex : ISearchIndex
public const string EpisodeType = "episode";
public const string OtherVideoType = "other_video";
public const string SongType = "song";
private readonly List<CultureInfo> _cultureInfos;
private readonly ILogger<SearchIndex> _logger;
@ -89,7 +95,7 @@ public sealed class SearchIndex : ISearchIndex @@ -89,7 +95,7 @@ public sealed class SearchIndex : ISearchIndex
_initialized = false;
}
public int Version => 33;
public int Version => 34;
public async Task<bool> Initialize(
ILocalFileSystem localFileSystem,
@ -382,14 +388,7 @@ public sealed class SearchIndex : ISearchIndex @@ -382,14 +388,7 @@ public sealed class SearchIndex : ISearchIndex
await AddLanguages(searchRepository, doc, movie.MediaVersions);
foreach (MediaVersion version in movie.MediaVersions.HeadOrNone())
{
doc.Add(
new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
doc.Add(new Int32Field(HeightField, version.Height, Field.Store.NO));
doc.Add(new Int32Field(WidthField, version.Width, Field.Store.NO));
}
AddStatistics(doc, movie.MediaVersions);
if (!string.IsNullOrWhiteSpace(metadata.ContentRating))
{
@ -752,14 +751,7 @@ public sealed class SearchIndex : ISearchIndex @@ -752,14 +751,7 @@ public sealed class SearchIndex : ISearchIndex
await AddLanguages(searchRepository, doc, musicVideo.MediaVersions);
foreach (MediaVersion version in musicVideo.MediaVersions.HeadOrNone())
{
doc.Add(
new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
doc.Add(new Int32Field(HeightField, version.Height, Field.Store.NO));
doc.Add(new Int32Field(WidthField, version.Width, Field.Store.NO));
}
AddStatistics(doc, musicVideo.MediaVersions);
if (metadata.ReleaseDate.HasValue)
{
@ -891,14 +883,7 @@ public sealed class SearchIndex : ISearchIndex @@ -891,14 +883,7 @@ public sealed class SearchIndex : ISearchIndex
await AddLanguages(searchRepository, doc, episode.MediaVersions);
foreach (MediaVersion version in episode.MediaVersions.HeadOrNone())
{
doc.Add(
new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
doc.Add(new Int32Field(HeightField, version.Height, Field.Store.NO));
doc.Add(new Int32Field(WidthField, version.Width, Field.Store.NO));
}
AddStatistics(doc, episode.MediaVersions);
if (metadata.ReleaseDate.HasValue)
{
@ -988,14 +973,7 @@ public sealed class SearchIndex : ISearchIndex @@ -988,14 +973,7 @@ public sealed class SearchIndex : ISearchIndex
await AddLanguages(searchRepository, doc, otherVideo.MediaVersions);
foreach (MediaVersion version in otherVideo.MediaVersions.HeadOrNone())
{
doc.Add(
new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
doc.Add(new Int32Field(HeightField, version.Height, Field.Store.NO));
doc.Add(new Int32Field(WidthField, version.Width, Field.Store.NO));
}
AddStatistics(doc, otherVideo.MediaVersions);
if (!string.IsNullOrWhiteSpace(metadata.ContentRating))
{
@ -1089,11 +1067,7 @@ public sealed class SearchIndex : ISearchIndex @@ -1089,11 +1067,7 @@ public sealed class SearchIndex : ISearchIndex
await AddLanguages(searchRepository, doc, song.MediaVersions);
foreach (MediaVersion version in song.MediaVersions.HeadOrNone())
{
doc.Add(
new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
}
AddStatistics(doc, song.MediaVersions);
doc.Add(new StringField(AddedDateField, metadata.DateAdded.ToString("yyyyMMdd"), Field.Store.NO));
@ -1152,6 +1126,42 @@ public sealed class SearchIndex : ISearchIndex @@ -1152,6 +1126,42 @@ public sealed class SearchIndex : ISearchIndex
return query;
}
private void AddStatistics(Document doc, List<MediaVersion> mediaVersions)
{
foreach (MediaVersion version in mediaVersions)
{
doc.Add(new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
if (version.Streams.Any(s => s.MediaStreamKind == MediaStreamKind.Video))
{
doc.Add(new Int32Field(HeightField, version.Height, Field.Store.NO));
doc.Add(new Int32Field(WidthField, version.Width, Field.Store.NO));
}
foreach (MediaStream videoStream in version.Streams.Filter(s => s.MediaStreamKind == MediaStreamKind.Video))
{
doc.Add(new StringField(VideoCodecField, videoStream.Codec, Field.Store.NO));
Option<IPixelFormat> maybePixelFormat =
AvailablePixelFormats.ForPixelFormat(videoStream.PixelFormat, null);
foreach (IPixelFormat pixelFormat in maybePixelFormat)
{
doc.Add(new Int32Field(VideoBitDepthField, pixelFormat.BitDepth, Field.Store.NO));
}
var colorParams = new ColorParams(
videoStream.ColorRange,
videoStream.ColorSpace,
videoStream.ColorTransfer,
videoStream.ColorPrimaries);
string dynamicRange = colorParams.IsHdr ? "hdr" : "sdr";
doc.Add(new TextField(VideoDynamicRange, dynamicRange, Field.Store.NO));
}
}
}
private static void AddMetadataGuids(Metadata metadata, Document doc)
{

12
docs/user-guide/search.md

@ -28,6 +28,9 @@ The following fields are available for searching movies: @@ -28,6 +28,9 @@ The following fields are available for searching movies:
- `minutes`: The rounded-up whole number duration of the movie in minutes
- `height`: The movie height
- `width`: The movie width
- `video_codec`: The video codec
- `video_bit_depth`: The number of bits in the movie's pixel format
- `video_dynamic_range`: The movie's dynamic range (`sdr` or `hdr`)
- `type`: Always `movie`
### Shows
@ -79,6 +82,9 @@ The following fields are available for searching episodes: @@ -79,6 +82,9 @@ The following fields are available for searching episodes:
- `show_title`: The title of the show that contains the episode
- `show_genre`: The genre of the show that contains the episode
- `show_tag`: The tag of the show that contains the episode
- `video_codec`: The video codec
- `video_bit_depth`: The number of bits in the episode's pixel format
- `video_dynamic_range`: The episode's dynamic range (`sdr` or `hdr`)
- `type`: Always `episode`
### Artists
@ -108,6 +114,9 @@ The following fields are available for searching music videos: @@ -108,6 +114,9 @@ The following fields are available for searching music videos:
- `minutes`: The rounded-up whole number duration of the music video in minutes
- `height`: The music video height
- `width`: The music video width
- `video_codec`: The video codec
- `video_bit_depth`: The number of bits in the music video's pixel format
- `video_dynamic_range`: The music video's dynamic range (`sdr` or `hdr`)
- `type`: Always `music_video`
### Other Videos
@ -130,6 +139,9 @@ The following fields are available for searching other videos: @@ -130,6 +139,9 @@ The following fields are available for searching other videos:
- `minutes`: The rounded-up whole number duration of the video in minutes
- `height`: The video height
- `width`: The video width
- `video_codec`: The video codec
- `video_bit_depth`: The number of bits in the other video's pixel format
- `video_dynamic_range`: The other video's dynamic range (`sdr` or `hdr`)
- `type`: Always `other_video`
### Songs

Loading…
Cancel
Save