Skip to content

Commit

Permalink
Support http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Dec 14, 2023
1 parent 6545d6f commit c678c9d
Show file tree
Hide file tree
Showing 23 changed files with 160 additions and 30 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ mingw32-make -C build wiliwili -j$(nproc)

由于 SDL2 支持的平台更多,考虑到未来向其他平台移植,所以 wiliwili 也支持切换到 SDL2 环境构建。

⚠️:PC 平台非测试所需请不要使用此方式构建,没有经过太多的测试,且不支持 PC 系统输入法。

```shell
cmake -B build -DPLATFORM_DESKTOP=ON -DUSE_SDL2=ON
cmake --build build
Expand Down Expand Up @@ -310,7 +308,7 @@ sudo dkp-pacman -S switch-glfw switch-libwebp switch-cmake switch-curl devkitA64
base_url="https://github.com/xfangfang/wiliwili/releases/download/v0.1.0"
sudo dkp-pacman -U \
$base_url/switch-libass-0.17.1-1-any.pkg.tar.zst \
$base_url/switch-ffmpeg-6.1-3-any.pkg.tar.zst \
$base_url/switch-ffmpeg-6.1-4-any.pkg.tar.zst \
$base_url/switch-libmpv-0.36.0-1-any.pkg.tar.zst

# 4. 可选:安装依赖库 nspmini:https://github.com/StarDustCFW/nspmini
Expand Down
5 changes: 5 additions & 0 deletions resources/i18n/en-US/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"texture": "Number of picture texture caches",
"threads": "Number of image loading threads"
},
"network": {
"header": "Network",
"proxy": "Proxy",
"proxy_hint": "example: http://127.0.0.1:7890"
},
"others": {
"header": "Others",
"vibration": "Gamepad vibration",
Expand Down
5 changes: 5 additions & 0 deletions resources/i18n/zh-Hans/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"texture": "图片纹理缓存数量",
"threads": "图片加载线程数"
},
"network": {
"header": "网络设置",
"proxy": "网络代理",
"proxy_hint": "示例: http://127.0.0.1:7890"
},
"others": {
"header": "其他",
"vibration": "手柄振动",
Expand Down
5 changes: 5 additions & 0 deletions resources/i18n/zh-Hant/wiliwili.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"texture": "圖片紋理快取數量",
"threads": "圖片加載線程數"
},
"network": {
"header": "網絡設定",
"proxy": "網絡代理",
"proxy_hint": "示例: http://127.0.0.1:7890"
},
"others": {
"header": "其他",
"vibration": "手柄振動",
Expand Down
18 changes: 18 additions & 0 deletions resources/xml/activity/setting_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@
<SelectorCell
id="setting/image/threads"/>

</brls:Box>
<brls:Header
width="auto"
height="auto"
title="@i18n/wiliwili/setting/app/network/header"
marginBottom="0px"/>
<brls:Box
width="100%"
height="auto"
axis="column"
marginBottom="30px">

<brls:BooleanCell
id="setting/network/proxy"/>

<brls:InputCell
id="setting/network/input"/>

</brls:Box>
<brls:Header
width="auto"
Expand Down
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ done
base_url="https://github.com/xfangfang/wiliwili/releases/download/v0.1.0"
sudo dkp-pacman -U \
$base_url/switch-libass-0.17.1-1-any.pkg.tar.zst \
$base_url/switch-ffmpeg-6.1-3-any.pkg.tar.zst \
$base_url/switch-ffmpeg-6.1-4-any.pkg.tar.zst \
$base_url/switch-libmpv-0.36.0-1-any.pkg.tar.zst
```

