public Worker( VideoFile video, ILogger logger, IWorkerQueue workerQueue, ISubtitleProvider subtitleProvider, IStatusReporter <WorkerStatus> statusReporter, HashSet <string> subtitleExtensions, int retryCount = 0) { this.video = video; this.logger = logger; this.workerQueue = workerQueue; this.subtitleProvider = subtitleProvider; this.statusReporter = statusReporter; this.subtitleExtensions = subtitleExtensions; this.retryCount = retryCount; }
private void Sync(string fullFilePath) { try { var video = new VideoFile(fullFilePath); if (IsSynchronized(video)) { Interlocked.Increment(ref skipped); return; } workerQueue.Enqueue(video); } catch (Exception exc) { logger.Error($"Unable to sync subtitles for @yellow@{fullFilePath} @red@, reason: {exc.Message}."); } }
private bool IsSynchronized(VideoFile videoFile) { if (settings.ResyncAll) { // regardless, redownload this subtitle return(false); } if (BlacklistedFile(videoFile)) { return(true); } if (videoIgnore.Match(videoFile)) { return(true); } if (videoFile.Directory == null) { throw new NullReferenceException(nameof(videoFile.Directory)); } var hasSubtitleFile = HasSubtitleFile(settings, videoFile); // check if in sync list if (syncList.Contains(videoFile) && hasSubtitleFile) { return(true); } if (settings.Resync) { // normal --resync flag just means we want to redownload any subtitles subsync has not synced. return(false); } return(hasSubtitleFile); }
public async Task <string> GetAsync(VideoFile video) { providerCache.TryGetValue(video.Name, out var index); try { var result = await _providers[index].GetAsync(video); providerCache.TryRemove(video.Name, out _); syncList.Add(video); return(result); } catch (Exception exc) { providerCache[video.Name] = index + 1; if (index + 1 > MaxRetryCount || index + 1 >= _providers.Length) { providerCache.TryRemove(video.Name, out _); throw exc; } return(await GetAsync(video)); } }
private static bool HasSubtitleFile(SubSyncSettings settings, VideoFile videoFile) { return(settings.SubtitleExt.SelectMany(x => videoFile.Directory.GetFiles($"{Path.GetFileNameWithoutExtension(videoFile.Name)}{x}", SearchOption.AllDirectories)) .Any()); }
private static bool BlacklistedFile(VideoFile video) { // todo: make this configurable. but for now, ignore all sample.<vid ext> files. return(Path.GetFileNameWithoutExtension(video.Name).Equals("sample", StringComparison.OrdinalIgnoreCase)); }
public abstract Task <string> GetAsync(VideoFile video);
public bool Match(VideoFile video) { return(Match(video.FilePath)); }
public bool Match(VideoFile video) => false;