Skip to content

Commit

Permalink
Merge pull request #3213 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LukePulverenti authored Mar 27, 2018
2 parents 4095c06 + ae86032 commit 161d9e6
Show file tree
Hide file tree
Showing 42 changed files with 234 additions and 256 deletions.
10 changes: 8 additions & 2 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,14 +2065,20 @@ private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address, Cancellati
return cachedResult;
}

var logPing = false;

#if DEBUG
logPing = true;
#endif

try
{
using (var response = await HttpClient.SendAsync(new HttpRequestOptions
{
Url = apiUrl,
LogErrorResponseBody = false,
LogErrors = false,
LogRequest = false,
LogErrors = logPing,
LogRequest = logPing,
TimeoutMs = 30000,
BufferContent = false,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,16 @@ public ChannelDynamicMediaSourceProvider(IChannelManager channelManager)
_channelManager = (ChannelManager)channelManager;
}

public async Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
public Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
{
var baseItem = (BaseItem)item;

if (baseItem.SourceType == SourceType.Channel)
{
var result = await _channelManager.GetDynamicMediaSources(baseItem, cancellationToken).ConfigureAwait(false);

foreach (var info in result)
{
// There could be hls streams here and this isn't supported via direct stream through the server
info.SupportsDirectStream = false;
}

return result;
return _channelManager.GetDynamicMediaSources(baseItem, cancellationToken);
}

return new List<MediaSourceInfo>();
return Task.FromResult<IEnumerable<MediaSourceInfo>>(new List<MediaSourceInfo>());
}

public Task<Tuple<MediaSourceInfo, IDirectStreamProvider, bool>> OpenMediaSource(string openToken, CancellationToken cancellationToken)
Expand Down
13 changes: 7 additions & 6 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public IEnumerable<Guid> GetInstalledChannelIds()
return GetAllChannels().Select(i => GetInternalChannelId(i.Name));
}

public async Task<QueryResult<Channel>> GetChannelsInternal(ChannelQuery query, CancellationToken cancellationToken)
public QueryResult<Channel> GetChannelsInternal(ChannelQuery query)
{
var user = string.IsNullOrEmpty(query.UserId)
? null
Expand Down Expand Up @@ -241,7 +241,8 @@ public async Task<QueryResult<Channel>> GetChannelsInternal(ChannelQuery query,
{
foreach (var item in returnItems)
{
await RefreshLatestChannelItems(GetChannelProvider(item), cancellationToken).ConfigureAwait(false);
var task = RefreshLatestChannelItems(GetChannelProvider(item), CancellationToken.None);
Task.WaitAll(task);
}
}

Expand All @@ -252,13 +253,13 @@ public async Task<QueryResult<Channel>> GetChannelsInternal(ChannelQuery query,
};
}

public async Task<QueryResult<BaseItemDto>> GetChannels(ChannelQuery query, CancellationToken cancellationToken)
public QueryResult<BaseItemDto> GetChannels(ChannelQuery query)
{
var user = string.IsNullOrEmpty(query.UserId)
? null
: _userManager.GetUserById(query.UserId);

var internalResult = await GetChannelsInternal(query, cancellationToken).ConfigureAwait(false);
var internalResult = GetChannelsInternal(query);

var dtoOptions = new DtoOptions()
{
Expand Down Expand Up @@ -480,7 +481,7 @@ private async Task<Channel> GetChannel(IChannel channelInfo, CancellationToken c
if (isNew)
{
item.OnMetadataChanged();
_libraryManager.CreateItem(item, cancellationToken);
_libraryManager.CreateItem(item);
}

await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
Expand Down Expand Up @@ -1150,7 +1151,7 @@ private BaseItem GetChannelItemEntity(ChannelItemInfo info, IChannel channelProv

if (isNew)
{
_libraryManager.CreateItem(item, cancellationToken);
_libraryManager.CreateItem(item);

if (info.People != null && info.People.Count > 0)
{
Expand Down
57 changes: 35 additions & 22 deletions Emby.Server.Implementations/Library/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,26 @@ private BaseItem ResolvePath(FileSystemMetadata fileInfo,
// When resolving the root, we need it's grandchildren (children of user views)
var flattenFolderDepth = isPhysicalRoot ? 2 : 0;

var files = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);
FileSystemMetadata[] files;
var isVf = args.IsVf;

try
{
files = FileData.GetFilteredFileSystemEntries(directoryService, args.Path, _fileSystem, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || isVf);
}
catch (Exception ex)
{
if (parent != null && parent.IsPhysicalRoot)
{
_logger.ErrorException("Error in GetFilteredFileSystemEntries isPhysicalRoot: {0} IsVf: {1}", ex, isPhysicalRoot, isVf);

files = new FileSystemMetadata[] { };
}
else
{
throw;
}
}

// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
Expand Down Expand Up @@ -964,7 +983,7 @@ private T CreateItemByName<T>(Func<string, string> getPathFn, string name, DtoOp
Path = path
};

CreateItem(item, CancellationToken.None);
CreateItem(item);
}

return item;
Expand Down Expand Up @@ -1529,8 +1548,7 @@ private void AddUserToQuery(InternalItemsQuery query, User user, bool allowExter
UserId = user.Id.ToString("N"),
IncludeHidden = true,
IncludeExternalContent = allowExternalContent

}, CancellationToken.None).Result;
});

query.TopParentIds = userViews.SelectMany(i => GetTopParentIdsForQuery(i, user)).Select(i => i.ToString("N")).ToArray();
}
Expand Down Expand Up @@ -1811,9 +1829,9 @@ private IBaseItemComparer GetComparer(string name, User user)
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public void CreateItem(BaseItem item, CancellationToken cancellationToken)
public void CreateItem(BaseItem item)
{
CreateItems(new[] { item }, item.GetParent(), cancellationToken);
CreateItems(new[] { item }, item.GetParent(), CancellationToken.None);
}

/// <summary>
Expand Down Expand Up @@ -2110,16 +2128,14 @@ private string GetTopFolderContentType(BaseItem item)
public UserView GetNamedView(User user,
string name,
string viewType,
string sortName,
CancellationToken cancellationToken)
string sortName)
{
return GetNamedView(user, name, null, viewType, sortName, cancellationToken);
return GetNamedView(user, name, null, viewType, sortName);
}

public UserView GetNamedView(string name,
string viewType,
string sortName,
CancellationToken cancellationToken)
string sortName)
{
var path = Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "views");

Expand All @@ -2145,7 +2161,7 @@ public UserView GetNamedView(string name,
ForcedSortName = sortName
};

CreateItem(item, cancellationToken);
CreateItem(item);

refresh = true;
}
Expand Down Expand Up @@ -2174,8 +2190,7 @@ public UserView GetNamedView(User user,
string name,
string parentId,
string viewType,
string sortName,
CancellationToken cancellationToken)
string sortName)
{
var idValues = "38_namedview_" + name + user.Id.ToString("N") + (parentId ?? string.Empty) + (viewType ?? string.Empty);

Expand Down Expand Up @@ -2207,7 +2222,7 @@ public UserView GetNamedView(User user,
item.DisplayParentId = new Guid(parentId);
}

CreateItem(item, cancellationToken);
CreateItem(item);

isNew = true;
}
Expand Down Expand Up @@ -2235,8 +2250,7 @@ public UserView GetNamedView(User user,

public UserView GetShadowView(BaseItem parent,
string viewType,
string sortName,
CancellationToken cancellationToken)
string sortName)
{
if (parent == null)
{
Expand Down Expand Up @@ -2272,7 +2286,7 @@ public UserView GetShadowView(BaseItem parent,

item.DisplayParentId = parentId;

CreateItem(item, cancellationToken);
CreateItem(item);

isNew = true;
}
Expand Down Expand Up @@ -2302,8 +2316,7 @@ public UserView GetNamedView(string name,
string parentId,
string viewType,
string sortName,
string uniqueId,
CancellationToken cancellationToken)
string uniqueId)
{
if (string.IsNullOrEmpty(name))
{
Expand Down Expand Up @@ -2343,15 +2356,15 @@ public UserView GetNamedView(string name,
item.DisplayParentId = new Guid(parentId);
}

CreateItem(item, cancellationToken);
CreateItem(item);

isNew = true;
}

if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{
item.ViewType = viewType;
item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken);
item.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
}

var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval;
Expand Down
37 changes: 31 additions & 6 deletions Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,11 @@ await item.RefreshMetadata(new MediaBrowser.Controller.Providers.MetadataRefresh
{
SetUserProperties(hasMediaSources as BaseItem, source, user);
}
if (source.Protocol == MediaProtocol.File || source.Protocol == MediaProtocol.Http)

// Validate that this is actually possible
if (source.SupportsDirectStream)
{
// trust whatever was set by the media source provider
}
else
{
source.SupportsDirectStream = false;
source.SupportsDirectStream = SupportsDirectStream(source.Path, source.Protocol);
}

list.Add(source);
Expand All @@ -179,6 +177,27 @@ await item.RefreshMetadata(new MediaBrowser.Controller.Providers.MetadataRefresh
return SortMediaSources(list).Where(i => i.Type != MediaSourceType.Placeholder);
}

private bool SupportsDirectStream(string path, MediaProtocol protocol)
{
if (protocol == MediaProtocol.File)
{
return true;
}

if (protocol == MediaProtocol.Http)
{
if (path != null)
{
if (path.IndexOf(".m3u", StringComparison.OrdinalIgnoreCase) == -1)
{
//return true;
}
}
}

return false;
}

private async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
{
var tasks = _providers.Select(i => GetDynamicMediaSources(item, i, cancellationToken));
Expand Down Expand Up @@ -360,6 +379,12 @@ public async Task<LiveStreamResponse> OpenLiveStream(LiveStreamRequest request,

var mediaSource = mediaSourceTuple.Item1;

// Validate that this is actually possible
if (mediaSource.SupportsDirectStream)
{
mediaSource.SupportsDirectStream = SupportsDirectStream(mediaSource.Path, mediaSource.Protocol);
}

if (string.IsNullOrEmpty(mediaSource.LiveStreamId))
{
throw new InvalidOperationException(string.Format("{0} returned null LiveStreamId", provider.GetType().Name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private MultiItemResolverResult ResolveMultipleAudio<T>(Folder parent, IEnumerab
{
Path = firstMedia.Path,
IsInMixedFolder = isInMixedFolder,
//ProductionYear = resolvedItem.Year,
ProductionYear = resolvedItem.Year,
Name = parseName ?
resolvedItem.Name :
Path.GetFileNameWithoutExtension(firstMedia.Path),
Expand Down
Loading

0 comments on commit 161d9e6

Please sign in to comment.