| 
					
				 | 
			
			
				@@ -187,7 +187,6 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsSports = query.IsSports, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsSeries = query.IsSeries, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IncludeItemTypes = new[] { typeof(LiveTvChannel).Name }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortOrder = query.SortOrder ?? SortOrder.Ascending, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 TopParentIds = new[] { topFolder.Id.ToString("N") }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsFavorite = query.IsFavorite, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsLiked = query.IsLiked, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -196,18 +195,22 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 DtoOptions = dtoOptions 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            internalQuery.OrderBy.AddRange(query.SortBy.Select(i => new Tuple<string, SortOrder>(i, query.SortOrder ?? SortOrder.Ascending))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var orderBy = internalQuery.OrderBy.ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            orderBy.AddRange(query.SortBy.Select(i => new Tuple<string, SortOrder>(i, query.SortOrder ?? SortOrder.Ascending))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (query.EnableFavoriteSorting) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                internalQuery.OrderBy.Insert(0, new Tuple<string, SortOrder>(ItemSortBy.IsFavoriteOrLiked, SortOrder.Descending)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderBy.Insert(0, new Tuple<string, SortOrder>(ItemSortBy.IsFavoriteOrLiked, SortOrder.Descending)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!internalQuery.OrderBy.Any(i => string.Equals(i.Item1, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                internalQuery.OrderBy.Add(new Tuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderBy.Add(new Tuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            internalQuery.OrderBy = orderBy.ToArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return _libraryManager.GetItemsResult(internalQuery); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -918,10 +921,10 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var topFolder = await GetInternalLiveTvFolder(cancellationToken).ConfigureAwait(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (query.SortBy.Length == 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (query.OrderBy.Length == 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // Unless something else was specified, order by start date to take advantage of a specialized index 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                query.SortBy = new[] { ItemSortBy.StartDate }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                query.OrderBy = new Tuple<string, SortOrder>[] { new Tuple<string, SortOrder>(ItemSortBy.StartDate, SortOrder.Ascending) }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             RemoveFields(options); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -942,8 +945,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Genres = query.Genres, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 StartIndex = query.StartIndex, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Limit = query.Limit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortBy = query.SortBy, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortOrder = query.SortOrder ?? SortOrder.Ascending, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OrderBy = query.OrderBy, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 EnableTotalRecordCount = query.EnableTotalRecordCount, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 TopParentIds = new[] { topFolder.Id.ToString("N") }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Name = query.Name, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1012,7 +1014,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsSports = query.IsSports, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsKids = query.IsKids, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 EnableTotalRecordCount = query.EnableTotalRecordCount, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortBy = new[] { ItemSortBy.StartDate }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.StartDate, SortOrder.Ascending) }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 TopParentIds = new[] { topFolder.Id.ToString("N") }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 DtoOptions = options 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1644,8 +1646,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IsVirtualItem = false, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Limit = query.Limit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 StartIndex = query.StartIndex, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortBy = new[] { ItemSortBy.DateCreated }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortOrder = SortOrder.Descending, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.DateCreated, SortOrder.Descending) }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 EnableTotalRecordCount = query.EnableTotalRecordCount, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IncludeItemTypes = includeItemTypes.ToArray(includeItemTypes.Count), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ExcludeItemTypes = excludeItemTypes.ToArray(excludeItemTypes.Count), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1692,8 +1693,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Recursive = true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 AncestorIds = folders.Select(i => i.Id.ToString("N")).ToArray(folders.Count), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Limit = query.Limit, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortBy = new[] { ItemSortBy.DateCreated }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortOrder = SortOrder.Descending, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.DateCreated, SortOrder.Descending) }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 EnableTotalRecordCount = query.EnableTotalRecordCount, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 IncludeItemTypes = includeItemTypes.ToArray(includeItemTypes.Count), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ExcludeItemTypes = excludeItemTypes.ToArray(excludeItemTypes.Count), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1927,11 +1927,11 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var info = recording; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            dto.SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            dto.SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) || service == null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ? null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 : _tvDtoService.GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            dto.TimerId = string.IsNullOrEmpty(info.TimerId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            dto.TimerId = string.IsNullOrEmpty(info.TimerId) || service == null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ? null 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 : _tvDtoService.GetInternalTimerId(service.Name, info.TimerId).ToString("N"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -2037,7 +2037,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var internalResult = await GetInternalRecordings(query, options, cancellationToken).ConfigureAwait(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var returnArray =  _dtoService.GetBaseItemDtos(internalResult.Items, options, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var returnArray = _dtoService.GetBaseItemDtos(internalResult.Items, options, user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return new QueryResult<BaseItemDto> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -2377,7 +2377,7 @@ namespace Emby.Server.Implementations.LiveTv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 MaxStartDate = now, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 MinEndDate = now, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Limit = channelIds.Length, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                SortBy = new[] { "StartDate" }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                OrderBy = new[] { new Tuple<string, SortOrder>(ItemSortBy.StartDate, SortOrder.Ascending) }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 TopParentIds = new[] { GetInternalLiveTvFolder(CancellationToken.None).Result.Id.ToString("N") }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 DtoOptions = options 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |