redirect to item page when only one new item

pull/702/head
Luke Pulverenti 11 years ago
parent 651d483dec
commit 7a099f92ba

@ -55,8 +55,6 @@ namespace MediaBrowser.Api.Playback.Hls
public object Get(GetMasterHlsVideoStream request)
{
var result = GetAsync(request).Result;
if (string.Equals(request.AudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("Audio codec copy is not allowed here.");
@ -67,6 +65,8 @@ namespace MediaBrowser.Api.Playback.Hls
throw new ArgumentException("Video codec copy is not allowed here.");
}
var result = GetAsync(request).Result;
return result;
}

@ -123,14 +123,10 @@ namespace MediaBrowser.Api.Playback.Progressive
{
AddDlnaHeaders(state, responseHeaders, true);
try
using (state)
{
return GetStaticRemoteStreamResult(state, responseHeaders, isHeadRequest).Result;
}
finally
{
state.Dispose();
}
}
if (request.Static && state.InputProtocol != MediaProtocol.File)
@ -151,14 +147,10 @@ namespace MediaBrowser.Api.Playback.Progressive
{
var contentType = state.GetMimeType(state.MediaPath);
try
using (state)
{
return ResultFactory.GetStaticFileResult(Request, state.MediaPath, contentType, FileShare.Read, responseHeaders, isHeadRequest);
}
finally
{
state.Dispose();
}
}
// Not static but transcode cache file exists

@ -734,7 +734,7 @@ namespace MediaBrowser.Dlna.PlayTo
var info = StreamParams.ParseFromUrl(media.Url, _libraryManager);
var progress = GetProgressInfo(media, info);
if (info.Item != null && !info.IsDirectStream)
if (info.Item != null)
{
var newPosition = progress.PositionTicks ?? 0;
@ -760,7 +760,7 @@ namespace MediaBrowser.Dlna.PlayTo
var info = StreamParams.ParseFromUrl(media.Url, _libraryManager);
var progress = GetProgressInfo(media, info);
if (info.Item != null && !info.IsDirectStream)
if (info.Item != null)
{
var newPosition = progress.PositionTicks ?? 0;

@ -295,11 +295,19 @@ namespace MediaBrowser.Providers.Manager
var temp = CreateNew();
temp.Path = item.Path;
var successfulProviderCount = 0;
var failedProviderCount = 0;
// If replacing all metadata, run internet providers first
if (options.ReplaceAllMetadata)
{
await ExecuteRemoteProviders(item, temp, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), refreshResult, cancellationToken).ConfigureAwait(false);
var remoteResult = await ExecuteRemoteProviders(item, temp, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), cancellationToken)
.ConfigureAwait(false);
refreshResult.UpdateType = refreshResult.UpdateType | remoteResult.UpdateType;
refreshResult.Status = remoteResult.Status;
refreshResult.ErrorMessage = remoteResult.ErrorMessage;
successfulProviderCount += remoteResult.Successes;
failedProviderCount += remoteResult.Failures;
}
var hasLocalMetadata = false;
@ -327,10 +335,11 @@ namespace MediaBrowser.Providers.Manager
// Only one local provider allowed per item
hasLocalMetadata = true;
item.IsUnidentified = false;
successfulProviderCount++;
break;
}
failedProviderCount++;
Logger.Debug("{0} returned no metadata for {1}", providerName, item.Path ?? item.Name);
}
catch (OperationCanceledException)
@ -339,6 +348,8 @@ namespace MediaBrowser.Providers.Manager
}
catch (Exception ex)
{
failedProviderCount++;
Logger.ErrorException("Error in {0}", ex, provider.Name);
// If a local provider fails, consider that a failure
@ -356,7 +367,16 @@ namespace MediaBrowser.Providers.Manager
// Local metadata is king - if any is found don't run remote providers
if (!options.ReplaceAllMetadata && (!hasLocalMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh))
{
await ExecuteRemoteProviders(item, temp, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), refreshResult, cancellationToken).ConfigureAwait(false);
var remoteResult = await ExecuteRemoteProviders(item, temp, id, providers.OfType<IRemoteMetadataProvider<TItemType, TIdType>>(), cancellationToken)
.ConfigureAwait(false);
refreshResult.UpdateType = refreshResult.UpdateType | remoteResult.UpdateType;
if (remoteResult.Status != ProviderRefreshStatus.Success)
{
refreshResult.Status = remoteResult.Status;
refreshResult.ErrorMessage = remoteResult.ErrorMessage;
}
successfulProviderCount += remoteResult.Successes;
}
if (refreshResult.UpdateType > ItemUpdateType.None)
@ -364,6 +384,14 @@ namespace MediaBrowser.Providers.Manager
MergeData(temp, item, item.LockedFields, true, true);
}
var isUnidentified = failedProviderCount > 0 && successfulProviderCount == 0;
if (item.IsUnidentified != isUnidentified)
{
item.IsUnidentified = isUnidentified;
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;
}
foreach (var provider in customProviders.Where(i => !(i is IPreRefreshProvider)))
{
await RunCustomProvider(provider, item, options, refreshResult, cancellationToken).ConfigureAwait(false);
@ -397,10 +425,9 @@ namespace MediaBrowser.Providers.Manager
return new TItemType();
}
private async Task ExecuteRemoteProviders(TItemType item, TItemType temp, TIdType id, IEnumerable<IRemoteMetadataProvider<TItemType, TIdType>> providers, RefreshResult refreshResult, CancellationToken cancellationToken)
private async Task<RefreshResult> ExecuteRemoteProviders(TItemType item, TItemType temp, TIdType id, IEnumerable<IRemoteMetadataProvider<TItemType, TIdType>> providers, CancellationToken cancellationToken)
{
var unidentifiedCount = 0;
var identifiedCount = 0;
var refreshResult = new RefreshResult();
foreach (var provider in providers)
{
@ -422,11 +449,11 @@ namespace MediaBrowser.Providers.Manager
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataDownload;
identifiedCount++;
refreshResult.Successes++;
}
else
{
unidentifiedCount++;
refreshResult.Failures++;
Logger.Debug("{0} returned no metadata for {1}", providerName, item.Path ?? item.Name);
}
}
@ -436,20 +463,14 @@ namespace MediaBrowser.Providers.Manager
}
catch (Exception ex)
{
unidentifiedCount++;
refreshResult.Failures++;
refreshResult.Status = ProviderRefreshStatus.CompletedWithErrors;
refreshResult.ErrorMessage = ex.Message;
Logger.ErrorException("Error in {0}", ex, provider.Name);
}
}
var isUnidentified = unidentifiedCount > 0 && identifiedCount == 0;
if (item.IsUnidentified != isUnidentified)
{
item.IsUnidentified = isUnidentified;
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;
}
return refreshResult;
}
private async Task<TIdType> CreateInitialLookupInfo(TItemType item, CancellationToken cancellationToken)
@ -510,5 +531,7 @@ namespace MediaBrowser.Providers.Manager
public ProviderRefreshStatus Status { get; set; }
public string ErrorMessage { get; set; }
public List<Guid> Providers { get; set; }
public int Successes { get; set; }
public int Failures { get; set; }
}
}

