public void GetThreadIdTest() { Assert.AreEqual(NextVozRegex.GetThreadId("https://next.voz.vn/t/no-sex-ao-dai.14257/"), "no-sex-ao-dai.14257"); Assert.AreEqual(NextVozRegex.GetThreadId("https://next.voz.vn/t/no-sex-ao-dai.14257"), "no-sex-ao-dai.14257"); Assert.AreEqual(NextVozRegex.GetThreadId("https://next.voz.vn/t/no-sex-ao-dai.14257/page-1"), "no-sex-ao-dai.14257"); Assert.AreEqual(NextVozRegex.GetThreadId("https://next.voz.vn/t/no-sex-ao-dai.14257/page-1#post-1234"), "no-sex-ao-dai.14257"); Assert.AreNotEqual(NextVozRegex.GetThreadId("https://next.voz.vn/no-sex-ao-dai.14257/page-1#post-1234"), "no-sex-ao-dai.14257"); }
private async Task getImagesUrl() { var tasks = new List <Task>(); for (int i = 0; i < Math.Max(Setting.Instance.NumberThreads / 2, 1); i++) { var task = Task.Run(async() => { while (true) { if (_isPause) { await Task.Delay(500); continue; } if (_pages.IsEmpty || _isStop) { break; } if (_pages.TryDequeue(out string page)) { try { var content = await _client.GetContent(page); var images = NextVozRegex.GetImages(content).Select(url => getImageUrl(url)); var attachments = NextVozRegex.GetAttachmentImages(content).Select(url => getImageUrl($"attachments/{url}")); var linkExternal = NextVozRegex.GetImageInLinkExternal(content).Select(url => getImageUrl(url)); foreach (var item in images) { _images.Enqueue(new Tuple <string, string>(page, item)); } foreach (var item in attachments) { _images.Enqueue(new Tuple <string, string>(page, item)); } foreach (var item in linkExternal) { _images.Enqueue(new Tuple <string, string>(page, item)); } } catch (Exception ex) { Status.Set(ex.Message); System.Diagnostics.Debug.WriteLine(ex); } } await Task.Delay(500); } }); tasks.Add(task); await Task.Delay(500); } Task.WaitAll(tasks.ToArray()); _isGetThreadsEnd = true; }
private async Task download() { await Task.Delay(5000); var tasks = new List <Task>(); for (int i = 0; i < Setting.Instance.NumberThreads; i++) { var index = i; var task = Task.Run(async() => { while (true) { if (_isPause) { await Task.Delay(500); continue; } if (_images.IsEmpty && _isGetThreadsEnd) { break; } if (_isStop) { break; } if (_images.TryDequeue(out Tuple <string, string> item)) { var hashCode = item.Item2.GetHashCode(); if (this._downloadedImage.Contains(hashCode)) { continue; } this._downloadedImage.Add(hashCode); try { _store.Info.LastDownloadedPage = NextVozRegex.GetPage(item.Item1); using (var downloader = new ImageDownloader(item.Item2, Setting.Instance.Cookies)) { // var info = downloader.GetImageInfo(); DownloadProcess.Update(index, new ImageInfo { Url = item.Item2, }); downloader.ProgressChangedEventHandler += (sender, value) => { DownloadProcess.UpdateProcess(index, value); }; DownloadProcess.UpdateProcess(index, 0); var data = await downloader.DownloadAsync(); if (Setting.Instance.IgnoreSmallImage) { using (var imgStream = new MemoryStream(data.Data)) { using (var img = Image.FromStream(imgStream)) { if (img.Width < 200 || img.Height < 200) { continue; } } } } _store.Save(data.Data, data.GetFileName()); Status.IncrementSize(data.Size); Status.IncrementDownload(); Status.Update(); } } catch (Exception ex) { Status.Set(ex.Message); System.Diagnostics.Debug.WriteLine(item.Item1 + " " + item.Item2 + " " + ex.Message); } DownloadProcess.UpdateProcess(index, 100); } else { await Task.Delay(500); } } DownloadProcess.Update(index, new ImageInfo() { Url = "Xong", Size = 0, Extension = "" }); }); tasks.Add(task); await Task.Delay(100); } Task.WaitAll(tasks.ToArray()); _store.Info.TotalDownloadedImage = Status.TotalDownloadedImage; _store.Info.TotalDownloadedSize = Status.TotalDownloadedSize; _store.SaveInfo(); IsDownloading = false; DownloadFinishEvent?.Invoke(this); }
private async Task <string> getCsrf() { var html = await GetContent(NEXT_VOZ_HOME); return(NextVozRegex.GetToken(html)); }