parent
ea81db67f4
commit
6acd146d17
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,133 @@
|
||||
namespace Jellyfin.Data.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// The person kind.
|
||||
/// </summary>
|
||||
public enum PeopleKind
|
||||
{
|
||||
/// <summary>
|
||||
/// An unknown person kind.
|
||||
/// </summary>
|
||||
Unknown,
|
||||
|
||||
/// <summary>
|
||||
/// A person whose profession is acting on the stage, in films, or on television.
|
||||
/// </summary>
|
||||
Actor,
|
||||
|
||||
/// <summary>
|
||||
/// A person who supervises the actors and other staff in a film, play, or similar production.
|
||||
/// </summary>
|
||||
Director,
|
||||
|
||||
/// <summary>
|
||||
/// A person who writes music, especially as a professional occupation.
|
||||
/// </summary>
|
||||
Composer,
|
||||
|
||||
/// <summary>
|
||||
/// A writer of a book, article, or document. Can also be used as a generic term for music writer if there is a lack of specificity.
|
||||
/// </summary>
|
||||
Writer,
|
||||
|
||||
/// <summary>
|
||||
/// A well-known actor or other performer who appears in a work in which they do not have a regular role.
|
||||
/// </summary>
|
||||
GuestStar,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for the financial and managerial aspects of the making of a film or broadcast or for staging a play, opera, etc.
|
||||
/// </summary>
|
||||
Producer,
|
||||
|
||||
/// <summary>
|
||||
/// A person who directs the performance of an orchestra or choir.
|
||||
/// </summary>
|
||||
Conductor,
|
||||
|
||||
/// <summary>
|
||||
/// A person who writes the words to a song or musical.
|
||||
/// </summary>
|
||||
Lyricist,
|
||||
|
||||
/// <summary>
|
||||
/// A person who adapts a musical composition for performance.
|
||||
/// </summary>
|
||||
Arranger,
|
||||
|
||||
/// <summary>
|
||||
/// An audio engineer who performed a general engineering role.
|
||||
/// </summary>
|
||||
Engineer,
|
||||
|
||||
/// <summary>
|
||||
/// An engineer responsible for using a mixing console to mix a recorded track into a single piece of music suitable for release.
|
||||
/// </summary>
|
||||
Mixer,
|
||||
|
||||
/// <summary>
|
||||
/// A person who remixed a recording by taking one or more other tracks, substantially altering them and mixing them together with other material.
|
||||
/// </summary>
|
||||
Remixer,
|
||||
|
||||
/// <summary>
|
||||
/// A person who created the material.
|
||||
/// </summary>
|
||||
Creator,
|
||||
|
||||
/// <summary>
|
||||
/// A person who was the artist.
|
||||
/// </summary>
|
||||
Artist,
|
||||
|
||||
/// <summary>
|
||||
/// A person who was the album artist.
|
||||
/// </summary>
|
||||
AlbumArtist,
|
||||
|
||||
/// <summary>
|
||||
/// A person who was the author.
|
||||
/// </summary>
|
||||
Author,
|
||||
|
||||
/// <summary>
|
||||
/// A person who was the illustrator.
|
||||
/// </summary>
|
||||
Illustrator,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for drawing the art.
|
||||
/// </summary>
|
||||
Penciller,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for inking the pencil art.
|
||||
/// </summary>
|
||||
Inker,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for applying color to drawings.
|
||||
/// </summary>
|
||||
Colorist,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for drawing text and speech bubbles.
|
||||
/// </summary>
|
||||
Letterer,
|
||||
|
||||
/// <summary>
|
||||
/// A person responsible for drawing the cover art.
|
||||
/// </summary>
|
||||
CoverArtist,
|
||||
|
||||
/// <summary>
|
||||
/// A person contributing to a resource by revising or elucidating the content, e.g., adding an introduction, notes, or other critical matter.
|
||||
/// An editor may also prepare a resource for production, publication, or distribution.
|
||||
/// </summary>
|
||||
Editor,
|
||||
|
||||
/// <summary>
|
||||
/// A person who renders a text from one language into another.
|
||||
/// </summary>
|
||||
Translator
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Jellyfin.Data.Entities;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Item;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaStreamManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dbProvider"></param>
|
||||
/// <param name="serverApplicationHost"></param>
|
||||
/// <param name="localization"></param>
|
||||
public class MediaStreamManager(IDbContextFactory<JellyfinDbContext> dbProvider, IServerApplicationHost serverApplicationHost, ILocalizationManager localization)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void SaveMediaStreams(Guid id, IReadOnlyList<MediaStream> streams, CancellationToken cancellationToken)
|
||||
{
|
||||
using var context = dbProvider.CreateDbContext();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
context.MediaStreamInfos.Where(e => e.ItemId.Equals(id)).ExecuteDelete();
|
||||
context.MediaStreamInfos.AddRange(streams.Select(f => Map(f, id)));
|
||||
context.SaveChanges();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<MediaStream> GetMediaStreams(MediaStreamQuery filter)
|
||||
{
|
||||
using var context = dbProvider.CreateDbContext();
|
||||
return TranslateQuery(context.MediaStreamInfos, filter).ToList().Select(Map).ToImmutableArray();
|
||||
}
|
||||
|
||||
private string? GetPathToSave(string? path)
|
||||
{
|
||||
if (path is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return serverApplicationHost.ReverseVirtualPath(path);
|
||||
}
|
||||
|
||||
private string? RestorePath(string? path)
|
||||
{
|
||||
if (path is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return serverApplicationHost.ExpandVirtualPath(path);
|
||||
}
|
||||
|
||||
private IQueryable<MediaStreamInfo> TranslateQuery(IQueryable<MediaStreamInfo> query, MediaStreamQuery filter)
|
||||
{
|
||||
query = query.Where(e => e.ItemId.Equals(filter.ItemId));
|
||||
if (filter.Index.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.StreamIndex == filter.Index);
|
||||
}
|
||||
|
||||
if (filter.Type.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.StreamType == filter.Type.ToString());
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private MediaStream Map(MediaStreamInfo entity)
|
||||
{
|
||||
var dto = new MediaStream();
|
||||
dto.Index = entity.StreamIndex;
|
||||
if (entity.StreamType != null)
|
||||
{
|
||||
dto.Type = Enum.Parse<MediaStreamType>(entity.StreamType);
|
||||
}
|
||||
|
||||
dto.IsAVC = entity.IsAvc;
|
||||
dto.Codec = entity.Codec;
|
||||
dto.Language = entity.Language;
|
||||
dto.ChannelLayout = entity.ChannelLayout;
|
||||
dto.Profile = entity.Profile;
|
||||
dto.AspectRatio = entity.AspectRatio;
|
||||
dto.Path = RestorePath(entity.Path);
|
||||
dto.IsInterlaced = entity.IsInterlaced;
|
||||
dto.BitRate = entity.BitRate;
|
||||
dto.Channels = entity.Channels;
|
||||
dto.SampleRate = entity.SampleRate;
|
||||
dto.IsDefault = entity.IsDefault;
|
||||
dto.IsForced = entity.IsForced;
|
||||
dto.IsExternal = entity.IsExternal;
|
||||
dto.Height = entity.Height;
|
||||
dto.Width = entity.Width;
|
||||
dto.AverageFrameRate = entity.AverageFrameRate;
|
||||
dto.RealFrameRate = entity.RealFrameRate;
|
||||
dto.Level = entity.Level;
|
||||
dto.PixelFormat = entity.PixelFormat;
|
||||
dto.BitDepth = entity.BitDepth;
|
||||
dto.IsAnamorphic = entity.IsAnamorphic;
|
||||
dto.RefFrames = entity.RefFrames;
|
||||
dto.CodecTag = entity.CodecTag;
|
||||
dto.Comment = entity.Comment;
|
||||
dto.NalLengthSize = entity.NalLengthSize;
|
||||
dto.Title = entity.Title;
|
||||
dto.TimeBase = entity.TimeBase;
|
||||
dto.CodecTimeBase = entity.CodecTimeBase;
|
||||
dto.ColorPrimaries = entity.ColorPrimaries;
|
||||
dto.ColorSpace = entity.ColorSpace;
|
||||
dto.ColorTransfer = entity.ColorTransfer;
|
||||
dto.DvVersionMajor = entity.DvVersionMajor;
|
||||
dto.DvVersionMinor = entity.DvVersionMinor;
|
||||
dto.DvProfile = entity.DvProfile;
|
||||
dto.DvLevel = entity.DvLevel;
|
||||
dto.RpuPresentFlag = entity.RpuPresentFlag;
|
||||
dto.ElPresentFlag = entity.ElPresentFlag;
|
||||
dto.BlPresentFlag = entity.BlPresentFlag;
|
||||
dto.DvBlSignalCompatibilityId = entity.DvBlSignalCompatibilityId;
|
||||
dto.IsHearingImpaired = entity.IsHearingImpaired;
|
||||
dto.Rotation = entity.Rotation;
|
||||
|
||||
if (dto.Type is MediaStreamType.Audio or MediaStreamType.Subtitle)
|
||||
{
|
||||
dto.LocalizedDefault = localization.GetLocalizedString("Default");
|
||||
dto.LocalizedExternal = localization.GetLocalizedString("External");
|
||||
|
||||
if (dto.Type is MediaStreamType.Subtitle)
|
||||
{
|
||||
dto.LocalizedUndefined = localization.GetLocalizedString("Undefined");
|
||||
dto.LocalizedForced = localization.GetLocalizedString("Forced");
|
||||
dto.LocalizedHearingImpaired = localization.GetLocalizedString("HearingImpaired");
|
||||
}
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private MediaStreamInfo Map(MediaStream dto, Guid itemId)
|
||||
{
|
||||
var entity = new MediaStreamInfo
|
||||
{
|
||||
Item = null!,
|
||||
ItemId = itemId,
|
||||
StreamIndex = dto.Index,
|
||||
StreamType = dto.Type.ToString(),
|
||||
IsAvc = dto.IsAVC.GetValueOrDefault(),
|
||||
|
||||
Codec = dto.Codec,
|
||||
Language = dto.Language,
|
||||
ChannelLayout = dto.ChannelLayout,
|
||||
Profile = dto.Profile,
|
||||
AspectRatio = dto.AspectRatio,
|
||||
Path = GetPathToSave(dto.Path),
|
||||
IsInterlaced = dto.IsInterlaced,
|
||||
BitRate = dto.BitRate.GetValueOrDefault(0),
|
||||
Channels = dto.Channels.GetValueOrDefault(0),
|
||||
SampleRate = dto.SampleRate.GetValueOrDefault(0),
|
||||
IsDefault = dto.IsDefault,
|
||||
IsForced = dto.IsForced,
|
||||
IsExternal = dto.IsExternal,
|
||||
Height = dto.Height.GetValueOrDefault(0),
|
||||
Width = dto.Width.GetValueOrDefault(0),
|
||||
AverageFrameRate = dto.AverageFrameRate.GetValueOrDefault(0),
|
||||
RealFrameRate = dto.RealFrameRate.GetValueOrDefault(0),
|
||||
Level = (float)dto.Level.GetValueOrDefault(),
|
||||
PixelFormat = dto.PixelFormat,
|
||||
BitDepth = dto.BitDepth.GetValueOrDefault(0),
|
||||
IsAnamorphic = dto.IsAnamorphic.GetValueOrDefault(0),
|
||||
RefFrames = dto.RefFrames.GetValueOrDefault(0),
|
||||
CodecTag = dto.CodecTag,
|
||||
Comment = dto.Comment,
|
||||
NalLengthSize = dto.NalLengthSize,
|
||||
Title = dto.Title,
|
||||
TimeBase = dto.TimeBase,
|
||||
CodecTimeBase = dto.CodecTimeBase,
|
||||
ColorPrimaries = dto.ColorPrimaries,
|
||||
ColorSpace = dto.ColorSpace,
|
||||
ColorTransfer = dto.ColorTransfer,
|
||||
DvVersionMajor = dto.DvVersionMajor.GetValueOrDefault(0),
|
||||
DvVersionMinor = dto.DvVersionMinor.GetValueOrDefault(0),
|
||||
DvProfile = dto.DvProfile.GetValueOrDefault(0),
|
||||
DvLevel = dto.DvLevel.GetValueOrDefault(0),
|
||||
RpuPresentFlag = dto.RpuPresentFlag.GetValueOrDefault(0),
|
||||
ElPresentFlag = dto.ElPresentFlag.GetValueOrDefault(0),
|
||||
BlPresentFlag = dto.BlPresentFlag.GetValueOrDefault(0),
|
||||
DvBlSignalCompatibilityId = dto.DvBlSignalCompatibilityId.GetValueOrDefault(0),
|
||||
IsHearingImpaired = dto.IsHearingImpaired,
|
||||
Rotation = dto.Rotation.GetValueOrDefault(0)
|
||||
};
|
||||
return entity;
|
||||
}
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Jellyfin.Data.Entities;
|
||||
using Jellyfin.Data.Enums;
|
||||
using Jellyfin.Extensions;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Item;
|
||||
|
||||
public class PeopleManager
|
||||
{
|
||||
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PeopleManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dbProvider">The EFCore Context factory.</param>
|
||||
public PeopleManager(IDbContextFactory<JellyfinDbContext> dbProvider)
|
||||
{
|
||||
_dbProvider = dbProvider;
|
||||
}
|
||||
|
||||
public IReadOnlyList<PersonInfo> GetPeople(InternalPeopleQuery filter)
|
||||
{
|
||||
using var context = _dbProvider.CreateDbContext();
|
||||
var dbQuery = TranslateQuery(context.Peoples.AsNoTracking(), context, filter);
|
||||
|
||||
dbQuery = dbQuery.OrderBy(e => e.ListOrder);
|
||||
if (filter.Limit > 0)
|
||||
{
|
||||
dbQuery = dbQuery.Take(filter.Limit);
|
||||
}
|
||||
|
||||
return dbQuery.ToList().Select(Map).ToImmutableArray();
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> GetPeopleNames(InternalPeopleQuery filter)
|
||||
{
|
||||
using var context = _dbProvider.CreateDbContext();
|
||||
var dbQuery = TranslateQuery(context.Peoples.AsNoTracking(), context, filter);
|
||||
|
||||
dbQuery = dbQuery.OrderBy(e => e.ListOrder);
|
||||
if (filter.Limit > 0)
|
||||
{
|
||||
dbQuery = dbQuery.Take(filter.Limit);
|
||||
}
|
||||
|
||||
return dbQuery.Select(e => e.Name).ToImmutableArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UpdatePeople(Guid itemId, IReadOnlyList<PersonInfo> people)
|
||||
{
|
||||
using var context = _dbProvider.CreateDbContext();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
context.Peoples.Where(e => e.ItemId.Equals(itemId)).ExecuteDelete();
|
||||
context.Peoples.AddRange(people.Select(Map));
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
private PersonInfo Map(People people)
|
||||
{
|
||||
var personInfo = new PersonInfo()
|
||||
{
|
||||
ItemId = people.ItemId,
|
||||
Name = people.Name,
|
||||
Role = people.Role,
|
||||
SortOrder = people.SortOrder,
|
||||
};
|
||||
if (Enum.TryParse<PersonKind>(people.PersonType, out var kind))
|
||||
{
|
||||
personInfo.Type = kind;
|
||||
}
|
||||
|
||||
return personInfo;
|
||||
}
|
||||
|
||||
private People Map(PersonInfo people)
|
||||
{
|
||||
var personInfo = new People()
|
||||
{
|
||||
ItemId = people.ItemId,
|
||||
Name = people.Name,
|
||||
Role = people.Role,
|
||||
SortOrder = people.SortOrder,
|
||||
PersonType = people.Type.ToString()
|
||||
};
|
||||
|
||||
return personInfo;
|
||||
}
|
||||
|
||||
private IQueryable<People> TranslateQuery(IQueryable<People> query, JellyfinDbContext context, InternalPeopleQuery filter)
|
||||
{
|
||||
if (filter.User is not null && filter.IsFavorite.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.PersonType == typeof(Person).FullName)
|
||||
.Where(e => context.BaseItems.Where(d => context.UserData.Where(e => e.IsFavorite == filter.IsFavorite && e.UserId.Equals(filter.User.Id)).Any(f => f.Key == d.UserDataKey))
|
||||
.Select(f => f.Name).Contains(e.Name));
|
||||
}
|
||||
|
||||
if (!filter.ItemId.IsEmpty())
|
||||
{
|
||||
query = query.Where(e => e.ItemId.Equals(filter.ItemId));
|
||||
}
|
||||
|
||||
if (!filter.AppearsInItemId.IsEmpty())
|
||||
{
|
||||
query = query.Where(e => context.Peoples.Where(f => f.ItemId.Equals(filter.AppearsInItemId)).Select(e => e.Name).Contains(e.Name));
|
||||
}
|
||||
|
||||
var queryPersonTypes = filter.PersonTypes.Where(IsValidPersonType).ToList();
|
||||
if (queryPersonTypes.Count > 0)
|
||||
{
|
||||
query = query.Where(e => queryPersonTypes.Contains(e.PersonType));
|
||||
}
|
||||
|
||||
var queryExcludePersonTypes = filter.ExcludePersonTypes.Where(IsValidPersonType).ToList();
|
||||
|
||||
if (queryExcludePersonTypes.Count > 0)
|
||||
{
|
||||
query = query.Where(e => !queryPersonTypes.Contains(e.PersonType));
|
||||
}
|
||||
|
||||
if (filter.MaxListOrder.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.ListOrder <= filter.MaxListOrder.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filter.NameContains))
|
||||
{
|
||||
query = query.Where(e => e.Name.Contains(filter.NameContains));
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private bool IsAlphaNumeric(string str)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!char.IsLetter(str[i]) && !char.IsNumber(str[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsValidPersonType(string value)
|
||||
{
|
||||
return IsAlphaNumeric(value);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue