mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
rework media versions to be based on original item id
This commit is contained in:
@@ -267,12 +267,14 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
PlayableMediaTypes = session.PlayableMediaTypes,
|
||||
RemoteEndPoint = session.RemoteEndPoint,
|
||||
AdditionalUsers = session.AdditionalUsers,
|
||||
SupportsFullscreenToggle = session.SupportsFullscreenToggle
|
||||
SupportsFullscreenToggle = session.SupportsFullscreenToggle,
|
||||
SupportsNavigationControl = session.SupportsNavigationControl,
|
||||
SupportsOsdToggle = session.SupportsOsdToggle
|
||||
};
|
||||
|
||||
if (session.NowPlayingItem != null)
|
||||
{
|
||||
dto.NowPlayingItem = GetBaseItemInfo(session.NowPlayingItem);
|
||||
dto.NowPlayingItem = GetNowPlayingInfo(session.NowPlayingItem, session.NowPlayingMediaVersionId, session.NowPlayingRunTimeTicks);
|
||||
}
|
||||
|
||||
if (session.UserId.HasValue)
|
||||
@@ -288,9 +290,11 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
/// Converts a BaseItem to a BaseItemInfo
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="mediaVersionId">The media version identifier.</param>
|
||||
/// <param name="nowPlayingRuntimeTicks">The now playing runtime ticks.</param>
|
||||
/// <returns>BaseItemInfo.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">item</exception>
|
||||
public BaseItemInfo GetBaseItemInfo(BaseItem item)
|
||||
private BaseItemInfo GetNowPlayingInfo(BaseItem item, string mediaVersionId, long? nowPlayingRuntimeTicks)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
@@ -303,7 +307,8 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
Name = item.Name,
|
||||
MediaType = item.MediaType,
|
||||
Type = item.GetClientTypeName(),
|
||||
RunTimeTicks = item.RunTimeTicks
|
||||
RunTimeTicks = nowPlayingRuntimeTicks,
|
||||
MediaVersionId = mediaVersionId
|
||||
};
|
||||
|
||||
info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary);
|
||||
@@ -1103,9 +1108,7 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
|
||||
if (dto.MediaVersions != null && dto.MediaVersions.Count > 0)
|
||||
{
|
||||
chapters = dto.MediaVersions.Where(i => i.IsPrimaryVersion)
|
||||
.SelectMany(i => i.Chapters)
|
||||
.ToList();
|
||||
chapters = _itemRepo.GetChapters(item.Id).Select(c => GetChapterInfoDto(c, item)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1292,24 +1295,25 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
|
||||
private List<MediaVersionInfo> GetMediaVersions(Audio item)
|
||||
{
|
||||
var result = new List<MediaVersionInfo>();
|
||||
|
||||
result.Add(GetVersionInfo(item, true));
|
||||
var result = new List<MediaVersionInfo>
|
||||
{
|
||||
GetVersionInfo(item, true)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private MediaVersionInfo GetVersionInfo(Video i, bool isPrimary)
|
||||
{
|
||||
var mediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery {ItemId = i.Id}).ToList();
|
||||
|
||||
return new MediaVersionInfo
|
||||
{
|
||||
Chapters = _itemRepo.GetChapters(i.Id).Select(c => GetChapterInfoDto(c, i)).ToList(),
|
||||
|
||||
ItemId = i.Id.ToString("N"),
|
||||
Id = i.Id.ToString("N"),
|
||||
IsoType = i.IsoType,
|
||||
LocationType = i.LocationType,
|
||||
MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList(),
|
||||
Name = GetAlternateVersionName(i),
|
||||
MediaStreams = mediaStreams,
|
||||
Name = GetAlternateVersionName(i, mediaStreams),
|
||||
Path = GetMappedPath(i),
|
||||
RunTimeTicks = i.RunTimeTicks,
|
||||
Video3DFormat = i.Video3DFormat,
|
||||
@@ -1322,7 +1326,7 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
{
|
||||
return new MediaVersionInfo
|
||||
{
|
||||
ItemId = i.Id.ToString("N"),
|
||||
Id = i.Id.ToString("N"),
|
||||
LocationType = i.LocationType,
|
||||
MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList(),
|
||||
Name = i.Name,
|
||||
@@ -1351,32 +1355,29 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
return path;
|
||||
}
|
||||
|
||||
private string GetAlternateVersionName(Video video)
|
||||
private string GetAlternateVersionName(Video video, List<MediaStream> mediaStreams)
|
||||
{
|
||||
var name = "";
|
||||
var terms = new List<string>();
|
||||
|
||||
var videoStream = video.GetDefaultVideoStream();
|
||||
var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
|
||||
var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
|
||||
|
||||
if (video.Video3DFormat.HasValue)
|
||||
{
|
||||
name = "3D " + name;
|
||||
name = name.Trim();
|
||||
terms.Add("3D");
|
||||
}
|
||||
|
||||
if (video.VideoType == VideoType.BluRay)
|
||||
{
|
||||
name = name + " " + "Bluray";
|
||||
name = name.Trim();
|
||||
terms.Add("Bluray");
|
||||
}
|
||||
else if (video.VideoType == VideoType.Dvd)
|
||||
{
|
||||
name = name + " " + "DVD";
|
||||
name = name.Trim();
|
||||
terms.Add("DVD");
|
||||
}
|
||||
else if (video.VideoType == VideoType.HdDvd)
|
||||
{
|
||||
name = name + " " + "HD-DVD";
|
||||
name = name.Trim();
|
||||
terms.Add("HD-DVD");
|
||||
}
|
||||
else if (video.VideoType == VideoType.Iso)
|
||||
{
|
||||
@@ -1384,18 +1385,17 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
{
|
||||
if (video.IsoType.Value == IsoType.BluRay)
|
||||
{
|
||||
name = name + " " + "Bluray";
|
||||
terms.Add("Bluray");
|
||||
}
|
||||
else if (video.IsoType.Value == IsoType.Dvd)
|
||||
{
|
||||
name = name + " " + "DVD";
|
||||
terms.Add("DVD");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = name + " " + "ISO";
|
||||
terms.Add("ISO");
|
||||
}
|
||||
name = name.Trim();
|
||||
}
|
||||
|
||||
if (videoStream != null)
|
||||
@@ -1404,44 +1404,45 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
{
|
||||
if (videoStream.Width.Value >= 3800)
|
||||
{
|
||||
name = name + " " + "4K";
|
||||
name = name.Trim();
|
||||
terms.Add("4K");
|
||||
}
|
||||
else if (videoStream.Width.Value >= 1900)
|
||||
{
|
||||
name = name + " " + "1080P";
|
||||
name = name.Trim();
|
||||
terms.Add("1080P");
|
||||
}
|
||||
else if (videoStream.Width.Value >= 1270)
|
||||
{
|
||||
name = name + " " + "720P";
|
||||
name = name.Trim();
|
||||
terms.Add("720P");
|
||||
}
|
||||
else if (videoStream.Width.Value >= 700)
|
||||
{
|
||||
name = name + " " + "480p";
|
||||
name = name.Trim();
|
||||
terms.Add("480P");
|
||||
}
|
||||
else
|
||||
{
|
||||
name = name + " " + "SD";
|
||||
name = name.Trim();
|
||||
terms.Add("SD");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
|
||||
{
|
||||
name = name + " " + videoStream.Codec.ToUpper();
|
||||
name = name.Trim();
|
||||
terms.Add(videoStream.Codec.ToUpper());
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
if (audioStream != null)
|
||||
{
|
||||
return video.Name;
|
||||
var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
|
||||
? audioStream.Profile
|
||||
: audioStream.Codec;
|
||||
|
||||
if (!string.IsNullOrEmpty(audioCodec))
|
||||
{
|
||||
terms.Add(audioCodec.ToUpper());
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
return string.Join("/", terms.ToArray());
|
||||
}
|
||||
|
||||
private string GetMappedPath(string path)
|
||||
|
||||
@@ -427,11 +427,11 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
{
|
||||
if (_updateTimer == null)
|
||||
{
|
||||
_updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.RealtimeWatcherDelay), TimeSpan.FromMilliseconds(-1));
|
||||
_updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.RealtimeMonitorDelay), TimeSpan.FromMilliseconds(-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
_updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.RealtimeWatcherDelay), TimeSpan.FromMilliseconds(-1));
|
||||
_updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.RealtimeMonitorDelay), TimeSpan.FromMilliseconds(-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Roku
|
||||
{
|
||||
@@ -23,6 +25,9 @@ namespace MediaBrowser.Server.Implementations.Roku
|
||||
{
|
||||
if (string.Equals(session.Client, "roku", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
session.PlayableMediaTypes = new List<string> { MediaType.Video, MediaType.Audio };
|
||||
session.SupportsFullscreenToggle = false;
|
||||
|
||||
return new RokuSessionController(_httpClient, _json, _appHost, session);
|
||||
}
|
||||
|
||||
|
||||
@@ -218,15 +218,29 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="mediaVersionId">The media version identifier.</param>
|
||||
/// <param name="isPaused">if set to <c>true</c> [is paused].</param>
|
||||
/// <param name="isMuted">if set to <c>true</c> [is muted].</param>
|
||||
/// <param name="currentPositionTicks">The current position ticks.</param>
|
||||
private void UpdateNowPlayingItem(SessionInfo session, BaseItem item, bool isPaused, bool isMuted, long? currentPositionTicks = null)
|
||||
private void UpdateNowPlayingItem(SessionInfo session, BaseItem item, string mediaVersionId, bool isPaused, bool isMuted, long? currentPositionTicks = null)
|
||||
{
|
||||
session.IsMuted = isMuted;
|
||||
session.IsPaused = isPaused;
|
||||
session.NowPlayingPositionTicks = currentPositionTicks;
|
||||
session.NowPlayingItem = item;
|
||||
session.LastActivityDate = DateTime.UtcNow;
|
||||
session.NowPlayingMediaVersionId = mediaVersionId;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(mediaVersionId))
|
||||
{
|
||||
session.NowPlayingRunTimeTicks = item.RunTimeTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
var version = _libraryManager.GetItemById(new Guid(mediaVersionId));
|
||||
|
||||
session.NowPlayingRunTimeTicks = version.RunTimeTicks;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -246,6 +260,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
session.NowPlayingItem = null;
|
||||
session.NowPlayingPositionTicks = null;
|
||||
session.IsPaused = false;
|
||||
session.NowPlayingRunTimeTicks = null;
|
||||
session.NowPlayingMediaVersionId = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +368,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
|
||||
var item = info.Item;
|
||||
|
||||
UpdateNowPlayingItem(session, item, false, false);
|
||||
var mediaVersionId = GetMediaVersionId(item, info.MediaVersionId);
|
||||
|
||||
UpdateNowPlayingItem(session, item, mediaVersionId, false, false);
|
||||
|
||||
session.CanSeek = info.CanSeek;
|
||||
session.QueueableMediaTypes = info.QueueableMediaTypes;
|
||||
@@ -371,7 +389,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
|
||||
{
|
||||
Item = item,
|
||||
Users = users
|
||||
Users = users,
|
||||
MediaVersionId = info.MediaVersionId
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
@@ -405,7 +424,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
|
||||
public async Task OnPlaybackProgress(PlaybackProgressInfo info)
|
||||
public async Task OnPlaybackProgress(Controller.Session.PlaybackProgressInfo info)
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
@@ -419,7 +438,9 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
|
||||
var session = Sessions.First(i => i.Id.Equals(info.SessionId));
|
||||
|
||||
UpdateNowPlayingItem(session, info.Item, info.IsPaused, info.IsMuted, info.PositionTicks);
|
||||
var mediaVersionId = GetMediaVersionId(info.Item, info.MediaVersionId);
|
||||
|
||||
UpdateNowPlayingItem(session, info.Item, mediaVersionId, info.IsPaused, info.IsMuted, info.PositionTicks);
|
||||
|
||||
var key = info.Item.GetUserDataKey();
|
||||
|
||||
@@ -434,7 +455,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
{
|
||||
Item = info.Item,
|
||||
Users = users,
|
||||
PlaybackPositionTicks = info.PositionTicks
|
||||
PlaybackPositionTicks = info.PositionTicks,
|
||||
MediaVersionId = mediaVersionId
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
@@ -458,7 +480,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">info</exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
|
||||
public async Task OnPlaybackStopped(PlaybackStopInfo info)
|
||||
public async Task OnPlaybackStopped(Controller.Session.PlaybackStopInfo info)
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
@@ -494,16 +516,32 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
playedToCompletion = await OnPlaybackStopped(user.Id, key, info.Item, info.PositionTicks).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var mediaVersionId = GetMediaVersionId(info.Item, info.MediaVersionId);
|
||||
|
||||
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackStopEventArgs
|
||||
{
|
||||
Item = info.Item,
|
||||
Users = users,
|
||||
PlaybackPositionTicks = info.PositionTicks,
|
||||
PlayedToCompletion = playedToCompletion
|
||||
PlayedToCompletion = playedToCompletion,
|
||||
MediaVersionId = mediaVersionId
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
|
||||
private string GetMediaVersionId(BaseItem item, string reportedMediaVersionId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(reportedMediaVersionId))
|
||||
{
|
||||
if (item is Video || item is Audio)
|
||||
{
|
||||
reportedMediaVersionId = item.Id.ToString("N");
|
||||
}
|
||||
}
|
||||
|
||||
return reportedMediaVersionId;
|
||||
}
|
||||
|
||||
private async Task<bool> OnPlaybackStopped(Guid userId, string userDataKey, BaseItem item, long? positionTicks)
|
||||
{
|
||||
var data = _userDataRepository.GetUserData(userId, userDataKey);
|
||||
@@ -899,6 +937,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
|
||||
session.PlayableMediaTypes = capabilities.PlayableMediaTypes.ToList();
|
||||
session.SupportsFullscreenToggle = capabilities.SupportsFullscreenToggle;
|
||||
session.SupportsOsdToggle = capabilities.SupportsOsdToggle;
|
||||
session.SupportsNavigationControl = capabilities.SupportsNavigationControl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,6 +223,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
|
||||
};
|
||||
|
||||
if (vals.Length > 3)
|
||||
{
|
||||
info.MediaVersionId = vals[3];
|
||||
}
|
||||
|
||||
_sessionManager.OnPlaybackStart(info);
|
||||
}
|
||||
}
|
||||
@@ -265,6 +270,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
SessionId = session.Id
|
||||
};
|
||||
|
||||
if (vals.Length > 4)
|
||||
{
|
||||
info.MediaVersionId = vals[4];
|
||||
}
|
||||
|
||||
_sessionManager.OnPlaybackProgress(info);
|
||||
}
|
||||
}
|
||||
@@ -304,6 +314,11 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
SessionId = session.Id
|
||||
};
|
||||
|
||||
if (vals.Length > 2)
|
||||
{
|
||||
info.MediaVersionId = vals[2];
|
||||
}
|
||||
|
||||
_sessionManager.OnPlaybackStopped(info);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user