Merge pull request #2580 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2017-04-15 15:46:46 -04:00 committed by GitHub
commit 8c4e69e1c6
15 changed files with 258 additions and 64 deletions

View File

@ -219,7 +219,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{
return FindMovie<MusicVideo>(args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
return FindMovie<MusicVideo>(args.Path, args.Parent, files, args.DirectoryService, collectionType, true);
}
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))

View File

@ -39,6 +39,7 @@ using MediaBrowser.Model.FileOrganization;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Threading;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Querying;
namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
@ -1512,7 +1513,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_timerProvider.AddOrUpdate(timer, false);
SaveRecordingMetadata(timer, recordPath, seriesPath);
EnforceKeepUpTo(timer);
EnforceKeepUpTo(timer, seriesPath);
};
await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken)
@ -1583,12 +1584,16 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}, _logger);
}
private async void EnforceKeepUpTo(TimerInfo timer)
private async void EnforceKeepUpTo(TimerInfo timer, string seriesPath)
{
if (string.IsNullOrWhiteSpace(timer.SeriesTimerId))
{
return;
}
if (string.IsNullOrWhiteSpace(seriesPath))
{
return;
}
var seriesTimerId = timer.SeriesTimerId;
var seriesTimer = _seriesTimerProvider.GetAll().FirstOrDefault(i => string.Equals(i.Id, seriesTimerId, StringComparison.OrdinalIgnoreCase));
@ -1621,6 +1626,43 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
.ToList();
await DeleteLibraryItemsForTimers(timersToDelete).ConfigureAwait(false);
var librarySeries = _libraryManager.FindByPath(seriesPath, true) as Folder;
if (librarySeries == null)
{
return;
}
var episodesToDelete = (await librarySeries.GetItems(new InternalItemsQuery
{
SortBy = new[] { ItemSortBy.DateCreated },
SortOrder = SortOrder.Descending,
IsVirtualItem = false,
IsFolder = false,
Recursive = true
}).ConfigureAwait(false))
.Items
.Where(i => i.LocationType == LocationType.FileSystem && _fileSystem.FileExists(i.Path))
.Skip(seriesTimer.KeepUpTo - 1)
.ToList();
foreach (var item in episodesToDelete)
{
try
{
await _libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = true
}).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting item", ex);
}
}
}
finally
{
@ -1658,7 +1700,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
await _libraryManager.DeleteItem(libraryItem, new DeleteOptions
{
DeleteFileLocation = true
});
}).ConfigureAwait(false);
}
else
{

View File

@ -84,7 +84,7 @@ namespace Emby.Server.Implementations.LiveTv
if (width >= 1900)
{
videoStream.BitRate = 8000000;
videoStream.BitRate = 15000000;
}
else if (width >= 1260)

View File

@ -185,7 +185,7 @@ namespace Emby.Server.Implementations.LiveTv
if (width >= 1900)
{
videoStream.BitRate = 8000000;
videoStream.BitRate = 15000000;
}
else if (width >= 1260)

View File

@ -134,6 +134,7 @@
<Compile Include="SearchService.cs" />
<Compile Include="Session\SessionsService.cs" />
<Compile Include="SimilarItemsHelper.cs" />
<Compile Include="SuggestionsService.cs" />
<Compile Include="System\ActivityLogService.cs" />
<Compile Include="System\ActivityLogWebSocketListener.cs" />
<Compile Include="System\SystemService.cs" />

View File

@ -826,6 +826,11 @@ namespace MediaBrowser.Api.Playback.Hls
args += " -ab " + bitrate.Value.ToString(UsCulture);
}
if (state.OutputAudioSampleRate.HasValue)
{
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
}
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
return args;

View File

@ -6,10 +6,7 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using System;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Services;
@ -60,6 +57,11 @@ namespace MediaBrowser.Api.Playback.Hls
args += " -ab " + bitrate.Value.ToString(UsCulture);
}
if (state.OutputAudioSampleRate.HasValue)
{
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
}
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
return args;

View File

