diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4f4e596 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build ytdlp-interface + +on: + push: + branches: [ feat/github-token-auth ] + workflow_dispatch: + +jobs: + build: + runs-on: windows-2022 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Extract dependencies + shell: pwsh + run: | + $deps = "ytdlp-interface dependencies.7z" + if (Test-Path $deps) { + 7z x $deps -o. -y + Write-Host "Dependencies extracted successfully" + Get-ChildItem -Directory | ForEach-Object { Write-Host $_.Name } + } else { + Write-Error "Dependencies archive not found: $deps" + exit 1 + } + + - name: Add MSVC to PATH + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + + - name: Build Release x64 + shell: pwsh + run: | + cd ytdlp-interface + msbuild ytdlp-interface.vcxproj ` + /p:Configuration=Release ` + /p:Platform=x64 ` + /p:PlatformToolset=v143 ` + /p:WindowsTargetPlatformVersion=10.0 ` + /m + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ytdlp-interface-x64 + path: ytdlp-interface/Release/x64/ytdlp-interface.exe + if-no-files-found: error diff --git a/ytdlp-interface/gui.cpp b/ytdlp-interface/gui.cpp index d985c16..aab3474 100644 --- a/ytdlp-interface/gui.cpp +++ b/ytdlp-interface/gui.cpp @@ -1876,7 +1876,7 @@ void GUI::get_releases(nana::window parent_for_msgbox) thr_releases = std::thread {[parent_for_msgbox, this] { using json = nlohmann::json; - auto jtext {util::get_inet_res("https://api.github.com/repos/ErrorFlynn/ytdlp-interface/releases", &inet_error)}; + auto jtext {util::get_inet_res("https://api.github.com/repos/ErrorFlynn/ytdlp-interface/releases", &inet_error, false, conf.github_token)}; if(!jtext.empty()) { try { releases = json::parse(jtext); } @@ -1956,8 +1956,8 @@ void GUI::get_latest_ffmpeg(nana::window parent_for_msgbox) { std::string jtext; if(win7) - jtext = util::get_inet_res("https://api.github.com/repos/kusaanko/FFmpeg-Auto-Build/releases/latest", &inet_error); - else jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/FFmpeg-Builds/releases/latest", &inet_error); + jtext = util::get_inet_res("https://api.github.com/repos/kusaanko/FFmpeg-Auto-Build/releases/latest", &inet_error, false, conf.github_token); + else jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/FFmpeg-Builds/releases/latest", &inet_error, false, conf.github_token); if(!jtext.empty()) { json json_ffmpeg; @@ -2016,16 +2016,16 @@ void GUI::get_latest_ytdlp(nana::window parent_for_msgbox) if(fname.empty()) fname = ytdlp_fname; if(fname == "ytdl-patched-red.exe") - jtext = util::get_inet_res("https://api.github.com/repos/ytdl-patched/ytdl-patched/releases/latest", &inet_error); - else + jtext = util::get_inet_res("https://api.github.com/repos/ytdl-patched/ytdl-patched/releases/latest", &inet_error, false, conf.github_token); + else { if(win7) - jtext = util::get_inet_res("https://api.github.com/repos/nicolaasjan/yt-dlp/releases/latest", &inet_error); + jtext = util::get_inet_res("https://api.github.com/repos/nicolaasjan/yt-dlp/releases/latest", &inet_error, false, conf.github_token); else { if(conf.ytdlp_nightly) - jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest", &inet_error); - else jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest", &inet_error); + jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest", &inet_error, false, conf.github_token); + else jtext = util::get_inet_res("https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest", &inet_error, false, conf.github_token); } } if(!jtext.empty() && thr_releases_ytdlp.joinable()) @@ -2078,7 +2078,7 @@ void GUI::get_latest_deno(nana::window parent_for_msgbox) thr_releases_deno = std::thread {[parent_for_msgbox, this] { using json = nlohmann::json; - auto jtext {util::get_inet_res("https://api.github.com/repos/denoland/deno/releases/latest", &inet_error)}; + auto jtext {util::get_inet_res("https://api.github.com/repos/denoland/deno/releases/latest", &inet_error, false, conf.github_token)}; if(!jtext.empty()) { json jrel; diff --git a/ytdlp-interface/types.cpp b/ytdlp-interface/types.cpp index 5ac85c2..e398050 100644 --- a/ytdlp-interface/types.cpp +++ b/ytdlp-interface/types.cpp @@ -760,6 +760,7 @@ void settings_t::to_json(nlohmann::json &j) const j["cb_display_custom_filenames"] = cb_display_custom_filenames; j["cb_cookies"] = cb_cookies; j["cookies_path"] = cookies_path; + j["github_token"] = github_token; } @@ -988,4 +989,8 @@ void settings_t::from_json(const nlohmann::json &j) cb_cookies = j["cb_cookies"]; cookies_path = j["cookies_path"].get(); } + if(j.contains("github_token")) // v2.20 + { + github_token = j["github_token"].get(); + } } \ No newline at end of file diff --git a/ytdlp-interface/types.hpp b/ytdlp-interface/types.hpp index 0f3c318..2120fa5 100644 --- a/ytdlp-interface/types.hpp +++ b/ytdlp-interface/types.hpp @@ -106,7 +106,7 @@ struct settings_t output_template_default_bandcamp {L"%(artist)s - %(album)s - %(track_number)02d - %(track)s.%(ext)s"}; std::wstring fmt1, fmt2, output_template {output_template_default}, playlist_indexing {playlist_indexing_default}, output_template_bandcamp {output_template_default_bandcamp}, proxy; - std::string argset, cookie_options, aria_options {"-x 6"}, sub_langs, sub_format; + std::string argset, cookie_options, aria_options {"-x 6"}, sub_langs, sub_format, github_token; std::vector argsets; std::vector>> unfinished_queue_items; std::unordered_set outpaths; diff --git a/ytdlp-interface/util.cpp b/ytdlp-interface/util.cpp index 4025268..b98b555 100644 --- a/ytdlp-interface/util.cpp +++ b/ytdlp-interface/util.cpp @@ -452,7 +452,7 @@ std::wstring util::get_sys_folder(REFKNOWNFOLDERID rfid) } -std::string util::get_inet_res(std::string res, std::string *error, bool truncate) +std::string util::get_inet_res(std::string res, std::string *error, bool truncate, std::string token) { std::string ret; if(error) error->clear(); @@ -471,7 +471,13 @@ std::string util::get_inet_res(std::string res, std::string *error, bool truncat auto hinet {InternetOpenA(agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)}; if(hinet) { - auto hfile {InternetOpenUrlA(hinet, res.data(), NULL, 0, 0, 0)}; + std::string auth_header; + if(!token.empty() && res.find("github.com") != std::string::npos) + auth_header = "Authorization: token " + token + "\r\n"; + + auto hfile {InternetOpenUrlA(hinet, res.data(), NULL, 0, + auth_header.empty() ? NULL : auth_header.c_str(), + auth_header.empty() ? 0 : -1L)}; if(hfile) { DWORD read {1}; diff --git a/ytdlp-interface/util.hpp b/ytdlp-interface/util.hpp index a605af9..e52ea4b 100644 --- a/ytdlp-interface/util.hpp +++ b/ytdlp-interface/util.hpp @@ -49,7 +49,7 @@ namespace util DWORD other_instance(std::wstring path = L""); unsigned close_children(bool report_only = false); std::wstring get_sys_folder(REFKNOWNFOLDERID rfid); - std::string get_inet_res(std::string res, std::string *error = nullptr, bool truncate = false); + std::string get_inet_res(std::string res, std::string *error = nullptr, bool truncate = false, std::string token = ""); std::string dl_inet_res(std::string res, fs::path fname, bool *working = nullptr, std::function cb = nullptr); std::string extract_7z(fs::path arc_path, fs::path out_path, unsigned ffmpeg = 0, bool ytdlp_interface = false); std::wstring get_clipboard_text();