about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/FindPCAP.cmake86
-rw-r--r--src/YtdlpWrapper.cpp14
-rw-r--r--src/main.cpp1
4 files changed, 102 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a31de..b5fbdca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,12 +29,14 @@ if(NOT ftxui_POPULATED)
   add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
 endif()
 
-FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
+FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) ##https://github.com/nlohmann/json/releases/latest/download/json.tar.xz
 
 FetchContent_MakeAvailable(json cpr)
 
 find_package(SQLite3 REQUIRED)
 
+## find_package(PCAP REQUIRED)
+
 # find_package(pybind11 REQUIRED)
 add_subdirectory(extern/pybind11)
 
@@ -50,5 +52,6 @@ target_link_libraries(${PROJECT_NAME}
     PRIVATE ftxui::component
     PRIVATE nlohmann_json::nlohmann_json
     PRIVATE SQLite::SQLite3
+    ## ${PCAP_LIBRARY}
     PRIVATE pybind11::embed
 )
diff --git a/cmake/FindPCAP.cmake b/cmake/FindPCAP.cmake
new file mode 100644
index 0000000..6e81778
--- /dev/null
+++ b/cmake/FindPCAP.cmake
@@ -0,0 +1,86 @@
+# - Try to find libpcap include dirs and libraries
+#
+# Usage of this module as follows:
+#
+#     find_package(PCAP)
+#
+# Variables used by this module, they can change the default behaviour and need
+# to be set before calling find_package:
+#
+#  PCAP_ROOT_DIR             Set this variable to the root installation of
+#                            libpcap if the module has problems finding the
+#                            proper installation path.
+#
+# Variables defined by this module:
+#
+#  PCAP_FOUND                System has libpcap, include and library dirs found
+#  PCAP_INCLUDE_DIR          The libpcap include directories.
+#  PCAP_LIBRARY              The libpcap library (possibly includes a thread
+#                            library e.g. required by pf_ring's libpcap)
+#  HAVE_PF_RING              If a found version of libpcap supports PF_RING
+
+find_path(PCAP_ROOT_DIR
+    NAMES include/pcap.h Include/pcap.h
+)
+
+find_path(PCAP_INCLUDE_DIR
+    NAMES pcap.h
+    HINTS ${PCAP_ROOT_DIR}/include
+)
+
+if ( MSVC AND COMPILER_ARCHITECTURE STREQUAL "x86_64" )
+    set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib/x64)
+else()
+    set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib)
+endif()
+
+find_library(PCAP_LIBRARY
+    NAMES pcap wpcap
+    HINTS ${_pcap_lib_hint_path}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PCAP DEFAULT_MSG
+    PCAP_LIBRARY
+    PCAP_INCLUDE_DIR
+)
+
+include(CheckCSourceCompiles)
+set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
+check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO)
+set(CMAKE_REQUIRED_LIBRARIES)
+
+# check if linking against libpcap also needs to link against a thread library
+if (NOT PCAP_LINKS_SOLO)
+    find_package(Threads)
+    if (THREADS_FOUND)
+        set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+        check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS)
+        set(CMAKE_REQUIRED_LIBRARIES)
+    endif ()
+    if (THREADS_FOUND AND PCAP_NEEDS_THREADS)
+        set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+        list(REMOVE_DUPLICATES _tmp)
+        set(PCAP_LIBRARY ${_tmp}
+            CACHE STRING "Libraries needed to link against libpcap" FORCE)
+    else ()
+        message(FATAL_ERROR "Couldn't determine how to link against libpcap")
+    endif ()
+endif ()
+
+string(FIND "${PCAP_LIBRARY}" "wpcap" _pcap_lib_is_wpcap)
+if ( _pcap_lib_is_wpcap GREATER_EQUAL 0 )
+    set(HAVE_WPCAP TRUE)
+endif()
+
+include(CheckFunctionExists)
+set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
+check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
+check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND)
+set(CMAKE_REQUIRED_LIBRARIES)
+
+mark_as_advanced(
+    PCAP_ROOT_DIR
+    PCAP_INCLUDE_DIR
+    PCAP_LIBRARY
+)
\ No newline at end of file
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp
index eca1cbc..ca1d4a4 100644
--- a/src/YtdlpWrapper.cpp
+++ b/src/YtdlpWrapper.cpp
@@ -8,10 +8,17 @@ using json = nlohmann::json;
 namespace py = pybind11;
 using namespace py::literals;
 
+std::string pyDictToJsonString(const py::dict& dict) {
+
+    pybind11::object json = py::module::import("json");
+    return json.attr("dumps")(dict).cast<std::string>();
+}
+
 py::object YtdlpWrapper::get_ytdl() {
     
     if (ytdl.is_none()) {
-        ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true)));
+        ytdl = py::module::import("yt_dlp");
+        ytdl = ytdl.attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true)));
     }
 
     return ytdl;
@@ -19,7 +26,8 @@ py::object YtdlpWrapper::get_ytdl() {
 
 json YtdlpWrapper::getJsonSearch(const string& searchTerm) {
 
-    py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
-    return json::parse(info.cast<std::string>());
+    // py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
+    py::dict info("test"_a=py::bool_(true), "test2"_a=py::str("yoyoyo"), "test3"_a=py::none());
+    return json::parse(pyDictToJsonString(info));
 }
 
diff --git a/src/main.cpp b/src/main.cpp
index 42cba4f..a03461f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,7 @@
 using namespace std;
 
 int main() {
+    py::scoped_interpreter guard{};
 
     YtdlpWrapper yt;
     nlohmann::json j = yt.getJsonSearch("All Quiet on the Western Front Ost");