public bool LoadPython27(TargetInfo Target)
{
bool isLibrarySupported = false;
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
isLibrarySupported = true;
string LibrariesPath = Path.Combine(ThirdPartyPath, "Python27", "libs");
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "python27.lib"));
}
if (isLibrarySupported)
{
// Include path
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Python27", "include"));
}
Definitions.Add(string.Format("WITH_PYTHON_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
public WeMeshOfficial(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking","OpenSSL" });
LoadPython27(Target);
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// if ((Target.Platform == UnrealTargetPlatform.Win32) || (Target.Platform == UnrealTargetPlatform.Win64))
// {
// if (UEBuildConfiguration.bCompileSteamOSS == true)
// {
// DynamicallyLoadedModuleNames.Add("OnlineSubsystemSteam");
// }
// }
}
And this is the function where I included it:
FString AyoutubeLinkScrapper::ScrapeLink(FString linkUrl) {
string i;
Py_Initialize();
char * a = Py_GetPath();
FString Fs = FString(ANSI_TO_TCHAR(a));
UE_LOG(LogTemp, Warning, TEXT("The default search dependecy is %s"), *Fs);
PyObject *sys_path = PySys_GetObject("path");
PyList_Append(sys_path, PyString_FromString("C:/Users/Mik/Documents/GitHub/youtube-dl")); //Need to change to a relative directory inside the project
PyObject * pythonFile = PyImport_ImportModule("wemesh_vr_scrapper");
if (!pythonFile) {
UE_LOG(LogTemp, Warning, TEXT("Failed to import module"));
}
if (pythonFile != NULL) {
UE_LOG(LogTemp, Warning, TEXT("Found the python file"));
PyObject * pDict = PyModule_GetDict(pythonFile);
if (pDict == NULL) {
UE_LOG(LogTemp, Warning, TEXT("Failed to get a dictionary from the module"));
}
PyObject * pythonFunction = PyDict_GetItemString(pDict, (char*)"scrapeLink");
if (pythonFunction == NULL) {
UE_LOG(LogTemp, Warning, TEXT("No function was found"));
}
if (PyCallable_Check(pythonFunction)) {
UE_LOG(LogTemp, Warning, TEXT("Found the python function, starts calling"));
PyObject * pValue = Py_BuildValue("(s)", (char*)"https://www.youtube.com/watch?v=pXRviuL6vMY");
PyObject * presult = PyObject_CallObject(pythonFunction, pValue);
PyErr_Print();
if (presult != NULL) {
UE_LOG(LogTemp, Warning, TEXT("Result is not empty"));
if (PyList_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a list"));
}
if (PyString_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a string"));
i = PyString_AsString(presult);
}
if (PyInt_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is an integer"));
}
if (PyDict_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a dictionary"));
}
if (PyFloat_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a float"));
}
if (PyTuple_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a tuple"));
}
if (PyFunction_Check(presult) == true) {
UE_LOG(LogTemp, Warning, TEXT("Result is a function"));
}
}
else {
UE_LOG(LogTemp, Warning, TEXT("No result is returned"));
i = "Error!";
}
}
}
Py_Finalize();
FString returnResult(i.c_str());
UE_LOG(LogTemp, Warning, TEXT("The final return result is %s"),*returnResult);
return returnResult;
}