/
MainWindow.xaml.cs
198 lines (150 loc) · 6.12 KB
/
MainWindow.xaml.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
using System;
using System.Windows;
using System.IO;
using System.Windows.Controls;
using System.Windows.Input;
namespace KEMT
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window{
public MainWindow(){
InitializeComponent();
tb_console.IsReadOnly = true;
}
//--- Print to TextBox console START ---///
public void c_print(String str){
tb_console.AppendText(str);
tb_console.ScrollToEnd();
KakaduaUtil.update_frame();
}
public void c_println(String str){
c_print(str+"\n");
}
//--- Print to TextBox console STOP ---///
//---Navbar START ---//
private void open_settings(object sender, RoutedEventArgs e)
{
Settings settingsWindow = new Settings();
settingsWindow.Show();
}
private void open_about(object sender, RoutedEventArgs e)
{
About aboutWindow = new About();
aboutWindow.Show();
}
private void close(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
//--- Navbar STOP ---//
//--- Select onClick URL bar START ---///
private void SelectAddress(object sender, RoutedEventArgs e){
TextBox tb = (sender as TextBox);
if(tb != null){
tb.SelectAll();
}
}
private void SelectivelyIgnoreMouseButton(object sender, MouseButtonEventArgs e){
TextBox tb = (sender as TextBox);
if(tb != null){
if(!tb.IsKeyboardFocusWithin){
e.Handled = true;
tb.Focus();
}
}
}
//--- Select onClick URL bar STOP ---///
//--- Controls START ---///
private void click_dl(object sender, RoutedEventArgs e) //Download button
{
if (!File.Exists("ffmpeg/ffmpeg.exe"))//If ffmpeg has not been downloaded
{
c_println("Downloading 7zip...");//Download and extract 7zip cli. Needed to extract ffmpeg
KakaduaUtil.download_file("http://www.7-zip.org/a/7za920.zip", "7za920.zip");
KakaduaUtil.unzip("7za920.zip", "7zip");
c_println("Extracting 7zip...");
File.Move("7za920.zip", "7zip/7za920.zip");
String ffmpeg = KakaduaUtil.file_get_contents_utf8("http://ffmpeg.zeranoe.com/builds/"); //Get link to latest stable ffmpeg build
ffmpeg = "http://ffmpeg.zeranoe.com/builds" + KakaduaUtil.get_between(ffmpeg, "<a class=\"latest\" href=\".", "\"");
c_println("Downloading ffmpeg...");//Download and extract ffmpeg
KakaduaUtil.download_file(ffmpeg, "ffmpeg.7z");
c_println("Extracting ffmpeg...");
KakaduaUtil.run_and_wait("7zip/7za.exe", "e ffmpeg.7z -offmpeg ffmpeg.exe -r");
File.Move("ffmpeg.7z", "ffmpeg/ffmpeg.7z");
}//if END
String url = tb_url.Text;
if (url.Contains("oppetarkiv.se"))//Öppet Arkiv
{
ServiceOppetArkiv oppetArkiv = new ServiceOppetArkiv(this);
oppetArkiv.generate("dl", url);
}//Öppet Arkiv END
else if (url.Contains("youtube"))//Youtube
{
String no_key = "You need to set a YouTube API key in the settings";
if (File.Exists("API_KEY"))
{
if(System.IO.File.ReadAllText("API_KEY") != null && System.IO.File.ReadAllText("API_KEY") != "")
{
ServiceYouTube youTube = new ServiceYouTube(this);
youTube.generate("strm", url);
}
else { c_println(no_key); }
}
else { c_println(no_key); }
}//YouTube END
else if (url.Contains("tv4play.se"))//TV4 Play
{
ServiceTV4 tv4 = new ServiceTV4(this);
tv4.generate("dl", url);
}//TV4 Play END
else
{
c_println("Usupported URL / Service");
}
}
private void click_strm(object sender, RoutedEventArgs e) //Generate strm button
{
String url = tb_url.Text;
if (url.Contains("oppetarkiv.se"))//Öppet Arkiv
{
ServiceOppetArkiv oppetArkiv = new ServiceOppetArkiv(this);
oppetArkiv.generate("strm", url);
}//Öppet Arkiv END
else if(url.Contains("youtube"))//Youtube
{
String no_key = "You need to set a YouTube API key in the settings";
if (File.Exists("API_KEY"))
{
if (System.IO.File.ReadAllText("API_KEY") != null && System.IO.File.ReadAllText("API_KEY") != "") {
ServiceYouTube youTube = new ServiceYouTube(this);
youTube.generate("strm", url);
}
else { c_println(no_key); }
}
else { c_println(no_key); }
}//YouTube END
else if (url.Contains("tv4play.se"))//TV4 Play
{
ServiceTV4 tv4 = new ServiceTV4(this);
tv4.generate("strm", url);
}//TV4 Play END
else
{
c_println("Usupported URL / Service");
}
}
//--- Controls START ---///
//--- Other Clicks START ---///
private void web_licence(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/Kakadua/Kakadua-Emby-Media-Tool/blob/master/LICENSE");
}
private void web_github(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/Kakadua/Kakadua-Emby-Media-Tool");
}
//--- Other Clicks STOP ---///
}
}