Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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}.");
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 5
0
 private static bool HasSubtitleFile(SubSyncSettings settings, VideoFile videoFile)
 {
     return(settings.SubtitleExt.SelectMany(x =>
                                            videoFile.Directory.GetFiles($"{Path.GetFileNameWithoutExtension(videoFile.Name)}{x}", SearchOption.AllDirectories))
            .Any());
 }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 public abstract Task <string> GetAsync(VideoFile video);
Ejemplo n.º 8
0
 public bool Match(VideoFile video)
 {
     return(Match(video.FilePath));
 }
Ejemplo n.º 9
0
 public bool Match(VideoFile video) => false;