-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproccess_lib.h
357 lines (299 loc) · 9.65 KB
/
proccess_lib.h
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
/*
Memo
youtube-dl gvsearch5:how to develop for android --no-playlist --write-info-json --write-annotation --write-thumbnail --write-sub --skip-download
*/
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
// Objects
void cs();
void download_video(string video_url);
void download_audio(string audio_url);
void stream_video(string video_url);
void stream_audio(string audio_url);
int main();
// Universal Variable
string search_result[20][2] = {};
string search_history[10] = {};
int history_count = 0;
string get_version(){
return "v3.1.2_beta";
}
void title_display(){
cs();
cout << "CMD YouTube Player and Downloader(CMDYTPD) " << get_version() << endl;
cout << "By Dee" << endl << endl;
}
void get_result(){
ifstream file("lib\\result.txt");
string line = "";
int counter = 0;
int counter1 = 0;
while (getline (file,line)){
if(counter % 2 == 0){
search_result[counter1][0] = line;
cout << counter1+1 << ". " << line << endl;
}
else{
search_result[counter1][1] = line;
counter1++;
}
counter++;
}
file.close();
}
/// Radio Online List
// https://www.dropbox.com/s/5q89kilper41jbt/radio_link.txt?dl=1
void play_radio(string name, string link){
title_display();
cout << "Playing: " << name << endl;
system(("lib\\mpv " + link +" --no-video").c_str());
system("pause");
}
void get_radio(){
title_display();
cout << "Getting Online Radio Channels..." << endl;
string command1 = "powershell -Command \"(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/5q89kilper41jbt/radio_link.txt?dl=1', 'lib\\radio_link.txt')\"";
string command2 = "powershell -Command \"Invoke-WebRequest https://www.dropbox.com/s/5q89kilper41jbt/radio_link.txt?dl=1 -OutFile lib\\radio_link.txt\"";
system((command1 + "\n" + command2).c_str());
title_display();
cout << "Available Radio Channel" << endl;
ifstream file("lib\\radio_link.txt");
string temp1, temp2;
string links[100][2] = {{}};
int i = 0;
while(file >> temp1 >> temp2){
links[i][0] = temp1;
links[i][1] = temp2;
cout << i+1 << ". " << links[i][0] << endl;
i++;
}
cout << "Command: ";
int ch;
cin >> ch;
play_radio(links[ch-1][0], links[ch-1][1]);
}
void get_history(bool display){
ifstream file("lib\\history.txt");
string line = "";
history_count = 0;
while(file >> line && history_count < 20){
search_history[history_count] = line;
history_count++;
}
file.close();
if(display == true){
cout << "Search History" << endl;
for(int i = 0; i < 20; i++){
if(search_history[i].empty()){
break;
}
cout << i+1 << ". " << search_history[i] << endl;
}
}
}
void add_history(string search){
string temp_data[100] = {};
temp_data[0] = search;
for(int i = 0; i <= history_count; i++){
temp_data[i+1] = search_history[i];
}
ofstream file("lib\\history.txt");
for(int i = 0; i <= history_count; i++){
file << temp_data[i] << endl;
}
file.close();
}
std::string removeAll( std::string str, const std::string& from) {
size_t start_pos = 0;
while( ( start_pos = str.find( from)) != std::string::npos) {
str.erase( start_pos, from.length());
}
return str;
}
//void search_display(string s){
// while(1){
// title_display();
// cout << "Search Input: " << s << endl;
// cout << "Loading";
// for(int i= 0; i < 5; i++){
// Sleep(500);
// cout << ".";
// }
// }
//// return NULL;
//}
//void start_search(string search_command){
// system((search_command + " > " + "lib\\result.txt").c_str());
//
//}
string search_youtube(string search_command, string search){
int ss = 1;
string line = "";
int result_counter = 0;
//system("pause");
title_display();
cout << "Search Input: " << search << endl;
cout << "Loading.." << endl;
system((search_command + " > " + "lib\\result.txt").c_str());
cout << "Search Results" << endl;
get_result();
cout << "Command: ";
int choice;
cin >> choice;
title_display();
choice--;
cout << "Choice: " << search_result[choice][0] << endl;
cout << "1. Download Video\n2. Download Audio\n3. Play Video\n4. Play Audio\n\nCommand: ";
int ch;
cin >> ch;
switch(ch){
case 1:{
download_video(search_result[choice][1]);
break;
}
case 2:{
download_audio(search_result[choice][1]);
break;
}
case 3:{
stream_video(search_result[choice][1]);
break;
}
case 4:{
stream_audio(search_result[choice][1]);
break;
}
default:{
search_youtube(search_command, search);
break;
}
}
}
void cs(){
system("cls");
}
void download_video(string video_url){
title_display();
string command = "";
if(video_url.rfind("https://www.youtube.com/playlist?list=", 0) == 0){
video_url = removeAll(video_url,"https://www.youtube.com/playlist?list=");
command = "lib\\youtube-dl -o \"Downloads/Video/%(title)s.%(ext)s\" -f 136+140 https://www.youtube.com/playlist?list=" + video_url;
}
else{
video_url = removeAll(video_url, "https://www.youtube.com/watch?v=");
command = "lib\\youtube-dl -o \"Downloads/Video/%(title)s.%(ext)s\" -f 136+140 https://www.youtube.com/watch?v=" + video_url;
}
system(command.c_str());
main();
}
void download_audio(string audio_url){
title_display();
string command = "";
if(audio_url.rfind("https://www.youtube.com/playlist?list=", 0) == 0){
audio_url = removeAll(audio_url, "https://www.youtube.com/playlist?list=");
command = "lib\\youtube-dl -o \"Downloads/Audio/%(title)s.%(ext)s\" --extract-audio --audio-format mp3 --audio-quality=320k https://www.youtube.com/playlist?list=" + audio_url;
}
else{
audio_url = removeAll(audio_url, "https://www.youtube.com/watch?v=");
command = "lib\\youtube-dl -o \"Downloads/Audio/%(title)s.%(ext)s\" --extract-audio --audio-format mp3 --audio-quality=320k https://ww.youtube.com/watch?v=" + audio_url;
}
system(command.c_str());
main();
}
void stream_video(string video_url){
title_display();
string command = "";
if(video_url.rfind("https://www.youtube.com/playlist?list=", 0) == 0){
video_url = removeAll(video_url, "https://www.youtube.com/playlist?list=");
command = "lib\\mpv https://www.youtube.com/playlist?list=" + video_url;
}
else{
video_url = removeAll(video_url, "https://www.youtube.com/watch?v=");
command = "lib\\mpv https://www.youtube.com/watch?v=" + video_url;
}
system(command.c_str());
main();
}
void stream_audio(string audio_url){
try{
title_display();
string command = "";
if(audio_url.rfind("https://www.youtube.com/playlist?list=", 0) == 0){
audio_url = removeAll(audio_url, "https://www.youtube.com/playlist?list=");
command = "lib\\mpv https://www.youtube.com/playlist?list="+ audio_url + " --no-video";
}
else{
audio_url = removeAll(audio_url, "https://www.youtube.com/watch?v=");
command = "lib\\mpv https://www.youtube.com/watch?v="+ audio_url + " --no-video";
}
system("pause");
system(command.c_str());
system("pause");
}catch(int e){
cout << "Stopped!!" << endl;
system("pause");
main();
}
}
/////// Note
// update code
//
//
// powershell -Command "(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/a4cydl3y5kj29bh/version.txt?dl=1', 'version.txt')"
// powershell -Command "Invoke-WebRequest https://www.dropbox.com/s/a4cydl3y5kj29bh/version.txt?dl=1 -OutFile version.txt"
//
//
///////
void get_update(){
system(("lib\\updater_lib " + get_version()).c_str());
}
//void silent_update(){
// system(("lib\\updater_lib " + get_version() + " silent").c_str());
//}
void updater_update(){
ifstream file("lib\\updater_version.txt");
if(file){
string temp1, temp2;
string updater_user_version = "";
while(file >> temp1 >> temp2){
updater_user_version = temp1;
}
file.close();
string command1 = "powershell -Command \"(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/fv2jrdggmmiv4i1/updater_version.txt?dl=1', 'lib\\updater_version.txt')\"";
string command2 = "powershell -Command \"Invoke-WebRequest https://www.dropbox.com/s/fv2jrdggmmiv4i1/updater_version.txt?dl=1 -OutFile lib\\updater_version.txt\"";
system((command1 + "\n" + command2).c_str());
ifstream file("lib\\updater_version.txt");
string new_version = "";
string version_link = "";
title_display();
cout << "Please wait.. ";
if(system("lib\\youtube-dl -U")){
get_update();
}
while(file >> temp1 >> temp2){
new_version = temp1;
version_link = temp2;
// cout << new_version << " " << version_link << endl;
// system("pause");
}
if(new_version != updater_user_version){
title_display();
cout << "Updating CMDYTPD Libaries.." << endl;
system("lib\\youtube-dl -U");
string command1 = "powershell -Command \"(New-Object Net.WebClient).DownloadFile('" + version_link + "', 'lib\\updater_lib.exe')\"";
string command2 = "powershell -Command \"Invoke-WebRequest " + version_link + " -OutFile lib\\updater_lib.exe\"";
system((command1 + "\n" + command2).c_str());
title_display();
cout << "Libraries Successfully Updated!! :)" << endl;
system("pause");
}
}
else{
system("powershell -Command \"(New-Object Net.WebClient).DownloadFile('https://www.dropbox.com/s/tj9210a2ny56b6b/temp_updater_version.txt?dl=1', 'lib\\updater_version.txt')\"");
system("powershell -Command \"Invoke-WebRequest https://www.dropbox.com/s/tj9210a2ny56b6b/temp_updater_version.txt?dl=1 -OutFile lib\\updater_version.txt\"");
updater_update();
}
}