update channels

This commit is contained in:
Luke Pulverenti 2014-06-06 13:14:02 -04:00
parent 6120286bfd
commit f271e358a1
24 changed files with 202 additions and 103 deletions

View File

@ -204,6 +204,11 @@ namespace MediaBrowser.Api.Playback
return Convert.ToInt32(newSize.Width);
}
if (VideoRequest == null)
{
return null;
}
return VideoRequest.MaxWidth ?? VideoRequest.Width;
}
}
@ -229,6 +234,11 @@ namespace MediaBrowser.Api.Playback
return Convert.ToInt32(newSize.Height);
}
if (VideoRequest == null)
{
return null;
}
return VideoRequest.MaxHeight ?? VideoRequest.Height;
}
}

View File

@ -48,6 +48,10 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.3.0.0.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector, Version=2.5.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SimpleInjector.2.5.0\lib\net45\SimpleInjector.dll</HintPath>
@ -63,9 +67,6 @@
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.1.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="SharpCompress">
<HintPath>..\packages\sharpcompress.0.10.2\lib\net40\SharpCompress.dll</HintPath>
</Reference>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="2.1.0" targetFramework="net45" />
<package id="NLog" version="3.0.0.0" targetFramework="net45" />
<package id="sharpcompress" version="0.10.2" targetFramework="net45" />
<package id="SimpleInjector" version="2.5.0" targetFramework="net45" />
</packages>

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Channels
{
@ -7,8 +6,6 @@ namespace MediaBrowser.Controller.Channels
{
public List<ChannelItemInfo> Items { get; set; }
public TimeSpan CacheLength { get; set; }
public int? TotalRecordCount { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace MediaBrowser.Controller.Channels
{
public enum ChannelParentalRating
{
GeneralAudience = 0,
UsPG = 1,
UsPG13 = 2,
UsR = 3,
Adult = 4
}
}

View File

@ -3,5 +3,7 @@
public class ChannelSearchInfo
{
public string SearchTerm { get; set; }
public string UserId { get; set; }
}
}

View File

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Threading;
@ -27,6 +26,12 @@ namespace MediaBrowser.Controller.Channels
/// <value>The home page URL.</value>
string HomePageUrl { get; }
/// <summary>
/// Gets the parental rating.
/// </summary>
/// <value>The parental rating.</value>
ChannelParentalRating ParentalRating { get; }
/// <summary>
/// Gets the channel information.
/// </summary>
@ -36,26 +41,9 @@ namespace MediaBrowser.Controller.Channels
/// <summary>
/// Determines whether [is enabled for] [the specified user].
/// </summary>
/// <param name="user">The user.</param>
/// <param name="userId">The user identifier.</param>
/// <returns><c>true</c> if [is enabled for] [the specified user]; otherwise, <c>false</c>.</returns>
bool IsEnabledFor(User user);
/// <summary>
/// Searches the specified search term.
/// </summary>
/// <param name="searchInfo">The search information.</param>
/// <param name="user">The user.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{ChannelItemInfo}}.</returns>
Task<IEnumerable<ChannelItemInfo>> Search(ChannelSearchInfo searchInfo, User user, CancellationToken cancellationToken);
/// <summary>
/// Gets all media.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{ChannelItemResult}.</returns>
Task<ChannelItemResult> GetAllMedia(InternalAllChannelMediaQuery query, CancellationToken cancellationToken);
bool IsEnabledFor(string userId);
/// <summary>
/// Gets the channel items.
@ -79,15 +67,4 @@ namespace MediaBrowser.Controller.Channels
/// <returns>IEnumerable{ImageType}.</returns>
IEnumerable<ImageType> GetSupportedChannelImages();
}
public interface IRequiresMediaInfoCallback
{
/// <summary>
/// Gets the channel item media information.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{ChannelMediaInfo}}.</returns>
Task<IEnumerable<ChannelMediaInfo>> GetChannelItemMediaInfo(string id, CancellationToken cancellationToken);
}
}

View File

@ -0,0 +1,13 @@

namespace MediaBrowser.Controller.Channels
{
public interface IHasCacheKey
{
/// <summary>
/// Gets the cache key.
/// </summary>
/// <param name="userId">The user identifier.</param>
/// <returns>System.String.</returns>
string GetCacheKey(string userId);
}
}

View File

@ -0,0 +1,16 @@
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Channels
{
public interface IIndexableChannel
{
/// <summary>
/// Gets all media.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{ChannelItemResult}.</returns>
Task<ChannelItemResult> GetAllMedia(InternalAllChannelMediaQuery query, CancellationToken cancellationToken);
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Channels
{
public interface IRequiresMediaInfoCallback
{
/// <summary>
/// Gets the channel item media information.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{ChannelMediaInfo}}.</returns>
Task<IEnumerable<ChannelMediaInfo>> GetChannelItemMediaInfo(string id, CancellationToken cancellationToken);
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Channels
{
public interface ISearchableChannel
{
/// <summary>
/// Searches the specified search term.
/// </summary>
/// <param name="searchInfo">The search information.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{ChannelItemInfo}}.</returns>
Task<IEnumerable<ChannelItemInfo>> Search(ChannelSearchInfo searchInfo, CancellationToken cancellationToken);
}
}

View File

@ -0,0 +1,8 @@

namespace MediaBrowser.Controller.Channels
{
public class InternalAllChannelMediaQuery
{
public string UserId { get; set; }
}
}

View File

@ -5,18 +5,6 @@ namespace MediaBrowser.Controller.Channels
{
public class InternalChannelFeatures
{
/// <summary>
/// Gets or sets a value indicating whether this instance can search.
/// </summary>
/// <value><c>true</c> if this instance can search; otherwise, <c>false</c>.</value>
public bool CanSearch { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance can get all media.
/// </summary>
/// <value><c>true</c> if this instance can get all media; otherwise, <c>false</c>.</value>
public bool CanGetAllMedia { get; set; }
/// <summary>
/// Gets or sets the media types.
/// </summary>

View File

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Channels;
namespace MediaBrowser.Controller.Channels
{
@ -7,7 +6,7 @@ namespace MediaBrowser.Controller.Channels
{
public string FolderId { get; set; }
public User User { get; set; }
public string UserId { get; set; }
public int? StartIndex { get; set; }
@ -17,9 +16,4 @@ namespace MediaBrowser.Controller.Channels
public bool SortDescending { get; set; }
}
public class InternalAllChannelMediaQuery
{
public User User { get; set; }
}
}

View File

@ -73,6 +73,7 @@
<Compile Include="Channels\ChannelItemResult.cs" />
<Compile Include="Channels\ChannelItemType.cs" />
<Compile Include="Channels\ChannelMediaInfo.cs" />
<Compile Include="Channels\ChannelParentalRating.cs" />
<Compile Include="Channels\ChannelSearchInfo.cs" />
<Compile Include="Channels\IChannel.cs" />
<Compile Include="Channels\IChannelFactory.cs" />
@ -82,8 +83,13 @@
<Compile Include="Channels\ChannelVideoItem.cs" />
<Compile Include="Channels\Channel.cs" />
<Compile Include="Channels\IChannelMediaItem.cs" />
<Compile Include="Channels\IHasCacheKey.cs" />
<Compile Include="Channels\IIndexableChannel.cs" />
<Compile Include="Channels\InternalAllChannelMediaQuery.cs" />
<Compile Include="Channels\InternalChannelFeatures.cs" />
<Compile Include="Channels\InternalChannelItemQuery.cs" />
<Compile Include="Channels\IRequiresMediaInfoCallback.cs" />
<Compile Include="Channels\ISearchableChannel.cs" />
<Compile Include="Chapters\ChapterSearchRequest.cs" />
<Compile Include="Chapters\IChapterProvider.cs" />
<Compile Include="Chapters\ChapterResponse.cs" />

View File

@ -22,12 +22,6 @@ namespace MediaBrowser.Model.Channels
/// <value><c>true</c> if this instance can search; otherwise, <c>false</c>.</value>
public bool CanSearch { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance can get all media.
/// </summary>
/// <value><c>true</c> if this instance can get all media; otherwise, <c>false</c>.</value>
public bool CanGetAllMedia { get; set; }
/// <summary>
/// Gets or sets the media types.
/// </summary>

View File

@ -45,6 +45,6 @@ namespace MediaBrowser.Model.Querying
/// <summary>
/// The is favorite or likes
/// </summary>
IsFavoriteOrLikes = 10,
IsFavoriteOrLikes = 10
}
}

View File

@ -9,6 +9,6 @@ namespace MediaBrowser.Model.Tasks
/// <summary>
/// The wake from sleep
/// </summary>
WakeFromSleep
WakeFromSleep = 0
}
}

View File

@ -97,7 +97,7 @@ namespace MediaBrowser.Server.Implementations.Channels
if (user != null)
{
channels = channels.Where(i => GetChannelProvider(i).IsEnabledFor(user) && i.IsVisible(user))
channels = channels.Where(i => GetChannelProvider(i).IsEnabledFor(user.Id.ToString("N")) && i.IsVisible(user))
.ToList();
}
@ -371,7 +371,8 @@ namespace MediaBrowser.Server.Implementations.Channels
Id = id,
DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo),
Path = path
Path = path,
OfficialRating = GetOfficialRating(channelInfo.ParentalRating)
};
isNew = true;
@ -394,6 +395,23 @@ namespace MediaBrowser.Server.Implementations.Channels
return item;
}
private string GetOfficialRating(ChannelParentalRating rating)
{
switch (rating)
{
case ChannelParentalRating.Adult:
return "XXX";
case ChannelParentalRating.UsR:
return "R";
case ChannelParentalRating.UsPG13:
return "PG-13";
case ChannelParentalRating.UsPG:
return "PG";
default:
return null;
}
}
public Channel GetChannel(string id)
{
return (Channel)_libraryManager.GetItemById(new Guid(id));
@ -412,16 +430,19 @@ namespace MediaBrowser.Server.Implementations.Channels
var channelProvider = GetChannelProvider(channel);
return GetChannelFeaturesDto(channel, channelProvider.GetChannelFeatures());
return GetChannelFeaturesDto(channel, channelProvider, channelProvider.GetChannelFeatures());
}
public ChannelFeatures GetChannelFeaturesDto(Channel channel, InternalChannelFeatures features)
public ChannelFeatures GetChannelFeaturesDto(Channel channel,
IChannel provider,
InternalChannelFeatures features)
{
var isIndexable = provider is IIndexableChannel;
return new ChannelFeatures
{
CanFilter = !features.MaxPageSize.HasValue,
CanGetAllMedia = features.CanGetAllMedia,
CanSearch = features.CanSearch,
CanSearch = provider is ISearchableChannel,
ContentTypes = features.ContentTypes,
DefaultSortFields = features.DefaultSortFields,
MaxPageSize = features.MaxPageSize,
@ -429,7 +450,7 @@ namespace MediaBrowser.Server.Implementations.Channels
SupportsSortOrderToggle = features.SupportsSortOrderToggle,
Name = channel.Name,
Id = channel.Id.ToString("N"),
CanDownloadAllMedia = features.CanGetAllMedia
CanDownloadAllMedia = isIndexable
};
}
@ -459,24 +480,28 @@ namespace MediaBrowser.Server.Implementations.Channels
}
var tasks = channels
.Where(i => i.GetChannelFeatures().CanGetAllMedia)
.Select(async i =>
{
try
var indexable = i as IIndexableChannel;
if (indexable != null)
{
var result = await i.GetAllMedia(new InternalAllChannelMediaQuery
try
{
User = user
var result = await indexable.GetAllMedia(new InternalAllChannelMediaQuery
{
UserId = query.UserId
}, cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
return new Tuple<IChannel, ChannelItemResult>(i, result);
}
catch (Exception ex)
{
_logger.ErrorException("Error getting all media from {0}", ex, i.Name);
return new Tuple<IChannel, ChannelItemResult>(i, new ChannelItemResult { });
return new Tuple<IChannel, ChannelItemResult>(i, result);
}
catch (Exception ex)
{
_logger.ErrorException("Error getting all media from {0}", ex, i.Name);
}
}
return new Tuple<IChannel, ChannelItemResult>(i, new ChannelItemResult { });
});
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
@ -600,7 +625,10 @@ namespace MediaBrowser.Server.Implementations.Channels
bool sortDescending,
CancellationToken cancellationToken)
{
var cachePath = GetChannelDataCachePath(channel, user, folderId, sortField, sortDescending);
var userId = user.Id.ToString("N");
var cacheLength = TimeSpan.FromDays(1);
var cachePath = GetChannelDataCachePath(channel, userId, folderId, sortField, sortDescending);
try
{
@ -608,7 +636,7 @@ namespace MediaBrowser.Server.Implementations.Channels
{
var channelItemResult = _jsonSerializer.DeserializeFromFile<ChannelItemResult>(cachePath);
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(channelItemResult.CacheLength) > DateTime.UtcNow)
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
{
return channelItemResult;
}
@ -633,7 +661,7 @@ namespace MediaBrowser.Server.Implementations.Channels
{
var channelItemResult = _jsonSerializer.DeserializeFromFile<ChannelItemResult>(cachePath);
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(channelItemResult.CacheLength) > DateTime.UtcNow)
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
{
return channelItemResult;
}
@ -650,7 +678,7 @@ namespace MediaBrowser.Server.Implementations.Channels
var query = new InternalChannelItemQuery
{
User = user,
UserId = userId,
StartIndex = startIndex,
Limit = limit,
SortBy = sortField,
@ -694,18 +722,27 @@ namespace MediaBrowser.Server.Implementations.Channels
}
private string GetChannelDataCachePath(IChannel channel,
User user,
string userId,
string folderId,
ChannelItemSortField? sortField,
bool sortDescending)
{
var channelId = GetInternalChannelId(channel.Name).ToString("N");
var folderKey = string.IsNullOrWhiteSpace(folderId) ? "root" : folderId.GetMD5().ToString("N");
var userCacheKey = string.Empty;
var hasCacheKey = channel as IHasCacheKey;
if (hasCacheKey != null)
{
userCacheKey = hasCacheKey.GetCacheKey(userId) ?? string.Empty;
}
var folderKey = string.IsNullOrWhiteSpace(folderId) ? "root" : folderId;
folderKey = (folderKey + userCacheKey).GetMD5().ToString("N");
var version = string.IsNullOrWhiteSpace(channel.DataVersion) ? "0" : channel.DataVersion;
var filename = user.Id.ToString("N");
var filename = userId;
var hashfilename = false;
if (sortField.HasValue)
@ -724,7 +761,12 @@ namespace MediaBrowser.Server.Implementations.Channels
filename = filename.GetMD5().ToString("N");
}
return Path.Combine(_config.ApplicationPaths.CachePath, "channels", channelId, version, folderKey, filename + ".json");
return Path.Combine(_config.ApplicationPaths.CachePath,
"channels",
channelId,
version,
folderKey,
filename + ".json");
}
private async Task<QueryResult<BaseItemDto>> GetReturnItems(IEnumerable<BaseItem> items, int? totalCountFromProvider, User user, ChannelItemQuery query, CancellationToken cancellationToken)
@ -770,7 +812,8 @@ namespace MediaBrowser.Server.Implementations.Channels
{
// Increment this as needed to force new downloads
// Incorporate Name because it's being used to convert channel entity to provider
return externalId + (channelProvider.DataVersion ?? string.Empty) + (channelProvider.Name ?? string.Empty) + "14";
return externalId + (channelProvider.DataVersion ?? string.Empty) +
(channelProvider.Name ?? string.Empty) + "15";
}
private async Task<BaseItem> GetChannelItemEntity(ChannelItemInfo info, IChannel channelProvider, Channel internalChannel, CancellationToken cancellationToken)

View File

@ -63,8 +63,9 @@
<Reference Include="MediaBrowser.IsoMounter">
<HintPath>..\packages\MediaBrowser.IsoMounting.3.0.65\lib\net45\MediaBrowser.IsoMounter.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.1.0\lib\net45\NLog.dll</HintPath>
<Reference Include="NLog, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.3.0.0.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="pfmclrapi">
<HintPath>..\packages\MediaBrowser.IsoMounting.3.0.65\lib\net45\pfmclrapi.dll</HintPath>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.IsoMounting" version="3.0.65" targetFramework="net45" />
<package id="NLog" version="2.1.0" targetFramework="net45" />
<package id="NLog" version="3.0.0.0" targetFramework="net45" />
</packages>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.394</version>
<version>3.0.397</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.394" />
<dependency id="MediaBrowser.Common" version="3.0.397" />
<dependency id="NLog" version="2.1.0" />
<dependency id="SimpleInjector" version="2.5.0" />
<dependency id="sharpcompress" version="0.10.2" />

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.394</version>
<version>3.0.397</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.394</version>
<version>3.0.397</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.394" />
<dependency id="MediaBrowser.Common" version="3.0.396" />
</dependencies>
</metadata>
<files>