// #include #include // #include // #include // #include #include // #include // #include #include #include #include #include #ifdef _WIN32 #include #elif (__unix || __posix) #include #include #include #endif #include "tui.hpp" #include "video.hpp" #include "invapi.hpp" #include "YtdlpWrapper.hpp" #include "sqliteinterface.hpp" // namespace py = pybind11; using namespace std; using json = nlohmann::json; namespace fs = std::filesystem; void validateStructConversions() { fs::path here("info.json"); cout << fs::absolute(here) << endl; ifstream ifs; ifs.open(fs::absolute(here).c_str(), ifstream::in); json info = json::parse(ifs); info = info["entries"][0]; Video::video v = info.get(); json j = v; for (auto& i: j.items()) { if (i.key() != "formats") { assert(i.value() == info.at(i.key())); cout << i.key() << ": " << i.value() << endl; } } for (auto i: j["formats"]) { for (auto& k: i.items()) { if (k.key() == "quality" || k.key() == "resolution") cout << k.key() << ": " << k.value() << endl; } } } void spawn(const char* url, bool wait) { #ifdef _WIN32 start mpv bool CreateProcessA() #elif (__unix || __posix) extern char **environ; pid_t pid{0}; char *const mpvArgs[] = {strdup("mpv"), strdup(url), nullptr}; int result = posix_spawnp(&pid, mpvArgs[0], NULL, NULL, mpvArgs, environ); if (result != 0) { cout << "ERROR RUNNING " << mpvArgs[0] << "! Error code " << result << ": " << strerror(result) << endl; } else { cout << "pid: " << pid << endl; if (wait) { do { if (waitpid(pid, &result, 0) != -1) { cout << "Child status: " << WEXITSTATUS(result) << endl; } else { perror("waitpid"); exit(1); } } while (!WIFEXITED(result) && !WIFSIGNALED(result)); } } #endif } void parseSysArgs(int argc, char **argv) { for (int i{0}; i < argc; ++i) { cout << argv[i] << " "; } cout << endl; string currentArg; for (int i{0}; i < argc; ++i) { if (strncmp(argv[i], "-", 1) == 0) { currentArg = argv[i]; } else { if (currentArg == "") { cout << argv[i] << endl; if (strncmp(argv[i], "http://", 7) == 0 || strncmp(argv[i], "https://", 8) == 0) { spawn(argv[i], true); } } else if (currentArg == "-S" || currentArg == "--search") { cout << "searching for: " << argv[i] << endl; currentArg = ""; } else { cout << currentArg << ": " << argv[i] << endl; } } } } int main(int argc, char **argv) { parseSysArgs(argc, argv); }