@ -0,0 +1,104 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
using System;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
namespace MediaBrowser.Api
{
[Route("/Users/{UserId}/Suggestions", "GET", Summary = "Gets items based on a query.")]
public class GetSuggestedItems : IReturn<QueryResult<BaseItem>>
{
public string MediaType { get; set; }
public string Type { get; set; }
public string UserId { get; set; }
public bool EnableTotalRecordCount { get; set; }
public int? StartIndex { get; set; }
public int? Limit { get; set; }
public string[] GetMediaTypes()
{
return (MediaType ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
public string[] GetIncludeItemTypes()
{
return (Type ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}
}
public class SuggestionsService : BaseApiService
{
private readonly IDtoService _dtoService;
private readonly IAuthorizationContext _authContext;
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
public SuggestionsService(IDtoService dtoService, IAuthorizationContext authContext, IUserManager userManager, ILibraryManager libraryManager)
{
_dtoService = dtoService;
_authContext = authContext;
_userManager = userManager;
_libraryManager = libraryManager;
}
public async Task<object> Get(GetSuggestedItems request)
{
var result = await GetResultItems(request).ConfigureAwait(false);
return ToOptimizedResult(result);
}
private async Task<QueryResult<BaseItemDto>> GetResultItems(GetSuggestedItems request)
{
var user = !string.IsNullOrWhiteSpace(request.UserId) ? _userManager.GetUserById(request.UserId) : null;
var dtoOptions = GetDtoOptions(_authContext, request);
var result = GetItems(request, user, dtoOptions);
var dtoList = await _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user).ConfigureAwait(false);
if (dtoList == null)
{
throw new InvalidOperationException("GetBaseItemDtos returned null");
}
return new QueryResult<BaseItemDto>
{
TotalRecordCount = result.TotalRecordCount,
Items = dtoList.ToArray()
};
}
private QueryResult<BaseItem> GetItems(GetSuggestedItems request, User user, DtoOptions dtoOptions)
{
var query = new InternalItemsQuery(user)
{
SortBy = new string[] { ItemSortBy.Random },
MediaTypes = request.GetMediaTypes(),
IncludeItemTypes = request.GetIncludeItemTypes(),
IsVirtualItem = false,
StartIndex = request.StartIndex,
Limit = request.Limit,
DtoOptions = dtoOptions
};
if (request.EnableTotalRecordCount)
{
return _libraryManager.GetItemsResult(query);
}
var items = _libraryManager.GetItemList(query).ToArray();
return new QueryResult<BaseItem>
{
Items = items
};
}
}
}

View File

@ -137,6 +137,7 @@ namespace MediaBrowser.Api
}
[Route("/Shows/{Id}/Episodes", "GET", Summary = "Gets episodes for a tv season")]
[Route("/Shows/Episodes", "GET", Summary = "Gets episodes for a tv season")]
public class GetEpisodes : IReturn<ItemsResult>, IHasItemFields, IHasDtoOptions
{
/// <summary>
@ -200,9 +201,11 @@ namespace MediaBrowser.Api
[ApiMember(Name = "EnableUserData", Description = "Optional, include user data", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? EnableUserData { get; set; }
public string SeriesName { get; set; }
}
[Route("/Shows/{Id}/Seasons", "GET", Summary = "Gets seasons for a tv series")]
[Route("/Shows/Seasons", "GET", Summary = "Gets seasons for a tv series")]
public class GetSeasons : IReturn<ItemsResult>, IHasItemFields, IHasDtoOptions
{
/// <summary>
@ -246,6 +249,7 @@ namespace MediaBrowser.Api
[ApiMember(Name = "EnableUserData", Description = "Optional, include user data", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]
public bool? EnableUserData { get; set; }
public string SeriesName { get; set; }
}
/// <summary>
@ -427,11 +431,11 @@ namespace MediaBrowser.Api
{
var user = _userManager.GetUserById(request.UserId);
var series = _libraryManager.GetItemById(request.Id) as Series;
var series = GetSeries(request.Id, request.SeriesName, user);
if (series == null)
{
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
throw new ResourceNotFoundException("Series not found");
}
var seasons = (await series.GetItems(new InternalItemsQuery(user)
@ -455,6 +459,26 @@ namespace MediaBrowser.Api
};
}
private Series GetSeries(string seriesId, string seriesName, User user)
{
if (!string.IsNullOrWhiteSpace(seriesId))
{
return _libraryManager.GetItemById(seriesId) as Series;
}
if (!string.IsNullOrWhiteSpace(seriesName))
{
return _libraryManager.GetItemList(new InternalItemsQuery(user)
{
Name = seriesName,
IncludeItemTypes = new string[] { typeof(Series).Name }
}).OfType<Series>().FirstOrDefault();
}
return null;
}
public async Task<object> Get(GetEpisodes request)
{
var user = _userManager.GetUserById(request.UserId);
@ -474,11 +498,11 @@ namespace MediaBrowser.Api
}
else if (request.Season.HasValue)
{
var series = _libraryManager.GetItemById(request.Id) as Series;
var series = GetSeries(request.Id, request.SeriesName, user);
if (series == null)
{
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
throw new ResourceNotFoundException("Series not found");
}
var season = series.GetSeasons(user).FirstOrDefault(i => i.IndexNumber == request.Season.Value);
@ -494,11 +518,11 @@ namespace MediaBrowser.Api
}
else
{
var series = _libraryManager.GetItemById(request.Id) as Series;
var series = GetSeries(request.Id, request.SeriesName, user);
if (series == null)
{
throw new ResourceNotFoundException("No series exists with Id " + request.Id);
throw new ResourceNotFoundException("Series not found");
}
episodes = series.GetEpisodes(user);

View File

@ -9,6 +9,7 @@ using MediaBrowser.Model.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
namespace MediaBrowser.Controller.Entities.Audio
{
@ -227,7 +228,39 @@ namespace MediaBrowser.Controller.Entities.Audio
// Refresh current item
await RefreshMetadata(parentRefreshOptions, cancellationToken).ConfigureAwait(false);
if (!refreshOptions.IsAutomated)
{
await RefreshArtists(refreshOptions, cancellationToken).ConfigureAwait(false);
}
progress.Report(100);
}
private async Task RefreshArtists(MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{
var artists = AllArtists.Select(i =>
{
// This should not be necessary but we're seeing some cases of it
if (string.IsNullOrWhiteSpace(i))
{
return null;
}
var artist = LibraryManager.GetArtist(i);
if (!artist.IsAccessedByName)
{
return null;
}
return artist;
}).Where(i => i != null).ToList();
foreach (var artist in artists)
{
await artist.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
}
}
}
}

View File

@ -29,7 +29,7 @@ namespace MediaBrowser.Controller.Entities
{
get
{
return true;
return false;
}
}

View File

@ -719,14 +719,15 @@ namespace MediaBrowser.Controller.MediaEncoding
}
}
// nvenc doesn't decode with param -level set ?!
else if (string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase)){
else if (string.Equals(videoEncoder, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
{
//param += "";
}
else if (!string.Equals(videoEncoder, "h264_omx", StringComparison.OrdinalIgnoreCase))
{
param += " -level " + level;
}
}
if (string.Equals(videoEncoder, "libx264", StringComparison.OrdinalIgnoreCase))
@ -1014,43 +1015,32 @@ namespace MediaBrowser.Controller.MediaEncoding
public string GetAudioFilterParam(EncodingJobInfo state, EncodingOptions encodingOptions, bool isHls)
{
var volParam = string.Empty;
var audioSampleRate = string.Empty;
var channels = state.OutputAudioChannels;
var filters = new List<string>();
// Boost volume to 200% when downsampling from 6ch to 2ch
if (channels.HasValue && channels.Value <= 2)
{
if (state.AudioStream != null && state.AudioStream.Channels.HasValue && state.AudioStream.Channels.Value > 5 && !encodingOptions.DownMixAudioBoost.Equals(1))
{
volParam = ",volume=" + encodingOptions.DownMixAudioBoost.ToString(_usCulture);
filters.Add("volume=" + encodingOptions.DownMixAudioBoost.ToString(_usCulture));
}
}
if (state.OutputAudioSampleRate.HasValue)
{
audioSampleRate = state.OutputAudioSampleRate.Value + ":";
}
var adelay = isHls ? "adelay=1," : string.Empty;
var pts = string.Empty;
if (state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode && !state.CopyTimestamps)
{
var seconds = TimeSpan.FromTicks(state.StartTimeTicks ?? 0).TotalSeconds;
pts = string.Format(",asetpts=PTS-{0}/TB", Math.Round(seconds).ToString(_usCulture));
filters.Add(string.Format("asetpts=PTS-{0}/TB", Math.Round(seconds).ToString(_usCulture)));
}
return string.Format("-af \"{0}aresample={1}async={4}{2}{3}\"",
if (filters.Count > 0)
{
return "-af \"" + string.Join(",", filters.ToArray()) + "\"";
}
adelay,
audioSampleRate,
volParam,
pts,
state.OutputAudioSync);
return string.Empty;
}
/// <summary>
@ -1282,7 +1272,7 @@ namespace MediaBrowser.Controller.MediaEncoding
}
var videoSizeParam = string.Empty;
if (state.VideoStream != null && state.VideoStream.Width.HasValue && state.VideoStream.Height.HasValue)
{
videoSizeParam = string.Format("scale={0}:{1}", state.VideoStream.Width.Value.ToString(_usCulture), state.VideoStream.Height.Value.ToString(_usCulture));
@ -1569,7 +1559,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var outputVideoCodec = GetVideoEncoder(state, encodingOptions);
// Important: If this is ever re-enabled, make sure not to use it with wtv because it breaks seeking
if (!string.Equals(state.InputContainer, "wtv", StringComparison.OrdinalIgnoreCase) &&
if (!string.Equals(state.InputContainer, "wtv", StringComparison.OrdinalIgnoreCase) &&
state.TranscodingType != TranscodingJobType.Progressive &&
state.EnableBreakOnNonKeyFrames(outputVideoCodec))
{
@ -1657,7 +1647,6 @@ namespace MediaBrowser.Controller.MediaEncoding
if (state.ReadInputAtNativeFramerate ||
mediaSource.Protocol == MediaProtocol.File && string.Equals(mediaSource.Container, "wtv", StringComparison.OrdinalIgnoreCase))
{
state.OutputAudioSync = "1000";
state.InputVideoSync = "-1";
state.InputAudioSync = "1";
}
@ -1715,7 +1704,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (state.SubtitleStream == null || state.SubtitleDeliveryMethod != SubtitleDeliveryMethod.Embed)
{
return ;
return;
}
// This is tricky to remux in, after converting to dvdsub it's not positioned correctly
@ -1985,7 +1974,12 @@ namespace MediaBrowser.Controller.MediaEncoding
{
args += " -ab " + bitrate.Value.ToString(_usCulture);
}
if (state.OutputAudioSampleRate.HasValue)
{
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(_usCulture);
}
args += " " + GetAudioFilterParam(state, encodingOptions, false);
return args;

View File

@ -55,7 +55,7 @@ namespace MediaBrowser.Controller.MediaEncoding
return "-1";
}
}
public string OutputAudioSync = "1";
public string InputAudioSync { get; set; }
public string InputVideoSync { get; set; }
public TransportStreamTimestamp InputTimestamp { get; set; }

View File

@ -664,28 +664,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
private bool DetectInterlaced(MediaSourceInfo video, MediaStream videoStream)
{
var formats = (video.Container ?? string.Empty).Split(',').ToList();
var enableInterlacedDection = formats.Contains("vob", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("m2ts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("ts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("mpegts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("wtv", StringComparer.OrdinalIgnoreCase);
// If it's mpeg based, assume true
if ((videoStream.Codec ?? string.Empty).IndexOf("mpeg", StringComparison.OrdinalIgnoreCase) != -1)
{
if (enableInterlacedDection)
{
return true;
}
}
else
{
// If the video codec is not some form of mpeg, then take a shortcut and limit this to containers that are likely to have interlaced content
if (!enableInterlacedDection)
{
return false;
}
var formats = (video.Container ?? string.Empty).Split(',').ToList();
return formats.Contains("vob", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("m2ts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("ts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("mpegts", StringComparer.OrdinalIgnoreCase) ||
formats.Contains("wtv", StringComparer.OrdinalIgnoreCase);
}
return false;

View File

@ -1,3 +1,3 @@
using System.Reflection;
[assembly: AssemblyVersion("3.2.12.5")]
[assembly: AssemblyVersion("3.2.12.6")]