From 43349deec5ddc7f7f6aad424de6989498b9aa700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Mon, 30 Dec 2024 14:15:24 +0800 Subject: [PATCH] . --- .github/scripts/build_lunatranslator.py | 3 + .gitignore | 1 + .gitmodules | 3 - cpp/exec/PyStand.cpp | 4 - cpp/libs/libs.cmake | 1 - cpp/libs/tinymp3 | 1 - cpp/version.cmake | 2 +- cpp/winsharedutils/CMakeLists.txt | 5 +- cpp/winsharedutils/mp3enc.cpp | 82 -------- py/LunaTranslator/cishu/goo.py | 13 +- py/LunaTranslator/cishu/mdict.py | 37 ++-- py/LunaTranslator/gui/dialog_savedgame.py | 62 ++---- .../gui/dialog_savedgame_common.py | 2 +- .../gui/dialog_savedgame_legacy.py | 1 - .../gui/dialog_savedgame_setting.py | 2 - py/LunaTranslator/gui/setting_display_ui.py | 18 +- py/LunaTranslator/gui/showword.py | 47 ++++- py/LunaTranslator/gui/transhist.py | 1 - py/LunaTranslator/gui/translatorUI.py | 2 +- py/LunaTranslator/gui/usefulwidget.py | 37 ++++ py/LunaTranslator/myutils/audioplayer.py | 193 +++++++++--------- py/LunaTranslator/myutils/hwnd.py | 2 +- py/LunaTranslator/myutils/utils.py | 17 +- py/LunaTranslator/qtsymbols.py | 8 +- py/LunaTranslator/rendertext/textbrowser.py | 3 +- py/LunaTranslator/winsharedutils.py | 15 -- py/files/defaultconfig/config.json | 15 +- py/files/lang/ar.json | 3 +- py/files/lang/cht.json | 3 +- py/files/lang/cs.json | 3 +- py/files/lang/de.json | 3 +- py/files/lang/en.json | 3 +- py/files/lang/es.json | 3 +- py/files/lang/fr.json | 3 +- py/files/lang/it.json | 3 +- py/files/lang/ja.json | 3 +- py/files/lang/ko.json | 3 +- py/files/lang/nl.json | 3 +- py/files/lang/pl.json | 3 +- py/files/lang/pt.json | 3 +- py/files/lang/ru.json | 3 +- py/files/lang/sv.json | 3 +- py/files/lang/th.json | 3 +- py/files/lang/tr.json | 3 +- py/files/lang/uk.json | 3 +- py/files/lang/vi.json | 3 +- py/files/lang/zh.json | 3 +- py/requirements.txt | 2 +- 48 files changed, 296 insertions(+), 343 deletions(-) delete mode 160000 cpp/libs/tinymp3 delete mode 100644 cpp/winsharedutils/mp3enc.cpp diff --git a/.github/scripts/build_lunatranslator.py b/.github/scripts/build_lunatranslator.py index c04d1bbf..9e5f0216 100644 --- a/.github/scripts/build_lunatranslator.py +++ b/.github/scripts/build_lunatranslator.py @@ -268,6 +268,9 @@ def downloadbass(): "https://www.un4seen.com/files/z/2/bass_spx24.zip", "https://www.un4seen.com/files/z/2/bass_aac24.zip", "https://www.un4seen.com/files/bassopus24.zip", + "https://www.un4seen.com/files/bassenc24.zip", + "https://www.un4seen.com/files/bassenc_mp324.zip", + "https://www.un4seen.com/files/bassenc_opus24.zip", ): name = link.split("/")[-1] d = name.split(".")[0] diff --git a/.gitignore b/.gitignore index 71f82d6f..afc605e4 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ cpp/LunaHook/builds cpp/builds cpp/libs/webview2 cpp/.vscode/settings.json +cpp/libs/bass cpp/libs/opencv-static/windows-x86 cpp/libs/opencv-static/windows-x64 cpp/libs/onnxruntime-static/windows-x86 diff --git a/.gitmodules b/.gitmodules index 5f68ef5a..87353623 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "src/plugins/libs/wechat-ocr"] path = cpp/libs/wechat-ocr url = https://github.com/swigger/wechat-ocr -[submodule "src/plugins/libs/tinymp3"] - path = cpp/libs/tinymp3 - url = https://github.com/HIllya51/tinymp3 [submodule "src/plugins/libs/Clipper2"] path = cpp/libs/Clipper2 url = https://github.com/AngusJohnson/Clipper2 diff --git a/cpp/exec/PyStand.cpp b/cpp/exec/PyStand.cpp index ae56067d..3ff8c2f1 100644 --- a/cpp/exec/PyStand.cpp +++ b/cpp/exec/PyStand.cpp @@ -224,10 +224,6 @@ int PyStand::DetectScript() } SetEnvironmentVariableW(L"PYSTAND_SCRIPT", _script.c_str()); - std::vector buffer(MAX_PATH); - GetModuleFileNameW(GetModuleHandle(0), buffer.data(), MAX_PATH); - SetEnvironmentVariableW(L"LUNA_EXE_NAME", buffer.data()); - return 0; } diff --git a/cpp/libs/libs.cmake b/cpp/libs/libs.cmake index 6a1833e3..9ef0fe94 100644 --- a/cpp/libs/libs.cmake +++ b/cpp/libs/libs.cmake @@ -12,7 +12,6 @@ else() add_library(wil INTERFACE) target_include_directories(wil INTERFACE ${CMAKE_CURRENT_LIST_DIR}/wil/include) - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tinymp3 ${CMAKE_BINARY_DIR}/tinymp3) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/rapidfuzz-cpp ${CMAKE_BINARY_DIR}/rapidfuzz-cpp) diff --git a/cpp/libs/tinymp3 b/cpp/libs/tinymp3 deleted file mode 160000 index 57972618..00000000 --- a/cpp/libs/tinymp3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 579726185979f877f2672b956b23538ff00c08ba diff --git a/cpp/version.cmake b/cpp/version.cmake index bfa61e43..50964542 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 16) -set(VERSION_PATCH 5) +set(VERSION_PATCH 6) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/cpp/winsharedutils/CMakeLists.txt b/cpp/winsharedutils/CMakeLists.txt index 720dde09..c70db6ce 100644 --- a/cpp/winsharedutils/CMakeLists.txt +++ b/cpp/winsharedutils/CMakeLists.txt @@ -10,16 +10,15 @@ generate_product_version( VERSION_MINOR ${VERSION_MINOR} VERSION_PATCH ${VERSION_PATCH} ) -add_library(winsharedutils MODULE mp3enc.cpp webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp +add_library(winsharedutils MODULE webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp applicationloopbackaudio/runer.cpp applicationloopbackaudio/LoopbackCapture.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo}) target_precompile_headers(winsharedutils REUSE_FROM pch) if(NOT WINXP) -target_link_libraries(winsharedutils tinymp3 rapidfuzz wil webview2 Mfplat mfuuid Mmdevapi dwmapi) +target_link_libraries(winsharedutils rapidfuzz wil webview2 Mfplat mfuuid Mmdevapi dwmapi) target_link_options(winsharedutils PRIVATE "/DELAYLOAD:Mmdevapi.dll") target_link_options(winsharedutils PRIVATE "/DELAYLOAD:Mfplat.dll") else() -target_link_libraries(winsharedutils tinymp3) endif() if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64") diff --git a/cpp/winsharedutils/mp3enc.cpp b/cpp/winsharedutils/mp3enc.cpp deleted file mode 100644 index 9180e5de..00000000 --- a/cpp/winsharedutils/mp3enc.cpp +++ /dev/null @@ -1,82 +0,0 @@ - - -#include -#include -#include -#include -#include -#include - -#define DR_WAV_IMPLEMENTATION -#include "dr_wav.h" - -int stereo = STEREO; - -DECLARE_API void encodemp3(void *ptr, size_t size, void (*cb)(void *ptr, size_t size), int bitrate) -{ - shine_config_t config; - shine_t s; - int written; - unsigned char *data; - /* Set the default MPEG encoding paramters - basically init the struct */ - shine_set_config_mpeg_defaults(&config.mpeg); - - config.mpeg.bitr = bitrate; // 8-320; - - uint32_t sampleRate = 0; - uint64_t totalSampleCount = 0; - uint32_t channels = 0; - int16_t *data_in = drwav_open_memory_and_read_pcm_frames_s16(ptr, size, &channels, &sampleRate, &totalSampleCount, NULL); - if (data_in == NULL) - return; - totalSampleCount *= channels; - double startTime = now(); - config.wave.samplerate = sampleRate; - config.wave.channels = (decltype(config.wave.channels))channels; - - /* See if samplerate and bitrate are valid */ - if (shine_check_config(config.wave.samplerate, config.mpeg.bitr) < 0) - return; - // printf("Unsupported samplerate/bitrate configuration."); - - /* Set to stereo mode if wave data is stereo, mono otherwise. */ - if (config.wave.channels > 1) - config.mpeg.mode = (decltype(config.mpeg.mode))stereo; - else - config.mpeg.mode = MONO; - - /* Initiate encoder */ - s = shine_initialise(&config); - - int samples_per_pass = shine_samples_per_pass(s) * channels; - std::string sdata; - /* All the magic happens here */ - size_t count = totalSampleCount / samples_per_pass; - int16_t *buffer = data_in; - for (int i = 0; i < count; i++) - { - data = shine_encode_buffer_interleaved(s, buffer, &written); - sdata += std::string((char *)data, written); - buffer += samples_per_pass; - } - size_t last = totalSampleCount % samples_per_pass; - if (last != 0) - { - int16_t *cache = (int16_t *)calloc(samples_per_pass, sizeof(int16_t)); - if (cache != NULL) - { - memcpy(cache, buffer, last * sizeof(int16_t)); - data = shine_encode_buffer_interleaved(s, cache, &written); - free(cache); - sdata += std::string((char *)data, written); - } - } - /* Flush and write remaining data. */ - data = shine_flush(s, &written); - sdata += std::string((char *)data, written); - /* Close encoder. */ - shine_close(s); - free(data_in); - double time_interval = calcElapsed(startTime, now()); - cb(sdata.data(), sdata.size()); -} diff --git a/py/LunaTranslator/cishu/goo.py b/py/LunaTranslator/cishu/goo.py index 472e672a..66b9f900 100644 --- a/py/LunaTranslator/cishu/goo.py +++ b/py/LunaTranslator/cishu/goo.py @@ -16,11 +16,16 @@ class goo(cishubase): xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/') if not self.style: - self.style = requests.get( - "https://dictionary.goo.ne.jp/mix/css/app.css", proxies=self.proxy - ).text + self.style = ( + requests.get( + "https://dictionary.goo.ne.jp/mix/css/app.css", proxies=self.proxy + ) + .text.replace("width:1004px", "") + .replace("width:1024px", "") + .replace("width:644px", "") + ) if len(xx): - return '
{}
'.format( + return '
{}
'.format( url, self.style, xx ) diff --git a/py/LunaTranslator/cishu/mdict.py b/py/LunaTranslator/cishu/mdict.py index 026fe0aa..2bb2e61e 100644 --- a/py/LunaTranslator/cishu/mdict.py +++ b/py/LunaTranslator/cishu/mdict.py @@ -1,8 +1,8 @@ import math, base64, uuid, gobject from cishu.cishubase import DictTree -from myutils.config import isascii +from myutils.config import isascii, globalconfig from traceback import print_exc -from myutils.audioplayer import bass_decode +from myutils.audioplayer import bass_code_cast import json, os cachejson = None @@ -2293,18 +2293,14 @@ class mdict(cishubase): file_content = self.parse_url_in_mdd(index, url[8:]) if not file_content: return - ext = os.path.splitext(url)[1].lower() - if ext in (".aac", ".spx", ".opus"): - mp3 = bass_decode(file_content, ext) - if not mp3: - print(ext, "decode error") - return - file_content = mp3 - ext = ".mp3" + ext = os.path.splitext(url)[1].lower()[1:] + if True: # ext in ("aac", "spx", "opus"): + new, ext = bass_code_cast(file_content, fr=ext) + file_content = new varname = "var_" + hashlib.md5(file_content).hexdigest() audiob64vals[varname] = base64.b64encode(file_content).decode() return 3, "javascript:mdict_play_sound('{}',{})".format( - query_mime(ext), varname + query_mime("." + ext), varname ) file_content = self.parse_url_in_mdd(index, url) if not file_content: @@ -2515,7 +2511,7 @@ class mdict(cishubase): ) ) idx += 1 - commonstyle = """ + res = """