Added subtitle drag and drop support

This commit is contained in:
Zarg 2025-01-26 22:03:48 +01:00
parent bf83deab4b
commit b69b78caa4
7 changed files with 24 additions and 5 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
project(stremio VERSION "5.0.14")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# Locate MPV

View file

@ -23,7 +23,12 @@ std::set<std::string> g_observedProps;
bool g_initialSet = false;
std::string g_initialVO = "gpu-next";
int g_currentVolume = 50;
const std::vector<std::wstring> g_subtitleExtensions = {
L".srt", L".ass", L".ssa", L".sub", L".vtt", L".ttml",
L".dfxp", L".smi", L".sami", L".sup", L".scc",
L".xml", L".lrc", L".pjs", L".mpl", L".usf",
L".qtvr"
};
// Node
std::atomic_bool g_nodeRunning = false;
std::thread g_nodeThread;

View file

@ -54,6 +54,7 @@ extern std::set<std::string> g_observedProps;
extern bool g_initialSet;
extern std::string g_initialVO;
extern int g_currentVolume;
extern const std::vector<std::wstring> g_subtitleExtensions;
// custom messages
#define WM_MPV_WAKEUP (WM_APP + 2)

View file

@ -17,5 +17,6 @@ void ToggleFullScreen(HWND hWnd, bool enable);
// Webview
void HandleInboundJSON(const std::string &msg);
void SendToJS(const std::string &eventName, const nlohmann::json &eventData);
void HandleEvent(const std::string &ev, std::vector<std::string> &args);
#endif // MAINWINDOW_H

View file

@ -1,6 +1,6 @@
#include "helpers.h"
#include <tlhelp32.h>
#include <iostream>
#include "../core/globals.h"
std::string WStringToUtf8(const std::wstring &wstr)
{
@ -109,4 +109,11 @@ std::wstring GetExeDirectory()
if(pos!=std::wstring::npos)
path.erase(pos);
return path;
}
bool isSubtitle(const std::wstring& filePath) {
std::wstring lowerFilePath = filePath;
std::transform(lowerFilePath.begin(), lowerFilePath.end(), lowerFilePath.begin(), towlower);
return std::any_of(g_subtitleExtensions.begin(), g_subtitleExtensions.end(),
[&](const std::wstring& ext) { return lowerFilePath.ends_with(ext); });
}

View file

@ -13,5 +13,6 @@ std::wstring GetExeDirectory();
bool FileExists(const std::wstring& path);
bool DirectoryExists(const std::wstring& dirPath);
bool IsDuplicateProcessRunning(const std::vector<std::wstring>& targetProcesses);
bool isSubtitle(const std::wstring& filePath);
#endif // HELPERS_H

View file

@ -1,6 +1,5 @@
#include "webview.h"
#include <string>
#include <vector>
#include <thread>
#include <cmath>
#include <iostream>
@ -400,13 +399,18 @@ static void SetupWebMessageHandler()
{
std::wstring filePath = wuri.substr(8);
std::string utf8FilePath = WStringToUtf8(filePath);
if (isSubtitle(filePath)) {
std::vector<std::string> subaddArgs = {"sub-add",utf8FilePath};
HandleEvent("mpv-command", subaddArgs);
return S_OK;
}
json j;
j["type"] = "FileDropped";
j["path"] = utf8FilePath;
SendToJS("FileDropped", j);
return S_OK;
}
// For non-file URIs, open externally
ShellExecuteW(nullptr, L"open", uri.get(), nullptr, nullptr, SW_SHOWNORMAL);
}