move language filters from QueryFiltersLegacy to QueryFilters

This commit is contained in:
TheMelmacian
2026-05-12 01:47:07 +02:00
parent 5701cdce68
commit 39049a726e
10 changed files with 82 additions and 44 deletions

View File

@@ -535,46 +535,12 @@ public sealed partial class BaseItemRepository
.OrderBy(g => g)
.ToArray();
// At the moment language filters are only available for video types (Movie and Series libraries).
// They are fetched directly from the MediaStreamInfos table and only filtered by StreamType.
// This is the fastest and most perfomant way to get the list of available languages,
// but the filter values can include language tags that are not linked to any item in the current library.
var subtitleLanguages = IncludesVideoTypes(filter)
? context.MediaStreamInfos
.Where(s => s.StreamType == MediaStreamTypeEntity.Subtitle)
.Select(s => string.IsNullOrEmpty(s.Language) ? "und" : s.Language) // und = undetermined
.Distinct()
.OrderBy(l => l)
.ToArray()
: [];
var audioLanguages = IncludesVideoTypes(filter)
? context.MediaStreamInfos
.Where(s => s.StreamType == MediaStreamTypeEntity.Audio)
.Select(s => string.IsNullOrEmpty(s.Language) ? "und" : s.Language) // und = undetermined
.Distinct()
.OrderBy(l => l)
.ToArray()
: [];
return new QueryFiltersLegacy
{
Years = years,
OfficialRatings = officialRatings,
Tags = tags,
Genres = genres,
SubtitleLanguages = subtitleLanguages,
AudioLanguages = audioLanguages
Genres = genres
};
}
private bool IncludesVideoTypes(InternalItemsQuery filter)
{
return filter.IncludeItemTypes.Contains(BaseItemKind.Movie)
|| filter.IncludeItemTypes.Contains(BaseItemKind.Video)
|| filter.IncludeItemTypes.Contains(BaseItemKind.Series)
|| filter.IncludeItemTypes.Contains(BaseItemKind.Season)
|| filter.IncludeItemTypes.Contains(BaseItemKind.Episode)
|| filter.IncludeItemTypes.Contains(BaseItemKind.Trailer);
}
}

View File

@@ -1078,6 +1078,7 @@ public sealed partial class BaseItemRepository
{
// Dvds and Blu-rays can either be stored in a folder structure or as an iso file
// => to find all matches we need to check both: VideoType and IsoType
// alternatively, we could provide specific IsoType filters
var videoTypeBs = filter.VideoTypes.Select(vt => $"\"VideoType\":\"{vt}\"").ToArray();
var isoTypeBs = filter.VideoTypes.Select(vt => $"\"IsoType\":\"{vt}\"").ToArray();
Expression<Func<BaseItemEntity, bool>> hasVideoType = e => videoTypeBs.Any(f => e.Data!.Contains(f)) || isoTypeBs.Any(f => e.Data!.Contains(f));

View File

@@ -55,6 +55,17 @@ public class MediaStreamRepository : IMediaStreamRepository
return TranslateQuery(context.MediaStreamInfos.AsNoTracking(), filter).AsEnumerable().Select(Map).ToArray();
}
/// <inheritdoc />
public IReadOnlyList<string> GetMediaStreamLanguages(MediaStreamType mediaStreamType)
{
using var context = _dbProvider.CreateDbContext();
return context.MediaStreamInfos
.Where(e => e.StreamType == (MediaStreamTypeEntity)mediaStreamType)
.Select(s => string.IsNullOrEmpty(s.Language) ? "und" : s.Language) // und = undetermined
.Distinct()
.ToArray();
}
private string? GetPathToSave(string? path)
{
if (path is null)