Skip to content

Commit

Permalink
add perfect match indicator to subtitle editor
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jun 30, 2017
1 parent 1cf680b commit 9b3038c
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 30 deletions.
80 changes: 77 additions & 3 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Tasks;

namespace Emby.Server.Implementations.Channels
{
public class ChannelManager : IChannelManager
{
private IChannel[] _channels;
internal IChannel[] Channels { get; private set; }

private readonly IUserManager _userManager;
private readonly IUserDataManager _userDataManager;
Expand Down Expand Up @@ -76,12 +78,12 @@ private TimeSpan CacheLength

public void AddParts(IEnumerable<IChannel> channels)
{
_channels = channels.ToArray();
Channels = channels.ToArray();
}

private IEnumerable<IChannel> GetAllChannels()
{
return _channels
return Channels
.OrderBy(i => i.Name);
}

Expand Down Expand Up @@ -1559,4 +1561,76 @@ public async Task<Folder> GetInternalChannelFolder(CancellationToken cancellatio
return await _libraryManager.GetNamedView(name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false);
}
}

public class ChannelsEntryPoint : IServerEntryPoint
{
private readonly IServerConfigurationManager _config;
private readonly IChannelManager _channelManager;
private readonly ITaskManager _taskManager;
private readonly IFileSystem _fileSystem;

public ChannelsEntryPoint(IChannelManager channelManager, ITaskManager taskManager, IServerConfigurationManager config, IFileSystem fileSystem)
{
_channelManager = channelManager;
_taskManager = taskManager;
_config = config;
_fileSystem = fileSystem;
}

public void Run()
{
var channels = ((ChannelManager)_channelManager).Channels
.Select(i => i.GetType().FullName.GetMD5().ToString("N"))
.ToArray();

var channelsString = string.Join(",", channels);

if (!string.Equals(channelsString, GetSavedLastChannels(), StringComparison.OrdinalIgnoreCase))
{
_taskManager.QueueIfNotRunning<RefreshChannelsScheduledTask>();

SetSavedLastChannels(channelsString);
}
}

private string DataPath
{
get { return Path.Combine(_config.ApplicationPaths.DataPath, "channels.txt"); }
}

private string GetSavedLastChannels()
{
try
{
return _fileSystem.ReadAllText(DataPath);
}
catch
{
return string.Empty;
}
}

private void SetSavedLastChannels(string value)
{
try
{
if (string.IsNullOrWhiteSpace(value))
{
_fileSystem.DeleteFile(DataPath);

}
else
{
_fileSystem.WriteAllText(DataPath, value);
}
}
catch
{
}
}

public void Dispose()
{
}
}
}
19 changes: 2 additions & 17 deletions Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,9 @@ public async Task Execute(CancellationToken cancellationToken, IProgress<double>
var rootChildren = _libraryManager.RootFolder.Children.ToList();
rootChildren = _libraryManager.GetUserRootFolder().Children.ToList();

var innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p =>
{
double newPercentCommplete = .45 * p;
progress.Report(newPercentCommplete);
});
await CleanDeadItems(cancellationToken, innerProgress).ConfigureAwait(false);
progress.Report(45);

innerProgress = new ActionableProgress<double>();
innerProgress.RegisterAction(p =>
{
double newPercentCommplete = 45 + .55 * p;
progress.Report(newPercentCommplete);
});
await CleanDeadItems(cancellationToken, progress).ConfigureAwait(false);

await _itemRepo.UpdateInheritedValues(cancellationToken).ConfigureAwait(false);
progress.Report(100);
//await _itemRepo.UpdateInheritedValues(cancellationToken).ConfigureAwait(false);
}

private async Task CleanDeadItems(CancellationToken cancellationToken, IProgress<double> progress)
Expand Down
6 changes: 4 additions & 2 deletions MediaBrowser.Api/Subtitles/SubtitleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class SearchRemoteSubtitles : IReturn<List<RemoteSubtitleInfo>>

[ApiMember(Name = "Language", Description = "Language", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Language { get; set; }

public bool? IsPerfectMatch { get; set; }
}

[Route("/Items/{Id}/RemoteSearch/Subtitles/Providers", "GET")]
Expand Down Expand Up @@ -247,11 +249,11 @@ private Task<Stream> GetSubtitles(GetSubtitle request)
CancellationToken.None);
}

public object Get(SearchRemoteSubtitles request)
public async Task<object> Get(SearchRemoteSubtitles request)
{
var video = (Video)_libraryManager.GetItemById(request.Id);

var response = _subtitleManager.SearchSubtitles(video, request.Language, CancellationToken.None).Result;
var response = await _subtitleManager.SearchSubtitles(video, request.Language, request.IsPerfectMatch, CancellationToken.None).ConfigureAwait(false);

return ToOptimizedResult(response);
}
Expand Down
5 changes: 1 addition & 4 deletions MediaBrowser.Controller/Subtitles/ISubtitleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public interface ISubtitleManager
/// <summary>
/// Searches the subtitles.
/// </summary>
/// <param name="video">The video.</param>
/// <param name="language">The language.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{RemoteSubtitleInfo}}.</returns>
Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(Video video,
string language,
bool? isPerfectMatch,
CancellationToken cancellationToken);

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.Model/LiveTv/LiveTvOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class TunerHostInfo
public TunerHostInfo()
{
AllowHWTranscoding = true;
EnableTvgId = true;
}
}

Expand Down
8 changes: 4 additions & 4 deletions MediaBrowser.Providers/Subtitles/SubtitleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public async Task DownloadSubtitles(Video video,
}
}

public Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(Video video, string language, CancellationToken cancellationToken)
public Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(Video video, string language, bool? isPerfectMatch, CancellationToken cancellationToken)
{
if (video.LocationType != LocationType.FileSystem ||
video.VideoType != VideoType.VideoFile)
Expand Down Expand Up @@ -207,7 +207,8 @@ public Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(Video video, string
ParentIndexNumber = video.ParentIndexNumber,
ProductionYear = video.ProductionYear,
ProviderIds = video.ProviderIds,
RuntimeTicks = video.RunTimeTicks
RuntimeTicks = video.RunTimeTicks,
IsPerfectMatch = isPerfectMatch ?? false
};

var episode = video as Episode;
Expand Down Expand Up @@ -261,8 +262,7 @@ public Task DeleteSubtitles(string itemId, int index)
_monitor.ReportFileSystemChangeComplete(path, false);
}

_libraryManager.GetItemById(itemId).ChangedExternally();
return Task.FromResult(true);
return _libraryManager.GetItemById(itemId).RefreshMetadata(CancellationToken.None);
}

public Task<SubtitleResponse> GetRemoteSubtitles(string id, CancellationToken cancellationToken)
Expand Down

0 comments on commit 9b3038c

Please sign in to comment.