Expand Down
2 changes: 1 addition & 1 deletion scripts/build_switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BASE_URL="https://github.com/xfangfang/wiliwili/releases/download/v0.1.0/"
PKGS=(
"switch-libass-0.17.1-1-any.pkg.tar.zst"
"switch-dav1d-1.2.1-1-any.pkg.tar.zst"
"switch-ffmpeg-6.1-3-any.pkg.tar.zst"
"switch-ffmpeg-6.1-4-any.pkg.tar.zst"
"switch-libmpv-0.36.0-1-any.pkg.tar.zst"
"switch-nspmini-48d4fc2-1-any.pkg.tar.xz"
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_switch_deko3d.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PKGS=(
"libuam-f8c9eef01ffe06334d530393d636d69e2b52744b-1-any.pkg.tar.zst"
"switch-dav1d-1.2.1-1-any.pkg.tar.zst"
"switch-libass-0.17.1-1-any.pkg.tar.zst"
"switch-ffmpeg-6.1-3-any.pkg.tar.zst"
"switch-ffmpeg-6.1-4-any.pkg.tar.zst"
"switch-libmpv_deko3d-0.35.1-4-any.pkg.tar.zst"
"switch-nspmini-48d4fc2-1-any.pkg.tar.xz"
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/ps4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN BASE_URL="https://github.com/xfangfang/wiliwili/releases/download/v0.1.0" &&
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-mbedtls-2.28.5-1-any.pkg.tar.xz && \
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-libcurl-7.80.0-3-any.pkg.tar.xz && \
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-cpr-1.10.5-1-any.pkg.tar.xz && \
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-ffmpeg-6.0-1-any.pkg.tar.xz && \
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-ffmpeg-6.0-2-any.pkg.tar.xz && \
pacbrew-pacman -U --needed --noconfirm $BASE_URL/ps4-openorbis-libmpv-0.36.0-1-any.pkg.tar.xz && \
pacbrew-pacman -S --needed --noconfirm ps4-openorbis-libwebp && \
yes | pacbrew-pacman -Scc
Expand Down
4 changes: 2 additions & 2 deletions scripts/ps4/ffmpeg/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgname=ps4-openorbis-ffmpeg
pkgver=6.0
pkgrel=1
pkgrel=2
pkgdesc='ffmpeg port'
arch=('any')
url='https://ffmpeg.org/'
Expand All @@ -27,7 +27,7 @@ build() {
--disable-programs --disable-debug --disable-doc \
--disable-avdevice --disable-hwaccels --disable-encoders --disable-muxers \
--enable-swscale --enable-swresample --enable-network \
--disable-protocols --enable-protocol=file,http,https,ftp,tcp,udp,rtmp --enable-version3 \
--disable-protocols --enable-protocol=file,http,https,ftp,tcp,udp,rtmp,rtp,crypto,httpproxy --enable-version3 \
--enable-zlib --enable-bzlib --enable-libass --enable-libfreetype --enable-libfribidi --enable-mbedtls \
--cc=$CC --cxx=$CXX --nm=$NM --strip=$STRIP --ar=$AR --ranlib=$RANLIB

Expand Down
6 changes: 3 additions & 3 deletions scripts/psv/ffmpeg/VITABUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkgname=ffmpeg
pkgver=7900d3684acc8e5e98fd39cbb12cb7ab73e6d4a5
pkgrel=1
pkgrel=2
url="https://ffmpeg.org/"
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/fish47/FFmpeg-vita/archive/${pkgver}.tar.gz")
sha256sums=('SKIP')
Expand Down Expand Up @@ -32,7 +32,7 @@ build() {
--enable-decoder='h264,aac,bmp,flv,flac,aac_vita,mp3_vita,h264_vita' \
--enable-network \
--disable-protocols \
--enable-protocol='file,http,tcp,tls,hls,https' \
--enable-protocol='file,http,tcp,tls,hls,https,rtp,crypto,httpproxy' \
--disable-iconv \
--disable-lzma \
--disable-sdl2 \
Expand All @@ -43,7 +43,7 @@ build() {

sed 's/#define HAVE_GETADDRINFO 1/#define HAVE_GETADDRINFO 0/g' -i config.h

make -j$(nproc)
make -j12
}

package () {
Expand Down
4 changes: 2 additions & 2 deletions scripts/switch/ffmpeg/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pkgname=switch-ffmpeg
pkgver=6.1
commit=ff3429991ec1bac1d1b71215402e3d195162e125
pkgrel=3
pkgrel=4
pkgdesc='ffmpeg port (for Nintendo Switch homebrew development)'
arch=('any')
url='https://ffmpeg.org/'
Expand Down Expand Up @@ -61,7 +61,7 @@ build() {
--enable-asm --enable-neon \
--disable-postproc --disable-avdevice --disable-encoders --disable-muxers \
--enable-swscale --enable-swresample --enable-network \
--disable-protocols --enable-protocol=file,http,tcp,udp,rtmp,hls,https,tls,ftp \
--disable-protocols --enable-protocol=file,http,tcp,udp,rtmp,hls,https,tls,ftp,rtp,crypto,httpproxy \
--enable-zlib --enable-bzlib --enable-libass --enable-libfreetype --enable-libfribidi --enable-libdav1d \
--enable-gpl --enable-tx1 \
--enable-version3 --enable-mbedtls
Expand Down
2 changes: 2 additions & 0 deletions wiliwili/include/activity/setting_activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SettingActivity : public brls::Activity {
BRLS_BIND(brls::RadioCell, btnOpenConfig, "tools/config_dir");
BRLS_BIND(brls::RadioCell, btnVibrationTest, "tools/vibration_test");
BRLS_BIND(brls::RadioCell, btnDLNA, "tools/dlna");
BRLS_BIND(brls::BooleanCell, btnProxy, "setting/network/proxy");
BRLS_BIND(brls::InputCell, btnProxyInput, "setting/network/input");
BRLS_BIND(SelectorCell, selectorLang, "setting/language");
BRLS_BIND(SelectorCell, selectorTheme, "setting/ui/theme");
BRLS_BIND(SelectorCell, selectorCustomTheme, "setting/custom/theme");
Expand Down
3 changes: 3 additions & 0 deletions wiliwili/include/api/bilibili.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ class BilibiliClient {
int timeout = 10000, const std::string& httpProxy = "",
const std::string& httpsProxy = "");

static void setProxy(const std::string& httpProxy = "",
const std::string& httpsProxy = "");

static std::string genRandomBuvid3();
};
} // namespace bilibili
8 changes: 8 additions & 0 deletions wiliwili/include/utils/config_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ enum class SettingItem {
DLNA_IP,
DLNA_PORT,
DLNA_NAME,
HTTP_PROXY,
HTTP_PROXY_STATUS,
};

class APPVersion : public brls::Singleton<APPVersion> {
Expand Down Expand Up @@ -220,13 +222,19 @@ class ProgramConfig : public brls::Singleton<ProgramConfig> {

std::vector<CustomTheme> getCustomThemes();

std::string getProxy();

void setProxy(const std::string& proxy);

std::vector<CustomTheme> customThemes;
Cookie cookie = {{"DedeUserID", "0"}};
std::string refreshToken;
nlohmann::json setting;
std::string client;
std::string device;
std::vector<std::string> searchHistory;
std::string httpProxy;
std::string httpsProxy;

static std::unordered_map<SettingItem, ProgramOption> SETTING_MAP;
};
Expand Down
64 changes: 50 additions & 14 deletions wiliwili/source/activity/setting_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Created by fang on 2022/8/22.
//

#include <pystring.h>

#include "activity/setting_activity.hpp"
#include "activity/hint_activity.hpp"
#include "activity/search_activity_tv.hpp"
Expand Down Expand Up @@ -295,19 +297,17 @@ void SettingActivity::onContentAvailable() {

/// Limited FPS
auto fpsOption = conf.getOptionData(SettingItem::LIMITED_FPS);
selectorFPS->init(
"wiliwili/setting/app/others/limited_fps"_i18n,
{"wiliwili/setting/app/others/limited_fps_vsync"_i18n,
"30",
"60",
"90",
"120"},
(size_t)conf.getIntOptionIndex(SettingItem::LIMITED_FPS), [fpsOption](int data) {
int fps = fpsOption.rawOptionList[data];
brls::Application::setLimitedFPS(fps);
ProgramConfig::instance().setSettingItem(SettingItem::LIMITED_FPS, fps);
return true;
});
selectorFPS->init("wiliwili/setting/app/others/limited_fps"_i18n,
{"wiliwili/setting/app/others/limited_fps_vsync"_i18n,
"30", "60", "90", "120"},
(size_t)conf.getIntOptionIndex(SettingItem::LIMITED_FPS),
[fpsOption](int data) {
int fps = fpsOption.rawOptionList[data];
brls::Application::setLimitedFPS(fps);
ProgramConfig::instance().setSettingItem(
SettingItem::LIMITED_FPS, fps);
return true;
});

/// TV Search Mode
cellTvSearch->init("wiliwili/setting/app/others/tv_search"_i18n,
Expand Down Expand Up @@ -375,7 +375,7 @@ void SettingActivity::onContentAvailable() {
selectorCustomTheme->setVisibility(brls::Visibility::GONE);
} else {
std::vector<std::string> customThemeNameList = {"hints/off"_i18n};
int customThemeIndex = 0;
int customThemeIndex = 0;
for (size_t index = 0; index < customThemeList.size(); index++) {
customThemeNameList.emplace_back(customThemeList[index].name);
if (customThemeID == customThemeList[index].id) {
Expand Down Expand Up @@ -598,6 +598,42 @@ void SettingActivity::onContentAvailable() {
MPVCore::instance().restart();
});

/// HTTP proxy
bool httpProxyStatus = conf.getBoolOption(SettingItem::HTTP_PROXY_STATUS);
btnProxy->init(
"wiliwili/setting/app/network/proxy"_i18n, httpProxyStatus,
[this](bool data) {
auto& conf = ProgramConfig::instance();
conf.setSettingItem(SettingItem::HTTP_PROXY_STATUS, data);
btnProxyInput->setVisibility(data ? brls::Visibility::VISIBLE
: brls::Visibility::GONE);
conf.setProxy(data ? conf.getSettingItem(SettingItem::HTTP_PROXY,
std::string{""})
: "");
});

btnProxyInput->setVisibility(httpProxyStatus ? brls::Visibility::VISIBLE
: brls::Visibility::GONE);
auto httpProxy =
conf.getSettingItem(SettingItem::HTTP_PROXY, std::string{""});
btnProxyInput->init(
"wiliwili/setting/app/network/proxy"_i18n, httpProxy,
[](const std::string& data) {
std::string httpProxy = data;
// 如果没有写协议,默认用 http
if (!httpProxy.empty() &&
!pystring::startswith(httpProxy, "http://") &&
!pystring::startswith(httpProxy, "https://") &&
!pystring::startswith(httpProxy, "socks5://")) {
httpProxy = "http://" + httpProxy;
}
ProgramConfig::instance().setSettingItem(SettingItem::HTTP_PROXY,
httpProxy);
ProgramConfig::instance().setProxy(httpProxy);
},
"http://127.0.0.1:7890",
"wiliwili/setting/app/network/proxy_hint"_i18n);

/// Hardware decode
#ifdef PS4
btnHWDEC->setVisibility(brls::Visibility::GONE);
Expand Down
2 changes: 2 additions & 0 deletions wiliwili/source/api/analytics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cpr/cpr.h>
#include "utils/config_helper.hpp"
#include "utils/number_helper.hpp"
#include "api/bilibili/util/http.hpp"
#include <fmt/format.h>
#include <borealis/core/thread.hpp>
#include <borealis/core/logger.hpp>
Expand Down Expand Up @@ -77,6 +78,7 @@ void Analytics::send() {
#ifndef VERIFY_SSL
cpr::VerifySsl{false},
#endif
bilibili::HTTP::PROXIES,
cpr::Url{GA_URL},
cpr::Header{{"User-Agent", "wiliwili/" + app_version},
{"Content-Type", "application/json"}},
Expand Down
7 changes: 7 additions & 0 deletions wiliwili/source/api/bilibili.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ void BilibiliClient::init(Cookies& data,
HTTP::PROXIES = {{"http", httpProxy}, {"https", httpsProxy}};
}

void BilibiliClient::setProxy(const std::string& httpProxy,
const std::string& httpsProxy) {
HTTP::PROXIES = {};
if (!httpProxy.empty() && !httpsProxy.empty())
HTTP::PROXIES = {{"http", httpProxy}, {"https", httpsProxy}};
}

} // namespace bilibili
4 changes: 4 additions & 0 deletions wiliwili/source/api/video_detail_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void BilibiliClient::get_webmask(
#ifndef VERIFY_SSL
cpr::VerifySsl{false},
#endif
HTTP::PROXIES,
cpr::Url{url}, HTTP::HEADERS, HTTP::COOKIES,
cpr::Timeout{HTTP::TIMEOUT});
}
Expand Down Expand Up @@ -329,6 +330,7 @@ void BilibiliClient::get_danmaku(
#ifndef VERIFY_SSL
cpr::VerifySsl{false},
#endif
HTTP::PROXIES,
cpr::Url{Api::VideoDanmaku}, HTTP::HEADERS,
cpr::Parameters({{"oid", std::to_string(cid)}}), HTTP::COOKIES,
cpr::Timeout{HTTP::TIMEOUT});
Expand All @@ -354,6 +356,7 @@ void BilibiliClient::get_highlight_progress(
#ifndef VERIFY_SSL
cpr::VerifySsl{false},
#endif
HTTP::PROXIES,
cpr::Url{Api::VideoHighlight}, HTTP::HEADERS,
cpr::Parameters({{"cid", std::to_string(cid)}}), HTTP::COOKIES,
cpr::Timeout{HTTP::TIMEOUT});
Expand Down Expand Up @@ -383,6 +386,7 @@ void BilibiliClient::get_subtitle(
#ifndef VERIFY_SSL
cpr::VerifySsl{false},
#endif
HTTP::PROXIES,
cpr::Url{url}, HTTP::HEADERS, cpr::Parameters({}), HTTP::COOKIES,
cpr::Timeout{HTTP::TIMEOUT});
}
Expand Down
Loading

0 comments on commit c678c9d

Please sign in to comment.