-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
1293 lines (1058 loc) · 48.3 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework;
using MetroFramework.Forms;
using Microsoft.VisualBasic;
using System.Globalization;
using System.Resources;
using System.Threading;
using WK.Libraries.BetterFolderBrowserNS;
using System.Security.Principal;
using MediaHarbor.Properties;
using Newtonsoft.Json.Linq;
using System.Linq;
using MediaHarbor.Classes;
using Newtonsoft.Json;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static MediaHarbor.Form1;
namespace MediaHarbor
{
public partial class Form1 : MetroForm
{
private List<string> songUrls = new List<string>();
private string ApiKey = "YOUR_API_KEY";
public string downloadDir;
public string downloadDir2;
public string downloadDir3;
string userLanguage = CultureInfo.InstalledUICulture.Name;
public string MP3Folder, MP4Folder;
public string LightTheme = Properties.Resources.lightTheme;
public string DarkTheme = Properties.Resources.darkTheme;
public string ThemeOption;
LanguageManager manager = new LanguageManager();
ThemeString themeString = new ThemeString();
public Form1()
{
InitializeComponent();
manager.SetCommonTranslations();
metroTextBox3.Text = manager.youtubeSearch;
comboBox2.Items.Add(manager.lightTheme);
comboBox2.Items.Add(manager.darkTheme);
richTextBox1.ReadOnly = true;
richTextBox2.ReadOnly = true;
richTextBox3.ReadOnly = true;
// richTextBox1 için renk değişimi
richTextBox1.ForeColor = Color.Black;
richTextBox1.BackColor = Color.White;
// richTextBox4 için renk değişimi
richTextBox4.ForeColor = Color.Black;
richTextBox4.BackColor = Color.White;
// richTextBox2 için renk değişimi
richTextBox2.ForeColor = Color.Black;
richTextBox2.BackColor = Color.White;
// richTextBox3 için renk değişimi
richTextBox3.ForeColor = Color.Black;
richTextBox3.BackColor = Color.White;
MP3Folder = $"\\MP3";
MP4Folder = $"\\MP4";
MP3Folder = $"\\MP3";
MP4Folder = $"\\MP4";
metroLabel9.Text = manager.appTheme;
notifyIcon2.BalloonTipClicked += NotifyIcon2_BalloonTipClicked;
MetroFramework.Components.MetroStyleManager styleManager = new MetroFramework.Components.MetroStyleManager();
styleManager.Owner = this;
styleManager.Style = MetroFramework.MetroColorStyle.Purple;
styleManager.Theme = MetroFramework.MetroThemeStyle.Default;
LoadSettings();
ChangeLanguage(userLanguage);
disneyAdet.Location = new System.Drawing.Point(metroLabel2.Right, disneyAdet.Top);
metroTextBox1.Location = new System.Drawing.Point(metroLabel3.Right, metroTextBox1.Top);
comboBox2.SelectedIndexChanged += ComboBox2_SelectedIndexChanged;
}
public class ThemeString
{
public string SelectedTheme { get; set; }
}
private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
// ComboBox'ın seçili öğesine göre tema ayarını değiştir
string selectedTheme = comboBox2.SelectedItem.ToString();
SetTheme(selectedTheme);
}
private void metroCheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void searchButton_ClickAsync(object sender, EventArgs e)
{
if (comboBox2.SelectedItem == manager.lightTheme)
{
ThemeOption = manager.lightTheme;
}
else if (comboBox2.SelectedItem == manager.darkTheme)
{
ThemeOption = manager.darkTheme;
}
ShowSearchResults();
}
private async Task ShowSearchResults()
{
string searchQuery = metroTextBox3.Text;
var videos = await SearchYouTubeVideos(searchQuery);
// SearchResultsForm'u aç ve arama sonuçlarını göster
SearchResultForm searchResultForm = new SearchResultForm(videos);
searchResultForm.ShowDialog();
}
int maxResults = 12;
private async Task<List<YouTubeVideo>> SearchYouTubeVideos(string query)
{
List<YouTubeVideo> videos = new List<YouTubeVideo>();
string apiUrl = $"https://www.googleapis.com/youtube/v3/search?q={Uri.EscapeDataString(query)}&key={ApiKey}&part=snippet&type=video&maxResults={maxResults}";
using (HttpClient client = new HttpClient())
{
try
{
var response = await client.GetStringAsync(apiUrl);
dynamic result = JsonConvert.DeserializeObject(response);
foreach (var item in result.items)
{
string videoId = item.id.videoId;
string videoTitle = item.snippet.title;
videos.Add(new YouTubeVideo { VideoId = videoId, Title = videoTitle });
}
}
catch (HttpRequestException ex)
{
// API isteği sırasında bir hata oluştuğunda
throw new HttpRequestException($"API Request Error: {ex.Message}");
}
catch (Exception ex)
{
// Diğer genel hata durumları için
throw new Exception($"There was an error: {ex.Message}");
}
}
return videos;
}
private void resultsListBox_DoubleClick(object sender, EventArgs e)
{
}
private void metroTextBox3_Enter(object sender, EventArgs e)
{
if (metroTextBox3.Text == manager.youtubeSearch)
{
metroTextBox3.Text = "";
metroTextBox3.ForeColor = SystemColors.WindowText;
}
}
private void metroTextBox3_Leave(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(metroTextBox3.Text))
{
metroTextBox3.Text = manager.youtubeSearch;
metroTextBox3.ForeColor = SystemColors.GrayText;
}
}
private void metroTextBox3_TextChanged(object sender, EventArgs e)
{
if (metroTextBox3.Text != manager.youtubeSearch)
{
metroTextBox3.ForeColor = SystemColors.WindowText;
}
}
private void metroTextBox3_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
GenericDownload();
//Düzeltilecek
}
private string enteratleastone, selectdownloadlocfirst, musicDownloadErrorText, entersongpodcasturl, pleasecheckapp, songURL, song, songkey;
private string updateNotification, newUpdateText, noUpdateMessage, noUpdateText;
private string downloadLocationText, downloadText, folderNotFoundText, howManyText, movieText, playlistText, processCompleteText, saveLocationText, seriesText, shutdownPCText, startText, openText, error, selectFolderText, downloads, noUpdate;
private string alreadyUpdatedText, ytdlpUpdate, updatingPleaseWait, updateError, updateCompleted, updateCompletedMessage, selectDownloadLocationText, inputCorrectint, movieseriesaudioformat, movieseriesvideoformat, movieserieskeyformat;
private string moviename, movieyear, seriesname, seriesseason, seriesstartep, moviecompleted, episodenumber, downloadcompleteText, downloadCompleteMessage, filenamingText, enterTextMessage, downloadError, shuttingdownText, enteryoutubelinkText, doformatselectionText;
private string autoUpdateText;
private bool isAdminMode = false;
private void ChangeLanguage(string cultureCode)
{
string currentCulture = CultureInfo.CurrentCulture.Name;
if (currentCulture == "tr-TR")
{
searchButton.Text = manager.searchText;
metroTabPage7.Text = manager.searchText;
metroLabel9.Text = manager.appTheme;
button1.Text = manager.downloadText;
metroCheckBox1.Text = manager.shutdownPCText;
autoUpdateText = Properties.Resources.ytdlpAutoUpdateText;
metroLabel5.Text = autoUpdateText;
richTextBox1.Text = Properties.Resources.richTextBox1_Text;
metroLabel2.Text = manager.howManyText;
button2.Text = manager.downloadText;
metroButton3.Text = manager.openText;
metroButton4.Text = manager.openText;
metroLabel4.Text = manager.downloadLocationText;
metroButton2.Text = manager.downloadText;
metroButton1.Text = manager.startText;
metroCheckBox2.Text = manager.playlistText;
movieText = manager.movieText;
seriesText = manager.seriesText;
metroLabel1.Text = manager.downloadLocationText;
metroLabel3.Text = manager.howManyText;
button2.Text = "İndir";
metroButton2.Text = "İndir";
manager.SetCommonTranslations();
}
else if (currentCulture == "tr-TR")
{
searchButton.Text = manager.searchText;
metroLabel9.Text = manager.appTheme;
updateNotification = "Update Avilable";
newUpdateText = "New Version:";
noUpdateMessage = "No Update";
noUpdateText = "You're Using Lastest Version.";
metroTabPage2.Text = "Generic";
metroTabPage5.Text = "Help";
metroTabPage4.Text = "Settings";
button2.Text = "Download";
metroButton2.Text = "Download";
button1.Text = manager.downloadText;
metroCheckBox1.Text = manager.shutdownPCText;
autoUpdateText = Properties.Resources.ytdlpAutoUpdateText;
metroLabel5.Text = autoUpdateText;
richTextBox1.Text = Properties.Resources.richTextBox1_Text;
metroLabel2.Text = manager.howManyText;
button2.Text = manager.downloadText;
metroButton3.Text = manager.openText;
metroButton4.Text = manager.openText;
metroLabel4.Text = manager.downloadLocationText;
metroButton2.Text = manager.downloadText;
metroButton1.Text = manager.startText;
metroCheckBox2.Text = manager.playlistText;
movieText = manager.movieText;
seriesText = manager.seriesText;
metroLabel1.Text = manager.downloadLocationText;
metroLabel3.Text = manager.howManyText;
manager.SetCommonTranslations();
movieText = metroRadioButton1.Text;
seriesText = metroRadioButton2.Text;
metroLabel1.Text = downloadLocationText;
metroLabel3.Text = howManyText;
manager.SetCommonTranslations();
}
else
{
movieText = metroRadioButton1.Text;
seriesText = metroRadioButton2.Text;
metroLabel1.Text = downloadLocationText;
metroLabel3.Text = howManyText;
manager.SetCommonTranslations();
}
}
private void NotifyIcon2_BalloonTipClicked(object sender, EventArgs e)
{
}
private void ShowNotification(string title, string content)
{
notifyIcon1.Visible = true;
notifyIcon1.Icon = Icon;
notifyIcon1.BalloonTipTitle = title;
notifyIcon1.BalloonTipText = content;
notifyIcon1.ShowBalloonTip(1000); // Bildirimi 1 saniye boyunca göster
notifyIcon1.Visible = true;
}
private void ProcessNotification(string title2, string content2)
{
notifyIcon2.Visible = true;
notifyIcon2.Icon = Icon;
notifyIcon2.BalloonTipTitle = title2;
notifyIcon2.BalloonTipText = content2;
notifyIcon2.ShowBalloonTip(3000);
notifyIcon2.Visible = false;
}
private bool isUpdateRequested = false;
private string ffmpegPath = ""; // ffmpeg.exe konumunu tutacak değişken
private void directory_button_Click(object sender, EventArgs e)
{
var folderBrowser = new BetterFolderBrowser
{
Title = manager.selectFolderText,
Multiselect = false
};
this.TopMost = false;
if (folderBrowser.ShowDialog() == DialogResult.OK)
{
string selectedFolderPath = folderBrowser.SelectedPath;
saveDirectory.Text = selectedFolderPath;
downloadDir = selectedFolderPath;
downloadDir2 = Path.Combine(downloadDir, "MediaHarbor");
downloadDir3 = Path.Combine(downloadDir2, "Spotify");
if (!Directory.Exists(downloadDir2))
{
Directory.CreateDirectory(downloadDir2);
}
}
this.TopMost = true;
}
private async Task UpdateYtDlpAsync()
{
try
{
Process process = new Process();
process.StartInfo.FileName = ".\\yt-dlp.exe";
process.StartInfo.Arguments = "-U";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
string output = await process.StandardOutput.ReadToEndAsync();
// Güncelleme işlemi başarıyla tamamlandıysa bildirimi göster
if (output.Contains("yt-dlp is up to date"))
{
ShowNotification($"{manager.noUpdate}", $"{manager.alreadyUpdatedText}");
}
else if (output.Contains("Updating to"))
{
MessageBox.Show($"{manager.updatingPleaseWait}", $"{manager.ytdlpUpdate}");
ShowNotification($"{manager.ytdlpUpdate}", $"{manager.updatingPleaseWait}");
}
else
{
MessageBox.Show($"{manager.updateError}");
}
if (output.Contains("Updated yt-dlp to"))
{
ShowNotification($"{manager.updateCompleted}", $"{manager.updateCompletedMessage}");
}
}
catch (Exception ex)
{
MessageBox.Show($"{manager.updateError}: {ex.Message}");
}
}
private async void Form1_Load(object sender, EventArgs e)
{
MP3Folder = Path.Combine(downloadDir, "MediaHarbor");
MP4Folder = Path.Combine(downloadDir, "MediaHarbor");
metroTabControl1.SelectedTab = metroTabPage6;
string systemCulture = System.Globalization.CultureInfo.CurrentCulture.Name;
GitHubUpdater.CheckForUpdates(systemCulture);
if (metroToggle1.Checked)
{
// Form yüklenmişse ve otomatik güncelleme isteği yapılmışsa güncelleme işlemini başlat
if (IsHandleCreated)
{
await UpdateYtDlpAsync();
}
else
{
// Form henüz yüklenmemişse, güncelleme isteği yapılmış durumda olduğunu işaretle
isUpdateRequested = true;
}
}
else
{
isUpdateRequested = false;
}
ffmpegPath = Path.Combine(Application.StartupPath, "ffmpeg.exe");
comboBox1.Hide();
}
public void SetTheme(string theme)
{
if (theme == manager.lightTheme)
{
ThemeOption = LightTheme;
// richTextBox1 için renk değişimi
richTextBox1.ForeColor = Color.Black;
richTextBox1.BackColor = Color.White;
// richTextBox4 için renk değişimi
richTextBox4.ForeColor = Color.Black;
richTextBox4.BackColor = Color.White;
// richTextBox2 için renk değişimi
richTextBox2.ForeColor = Color.Black;
richTextBox2.BackColor = Color.White;
// richTextBox3 için renk değişimi
richTextBox3.ForeColor = Color.Black;
richTextBox3.BackColor = Color.White;
richTextBox5.ForeColor = Color.Black;
richTextBox5.BackColor = Color.White;
comboBox2.ForeColor = Color.Black;
comboBox2.BackColor = Color.White;
comboBox1.ForeColor = Color.Black;
comboBox1.BackColor = Color.White;
this.Theme = MetroThemeStyle.Light;
metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Light;
metroStyleManager1.Style = MetroFramework.MetroColorStyle.Purple;
}
else if (theme == manager.darkTheme)
{
ThemeOption = DarkTheme;
richTextBox1.ForeColor = Color.FromArgb(153, 153, 153);
richTextBox1.BackColor = Color.FromArgb(17, 17, 17);
richTextBox4.ForeColor = Color.FromArgb(153, 153, 153);
richTextBox4.BackColor = Color.FromArgb(17, 17, 17);
richTextBox3.ForeColor = Color.FromArgb(153, 153, 153);
richTextBox3.BackColor = Color.FromArgb(17, 17, 17);
richTextBox2.ForeColor = Color.FromArgb(153, 153, 153);
richTextBox2.BackColor = Color.FromArgb(17, 17, 17);
richTextBox5.ForeColor = Color.FromArgb(153, 153, 153);
richTextBox5.BackColor = Color.FromArgb(17, 17, 17);
comboBox2.ForeColor = Color.FromArgb(153, 153, 153);
comboBox2.BackColor = Color.FromArgb(17, 17, 17);
comboBox1.ForeColor = Color.FromArgb(153, 153, 153);
comboBox1.BackColor = Color.FromArgb(17, 17, 17);
this.Theme = MetroThemeStyle.Dark;
metroStyleManager1.Theme = MetroFramework.MetroThemeStyle.Dark;
metroStyleManager1.Style = MetroFramework.MetroColorStyle.Purple;
}
}
private void SaveSettings()
{
// İndirme konumu ve toggle ayarlarını kaydet
Properties.Settings.Default.DownloadDirectory = saveDirectory.Text;
Properties.Settings.Default.DownDir = downloadDir;
Properties.Settings.Default.saveDir = downloadDir2;
Properties.Settings.Default.AutoUpdateEnabled = metroToggle1.Checked;
if (comboBox2.SelectedItem != null)
{
Properties.Settings.Default.theme = comboBox2.SelectedItem.ToString();
}
// Ayarları kaydet
Properties.Settings.Default.Save();
}
private void metroButton1_Click(object sender, EventArgs e)
{
if (saveDirectory.Text == "")
{
MessageBox.Show(manager.selectDownloadLocationText, manager.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
int numEpisodes;
if (!int.TryParse(disneyAdet.Text, out numEpisodes))
{
MessageBox.Show(manager.inputCorrectint);
return;
}
List<string> audioLinks = new List<string>();
List<string> videoLinks = new List<string>();
List<string> keys = new List<string>();
for (int i = 0; i < numEpisodes; i++)
{
string audioLink = Interaction.InputBox($"{i + 1}{movieseriesaudioformat} ", $"Episode {i + 1} - Audio Link", "");
string videoLink = Interaction.InputBox($"{i + 1}{movieseriesvideoformat} ", $"Episode {i + 1} - Video Link", "");
string key = Interaction.InputBox($"{i + 1}{movieserieskeyformat} {i + 1} - Key", "");
audioLinks.Add(audioLink);
videoLinks.Add(videoLink);
keys.Add(key);
}
string outputFormat = "";
int startEpisodeNumber = 0;
if (metroRadioButton1.Checked)
{
string filmName = Interaction.InputBox($"{moviename}", "Film Adı", "");
string filmYear = Interaction.InputBox($"{movieyear}", "Film Yılı", "");
outputFormat = $"{filmName} ({filmYear})";
}
else if (metroRadioButton2.Checked)
{
string seriesName = Interaction.InputBox($"{seriesname}", "Dizi Adı", "");
string seasonNumber = Interaction.InputBox($"{seriesseason}", "Sezon Numarası", "");
string startEpisode = Interaction.InputBox($"{seriesstartep}", "Başlangıç Bölümü", "");
if (!int.TryParse(startEpisode, out startEpisodeNumber))
{
MessageBox.Show(inputCorrectint);
return;
}
outputFormat = $"{seriesName} S{seasonNumber}";
}
for (int i = 0; i < numEpisodes; i++)
{
string audioUrl = audioLinks[i];
string videoUrl = videoLinks[i];
string key = keys[i];
Process.Start(".\\m3u8dl.exe", $"--saveName {i}s --workDir \"{downloadDir2}\" \"{audioUrl}\"").WaitForExit();
Process.Start(".\\m3u8dl.exe", $"--saveName {i}v --workDir \"{downloadDir2}\" \"{videoUrl}\"").WaitForExit();
Process.Start(".\\mp4decrypt.exe", $"--key {key} \"{downloadDir2}\\{i}v.mp4\" \"{downloadDir2}\\out{i}.mp4\"").WaitForExit();
string audioFile = Path.Combine(downloadDir2, $"{i}s.m4a");
string videoFile = Path.Combine(downloadDir2, $"out{i}.mp4");
string outputFile;
if (metroRadioButton2.Checked)
{
outputFile = Path.Combine(downloadDir, $"{outputFormat} E{startEpisodeNumber + i:D2}.mkv");
}
else
{
outputFile = Path.Combine(downloadDir, $"{outputFormat}.mkv");
}
Process.Start("mkvmerge", $"-o \"{outputFile}\" \"{audioFile}\" \"{videoFile}\"").WaitForExit();
if (metroRadioButton1.Checked)
{
richTextBox3.AppendText($"{i + 1}{manager.moviecompleted}" + Environment.NewLine);
}
else
{
richTextBox3.AppendText($"{i + 1}.{manager.seriesText} {i + 1}.{manager.episodenumber}" + Environment.NewLine);
}
}
if (metroCheckBox1.Checked)
{
richTextBox3.AppendText($"{manager.shuttingdownText}" + Environment.NewLine);
Process.Start("shutdown", "/s /t 1");
}
else
{
ProcessNotification(manager.downloadcompleteText, manager.processCompleteText);
}
}
}
private void DecryptAndConvert(string videoPath, string key, string outputPath)
{
// mp4decrypt ile decrypt işlemi
Process.Start(".\\mp4decrypt.exe", $"--key {key} \"{videoPath}\" \"{outputPath}\"").WaitForExit();
// ffmpeg ile MP3'e dönüştür
string mp3FilePath = Path.ChangeExtension(outputPath, ".mp3");
Process.Start(".\\ffmpeg", $"-i \"{outputPath}\" -codec:a libmp3lame -q:a 2 \"{mp3FilePath}\"").WaitForExit();
// Decrypt işlemi sonrasında artık kullanmadığımız orijinal video dosyasını silelim
File.Delete(outputPath);
}
private async Task DownloadAndDecryptAsync(string songUrl, string key, int songIndex)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(songUrl);
if (response.IsSuccessStatusCode)
{
// İndirilen dosyayı sabit bir isimle kaydet
string downloadPath = Path.Combine(downloadDir2, "inendosya");
using (FileStream fs = File.OpenWrite(downloadPath))
using (Stream stream = await response.Content.ReadAsStreamAsync())
{
await stream.CopyToAsync(fs);
}
// İnen dosyayı isimlendir
string userInput = Interaction.InputBox(manager.entersongpodcasturl, manager.filenamingText, "");
string fileName = $"{userInput}.mp3";
// mp4decrypt ve ffmpeg işlemleri
string decryptedFilePath = Path.Combine(downloadDir2, $"{userInput}.mp3");
DecryptAndConvert(downloadPath, key, decryptedFilePath);
ProcessNotification(manager.downloadcompleteText, manager.downloadCompleteMessage);
}
else
{
ShowNotification(manager.downloadError, manager.pleasecheckapp);
MessageBox.Show($"{manager.downloadError} {response.StatusCode}");
}
}
}
private async void metroButton2_Click(object sender, EventArgs e)
{
if (saveDirectory.Text == "")
{
MessageBox.Show(manager.selectdownloadlocfirst, manager.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
int numOfSong;
numOfSong = int.TryParse(metroTextBox1.Text, out numOfSong) ? numOfSong : 0;
if (numOfSong == 0)
{
MessageBox.Show(manager.enteratleastone);
}
else
{
//Using SpotdL
for (int i = 0; i < numOfSong; i++)
{
string songUrl = Interaction.InputBox($"{i + 1}. {song} {i + 1} - URL", $"{song} {i + 1} - URL", "");
songUrls.Add(songUrl);
}
if (songUrls.Count > 0)
{
foreach (var songUrl in songUrls)
{
spotDlDownloadAsync(songUrl);
// İndirme tamamlandı mesajı ya da başka bir işlem yapabilirsiniz.
}
}
else
{
MessageBox.Show("En az bir URL eklemelisiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Hata mesajı ya da başka bir işlem yapabilirsiniz.
}
// Şarkıları indir, decrypt işlemi yap ve MP3'e dönüştür
//for (int i = 0; i < numOfSong; i++)
//{
// string songUrl = Interaction.InputBox($"{i + 1}.{songURL} ", $"{song} {i + 1} - URL", "");
// string key = Interaction.InputBox($"{i + 1}.{songkey}: ", $"{song} {i + 1} - Key", "");
// await DownloadAndDecryptAsync(songUrl, key, i);
//}
}
}
}
private void metroTextBox1_Click(object sender, EventArgs e)
{
}
private string GetFormatCode(string selectedQuality)
{
try
{
if (selectedQuality == null)
{
throw new ArgumentNullException(nameof(selectedQuality), "Kalite seçeneği null olamaz.");
}
switch (selectedQuality)
{
case "144p":
return "144";
case "240p":
return "240";
case "360p":
return "360";
case "480p":
return "480";
case "720p":
return "720";
case "1080p":
return "1080";
case "1440p":
return "1440";
default:
return "best";
}
}
catch (Exception ex)
{
// Exception'ı logla, kullanıcıya bildir, vb.
MessageBox.Show($"Bir hata oluştu: {ex.Message}");
return string.Empty; // veya başka bir varsayılan değer
}
// comboBox1'den seçilen kaliteye göre format kodunu döndür
// Bu metodun içeriği, comboBox1'deki kalite seçeneklerine göre güncellenmelidir.
}
private void button1_Click(object sender, EventArgs e)
{
if (saveDirectory.Text == "")
{
MessageBox.Show(manager.selectDownloadLocationText, manager.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (!Directory.Exists(MP3Folder))
{
Directory.CreateDirectory(downloadDir2+MP3Folder);
}
else if (!Directory.Exists(MP4Folder))
{
Directory.CreateDirectory(downloadDir2+MP4Folder);
}
if (metroCheckBox2.Checked == true)
{
if (metroRadioButton3.Checked)
{
// mp3 olarak indir
DownloadAudioPlaylist();
}
else if (metroRadioButton4.Checked)
{
// video ve ses olarak indir
DownloadVideoAndAudioPlaylist();
}
else
{
MessageBox.Show(manager.doformatselectionText);
}
}
else
{
if (metroRadioButton3.Checked)
{
// mp3 olarak indir
DownloadAudio();
}
else if (metroRadioButton4.Checked)
{
// video ve ses olarak indir
DownloadVideoAndAudio();
}
else
{
MessageBox.Show(manager.doformatselectionText);
}
}
}
}
private async void DownloadAudio()
{
string youtubeLink = metroTextBox2.Text;
if (string.IsNullOrWhiteSpace(youtubeLink))
{
MessageBox.Show(manager.enteryoutubelinkText);
return;
}
string outputDir = MP3Folder; // Ses dosyalarını downloadDir2 klasörüne kaydet
Process process = new Process();
process.StartInfo.FileName = ".\\yt-dlp.exe";
process.StartInfo.Arguments = $"--ffmpeg-location \"{ffmpegPath}\" -o \"{outputDir}\\MP3\\%(title)s.%(ext)s\" --no-playlist --format bestaudio --extract-audio --audio-format mp3 {youtubeLink} ";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
this.Invoke(new Action(() =>
{
richTextBox2.AppendText(e.Data + Environment.NewLine);
richTextBox2.SelectionStart = richTextBox2.Text.Length;
richTextBox2.ScrollToCaret();
}));
}
};
process.Start();
process.BeginOutputReadLine();
await process.WaitForExitAsync();
richTextBox2.Clear();
richTextBox2.Text = manager.processCompleteText;
if (metroCheckBox1.Checked)
{
Process.Start("shutdown", "/s /f /t 0");
}
else
{
ProcessNotification(manager.downloadcompleteText, manager.processCompleteText);
}
}
private async void DownloadVideoAndAudio()
{
string youtubeLink = metroTextBox2.Text;
if (string.IsNullOrWhiteSpace(youtubeLink))
{
AlwaysOnTopMessageBox.Show(manager.enteryoutubelinkText);
return;
}
string outputDir = downloadDir2; // Video ve ses dosyalarını downloadDir2 klasörüne kaydet
string selectedQuality = comboBox1.SelectedItem?.ToString();
if (selectedQuality == null)
{
// selectedQuality null ise kullanıcıya bildir
AlwaysOnTopMessageBox.Show(manager.selectQuality);
return;
}
string formatCode = GetFormatCode(selectedQuality);
Process process = new Process();
process.StartInfo.FileName = ".\\yt-dlp.exe";
process.StartInfo.Arguments = $"--ffmpeg-location \"{ffmpegPath}\" -o \"{outputDir}\\MP4\\%(title)s.%(ext)s\" --no-playlist -S res:{formatCode} {youtubeLink}";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
this.Invoke(new Action(() =>
{
richTextBox2.AppendText(e.Data + Environment.NewLine);
richTextBox2.SelectionStart = richTextBox2.Text.Length;
richTextBox2.ScrollToCaret();
}));
}
};
process.Start();
process.BeginOutputReadLine();
await process.WaitForExitAsync();
richTextBox2.Clear();
richTextBox2.Text = manager.processCompleteText;
// Convert the last downloaded video file to MP4
ConvertLastDownloadedToMp4(outputDir);
if (metroCheckBox1.Checked)
{
Process.Start("shutdown", "/s /f /t 0");
}
else
{
ProcessNotification(manager.downloadcompleteText, manager.processCompleteText);
}
}
private void ConvertLastDownloadedToMp4(string outputDir)
{
// Get the list of all files in the output directory, ordered by creation time
var files = new DirectoryInfo(outputDir).GetFiles()
.OrderByDescending(f => f.CreationTime)
.ToList();
// Find the first video file
var videoFile = files.FirstOrDefault();
if (videoFile != null && !IsMp4File(videoFile))
{
// Construct the output file path with the MP4 extension
string mp4FilePath = Path.Combine(outputDir, Path.ChangeExtension(videoFile.Name, "mp4"));
// Run ffmpeg to convert the file to MP4
Process ffmpegProcess = new Process();
ffmpegProcess.StartInfo.FileName = "ffmpeg.exe"; // Make sure ffmpeg is in your PATH or provide the full path
ffmpegProcess.StartInfo.Arguments = $"-i \"{videoFile.FullName}\" -c:v libx264 -c:a aac \"{mp4FilePath}\"";
ffmpegProcess.StartInfo.UseShellExecute = false;
ffmpegProcess.StartInfo.RedirectStandardOutput = true;
ffmpegProcess.StartInfo.CreateNoWindow = true;
ffmpegProcess.Start();
ffmpegProcess.WaitForExit();
// Delete the original file after conversion
videoFile.Delete();
}
}
private bool IsMp4File(FileInfo file)
{
// Check if the file has an MP4 extension
return string.Equals(file.Extension, ".mp4", StringComparison.OrdinalIgnoreCase);
}
private async void DownloadAudioPlaylist()
{
string youtubeLink = metroTextBox2.Text;
if (string.IsNullOrWhiteSpace(youtubeLink))
{
MessageBox.Show(manager.enteryoutubelinkText);
return;
}
string outputDir = downloadDir2; // Ses dosyalarını downloadDir2 klasörüne kaydet
Process process = new Process();
process.StartInfo.FileName = ".\\yt-dlp.exe";
process.StartInfo.Arguments = $"--ffmpeg-location \"{ffmpegPath}\" -o \"{outputDir}\\MP3\\%(playlist_title)s\\%(title)s.%(ext)s\" --yes-playlist --format bestaudio --extract-audio --audio-format mp3 {youtubeLink} ";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;