Beispiel #1
0
        private async Task ExtractStart()
        {
            // This block suspends the task until the episodes list is full
            do
            {
                Thread.Sleep(500);
            }while (!AllEpisodesReadyToExtract);


            if (CurrentGridItem != null)
            {
                Downloader = new Downloader();
                Downloader.ProgressChanged += _downloader_ProgressChanged;
                Downloader.Completed       += _downloader_Completed;

                CurrentGridItem.StatusEnum = ExtractionStatus.Starting;

                // Sets Serie path
                string _title    = CurrentSerie.Title;
                string _epNumber = CurrentGridItem.Episode.EpisodeNumber.ToString();


                foreach (var _c in Path.GetInvalidFileNameChars())
                {
                    _title = _title.Replace(_c, '-');
                }

                foreach (var _c in Path.GetInvalidFileNameChars())
                {
                    _epNumber = _epNumber.Replace(_c, '-');
                }

                DirectoryInfo _directory = Directory.CreateDirectory($"{ Directory.GetCurrentDirectory()}\\{_title}");
                string        _fileName  = $"{_directory.FullName}\\Episode {_epNumber}.mp4";

                // File already exists, then ERROR
                if (File.Exists(_fileName))
                {
                    CurrentGridItem.StatusEnum = ExtractionStatus.Error;
                    // Next file
                    SetNextFile();
                }
                else
                { // Continue if file doesn't exist
                    // Get url
                    string _urlToExtract = null;

                    while (_urlToExtract == null)
                    {
                        try
                        {
                            AnimepaheExtractor.InitializePuppeteer(); // Try to bring to life the browser
                            _urlToExtract = await AnimepaheExtractor.GetUrlToExtract(CurrentGridItem.Episode.EpisodeLinksData[0].Url);
                        }
                        catch
                        {
                            Thread.Sleep(500);
                        }
                    }

                    // Aborts last thread
                    if (currentDownloadThread != null)
                    {
                        currentDownloadThread.Abort();
                    }

                    // Starts Download
                    Downloader.DownloadFile(_urlToExtract, _fileName);
                    CurrentGridItem.StatusEnum = ExtractionStatus.Downloading;
                }
            }
        }