22#include < string>
33#include < exception>
44#include < Windows.h>
5- #include " json.cpp"
65#include < conio.h>
6+ #include " json.cpp"
77
88std::string GetCurrentDirectory ()
99{
@@ -16,8 +16,27 @@ std::string GetCurrentDirectory()
1616
1717
1818int main () {
19+ std::string choice;
1920 std::string url;
20- bool logs = false ;
21+
22+ /*
23+ * Json file content
24+ */
25+ std::string destination;
26+ std::string path;
27+ std::string verboseString;
28+ bool verbose;
29+
30+ std::cout << " __ __ ____ __ \n "
31+ " /\\ \\ /\\ \\ /\\ _`\\ /\\ \\ __ \n "
32+ " \\ `\\ `\\\\ /'/\\ \\ \\ /\\ _\\ ___ ___ __ __ __ _ __ \\ \\ ,_\\ __ _ __ \n "
33+ " `\\ `\\ /' \\ \\ \\ /_/_ / __`\\ /' _ `\\ /\\ \\ /\\ \\ /'__`\\ /\\ `'__\\ \\ \\ \\ / /'__`\\ /\\ `'__\\\n "
34+ " `\\ \\ \\ \\ \\ \\ L\\ \\ /\\ \\ L\\ \\ /\\ \\ /\\ \\ \\ \\ \\ _/ |/\\ __/ \\ \\ \\ / \\ \\ \\ _ /\\ __/ \\ \\ \\ / \n "
35+ " \\ \\ _\\ \\ \\ ____/\\ \\ ____/\\ \\ _\\ \\ _\\ \\ \\ ___/ \\ \\ ____\\ \\ \\ _\\ \\ \\ __\\\\ \\ ____\\ \\ \\ _\\ \n "
36+ " \\ /_/ \\ /___/ \\ /___/ \\ /_/\\ /_/ \\ /__/ \\ /____/ \\ /_/ \\ /__/ \\ /____/ \\ /_/ \n "
37+ " \n "
38+ " \n "
39+ " " << std::endl;
2140
2241 if (!initiated ()) {
2342 createJson ();
@@ -31,65 +50,102 @@ int main() {
3150 initJson ();
3251 }
3352
34- std::cout << " Please enter youtube URL : " ;
35- std::getline (std::cin, url);
36-
37- if (url.find (url) == std::string::npos) {
38- std::cout << " Invalid URL" << std::endl;
39- return 0 ;
40- } else {
41- std::cout << " Valid URL" << std::endl;
42- }
43-
44- std::ifstream jsonFile (file);
45-
46- if (!jsonFile.is_open ()) {
47- std::cerr << " The file can't be open." << std::endl;
48- return 0 ;
49- }
50-
51- std::string jsonContent ((std::istreambuf_iterator<char >(jsonFile)), std::istreambuf_iterator<char >());
52-
53- jsonFile.close ();
54-
55- nlohmann::json jsonObj = nlohmann::json::parse (jsonContent);
56-
57- std::string destination = jsonObj[" destination" ];
58-
59-
60- if (destination.find (destination) == std::string::npos) {
61- std::cout << " Invalid file destination" << std::endl;
62- return 0 ;
63- } else {
64- std::cout << " Valid file destination" << std::endl;
65- }
66-
67- std::string verboseString = jsonObj[" verbose" ];
68- std::string path = jsonObj[" path" ];
69- bool verbose;
70-
71- if (verboseString == " true" ) {
72- verbose = true ;
73- } else {
74- verbose = false ;
75- }
76-
77- // Download the video
78- try {
79- if (verbose) {
80- std::cout << " Downloading..." << std::endl;
81- std::string command = path + " /yt-dlp_min.exe --verbose --ignore-errors -o \" " + destination + " /%(title)s.%(ext)s\" " + url;
82- system (command.c_str ());
53+ while (true ) {
54+ std::cout << " [1] Download a video" << std::endl;
55+ std::cout << " [2] Modify json information" << std::endl;
56+ std::cout << " [3] Exit" << std::endl;
57+ std::cout << " Choice : " ;
58+ std::getline (std::cin, choice);
59+
60+ if (choice == " 1" ) {
61+ std::cout << " Enter the URL of the video : " ;
62+ std::getline (std::cin, url);
63+
64+ if (url.find (url) == std::string::npos) {
65+ std::cout << " Invalid URL" << std::endl;
66+ return 0 ;
67+ } else {
68+ std::cout << " Valid URL" << std::endl;
69+
70+ std::ifstream jsonFile (file);
71+
72+ if (!jsonFile.is_open ()) {
73+ std::cerr << " The file can't be open." << std::endl;
74+ return 0 ;
75+ }
76+
77+ std::string jsonContent ((std::istreambuf_iterator<char >(jsonFile)), std::istreambuf_iterator<char >());
78+
79+ jsonFile.close ();
80+
81+ nlohmann::json jsonObj = nlohmann::json::parse (jsonContent);
82+
83+ destination = jsonObj[" destination" ];
84+
85+
86+ if (destination.find (destination) == std::string::npos) {
87+ std::cout << " Invalid file destination" << std::endl;
88+ std::cout << " Please modify the json file" << std::endl;
89+ std::cout << " Press any key to continue..." << std::endl;
90+ getch ();
91+ } else {
92+ std::cout << " Valid file destination" << std::endl;
93+ }
94+
95+ verboseString = jsonObj[" verbose" ];
96+ path = jsonObj[" path" ];
97+
98+ if (verboseString == " true" ) {
99+ verbose = true ;
100+ } else {
101+ verbose = false ;
102+ }
103+
104+ // Download the video
105+ try {
106+ std::string command = path + " /yt-dlp_min.exe --ignore-errors -o \" " + destination + " /%(title)s.%(ext)s\" " + url;
107+
108+ if (verbose) {
109+ std::cout << " Downloading..." << std::endl;
110+ command = command + " --verbose" ;
111+ system (command.c_str ());
112+ } else {
113+ std::cout << " Downloading..." << std::endl;
114+ system (command.c_str ());
115+ }
116+ } catch (std::exception& e) {
117+ std::cout << " Error : " << e.what () << std::endl;
118+ std::cout << " Press any key to continue..." << std::endl;
119+ getch ();
120+ }
121+
122+ std::cout << " Download completed in the folder " + destination << std::endl;
123+ std::cout << " Press any key to continue..." << std::endl;
124+ getch ();
125+
126+ }
127+
128+ } else if (choice == " 2" ) {
129+ std::cout << " Change the directoy wehre the videos are downloaded : " ;
130+ std::getline (std::cin, destination);
131+
132+ std::cout << " Change the path of YConverter : " ;
133+ std::getline (std::cin, path);
134+
135+ std::cout << " Do you want to see the download progression ? (y/n) : " ;
136+ std::getline (std::cin, verboseString);
137+
138+ if (verboseString == " y" ) {
139+ verboseString = " true" ;
140+ } else {
141+ verboseString = " false" ;
142+ }
143+
144+ modify (path, destination, verboseString);
145+ } else if (choice == " 3" ) {
146+ return 0 ;
83147 } else {
84- std::cout << " Downloading..." << std::endl;
85- std::string command = path + " /yt-dlp_min.exe --ignore-errors -o \" " + destination + " /%(title)s.%(ext)s\" " + url;
86- system (command.c_str ());
148+ std::cout << " Invalid choice" << std::endl;
87149 }
88- } catch (std::exception& e) {
89- std::cout << " Error : " << e.what () << std::endl;
90150 }
91-
92- std::cout << " Download completed" << std::endl;
93-
94- return 0 ;
95151}
0 commit comments