Advertisement
Guest User

Untitled

a guest
Feb 26th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 31.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. using System.Runtime.InteropServices;
  12. using System.Net;
  13. using System.IO;
  14. using System.Text.RegularExpressions;
  15. using System.Drawing.Drawing2D;
  16. using System.Web;
  17.  
  18. namespace Youtube_Downloader
  19. {
  20.     public partial class Form1 : Form
  21.     {
  22.         public const int WM_NCLBUTTONDOWN = 0xA1;
  23.         public const int HT_CAPTION = 0x2;
  24.  
  25.         [DllImportAttribute("user32.dll")]
  26.         public static extern int SendMessage(IntPtr hWnd,
  27.                          int Msg, int wParam, int lParam);
  28.         [DllImportAttribute("user32.dll")]
  29.         public static extern bool ReleaseCapture();
  30.  
  31.  
  32.         public Form1()
  33.         {
  34.             InitializeComponent();
  35.         }
  36.  
  37.         private void addText(object sender, EventArgs e)
  38.         {
  39.             if (String.IsNullOrWhiteSpace(bunifuMetroTextbox1.Text))
  40.             {
  41.                 bunifuMetroTextbox1.ForeColor = Color.FromArgb(150, 150, 150);
  42.                 bunifuMetroTextbox1.Text = "Ex: https://www.youtube.com/watch?v=5aopMm7UGYA";
  43.             }
  44.             bunifuMetroTextbox1.Parent.Parent.BackColor = Color.FromArgb(255, 255, 255);
  45.         }
  46.         private void removeText(object sender, EventArgs e)
  47.         {
  48.             if (bunifuMetroTextbox1.ForeColor == Color.FromArgb(150, 150, 150))
  49.             {
  50.                 bunifuMetroTextbox1.ForeColor = Color.FromArgb(255, 255, 255);
  51.                 bunifuMetroTextbox1.Text = "";
  52.             }
  53.             bunifuMetroTextbox1.Parent.Parent.BackColor = Color.FromArgb(46, 139, 87);
  54.         }
  55.         private void HoverEnterInput(object sender, EventArgs e)
  56.         {
  57.             if (!bunifuMetroTextbox1.Focused)
  58.             {
  59.                 panel8.BackColor = Color.FromArgb(60, 196, 120);
  60.             }
  61.         }
  62.         private void HoverLeaveInput(object sender, EventArgs e)
  63.         {
  64.             if (!bunifuMetroTextbox1.Focused)
  65.             {
  66.                 panel8.BackColor = Color.FromArgb(255, 255, 255);
  67.             }
  68.         }
  69.         private void ClickInput(object sender, EventArgs e)
  70.         {
  71.             bunifuMetroTextbox1.Focus();
  72.         }
  73.         private void HoverEnterButton(object sender, EventArgs e)
  74.         {
  75.             label5.BackColor = Color.FromArgb(60, 196, 120);
  76.             label5.Cursor = Cursors.Hand;
  77.         }
  78.         private void HoverLeaveButton(object sender, EventArgs e)
  79.         {
  80.             label5.BackColor = Color.FromArgb(46, 139, 87);
  81.             label5.Cursor = Cursors.Default;
  82.         }
  83.         private void closeEnter(object sender, EventArgs e)
  84.         {
  85.             Panel p = (Panel)sender;
  86.             p.Top -= 5;
  87.             p.Left -= 5;
  88.             p.Width += 10;
  89.             p.Height += 10;
  90.         }
  91.         private void closeLeave(object sender, EventArgs e)
  92.         {
  93.             Panel p = (Panel)sender;
  94.             p.Top += 5;
  95.             p.Left += 5;
  96.             p.Width -= 10;
  97.             p.Height -= 10;
  98.         }
  99.  
  100.  
  101.         private void Form1_Click(object sender, EventArgs e)
  102.         {
  103.             label2.Focus();
  104.         }
  105.         private void Form1_Load(object sender, EventArgs e)
  106.         {
  107.             this.ActiveControl = label2;
  108.             bunifuMetroTextbox1.ForeColor = Color.FromArgb(150, 150, 150);
  109.             bunifuMetroTextbox1.Text = "Ex: https://www.youtube.com/watch?v=5aopMm7UGYA";
  110.             panel5.AutoScroll = false;
  111.             panel5.HorizontalScroll.Enabled = false;
  112.             panel5.HorizontalScroll.Visible = false;
  113.             panel5.HorizontalScroll.Maximum = 0;
  114.             panel5.AutoScroll = true;
  115.         }
  116.         private void Form1_MouseDown(object sender, MouseEventArgs e)
  117.         {
  118.             if (e.Button == MouseButtons.Left)
  119.             {
  120.                 label2.Focus();
  121.                 ReleaseCapture();
  122.                 SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
  123.             }
  124.         }
  125.         private void Close(object sender, EventArgs e)
  126.         {
  127.             Application.Exit();
  128.         }
  129.         private void Download_Button(object sender, EventArgs e)
  130.         {
  131.             if (bunifuMetroTextbox1.ForeColor == Color.FromArgb(150, 150, 150))
  132.             {
  133.                 DialogResult dialogResult = MessageBox.Show("Je vois que vous n'avez pas encore rempli la zone de texte,\nsouhaitez-vous malgré tout télécharger la vidéo d'exemple ?","Est-ce une erreur de votre part ?",MessageBoxButtons.YesNo);
  134.                 if (dialogResult == DialogResult.Yes)
  135.                 {
  136.                     bunifuMetroTextbox1.ForeColor = Color.FromArgb(255, 255, 255);
  137.                     bunifuMetroTextbox1.Text = "https://www.youtube.com/watch?v=5aopMm7UGYA";
  138.                     Download(bunifuMetroTextbox1.Text);
  139.                 }
  140.             } else
  141.             {
  142.                 Download(bunifuMetroTextbox1.Text);
  143.             }
  144.         }
  145.         private void Download(string url)
  146.         {
  147.             string[] parameters = extractParameters(url);
  148.             string ID = getParameter("v", parameters);
  149.             if (!String.IsNullOrWhiteSpace(ID))
  150.             {
  151.                 panel3.Visible = true;
  152.                 Thread newThread = new Thread(getLinks);
  153.                 newThread.Start(ID);
  154.             } else
  155.             {
  156.                 MessageBox.Show("Désolé, nos détecteurs intergalatiques ne sont pas en mesure de détecter la moindre vidéo YouTube sur ce lien.\nMerci de nous confier une url YouTube propre ;)");
  157.             }
  158.         }
  159.  
  160.         public static string[] extractParameters(string url)
  161.         {
  162.             string pat = @"[?&][^?&]+=[^?&]*";
  163.             Regex r = new Regex(pat, RegexOptions.IgnoreCase);
  164.             Match m = r.Match(url);
  165.             string[] result = new string[m.Length];
  166.             int i = 0;
  167.             while (m.Success)
  168.             {
  169.                 result[i++] = m.Value;
  170.                 m = m.NextMatch();
  171.             }
  172.             return result;
  173.         }
  174.         public static string getParameter(string name, string[] parameters)
  175.         {
  176.             string result = "";
  177.             string[] na;
  178.             string n;
  179.             for (int i = 0; i < parameters.Length; i++)
  180.             {
  181.                 n = parameters[i].Substring(1);
  182.                 if (!String.IsNullOrWhiteSpace(n))
  183.                 {
  184.                     na = n.Split('=');
  185.                     if (na[0] == name)
  186.                     {
  187.                         return na[1];
  188.                     }
  189.                 }
  190.  
  191.             }
  192.             return result;
  193.         }
  194.         public static string getInfoFromItag(string itag)
  195.         {
  196.             string info = "";
  197.  
  198.             if (itag == "5")
  199.             {
  200.                 info = "FLV;FLV, FLV1 H.263;240p;MP3 Stereo, 22.05 KHz 64.0 Kbps";
  201.             }
  202.             else if (itag == "6")
  203.             {
  204.                 info = "FLV;FLV;270p;No Audio";
  205.             }
  206.             else if (itag == "13")
  207.             {
  208.                 info = "3GP;3GP;Mobile;No Audio";
  209.             }
  210.             else if (itag == "17")
  211.             {
  212.                 info = "3GP;3GP, MPEG-4;144p;AAC, Mono 22.05 KHz 24.0 - 25.6 Kbps";
  213.             }
  214.             else if (itag == "18")
  215.             {
  216.                 info = "MP4;MP4, AVC (MPEG4 H.264);360p;AAC, Stereo, 44.1 KHz 96.0 - 100 Kbps";
  217.             }
  218.             else if (itag == "22")
  219.             {
  220.                 info = "MP4;MP4, AVC (MPEG4 H.264);720p;AAC, 44.1 KHz 192.0 - 201 Kbps";
  221.             }
  222.             else if (itag == "34")
  223.             {
  224.                 info = "FLV;FLV;360p;No Audio";
  225.             }
  226.             else if (itag == "35")
  227.             {
  228.                 info = "FLV;FLV;480p;No Audio";
  229.             }
  230.             else if (itag == "36")
  231.             {
  232.                 info = "3GP;3GP, MPEG4 H.263;240p;AAC, Mono, 22.05 KHz 32.0 - 34.2 Kbps";
  233.             }
  234.             else if (itag == "37")
  235.             {
  236.                 info = "MP4;MP4;1080p;No Audio";
  237.             }
  238.             else if (itag == "38")
  239.             {
  240.                 info = "MP4;MP4;3072p;No Audio";
  241.             }
  242.             else if (itag == "43")
  243.             {
  244.                 info = "WEBM;WEBM, VP8;360p;Vorbis, Stereo, 44.1 KHz 128 Kbps";
  245.             }
  246.             else if (itag == "44")
  247.             {
  248.                 info = "WEBM;WEBM;480p;No Audio";
  249.             }
  250.             else if (itag == "45")
  251.             {
  252.                 info = "WEBM;WEBM;720p;No Audio";
  253.             }
  254.             else if (itag == "46")
  255.             {
  256.                 info = "WEBM;WEBM;1080p;No Audio";
  257.             }
  258.             else if (itag == "82")
  259.             {
  260.                 info = "MP4;MP4, AVC (MPEG4 H.264);360p (3D);AAC, Stereo, 44.1 KHz 128 - 134 Kbps";
  261.             }
  262.             else if (itag == "83")
  263.             {
  264.                 info = "MP4;MP4;480p (3D);No Audio";
  265.             }
  266.             else if (itag == "84")
  267.             {
  268.                 info = "MP4;MP4, AVC (MPEG4 H.264);720p (3D);AAC, Stereo, 44.1 KHz 192 - 201 Kbps";
  269.             }
  270.             else if (itag == "85")
  271.             {
  272.                 info = "MP4;MP4;1080p (3D);No Audio";
  273.             }
  274.             else if (itag == "100")
  275.             {
  276.                 info = "WEBM;WEBM;360p (3D);No Audio";
  277.             }
  278.             else if (itag == "101")
  279.             {
  280.                 info = "WEBM;WEBM;480p (3D);No Audio";
  281.             }
  282.             else if (itag == "102")
  283.             {
  284.                 info = "WEBM;WEBM;720p (3D);No Audio";
  285.             }
  286.             else if (itag == "133")
  287.             {
  288.                 info = "MP4;MP4, DASH video;240p;No Audio";
  289.             }
  290.             else if (itag == "134")
  291.             {
  292.                 info = "MP4;MP4, DASH video;360p;No Audio";
  293.             }
  294.             else if (itag == "135")
  295.             {
  296.                 info = "MP4;MP4, DASH video;480p;No Audio";
  297.             }
  298.             else if (itag == "136")
  299.             {
  300.                 info = "MP4;MP4, DASH video;720p;No Audio";
  301.             }
  302.             else if (itag == "137")
  303.             {
  304.                 info = "MP4;MP4, DASH video;1080p;No Audio";
  305.             }
  306.             else if (itag == "138")
  307.             {
  308.                 info = "MP4;MP4, DASH video;2160p;No Audio";
  309.             }
  310.             else if (itag == "160")
  311.             {
  312.                 info = "MP4;MP4, DASH video;144p;No Audio";
  313.             }
  314.             else if (itag == "264")
  315.             {
  316.                 info = "MP4;MP4, DASH video;1440p;No Audio";
  317.             }
  318.             else if (itag == "298")
  319.             {
  320.                 info = "MP4;MP4, DASH video H.264;720p;No Audio";
  321.             }
  322.             else if (itag == "299")
  323.             {
  324.                 info = "MP4;MP4, DASH video H.264;1080p;No Audio";
  325.             }
  326.             else if (itag == "266")
  327.             {
  328.                 info = "MP4;MP4, DASH video H.264;2160p;No Audio";
  329.             }
  330.             else if (itag == "139")
  331.             {
  332.                 info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 48 Kbps";
  333.             }
  334.             else if (itag == "140")
  335.             {
  336.                 info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 128 Kbps";
  337.             }
  338.             else if (itag == "141")
  339.             {
  340.                 info = "M4A;M4A;No Video;AAC [DASH audio], Stereo, 44.1 KHz 256 Kbps";
  341.             }
  342.             else if (itag == "167")
  343.             {
  344.                 info = "WEBM;WEBM, VP8 DASH video;360p;No Audio";
  345.             }
  346.             else if (itag == "168")
  347.             {
  348.                 info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
  349.             }
  350.             else if (itag == "169")
  351.             {
  352.                 info = "WEBM;WEBM, VP8 DASH video;720p;No Audio";
  353.             }
  354.             else if (itag == "170")
  355.             {
  356.                 info = "WEBM;WEBM, VP8 DASH video;1080p;No Audio";
  357.             }
  358.             else if (itag == "218")
  359.             {
  360.                 info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
  361.             }
  362.             else if (itag == "219")
  363.             {
  364.                 info = "WEBM;WEBM, VP9 DASH video;144p;No Audio";
  365.             }
  366.             else if (itag == "220")
  367.             {
  368.                 info = "WEBM;WEBM, VP9 DASH video;144p;No Audio";
  369.             }
  370.             else if (itag == "242")
  371.             {
  372.                 info = "WEBM;WEBM, VP8 DASH video;240p;No Audio";
  373.             }
  374.             else if (itag == "243")
  375.             {
  376.                 info = "WEBM;WEBM, VP8 DASH video;360p;No Audio";
  377.             }
  378.             else if (itag == "244")
  379.             {
  380.                 info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
  381.             }
  382.             else if (itag == "245")
  383.             {
  384.                 info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
  385.             }
  386.             else if (itag == "246")
  387.             {
  388.                 info = "WEBM;WEBM, VP8 DASH video;480p;No Audio";
  389.             }
  390.             else if (itag == "247")
  391.             {
  392.                 info = "WEBM;WEBM, VP8 DASH video;720p;No Audio";
  393.             }
  394.             else if (itag == "248")
  395.             {
  396.                 info = "WEBM;WEBM, VP8 DASH video;1080p;No Audio";
  397.             }
  398.             else if (itag == "249")
  399.             {
  400.                 info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 50 KHz";
  401.             }
  402.             else if (itag == "250")
  403.             {
  404.                 info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 70 KHz";
  405.             }
  406.             else if (itag == "251")
  407.             {
  408.                 info = "WEBM;WEBM;No Video;OPUS [DASH audio], Stereo, 160 KHz";
  409.             }
  410.             else if (itag == "271")
  411.             {
  412.                 info = "WEBM;WEBM, VP8 DASH video;1440p;No Audio";
  413.             }
  414.             else if (itag == "272")
  415.             {
  416.                 info = "WEBM;WEBM, VP8 DASH video;2160p;No Audio";
  417.             }
  418.             else if (itag == "302")
  419.             {
  420.                 info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
  421.             }
  422.             else if (itag == "303")
  423.             {
  424.                 info = "WEBM;WEBM, VP9 DASH video;1080p;No Audio";
  425.             }
  426.             else if (itag == "308")
  427.             {
  428.                 info = "WEBM;WEBM, VP9 DASH video;1440p;No Audio";
  429.             }
  430.             else if (itag == "313")
  431.             {
  432.                 info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
  433.             }
  434.             else if (itag == "315")
  435.             {
  436.                 info = "WEBM;WEBM, VP9 DASH video;2160p;No Audio";
  437.             }
  438.             else if (itag == "171")
  439.             {
  440.                 info = "WEBM;WEBM;No Video;AAC [DASH audio], Stereo, 44.1 KHz 128 Kbps";
  441.             }
  442.             else if (itag == "172")
  443.             {
  444.                 info = "WEBM;WEBM;No Video;AAC [DASH audio], Stereo, 44.1 KHz 256 Kbps";
  445.             }
  446.  
  447.             return info;
  448.         }
  449.         private void getLinks(object ID)
  450.         {
  451.             string data = XmlHttpRequest("https://api.youtubemultidownloader.com/video?id=" + ID.ToString());
  452.             string pat = @"(https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])";
  453.             Regex r = new Regex(pat, RegexOptions.IgnoreCase);
  454.             Match m = r.Match(data);
  455.  
  456.             List<string> resultt = new string[] { }.ToList();
  457.  
  458.             //string[] result = new string[m.Length];
  459.             int i = 0;
  460.             while (m.Success)
  461.             {
  462.                 if (!String.IsNullOrWhiteSpace(m.Value))
  463.                 {
  464.                     resultt.Insert(i, m.Value);
  465.                     //result[i++] = m.Value;
  466.                 }
  467.                 m = m.NextMatch();
  468.             }
  469.             string[] result = resultt.ToArray<string>();
  470.  
  471.             string pat2 = @"^[^,]+,";
  472.             Regex r2 = new Regex(pat2, RegexOptions.IgnoreCase);
  473.             Match m2 = r2.Match(data);
  474.             string[] titleArr = new string[m2.Length];
  475.             int i2 = 0;
  476.             while (m2.Success)
  477.             {
  478.                 titleArr[i2++] = m2.Value;
  479.                 m2 = m.NextMatch();
  480.             }
  481.             string title = titleArr[0].Substring(10, titleArr[0].Length-12);
  482.  
  483.             Next(true,title,result,ID.ToString());
  484.         }
  485.         delegate void StringArgReturningVoidDelegate(bool b, string text, string[] urls, string ID);
  486.         private void Next(bool b, string text, string[] urls, string ID)
  487.         {
  488.             if (this.panel3.InvokeRequired)
  489.             {
  490.                 StringArgReturningVoidDelegate d = new StringArgReturningVoidDelegate(Next);
  491.                 this.Invoke(d, new object[] { b, text, urls, ID });
  492.             }
  493.             else
  494.             {
  495.                 this.panel5.Visible = b;
  496.                 this.label1.Text = text;
  497.                 this.pictureBox1.ImageLocation = "http://img.youtube.com/vi/" + ID + "/0.jpg";
  498.  
  499.                 Panel Container = new Panel();
  500.                 Container.BackColor = Color.FromArgb(33, 33, 33);
  501.                 Container.Location = bunifuSeparator1.Location;
  502.                 Container.Width = bunifuSeparator1.Width;
  503.                 Container.Height = urls.Length * 90 + 100;
  504.                 panel5.Controls.Add(Container);
  505.  
  506.  
  507.                 Array.Sort(urls, delegate (string a1, string a2) {
  508.                     string[] a1parameters = extractParameters(a1);
  509.                     string[] a1info = getInfoFromItag(getParameter("itag", a1parameters)).Split(';');
  510.                     string a1Extension = "Unknown";
  511.                     string a1Video = "Unknown";
  512.                     string a1Quality = "Unknown";
  513.                     string a1Audio = "Unknown";
  514.                     if (a1info.Length > 2)
  515.                     {
  516.                         a1Extension = a1info[0];
  517.                         a1Video = a1info[1];
  518.                         a1Quality = a1info[2];
  519.                         a1Audio = a1info[3];
  520.                     }
  521.  
  522.  
  523.                     string[] a2parameters = extractParameters(a2);
  524.                     string[] a2info = getInfoFromItag(getParameter("itag", a2parameters)).Split(';');
  525.                     string a2Extension = "Unknown";
  526.                     string a2Video = "Unknown";
  527.                     string a2Quality = "Unknown";
  528.                     string a2Audio = "Unknown";
  529.                     if (a2info.Length > 2)
  530.                     {
  531.                         a2Extension = a2info[0];
  532.                         a2Video = a2info[1];
  533.                         a2Quality = a2info[2];
  534.                         a2Audio = a2info[3];
  535.                     }
  536.  
  537.  
  538.                     if (a1Audio == "No Audio")
  539.                     {
  540.                         return 1;
  541.                     }
  542.                     if (a2Audio == "No Audio")
  543.                     {
  544.                         return -1;
  545.                     }
  546.  
  547.                     if (a1Quality == "No Video")
  548.                     {
  549.                         return 1;
  550.                     }
  551.                     if (a2Quality == "No Video")
  552.                     {
  553.                         return -1;
  554.                     }
  555.  
  556.  
  557.                     return a2Quality.CompareTo(a1Quality);
  558.                 });
  559.  
  560.                 int i;
  561.                 int j = 0;
  562.                 for (i = 0; i < urls.Length; i++)
  563.                 {
  564.                     string[] parameters = extractParameters(urls[i]);
  565.                     //string mime = HttpUtility.UrlDecode(getParameter("mime", parameters));
  566.                     string[] info = getInfoFromItag(getParameter("itag", parameters)).Split(';');
  567.  
  568.                     string Extension = "Unknown";
  569.                     string Video = "Unknown";
  570.                     string Quality = "Unknown";
  571.                     string Audio = "Unknown";
  572.  
  573.                     if (info.Length > 2)
  574.                     {
  575.                         Extension = info[0];
  576.                         Video = info[1];
  577.                         Quality = info[2];
  578.                         Audio = info[3];
  579.                     }
  580.  
  581.                     if (Video != "Unknown")
  582.                     {
  583.                         Panel tmp = new Panel();
  584.                         tmp.BackColor = Color.FromArgb(46, 139, 87);
  585.                         tmp.Top = 90 * j + 20;
  586.                         tmp.Left = 0;
  587.                         tmp.Width = bunifuSeparator1.Width;
  588.                         tmp.Height = 80;
  589.  
  590.  
  591.                         Panel Panel_Quality = new Panel();
  592.                         Panel_Quality.BackColor = Color.FromArgb(100, 255, 255, 255);
  593.                         Panel_Quality.Top = 5;
  594.                         Panel_Quality.Width = Quality.Length * 8 + 30;
  595.                         Panel_Quality.Left = tmp.Width - (Panel_Quality.Width + 5);
  596.                         Panel_Quality.Height = 30;
  597.  
  598.                         Label Text_Quality = new Label();
  599.                         Text_Quality.ForeColor = Color.FromArgb(33, 33, 33);
  600.                         Text_Quality.Font = new Font("Century Gothic", 10);
  601.                         Text_Quality.AutoSize = false;
  602.                         Text_Quality.TextAlign = ContentAlignment.MiddleCenter;
  603.                         Text_Quality.Dock = DockStyle.Fill;
  604.                         Text_Quality.Text = Quality;
  605.  
  606.  
  607.                         Panel Panel_Audio = new Panel();
  608.                         Panel_Audio.BackColor = Color.FromArgb(100, 255, 255, 255);
  609.                         Panel_Audio.Top = 5;
  610.                         Panel_Audio.Width = Audio.Length * 8 + 30;
  611.                         Panel_Audio.Left = tmp.Width - (Panel_Quality.Width + Panel_Audio.Width + 10);
  612.                         Panel_Audio.Height = 30;
  613.  
  614.                         Label Text_Audio = new Label();
  615.                         Text_Audio.ForeColor = Color.FromArgb(33, 33, 33);
  616.                         Text_Audio.Font = new Font("Century Gothic", 10);
  617.                         Text_Audio.AutoSize = false;
  618.                         Text_Audio.TextAlign = ContentAlignment.MiddleCenter;
  619.                         Text_Audio.Dock = DockStyle.Fill;
  620.                         Text_Audio.Text = Audio;
  621.  
  622.  
  623.                         Panel Panel_Video = new Panel();
  624.                         Panel_Video.BackColor = Color.FromArgb(100, 255, 255, 255);
  625.                         Panel_Video.Top = 5;
  626.                         Panel_Video.Width = tmp.Width - (Panel_Quality.Width + Panel_Audio.Width + 20);
  627.                         Panel_Video.Left = 5;
  628.                         Panel_Video.Height = 30;
  629.  
  630.                         Label Text_Video = new Label();
  631.                         Text_Video.ForeColor = Color.FromArgb(33, 33, 33);
  632.                         Text_Video.Font = new Font("Century Gothic", 10);
  633.                         Text_Video.AutoSize = false;
  634.                         Text_Video.TextAlign = ContentAlignment.MiddleCenter;
  635.                         Text_Video.Dock = DockStyle.Fill;
  636.                         Text_Video.Text = Video;
  637.  
  638.  
  639.                        
  640.                         Panel Panel_Download = new Panel();
  641.                         Panel_Download.BackColor = Color.FromArgb(255, 255, 255);
  642.                         Panel_Download.Top = 40;
  643.                         Panel_Download.Width = tmp.Width - 10;
  644.                         Panel_Download.Left = 5;
  645.                         Panel_Download.Height = 35;
  646.  
  647.                         ProgressBar pbb = new ProgressBar();
  648.                         pbb.Dock = DockStyle.Fill;
  649.                         pbb.Visible = false;
  650.  
  651.  
  652.                         Label Text_Download = new Label();
  653.                         Text_Download.BackColor = Color.FromArgb(0, 0, 0, 0);
  654.                         Text_Download.ForeColor = Color.FromArgb(33, 33, 33);
  655.                         Text_Download.Font = new Font("Century Gothic", 15);
  656.                         Text_Download.AutoSize = false;
  657.                         Text_Download.TextAlign = ContentAlignment.MiddleCenter;
  658.                         Text_Download.Dock = DockStyle.Fill;
  659.                         Text_Download.Text = "Télécharger !";
  660.                         Text_Download.Tag = urls[i] + ";" + text + ";" + Extension + ";" + Quality;
  661.                         Text_Download.MouseEnter += Panel_Download_Enter;
  662.                         Text_Download.MouseLeave += Panel_Download_Leave;
  663.                         Text_Download.Click += (sender2, e2) => Panel_Download_Click(sender2, e2, pbb);
  664.  
  665.                         Panel_Download.Controls.Add(pbb);
  666.                         Panel_Download.Controls.Add(Text_Download);
  667.                        
  668.  
  669.  
  670.  
  671.                         tmp.Controls.Add(Panel_Download);
  672.  
  673.  
  674.  
  675.  
  676.                         Panel_Quality.Controls.Add(Text_Quality);
  677.                         Panel_Audio.Controls.Add(Text_Audio);
  678.                         Panel_Video.Controls.Add(Text_Video);
  679.  
  680.  
  681.                         tmp.Controls.Add(Panel_Quality);
  682.                         tmp.Controls.Add(Panel_Audio);
  683.                         tmp.Controls.Add(Panel_Video);
  684.  
  685.  
  686.                         Container.Controls.Add(tmp);
  687.                         j++;
  688.                     }
  689.                 }
  690.  
  691.                 Panel Panel_Re = new Panel();
  692.                 Panel_Re.BackColor = Color.FromArgb(255, 255, 255);
  693.                 Panel_Re.Top = (urls.Length-1) * 90 + 40;
  694.                 Panel_Re.Width = bunifuSeparator1.Width;
  695.                 Panel_Re.Left = 0;
  696.                 Panel_Re.Height = 45;
  697.                
  698.  
  699.  
  700.                 Label Text_Re = new Label();
  701.                 Text_Re.BackColor = Color.FromArgb(0, 0, 0, 0);
  702.                 Text_Re.ForeColor = Color.FromArgb(255, 0, 0);
  703.                 Text_Re.Font = new Font("Century Gothic", 20);
  704.                 Text_Re.AutoSize = false;
  705.                 Text_Re.TextAlign = ContentAlignment.MiddleCenter;
  706.                 Text_Re.Dock = DockStyle.Fill;
  707.                 Text_Re.Text = "Télécharger une autre vidéo !";
  708.                 Text_Re.MouseEnter += Panel_Re_Enter;
  709.                 Text_Re.MouseLeave += Panel_Re_Leave;
  710.                 Text_Re.Click += (sender2, e2) => Panel_Re_Click(sender2, e2, Container);
  711.  
  712.                 Panel_Re.Controls.Add(Text_Re);
  713.                 Container.Controls.Add(Panel_Re);
  714.             }
  715.         }
  716.  
  717.         private void Panel_Download_Click(object sender, EventArgs e, object progressBar)
  718.         {
  719.             Label senderLabel = (Label)sender;
  720.             ProgressBar pb = progressBar as ProgressBar;
  721.             pb.Visible = true;
  722.             string[] Info = senderLabel.Tag.ToString().Split(';');
  723.  
  724.             string url = Info[0];
  725.             string title = Info[1];
  726.             string extension = Info[2];
  727.             string quality = Info[3];
  728.             string filename = title + "." + quality + "." + extension.ToLower();
  729.  
  730.             SaveFileDialog saveFileDialog = new SaveFileDialog();
  731.             saveFileDialog.RestoreDirectory = true;
  732.             saveFileDialog.FileName = filename;
  733.             if (saveFileDialog.ShowDialog() == DialogResult.OK)
  734.             {
  735.                 WebClient client = new WebClient();
  736.                 client.DownloadProgressChanged += (sender2, e2) => On_Download(sender2, e2, progressBar);
  737.                 client.DownloadFileCompleted += (sender2, e2) => On_EndDownload(sender2, e2, progressBar);
  738.                 client.DownloadFileAsync(new Uri(url), saveFileDialog.FileName);
  739.             }
  740.         }
  741.         void On_Download(object sender, DownloadProgressChangedEventArgs e, object progressBar)
  742.         {
  743.             ProgressBar pb = progressBar as ProgressBar;
  744.             pb.Value = e.ProgressPercentage;
  745.         }
  746.         void On_EndDownload(object sender, EventArgs e, object progressBar)
  747.         {
  748.             ProgressBar pb = progressBar as ProgressBar;
  749.             pb.Visible = false;
  750.             pb.Value = 0;
  751.             MessageBox.Show("Téléchargement terminé !");
  752.         }
  753.         private void Panel_Download_Enter(object sender, EventArgs e)
  754.         {
  755.             Label senderLabel = (Label)sender;
  756.             senderLabel.ForeColor = Color.FromArgb(255, 255, 255);
  757.             senderLabel.Cursor = Cursors.Hand;
  758.             senderLabel.Parent.BackColor = Color.FromArgb(33, 33, 33);
  759.         }
  760.         private void Panel_Download_Leave(object sender, EventArgs e)
  761.         {
  762.             Label senderLabel = (Label)sender;
  763.             senderLabel.ForeColor = Color.FromArgb(33, 33, 33);
  764.             senderLabel.Cursor = Cursors.Default;
  765.             senderLabel.Parent.BackColor = Color.FromArgb(255, 255, 255);
  766.         }
  767.  
  768.         private void Panel_Re_Click(object sender, EventArgs e, object panel)
  769.         {
  770.             this.panel3.Visible = false;
  771.             this.panel5.Visible = false;
  772.             Panel Container = (Panel)panel;
  773.             Container.Dispose();
  774.         }
  775.         private void Panel_Re_Enter(object sender, EventArgs e)
  776.         {
  777.             Label senderLabel = (Label)sender;
  778.             senderLabel.ForeColor = Color.FromArgb(255, 255, 255);
  779.             senderLabel.Cursor = Cursors.Hand;
  780.             senderLabel.Parent.BackColor = Color.FromArgb(255, 0, 0);
  781.         }
  782.         private void Panel_Re_Leave(object sender, EventArgs e)
  783.         {
  784.             Label senderLabel = (Label)sender;
  785.             senderLabel.ForeColor = Color.FromArgb(255, 0, 0);
  786.             senderLabel.Cursor = Cursors.Default;
  787.             senderLabel.Parent.BackColor = Color.FromArgb(255, 255, 255);
  788.         }
  789.  
  790.         public static string XmlHttpRequest(string urlString)
  791.         {
  792.             string response = null;
  793.             HttpWebRequest httpWebRequest = null;//Declare an HTTP-specific implementation of the WebRequest class.
  794.             HttpWebResponse httpWebResponse = null;//Declare an HTTP-specific implementation of the WebResponse class
  795.  
  796.             //Creates an HttpWebRequest for the specified URL.
  797.             httpWebRequest = (HttpWebRequest)WebRequest.Create(urlString);
  798.  
  799.             try
  800.             {
  801.                 //Set HttpWebRequest properties
  802.                 httpWebRequest.Method = "GET";
  803.  
  804.                 //Sends the HttpWebRequest, and waits for a response.
  805.                 httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  806.  
  807.                 if (httpWebResponse.StatusCode == HttpStatusCode.OK)
  808.                 {
  809.                     //Get response stream into StreamReader
  810.                     using (Stream responseStream = httpWebResponse.GetResponseStream())
  811.                     {
  812.                         using (StreamReader reader = new StreamReader(responseStream))
  813.                             response = reader.ReadToEnd();
  814.                     }
  815.                 }
  816.                 httpWebResponse.Close();//Close HttpWebResponse
  817.             }
  818.             catch (WebException we)
  819.             {   //TODO: Add custom exception handling
  820.                 throw new Exception(we.Message);
  821.             }
  822.             catch (Exception ex) { throw new Exception(ex.Message); }
  823.             finally
  824.             {
  825.                 httpWebResponse.Close();
  826.                 //Release objects
  827.                 httpWebResponse = null;
  828.                 httpWebRequest = null;
  829.             }
  830.             return response;
  831.         }
  832.     }
  833. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement