Advertisement
Guest User

Untitled

a guest
Oct 10th, 2021
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Drawing.Imaging;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using unfreez_wrapper;
  16.  
  17. namespace Extract
  18. {
  19. public partial class Form1 : Form
  20. {
  21. string[] statements;
  22. List<string> urls = new List<string>();
  23. WebClient client;
  24.  
  25. public Form1()
  26. {
  27. InitializeComponent();
  28.  
  29. label3.Text = "";
  30.  
  31. ExtractLinks();
  32. }
  33.  
  34. private void ExtractLinks()
  35. {
  36. using (WebClient client = new WebClient())
  37. {
  38. client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36");
  39. client.DownloadFile("https://de.sat24.com/de/eu/infraPolair/", @"D:\localfile.html");
  40.  
  41. var file = File.ReadAllText(@"D:\localfile.html");
  42.  
  43. int idx = file.IndexOf("arrayImageTimes.push");
  44. int idx1 = file.IndexOf("</script>", idx);
  45.  
  46. string results = file.Substring(idx, idx1 - idx);
  47. statements = results.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
  48.  
  49. for (int i = 0; i < statements.Length; i++)
  50. {
  51. if (i == 10)
  52. {
  53. break;
  54. }
  55.  
  56. string number = statements[i].Split('\'')[1];
  57.  
  58. urls.Add("https://de.sat24.com/image?type=infraPolair&region=eu&timestamp=" + number);
  59. }
  60. }
  61. }
  62.  
  63. private async Task DownloadAsync()
  64. {
  65. using (var client = new WebClient())
  66. {
  67. client.DownloadFileCompleted += (s, e) => label1.Text = "Download file completed.";
  68. client.DownloadProgressChanged += (s, e) => progressBar1.Value = e.ProgressPercentage;
  69. client.DownloadProgressChanged += (s, e) => label2.Text = FormatBytes(e.BytesReceived);
  70. client.DownloadProgressChanged += (s, e) =>
  71. {
  72. label3.Text = "%" + e.ProgressPercentage.ToString();
  73. label3.Left = Math.Min(
  74. (int)(progressBar1.Left + e.ProgressPercentage / 100f * progressBar1.Width),
  75. progressBar1.Width - label3.Width
  76. );
  77. };
  78. for (int i = 0; i < urls.Count; i++)
  79. {
  80. await client.DownloadFileTaskAsync(new Uri(urls[i]), @"d:\satImages\img" + i + ".gif");
  81. }
  82. }
  83. }
  84.  
  85. void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  86. {
  87.  
  88. }
  89.  
  90. private void Form1_Load(object sender, EventArgs e)
  91. {
  92.  
  93. }
  94.  
  95. private async void Button1_Click(object sender, EventArgs e)
  96. {
  97. await DownloadAsync();
  98. }
  99.  
  100. private void timer1_Tick(object sender, EventArgs e)
  101. {
  102.  
  103. }
  104.  
  105. private string FormatBytes(long bytes)
  106. {
  107. string[] Suffix = { "B", "KB", "MB", "GB", "TB" };
  108. int i;
  109. double dblSByte = bytes;
  110. for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024)
  111. {
  112. dblSByte = bytes / 1024.0;
  113. }
  114.  
  115. return String.Format("{0:0.00} {1}", dblSByte, Suffix[i]);
  116. }
  117. }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement