Merge pull request #1884 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-06-28 00:49:29 -04:00 committed by GitHub
commit 7ae83e3c45
9 changed files with 168 additions and 117 deletions

View File

@ -70,11 +70,7 @@ namespace MediaBrowser.Api
Cultures = _localizationManager.GetCultures().ToList() Cultures = _localizationManager.GetCultures().ToList()
}; };
var locationType = item.LocationType; if (!item.IsVirtualItem && !(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName))
if (locationType == LocationType.FileSystem ||
locationType == LocationType.Offline)
{
if (!(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName))
{ {
var inheritedContentType = _libraryManager.GetInheritedContentType(item); var inheritedContentType = _libraryManager.GetInheritedContentType(item);
var configuredContentType = _libraryManager.GetConfiguredContentType(item); var configuredContentType = _libraryManager.GetConfiguredContentType(item);
@ -92,7 +88,6 @@ namespace MediaBrowser.Api
} }
} }
} }
}
return ToOptimizedResult(info); return ToOptimizedResult(info);
} }

View File

@ -278,7 +278,7 @@ namespace MediaBrowser.Providers.Manager
/// <returns>IEnumerable{System.String}.</returns> /// <returns>IEnumerable{System.String}.</returns>
private string[] GetSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally) private string[] GetSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
{ {
if (!saveLocally) if (!saveLocally || (_config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy))
{ {
return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, saveLocally) }; return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, saveLocally) };
} }

View File

@ -2791,6 +2791,31 @@ namespace MediaBrowser.Server.Implementations.Library
} }
_fileSystem.CreateShortcut(lnk, path); _fileSystem.CreateShortcut(lnk, path);
RemoveContentTypeOverrides(path);
}
private void RemoveContentTypeOverrides(string path)
{
var removeList = new List<NameValuePair>();
foreach (var contentType in ConfigurationManager.Configuration.ContentTypes)
{
if (string.Equals(path, contentType.Name, StringComparison.OrdinalIgnoreCase)
|| _fileSystem.ContainsSubPath(path, contentType.Name))
{
removeList.Add(contentType);
}
}
if (removeList.Count > 0)
{
ConfigurationManager.Configuration.ContentTypes = ConfigurationManager.Configuration.ContentTypes
.Except(removeList)
.ToArray();
ConfigurationManager.SaveConfiguration();
}
} }
public void RemoveMediaPath(string virtualFolderName, string mediaPath) public void RemoveMediaPath(string virtualFolderName, string mediaPath)

View File

@ -979,16 +979,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
var recordPath = GetRecordingPath(timer, info); var recordPath = GetRecordingPath(timer, info);
var recordingStatus = RecordingStatus.New; var recordingStatus = RecordingStatus.New;
var isResourceOpen = false;
SemaphoreSlim semaphore = null;
try try
{ {
var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false); var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false);
isResourceOpen = true;
semaphore = result.Item3;
var mediaStreamInfo = result.Item1; var mediaStreamInfo = result.Item1;
var isResourceOpen = true;
// Unfortunately due to the semaphore we have to have a nested try/finally
try
{
// HDHR doesn't seem to release the tuner right away after first probing with ffmpeg // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg
//await Task.Delay(3000, cancellationToken).ConfigureAwait(false); //await Task.Delay(3000, cancellationToken).ConfigureAwait(false);
@ -1031,16 +1031,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
recordingStatus = RecordingStatus.Completed; recordingStatus = RecordingStatus.Completed;
_logger.Info("Recording completed: {0}", recordPath); _logger.Info("Recording completed: {0}", recordPath);
} }
finally
{
if (isResourceOpen)
{
result.Item3.Release();
}
_libraryMonitor.ReportFileSystemChangeComplete(recordPath, true);
}
}
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
_logger.Info("Recording stopped: {0}", recordPath); _logger.Info("Recording stopped: {0}", recordPath);
@ -1053,6 +1043,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
} }
finally finally
{ {
if (isResourceOpen && semaphore != null)
{
semaphore.Release();
}
_libraryMonitor.ReportFileSystemChangeComplete(recordPath, true);
ActiveRecordingInfo removed; ActiveRecordingInfo removed;
_activeRecordings.TryRemove(timer.Id, out removed); _activeRecordings.TryRemove(timer.Id, out removed);
} }
@ -1060,10 +1057,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
if (recordingStatus == RecordingStatus.Completed) if (recordingStatus == RecordingStatus.Completed)
{ {
timer.Status = RecordingStatus.Completed; timer.Status = RecordingStatus.Completed;
_timerProvider.AddOrUpdate(timer, false); _timerProvider.Delete(timer);
OnSuccessfulRecording(info.IsSeries, recordPath); OnSuccessfulRecording(info.IsSeries, recordPath);
_timerProvider.Delete(timer);
} }
else if (DateTime.UtcNow < timer.EndDate) else if (DateTime.UtcNow < timer.EndDate)
{ {

View File

@ -61,9 +61,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
.ConfigureAwait(false); .ConfigureAwait(false);
} }
finally finally
{
try
{ {
File.Delete(tempfile); File.Delete(tempfile);
} }
catch (Exception ex)
{
_logger.ErrorException("Error deleting recording temp file", ex);
}
}
} }
public async Task RecordInternal(MediaSourceInfo mediaSource, string tempFile, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken) public async Task RecordInternal(MediaSourceInfo mediaSource, string tempFile, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken)

