OldSchoolHack

Registrieren / Anmelden Deutsch

C# - Der Fernsehkritik-TV Downloader

Veröffentlicht von (15. Mai 2015)
Beschreibung
Der Downloader ermöglicht es, beliebige Folgen von Fernsehkritik-TV herunterzuladen und offline anzuschauen.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6. using System.Diagnostics;
  7. using System.Windows.Forms;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10.  
  11. namespace ConsoleApplication1
  12. {
  13. class Program
  14. {
  15. struct DownloadInfo
  16. {
  17. public string filename;
  18. public string temp;
  19. public string url;
  20. }
  21.  
  22. static void Main(string[] args)
  23. {
  24. Console.WriteLine("Fernsehkritik-TV Downloader");
  25. Console.WriteLine("(C) 2011 - KN4CK3R");
  26.  
  27. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://fernsehkritik.tv/tv-magazin/");
  28. request.Proxy = null;
  29. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  30.  
  31. int maxEpisode = -1;
  32. using (StreamReader sr = new StreamReader(response.GetResponseStream()))
  33. {
  34. string raw = sr.ReadToEnd();
  35. raw = raw.Substring(raw.IndexOf(">Folge ") + ">Folge ".Length);
  36. raw = raw.Substring(0, raw.IndexOf(' '));
  37. maxEpisode = int.Parse(raw);
  38. }
  39.  
  40. Console.Write("Folge auswählen (aktuell: " + maxEpisode + "): ");
  41. int downloadEpisode = -1;
  42. if (!int.TryParse(Console.ReadLine(), out downloadEpisode))
  43. {
  44. return;
  45. }
  46.  
  47. if (downloadEpisode < 1 || downloadEpisode > maxEpisode)
  48. {
  49. return;
  50. }
  51.  
  52. request = (HttpWebRequest)WebRequest.Create("http://fernsehkritik.tv/folge-" + downloadEpisode + "/play/");
  53. request.Proxy = null;
  54. response = (HttpWebResponse)request.GetResponse();
  55.  
  56. List<DownloadInfo> fileList = new List<DownloadInfo>();
  57. using (StreamReader sr = new StreamReader(response.GetResponseStream()))
  58. {
  59. string raw = sr.ReadToEnd();
  60. raw = raw.Substring(raw.IndexOf("type=\"video/mp4\" src=\"") + "type=\"video/mp4\" src=\"".Length);
  61. string baseUrl = raw.Substring(0, raw.IndexOf('"'));
  62.  
  63. DownloadInfo info = new DownloadInfo();
  64. info.filename = "FernsehKritik-TV_E" + downloadEpisode + ".mp4";
  65. info.url = baseUrl;
  66. info.temp = Application.StartupPath + @"\" + info.filename;
  67. DownloadFile(info);
  68. }
  69.  
  70. Console.WriteLine();
  71. Console.WriteLine("Vorgang abgeschlossen");
  72. }
  73.  
  74. static void DownloadFile(DownloadInfo info)
  75. {
  76. if (!File.Exists(info.temp))
  77. {
  78. Console.WriteLine("Download file '" + info.filename + "'");
  79. using (WebClientTimeOut client = new WebClientTimeOut())
  80. {
  81. client.Proxy = null;
  82. client.TimeOut = int.MaxValue;
  83. client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(delegate(object sender, DownloadProgressChangedEventArgs eventArgs)
  84. {
  85. Console.Write("\r{0}%", eventArgs.ProgressPercentage);
  86. });
  87. client.DownloadFileTaskAsync(new Uri(info.url), info.temp).Wait();
  88. //client.DownloadFile(info.url, info.temp);
  89. }
  90. }
  91. //Console.WriteLine("Download file '" + info.filename + "' complete");
  92. }
  93.  
  94. static void JoinFiles(string outfile, List<DownloadInfo> fileList)
  95. {
  96. if (!File.Exists(outfile))
  97. {
  98. Process bind = new Process();
  99. bind.StartInfo.FileName = "FlvBind.exe";
  100. bind.StartInfo.Arguments = outfile;
  101. foreach (DownloadInfo info in fileList)
  102. {
  103. bind.StartInfo.Arguments += " \"" + info.temp + "\"";
  104. }
  105. bind.StartInfo.UseShellExecute = false;
  106. bind.StartInfo.RedirectStandardOutput = true;
  107. bind.Start();
  108. Console.WriteLine(bind.StandardOutput.ReadToEnd());
  109. bind.WaitForExit();
  110. }
  111. }
  112.  
  113. static void ConvertToMP4(string source, string destination)
  114. {
  115. Process convert = new Process();
  116. convert.StartInfo.FileName = "ffmpeg.exe";
  117. convert.StartInfo.Arguments = "-i \"" + source + "\" -vcodec libx264 -acodec libvo_aacenc -ab 96 -ac 2 -ar 22050 \"" + destination + "\"";
  118. convert.StartInfo.UseShellExecute = false;
  119. convert.StartInfo.RedirectStandardOutput = true;
  120. convert.Start();
  121. Console.WriteLine(convert.StandardOutput.ReadToEnd());
  122. convert.WaitForExit();
  123. }
  124. }
  125.  
  126. public class WebClientTimeOut : WebClient
  127. {
  128. protected override WebRequest GetWebRequest(Uri address)
  129. {
  130. WebRequest webRequest = base.GetWebRequest(address);
  131. webRequest.Timeout = TimeOut;
  132. return webRequest;
  133. }
  134. public int TimeOut { set; get; }
  135. }
  136. }
Schlagwörter Das Snippet wurde getaggt mit: c#, download, fernseh, offline, webclient
Zu diesem Snippet existieren keine Kommentare.
Kommentar hinzufügen