|
10 | 10 | using System.Windows.Forms; |
11 | 11 | using YoutubeExtractor; |
12 | 12 |
|
13 | | -namespace Ytd_Extractor |
| 13 | +namespace TubeDl |
14 | 14 | { |
15 | 15 | public partial class Main : Form |
16 | 16 | { |
@@ -58,97 +58,97 @@ private void btndownload_Click(object sender, EventArgs e) |
58 | 58 | * Execute the video downloader. |
59 | 59 | * For GUI applications note, that this method runs synchronously. |
60 | 60 | */ |
61 | | - //try |
62 | | - //{ |
63 | | - btndownload.Enabled = false; |
| 61 | + try |
| 62 | + { |
| 63 | + btndownload.Enabled = false; |
64 | 64 |
|
65 | 65 |
|
66 | | - var ext = video.Resolution.ToString(); |
67 | | - if (ext == "0") |
68 | | - ext = ".mp3"; |
69 | | - else |
70 | | - ext = ".Mp4"; |
71 | | - bool found = true; |
| 66 | + var ext = video.Resolution.ToString(); |
| 67 | + if (ext == "0") |
| 68 | + ext = ".mp3"; |
| 69 | + else |
| 70 | + ext = ".Mp4"; |
| 71 | + bool found = true; |
72 | 72 |
|
73 | | - ListViewItem item = list_Items.FindItemWithText(name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString())); |
| 73 | + ListViewItem item = list_Items.FindItemWithText(name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString())); |
74 | 74 |
|
75 | | - if (item != null) |
76 | | - MessageBox.Show("Video Already in downloading", Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); |
77 | | - // video exists |
| 75 | + if (item != null) |
| 76 | + MessageBox.Show("Video Already in downloading", Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); |
| 77 | + // video exists |
78 | 78 |
|
79 | | - else |
80 | | - { |
| 79 | + else |
| 80 | + { |
81 | 81 |
|
82 | | - // doesn't exist |
| 82 | + // doesn't exist |
83 | 83 |
|
84 | 84 |
|
85 | | - if (File.Exists(Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString()) + ext))) |
86 | | - { |
87 | | - if (MessageBox.Show("File Already exist, Replace?", Text, |
88 | | - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
| 85 | + if (File.Exists(Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString()) + ext))) |
| 86 | + { |
| 87 | + if (MessageBox.Show("File Already exist, Replace?", Text, |
| 88 | + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) |
| 89 | + { |
| 90 | + File.Delete(Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString()) + ext)); |
| 91 | + |
| 92 | + int indx = list_Items.Items.Count; |
| 93 | + list_Items.Items.Add(name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString())); |
| 94 | + for (int i = 1; i < 6; i++) |
| 95 | + { |
| 96 | + list_Items.Items[indx].SubItems.Add(""); |
| 97 | + } |
| 98 | + |
| 99 | + DownloadHelper.downloadFile d = |
| 100 | + new DownloadHelper.downloadFile(url, Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString()) + ext)); |
| 101 | + ldf.Add(d); |
| 102 | + |
| 103 | + Action<int, int, object> act1 = new Action<int, int, object>(delegate (int idx, int sidx, object obj) |
| 104 | + { list_Items.Invoke(new Action(() => list_Items.Items[idx].SubItems[sidx].Text = obj.ToString())); }); |
| 105 | + |
| 106 | + d.eSize += (object s1, string size) => act1.Invoke(indx, 1, size); |
| 107 | + d.eDownloadedSize += (object s1, string size) => act1.Invoke(indx, 2, size); |
| 108 | + d.eSpeed += (object s1, string size) => act1.Invoke(indx, 3, size); |
| 109 | + d.eDownloadState += (object s1, string size) => act1.Invoke(indx, 4, size); |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + btndownload.Enabled = true; |
| 114 | + btnPause.Enabled = false; |
| 115 | + } |
| 116 | + } |
| 117 | + else |
89 | 118 | { |
90 | | - File.Delete(Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString()) + ext)); |
91 | | - |
92 | 119 | int indx = list_Items.Items.Count; |
93 | | - list_Items.Items.Add(name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString())); |
| 120 | + list_Items.Items.Add(name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString())); |
94 | 121 | for (int i = 1; i < 6; i++) |
95 | 122 | { |
96 | 123 | list_Items.Items[indx].SubItems.Add(""); |
97 | 124 | } |
98 | 125 |
|
99 | | - DownloadHelper.downloadFile d = |
100 | | - new DownloadHelper.downloadFile(url, Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString()) + ext)); |
| 126 | + DownloadHelper.downloadFile d = new DownloadHelper.downloadFile(url, Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext.Replace(".", "") : video.Resolution.ToString()) + ext)); |
101 | 127 | ldf.Add(d); |
102 | 128 |
|
103 | 129 | Action<int, int, object> act1 = new Action<int, int, object>(delegate (int idx, int sidx, object obj) |
104 | | - { list_Items.Invoke(new Action(() => list_Items.Items[idx].SubItems[sidx].Text = obj.ToString())); }); |
| 130 | + { |
| 131 | + list_Items.Invoke(new Action(() => list_Items.Items[idx].SubItems[sidx].Text = obj.ToString())); |
| 132 | + }); |
105 | 133 |
|
106 | 134 | d.eSize += (object s1, string size) => act1.Invoke(indx, 1, size); |
107 | 135 | d.eDownloadedSize += (object s1, string size) => act1.Invoke(indx, 2, size); |
108 | 136 | d.eSpeed += (object s1, string size) => act1.Invoke(indx, 3, size); |
109 | 137 | d.eDownloadState += (object s1, string size) => act1.Invoke(indx, 4, size); |
110 | 138 | } |
111 | | - else |
112 | | - { |
113 | | - btndownload.Enabled = true; |
114 | | - btnPause.Enabled = false; |
115 | | - } |
116 | | - } |
117 | | - else |
118 | | - { |
119 | | - int indx = list_Items.Items.Count; |
120 | | - list_Items.Items.Add(name + " "+ (video.Resolution == 0 ? ext : video.Resolution.ToString())); |
121 | | - for (int i = 1; i < 6; i++) |
122 | | - { |
123 | | - list_Items.Items[indx].SubItems.Add(""); |
124 | | - } |
125 | | - |
126 | | - DownloadHelper.downloadFile d = new DownloadHelper.downloadFile(url, Path.Combine(savePath, name + " " + (video.Resolution == 0 ? ext : video.Resolution.ToString()) + ext)); |
127 | | - ldf.Add(d); |
128 | | - |
129 | | - Action<int, int, object> act1 = new Action<int, int, object>(delegate (int idx, int sidx, object obj) |
130 | | - { |
131 | | - list_Items.Invoke(new Action(() => list_Items.Items[idx].SubItems[sidx].Text = obj.ToString())); |
132 | | - }); |
133 | | - |
134 | | - d.eSize += (object s1, string size) => act1.Invoke(indx, 1, size); |
135 | | - d.eDownloadedSize += (object s1, string size) => act1.Invoke(indx, 2, size); |
136 | | - d.eSpeed += (object s1, string size) => act1.Invoke(indx, 3, size); |
137 | | - d.eDownloadState += (object s1, string size) => act1.Invoke(indx, 4, size); |
138 | 139 | } |
139 | 140 | } |
140 | | - //} |
141 | | - //catch (Exception ex) |
142 | | - //{ |
143 | | - // MessageBox.Show(ex.Message); |
144 | | - // btndownload.Enabled = true; |
145 | | - // btnPause.Enabled = false; |
| 141 | + catch (Exception ex) |
| 142 | + { |
| 143 | + MessageBox.Show(ex.Message); |
| 144 | + btndownload.Enabled = true; |
| 145 | + btnPause.Enabled = false; |
146 | 146 |
|
147 | | - //} |
| 147 | + } |
148 | 148 |
|
149 | 149 | } |
150 | 150 |
|
151 | | - |
| 151 | + /* |
152 | 152 | public void DownloadFile(string urlAddress, string location) |
153 | 153 | { |
154 | 154 | using (webClient = new WebClient()) |
@@ -213,7 +213,7 @@ private void Completed(object sender, AsyncCompletedEventArgs e) |
213 | 213 | File.Move(Path.Combine(savePath, name + ".tubedl"), Path.Combine(savePath, name + video.VideoExtension)); |
214 | 214 | } |
215 | 215 | } |
216 | | - |
| 216 | + */ |
217 | 217 | private void Main_Load(object sender, EventArgs e) |
218 | 218 | { |
219 | 219 | #if DEBUG |
@@ -331,7 +331,7 @@ private void button1_Click(object sender, EventArgs e) |
331 | 331 | RemoveIllegalPathCharacters(video.Title); |
332 | 332 | btndownload.Enabled = true; |
333 | 333 | #if DEBUG |
334 | | - MessageBox.Show(url + "\n" + savePath + "\n" + name); |
| 334 | + // MessageBox.Show(url + "\n" + savePath + "\n" + name); |
335 | 335 |
|
336 | 336 | #endif |
337 | 337 | } |
|
0 commit comments