@ -19,7 +19,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
public class MovieDbEpisodeImageProvider/* : IRemoteImageProvider, IHasOrder*/
public class MovieDbEpisodeImageProvider : IRemoteImageProvider, IHasOrder
{
private const string GetTvInfo3 = @"http://api.themoviedb.org/3/tv/{0}/season/{1}/episode/{2}?api_key={3}&append_to_response=images,external_ids,credits,videos";
private readonly IHttpClient _httpClient;

@ -5,6 +5,8 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Providers.Movies;
@ -13,6 +15,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@ -26,14 +29,16 @@ namespace MediaBrowser.Providers.TV
private readonly IJsonSerializer _jsonSerializer;
private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization;
private readonly ILogger _logger;
public MovieDbSeasonProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer)
public MovieDbSeasonProvider(IHttpClient httpClient, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, ILogManager logManager)
{
_httpClient = httpClient;
_configurationManager = configurationManager;
_fileSystem = fileSystem;
_localization = localization;
_jsonSerializer = jsonSerializer;
_logger = logManager.GetLogger(GetType().Name);
}
public async Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, CancellationToken cancellationToken)
@ -43,42 +48,58 @@ namespace MediaBrowser.Providers.TV
string seriesTmdbId;
info.SeriesProviderIds.TryGetValue(MetadataProviders.Tmdb.ToString(), out seriesTmdbId);
if (!string.IsNullOrWhiteSpace(seriesTmdbId) && info.IndexNumber.HasValue)
var seasonNumber = info.IndexNumber;
if (!string.IsNullOrWhiteSpace(seriesTmdbId) && seasonNumber.HasValue)
{
result.HasMetadata = true;
result.Item = new Season();
var seasonInfo = await GetSeasonInfo(seriesTmdbId, info.IndexNumber.Value, info.MetadataLanguage, cancellationToken)
.ConfigureAwait(false);
result.Item.Name = seasonInfo.name;
result.Item.Overview = seasonInfo.overview;
result.Item.IndexNumber = info.IndexNumber;
if (seasonInfo.external_ids.tvdb_id > 0)
try
{
result.Item.SetProviderId(MetadataProviders.Tvdb, seasonInfo.external_ids.tvdb_id.ToString(CultureInfo.InvariantCulture));
}
var seasonInfo = await GetSeasonInfo(seriesTmdbId, seasonNumber.Value, info.MetadataLanguage, cancellationToken)
.ConfigureAwait(false);
var credits = seasonInfo.credits;
if (credits != null)
{
//Actors, Directors, Writers - all in People
//actors come from cast
if (credits.cast != null)
result.Item.Name = seasonInfo.name;
result.Item.Overview = seasonInfo.overview;
result.Item.IndexNumber = seasonNumber;
if (seasonInfo.external_ids.tvdb_id > 0)
{
//foreach (var actor in credits.cast.OrderBy(a => a.order)) result.Item.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
result.Item.SetProviderId(MetadataProviders.Tvdb, seasonInfo.external_ids.tvdb_id.ToString(CultureInfo.InvariantCulture));
}
//and the rest from crew
if (credits.crew != null)
var credits = seasonInfo.credits;
if (credits != null)
{
//foreach (var person in credits.crew) result.Item.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department });
//Actors, Directors, Writers - all in People
//actors come from cast
if (credits.cast != null)
{
//foreach (var actor in credits.cast.OrderBy(a => a.order)) result.Item.AddPerson(new PersonInfo { Name = actor.name.Trim(), Role = actor.character, Type = PersonType.Actor, SortOrder = actor.order });
}
//and the rest from crew
if (credits.crew != null)
{
//foreach (var person in credits.crew) result.Item.AddPerson(new PersonInfo { Name = person.name.Trim(), Role = person.job, Type = person.department });
}
}
result.Item.PremiereDate = seasonInfo.air_date;
result.Item.ProductionYear = result.Item.PremiereDate.Value.Year;
}
catch (HttpException ex)
{
_logger.Error("No metadata found for {0}", seasonNumber.Value);
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
{
return result;
}
result.Item.PremiereDate = seasonInfo.air_date;
result.Item.ProductionYear = result.Item.PremiereDate.Value.Year;
throw;
}
}
return result;

Loading…
Cancel
Save