improved chapter saving to respect forced refreshing

pull/702/head
Luke Pulverenti 11 years ago
parent 339c514ff4
commit 80a256bdea

@ -7,6 +7,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
@ -84,6 +85,14 @@ namespace MediaBrowser.Providers.MediaInfo
} }
} }
public override MetadataProviderPriority Priority
{
get
{
return MetadataProviderPriority.Second;
}
}
/// <summary> /// <summary>
/// Supports video files and dvd structures /// Supports video files and dvd structures
/// </summary> /// </summary>
@ -149,7 +158,7 @@ namespace MediaBrowser.Providers.MediaInfo
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
await Fetch(myItem, cancellationToken, result, isoMount).ConfigureAwait(false); await Fetch(myItem, force, cancellationToken, result, isoMount).ConfigureAwait(false);
SetLastRefreshed(item, DateTime.UtcNow); SetLastRefreshed(item, DateTime.UtcNow);
} }
@ -243,11 +252,12 @@ namespace MediaBrowser.Providers.MediaInfo
/// Fetches the specified video. /// Fetches the specified video.
/// </summary> /// </summary>
/// <param name="video">The video.</param> /// <param name="video">The video.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <param name="data">The data.</param> /// <param name="data">The data.</param>
/// <param name="isoMount">The iso mount.</param> /// <param name="isoMount">The iso mount.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
protected async Task Fetch(Video video, CancellationToken cancellationToken, MediaInfoResult data, IIsoMount isoMount) protected async Task Fetch(Video video, bool force, CancellationToken cancellationToken, MediaInfoResult data, IIsoMount isoMount)
{ {
if (data.format != null) if (data.format != null)
{ {
@ -277,7 +287,7 @@ namespace MediaBrowser.Providers.MediaInfo
AddExternalSubtitles(video); AddExternalSubtitles(video);
FetchWtvInfo(video, data); FetchWtvInfo(video, force, data);
if (chapters.Count == 0 && video.MediaStreams.Any(i => i.Type == MediaStreamType.Video)) if (chapters.Count == 0 && video.MediaStreams.Any(i => i.Type == MediaStreamType.Video))
{ {
@ -286,21 +296,28 @@ namespace MediaBrowser.Providers.MediaInfo
await Kernel.Instance.FFMpegManager.PopulateChapterImages(video, chapters, false, false, cancellationToken).ConfigureAwait(false); await Kernel.Instance.FFMpegManager.PopulateChapterImages(video, chapters, false, false, cancellationToken).ConfigureAwait(false);
// Only save chapters if forcing or there are not already any saved ones
if (force || _itemRepo.GetChapter(video.Id, 0) == null)
{
await _itemRepo.SaveChapters(video.Id, chapters, cancellationToken).ConfigureAwait(false); await _itemRepo.SaveChapters(video.Id, chapters, cancellationToken).ConfigureAwait(false);
} }
}
/// <summary> /// <summary>
/// Fetches the WTV info. /// Fetches the WTV info.
/// </summary> /// </summary>
/// <param name="video">The video.</param> /// <param name="video">The video.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="data">The data.</param> /// <param name="data">The data.</param>
private void FetchWtvInfo(Video video, MediaInfoResult data) private void FetchWtvInfo(Video video, bool force, MediaInfoResult data)
{ {
if (data.format == null || data.format.tags == null) if (data.format == null || data.format.tags == null)
{ {
return; return;
} }
if (force || video.Genres.Count == 0)
{
if (!video.LockedFields.Contains(MetadataFields.Genres)) if (!video.LockedFields.Contains(MetadataFields.Genres))
{ {
var genres = GetDictionaryValue(data.format.tags, "genre"); var genres = GetDictionaryValue(data.format.tags, "genre");
@ -313,21 +330,35 @@ namespace MediaBrowser.Providers.MediaInfo
.ToList(); .ToList();
} }
} }
}
if (force || string.IsNullOrEmpty(video.Overview))
{
if (!video.LockedFields.Contains(MetadataFields.Overview))
{
var overview = GetDictionaryValue(data.format.tags, "WM/SubTitleDescription"); var overview = GetDictionaryValue(data.format.tags, "WM/SubTitleDescription");
if (!string.IsNullOrWhiteSpace(overview)) if (!string.IsNullOrWhiteSpace(overview))
{ {
video.Overview = overview; video.Overview = overview;
} }
}
}
if (force || string.IsNullOrEmpty(video.OfficialRating))
{
var officialRating = GetDictionaryValue(data.format.tags, "WM/ParentalRating"); var officialRating = GetDictionaryValue(data.format.tags, "WM/ParentalRating");
if (!string.IsNullOrWhiteSpace(officialRating)) if (!string.IsNullOrWhiteSpace(officialRating))
{ {
video.OfficialRating = officialRating; video.OfficialRating = officialRating;
} }
}
if (force || video.People.Count == 0)
{
if (!video.LockedFields.Contains(MetadataFields.Cast))
{
var people = GetDictionaryValue(data.format.tags, "WM/MediaCredits"); var people = GetDictionaryValue(data.format.tags, "WM/MediaCredits");
if (!string.IsNullOrEmpty(people)) if (!string.IsNullOrEmpty(people))
@ -337,7 +368,11 @@ namespace MediaBrowser.Providers.MediaInfo
.Select(i => new PersonInfo { Name = i.Trim(), Type = PersonType.Actor }) .Select(i => new PersonInfo { Name = i.Trim(), Type = PersonType.Actor })
.ToList(); .ToList();
} }
}
}
if (force || !video.ProductionYear.HasValue)
{
var year = GetDictionaryValue(data.format.tags, "WM/OriginalReleaseTime"); var year = GetDictionaryValue(data.format.tags, "WM/OriginalReleaseTime");
if (!string.IsNullOrWhiteSpace(year)) if (!string.IsNullOrWhiteSpace(year))
@ -350,6 +385,7 @@ namespace MediaBrowser.Providers.MediaInfo
} }
} }
} }
}
/// <summary> /// <summary>
/// Adds the external subtitles. /// Adds the external subtitles.