View File

@ -11,6 +11,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Emby.XmlTv.Classes; using Emby.XmlTv.Classes;
using Emby.XmlTv.Entities;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
@ -109,12 +110,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
return results.Select(p => new ProgramInfo() return results.Select(p => new ProgramInfo()
{ {
ChannelId = p.ChannelId, ChannelId = p.ChannelId,
EndDate = p.EndDate, EndDate = GetDate(p.EndDate),
EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeNumber = p.Episode == null ? null : p.Episode.Episode,
EpisodeTitle = p.Episode == null ? null : p.Episode.Title, EpisodeTitle = p.Episode == null ? null : p.Episode.Title,
Genres = p.Categories, Genres = p.Categories,
Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date, Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date,
StartDate = p.StartDate, StartDate = GetDate(p.StartDate),
Name = p.Title, Name = p.Title,
Overview = p.Description, Overview = p.Description,
ShortOverview = p.Description, ShortOverview = p.Description,
@ -135,6 +136,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
}); });
} }
private DateTime GetDate(DateTime date)
{
if (date.Kind != DateTimeKind.Utc)
{
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
}
return date;
}
public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken) public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken)
{ {
// Add the channel image url // Add the channel image url

View File

@ -656,7 +656,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
item.Audio = info.Audio; item.Audio = info.Audio;
item.ChannelId = channel.Id.ToString("N"); item.ChannelId = channel.Id.ToString("N");
item.CommunityRating = item.CommunityRating ?? info.CommunityRating; item.CommunityRating = item.CommunityRating ?? info.CommunityRating;
item.EndDate = info.EndDate;
item.EpisodeTitle = info.EpisodeTitle; item.EpisodeTitle = info.EpisodeTitle;
item.ExternalId = info.Id; item.ExternalId = info.Id;
item.Genres = info.Genres; item.Genres = info.Genres;
@ -673,7 +673,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv
item.OfficialRating = item.OfficialRating ?? info.OfficialRating; item.OfficialRating = item.OfficialRating ?? info.OfficialRating;
item.Overview = item.Overview ?? info.Overview; item.Overview = item.Overview ?? info.Overview;
item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks; item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks;
if (item.StartDate != info.StartDate)
{
forceUpdate = true;
}
item.StartDate = info.StartDate; item.StartDate = info.StartDate;
if (item.EndDate != info.EndDate)
{
forceUpdate = true;
}
item.EndDate = info.EndDate;
item.HomePageUrl = info.HomePageUrl; item.HomePageUrl = info.HomePageUrl;
item.ProductionYear = info.ProductionYear; item.ProductionYear = info.ProductionYear;

View File

@ -160,8 +160,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
"create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT Priority INT, PRIMARY KEY (ItemId, UserDataKey))", "create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT Priority INT, PRIMARY KEY (ItemId, UserDataKey))",
"create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)",
//"create index if not exists idx_ItemValues on ItemValues(ItemId)",
"create index if not exists idx_ItemValues2 on ItemValues(ItemId,Type)",
"create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))", "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))",
// covering index // covering index
@ -321,6 +319,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
// items by name // items by name
"create index if not exists idx_ItemValues6 on ItemValues(ItemId,Type,CleanValue)", "create index if not exists idx_ItemValues6 on ItemValues(ItemId,Type,CleanValue)",
"create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)",
// covering index // covering index
"create index if not exists idx_UserDataKeys3 on UserDataKeys(ItemId,Priority,UserDataKey)" "create index if not exists idx_UserDataKeys3 on UserDataKeys(ItemId,Priority,UserDataKey)"
@ -1776,9 +1775,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
return string.Empty; return string.Empty;
} }
private string GetFromText() private string GetFromText(string alias = "A")
{ {
return " from TypedBaseItems A"; return " from TypedBaseItems " + alias;
} }
public List<BaseItem> GetItemList(InternalItemsQuery query) public List<BaseItem> GetItemList(InternalItemsQuery query)
@ -3661,19 +3660,14 @@ namespace MediaBrowser.Server.Implementations.Persistence
var typesToCount = query.IncludeItemTypes.ToList(); var typesToCount = query.IncludeItemTypes.ToList();
if (typesToCount.Count == 0) if (typesToCount.Count > 0)
{ {
//typesToCount.Add("Item"); var itemCountColumnQuery = "select group_concat(type, '|')" + GetFromText("B");
}
foreach (var type in typesToCount)
{
var itemCountColumnQuery = "Select Count(CleanValue) from ItemValues where ItemValues.CleanValue=CleanName AND Type=@ItemValueType AND ItemId in (";
itemCountColumnQuery += "select guid" + GetFromText();
var typeSubQuery = new InternalItemsQuery(query.User) var typeSubQuery = new InternalItemsQuery(query.User)
{ {
ExcludeItemTypes = query.ExcludeItemTypes, ExcludeItemTypes = query.ExcludeItemTypes,
IncludeItemTypes = query.IncludeItemTypes,
MediaTypes = query.MediaTypes, MediaTypes = query.MediaTypes,
AncestorIds = query.AncestorIds, AncestorIds = query.AncestorIds,
ExcludeItemIds = query.ExcludeItemIds, ExcludeItemIds = query.ExcludeItemIds,
@ -3682,15 +3676,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
ParentId = query.ParentId, ParentId = query.ParentId,
IsPlayed = query.IsPlayed IsPlayed = query.IsPlayed
}; };
if (string.Equals(type, "Item", StringComparison.OrdinalIgnoreCase)) var whereClauses = GetWhereClauses(typeSubQuery, cmd, "itemTypes");
{
typeSubQuery.IncludeItemTypes = query.IncludeItemTypes; whereClauses.Add("guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND Type=@ItemValueType)");
}
else
{
typeSubQuery.IncludeItemTypes = new[] { type };
}
var whereClauses = GetWhereClauses(typeSubQuery, cmd, type);
var typeWhereText = whereClauses.Count == 0 ? var typeWhereText = whereClauses.Count == 0 ?
string.Empty : string.Empty :
@ -3698,11 +3686,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
itemCountColumnQuery += typeWhereText; itemCountColumnQuery += typeWhereText;
itemCountColumnQuery += ")"; //itemCountColumnQuery += ")";
var columnName = type + "Count"; itemCountColumns.Add(new Tuple<string, string>("itemTypes", "(" + itemCountColumnQuery + ") as itemTypes"));
itemCountColumns.Add(new Tuple<string, string>(columnName, "(" + itemCountColumnQuery + ") as " + columnName));
} }
var columns = _retriveItemColumns.ToList(); var columns = _retriveItemColumns.ToList();
@ -3731,7 +3717,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
" where " + string.Join(" AND ", innerWhereClauses.ToArray()); " where " + string.Join(" AND ", innerWhereClauses.ToArray());
var whereText = " where Type=@SelectType"; var whereText = " where Type=@SelectType";
if (typesToCount.Count == 0)
{
whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))";
}
else
{
whereText += " And itemTypes not null";
}
var outerQuery = new InternalItemsQuery(query.User) var outerQuery = new InternalItemsQuery(query.User)
{ {
@ -3812,6 +3806,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
? (CommandBehavior.SequentialAccess | CommandBehavior.SingleResult) ? (CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)
: CommandBehavior.SequentialAccess; : CommandBehavior.SequentialAccess;
//Logger.Debug("GetItemValues: " + cmd.CommandText);
using (var reader = cmd.ExecuteReader(commandBehavior)) using (var reader = cmd.ExecuteReader(commandBehavior))
{ {
LogQueryTime("GetItemValues", cmd, now); LogQueryTime("GetItemValues", cmd, now);
@ -3830,7 +3826,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
var item = GetItem(reader); var item = GetItem(reader);
if (item != null) if (item != null)
{ {
var countStartColumn = columns.Count - typesToCount.Count; var countStartColumn = columns.Count - 1;
list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(reader, countStartColumn, typesToCount))); list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(reader, countStartColumn, typesToCount)));
} }
@ -3861,35 +3857,54 @@ namespace MediaBrowser.Server.Implementations.Persistence
{ {
var counts = new ItemCounts(); var counts = new ItemCounts();
for (var i = 0; i < typesToCount.Count; i++) if (typesToCount.Count == 0)
{ {
var value = reader.GetInt32(countStartColumn + i); return counts;
}
var type = typesToCount[i]; var typeString = reader.IsDBNull(countStartColumn) ? null : reader.GetString(countStartColumn);
if (string.Equals(type, "Series", StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrWhiteSpace(typeString))
{
return counts;
}
var allTypes = typeString.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries)
.ToLookup(i => i).ToList();
foreach (var type in allTypes)
{
var value = type.ToList().Count;
var typeName = type.Key;
if (string.Equals(typeName, typeof(Series).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.SeriesCount = value; counts.SeriesCount = value;
} }
else if (string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(typeName, typeof(Episode).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.EpisodeCount = value; counts.EpisodeCount = value;
} }
else if (string.Equals(type, "Movie", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(typeName, typeof(Movie).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.MovieCount = value; counts.MovieCount = value;
} }
else if (string.Equals(type, "MusicAlbum", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(typeName, typeof(MusicAlbum).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.AlbumCount = value; counts.AlbumCount = value;
} }
else if (string.Equals(type, "Audio", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(typeName, typeof(Audio).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.SongCount = value; counts.SongCount = value;
} }
else if (string.Equals(type, "Game", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(typeName, typeof(Game).FullName, StringComparison.OrdinalIgnoreCase))
{ {
counts.GameCount = value; counts.GameCount = value;
} }
else if (string.Equals(typeName, typeof(Trailer).FullName, StringComparison.OrdinalIgnoreCase))
{
counts.TrailerCount = value;
}
counts.ItemCount += value; counts.ItemCount += value;
} }

View File

@ -353,9 +353,6 @@
<Content Include="dashboard-ui\scripts\autoorganizesmart.js"> <Content Include="dashboard-ui\scripts\autoorganizesmart.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\scripts\searchmenu.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\searchpage.js"> <Content Include="dashboard-ui\scripts\searchpage.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -830,9 +827,6 @@
<Content Include="dashboard-ui\css\librarybrowser.css"> <Content Include="dashboard-ui\css\librarybrowser.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\css\search.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\css\tileitem.css"> <Content Include="dashboard-ui\css\tileitem.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -1155,9 +1149,6 @@
<Content Include="dashboard-ui\scripts\remotecontrol.js"> <Content Include="dashboard-ui\scripts\remotecontrol.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="dashboard-ui\scripts\search.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\moviecollections.js"> <Content Include="dashboard-ui\scripts\moviecollections.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>