@ -49,7 +49,7 @@ namespace MediaBrowser.Providers.Movies
/// <value>The priority.</value> /// <value>The priority.</value>
public override MetadataProviderPriority Priority public override MetadataProviderPriority Priority
{ {
get { return MetadataProviderPriority.Second; } get { return MetadataProviderPriority.First; }
} }
/// <summary> /// <summary>

@ -43,7 +43,7 @@ namespace MediaBrowser.Providers.TV
/// <value>The priority.</value> /// <value>The priority.</value>
public override MetadataProviderPriority Priority public override MetadataProviderPriority Priority
{ {
get { return MetadataProviderPriority.Second; } get { return MetadataProviderPriority.First; }
} }
/// <summary> /// <summary>

@ -38,7 +38,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
private readonly List<Video> _newlyAddedItems = new List<Video>(); private readonly List<Video> _newlyAddedItems = new List<Video>();
private const int NewItemDelay = 60000; private const int NewItemDelay = 30000;
/// <summary> /// <summary>
/// The current new item timer /// The current new item timer
@ -107,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
// Limit to video files to reduce changes of ffmpeg crash dialog // Limit to video files to reduce changes of ffmpeg crash dialog
foreach (var item in newItems foreach (var item in newItems
.Where(i => i.LocationType == LocationType.FileSystem && i.VideoType == VideoType.VideoFile && string.IsNullOrEmpty(i.PrimaryImagePath) && i.MediaStreams.Any(m => m.Type == MediaStreamType.Video)) .Where(i => i.LocationType == LocationType.FileSystem && i.VideoType == VideoType.VideoFile && string.IsNullOrEmpty(i.PrimaryImagePath) && i.MediaStreams.Any(m => m.Type == MediaStreamType.Video))
.Take(1)) .Take(2))
{ {
try try
{ {

Loading…
Cancel
Save