mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 14:57:52 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f1c0884c0 | ||
|
|
e8b97ef872 | ||
|
|
73a7fd15ed | ||
|
|
72beefbebe | ||
|
|
2b0e1e3cbb | ||
|
|
8a605887ff | ||
|
|
56637adc3c | ||
|
|
886853b46f | ||
|
|
ceb56a2eee | ||
|
|
4cee0f3031 |
@@ -1,6 +1,8 @@
|
|||||||
module github.com/OwO-Network/DeepLX
|
module github.com/OwO-Network/DeepLX
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.0
|
||||||
|
|
||||||
|
toolchain go1.24.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/abadojack/whatlanggo v1.0.1
|
github.com/abadojack/whatlanggo v1.0.1
|
||||||
@@ -15,7 +17,7 @@ require (
|
|||||||
github.com/bytedance/sonic v1.11.2 // indirect
|
github.com/bytedance/sonic v1.11.2 // indirect
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||||
github.com/cloudflare/circl v1.4.0 // indirect
|
github.com/cloudflare/circl v1.6.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
@@ -38,20 +40,20 @@ require (
|
|||||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||||
github.com/quic-go/qpack v0.5.1 // indirect
|
github.com/quic-go/qpack v0.5.1 // indirect
|
||||||
github.com/quic-go/quic-go v0.48.2 // indirect
|
github.com/quic-go/quic-go v0.48.2 // indirect
|
||||||
github.com/refraction-networking/utls v1.6.7 // indirect
|
github.com/refraction-networking/utls v1.7.0 // indirect
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/tidwall/pretty v1.2.0 // indirect
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
go.uber.org/mock v0.4.0 // indirect
|
go.uber.org/mock v0.4.0 // indirect
|
||||||
golang.org/x/arch v0.7.0 // indirect
|
golang.org/x/arch v0.7.0 // indirect
|
||||||
golang.org/x/crypto v0.35.0 // indirect
|
golang.org/x/crypto v0.36.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||||
golang.org/x/mod v0.21.0 // indirect
|
golang.org/x/mod v0.21.0 // indirect
|
||||||
golang.org/x/net v0.36.0 // indirect
|
golang.org/x/net v0.38.0 // indirect
|
||||||
golang.org/x/sync v0.11.0 // indirect
|
golang.org/x/sync v0.12.0 // indirect
|
||||||
golang.org/x/sys v0.30.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
golang.org/x/text v0.22.0 // indirect
|
golang.org/x/text v0.23.0 // indirect
|
||||||
golang.org/x/tools v0.25.0 // indirect
|
golang.org/x/tools v0.25.0 // indirect
|
||||||
google.golang.org/protobuf v1.34.1 // indirect
|
google.golang.org/protobuf v1.34.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpV
|
|||||||
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||||
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
|
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
|
||||||
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||||
github.com/cloudflare/circl v1.4.0 h1:BV7h5MgrktNzytKmWjpOtdYrf0lkkbF8YMlBGPhJQrY=
|
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||||
github.com/cloudflare/circl v1.4.0/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU=
|
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
@@ -86,8 +86,8 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
|||||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||||
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
|
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
|
||||||
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
|
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
|
||||||
github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM=
|
github.com/refraction-networking/utls v1.7.0 h1:9JTnze/Md74uS3ZWiRAabityY0un69rOLXsBf8LGgTs=
|
||||||
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
github.com/refraction-networking/utls v1.7.0/go.mod h1:lV0Gwc1/Fi+HYH8hOtgFRdHfKo4FKSn6+FdyOz9hRms=
|
||||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
@@ -116,22 +116,22 @@ go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
|||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
||||||
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||||
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
|
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||||
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
|
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
||||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||||
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
|
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||||
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
|
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||||
|
|||||||
+92
-181
@@ -2,7 +2,7 @@
|
|||||||
* @Author: Vincent Young
|
* @Author: Vincent Young
|
||||||
* @Date: 2024-09-16 11:59:24
|
* @Date: 2024-09-16 11:59:24
|
||||||
* @LastEditors: Vincent Yang
|
* @LastEditors: Vincent Yang
|
||||||
* @LastEditTime: 2025-04-08 14:26:33
|
* @LastEditTime: 2025-07-13 23:09:49
|
||||||
* @FilePath: /DeepLX/translate/translate.go
|
* @FilePath: /DeepLX/translate/translate.go
|
||||||
* @Telegram: https://t.me/missuo
|
* @Telegram: https://t.me/missuo
|
||||||
* @GitHub: https://github.com/missuo
|
* @GitHub: https://github.com/missuo
|
||||||
@@ -29,28 +29,25 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
// makeRequest makes an HTTP request to DeepL API
|
// makeRequestWithBody makes an HTTP request with pre-formatted body using minimal headers
|
||||||
func makeRequest(postData *PostData, proxyURL string, dlSession string) (gjson.Result, error) {
|
func makeRequestWithBody(postStr string, proxyURL string, dlSession string) (gjson.Result, error) {
|
||||||
urlFull := "https://www2.deepl.com/jsonrpc"
|
urlFull := "https://www2.deepl.com/jsonrpc"
|
||||||
postStr := formatPostString(postData)
|
|
||||||
|
|
||||||
// Create a new req client
|
// Create a new req client
|
||||||
client := req.C().SetTLSFingerprintRandomized()
|
client := req.C().SetTLSFingerprintRandomized()
|
||||||
|
|
||||||
// Set headers
|
// Set headers to simulate browser request
|
||||||
headers := http.Header{
|
headers := http.Header{
|
||||||
"Content-Type": []string{"application/json"},
|
"Content-Type": []string{"application/json"},
|
||||||
"User-Agent": []string{"DeepL/1627620 CFNetwork/3826.500.62.2.1 Darwin/24.4.0"},
|
"Accept": []string{"*/*"},
|
||||||
"Accept": []string{"*/*"},
|
"Accept-Language": []string{"en-US,en;q=0.9"},
|
||||||
"X-App-Os-Name": []string{"iOS"},
|
"Accept-Encoding": []string{"gzip, deflate, br, zstd"},
|
||||||
"X-App-Os-Version": []string{"18.4.0"},
|
"Origin": []string{"https://www.deepl.com"},
|
||||||
"Accept-Language": []string{"en-US,en;q=0.9"},
|
"Referer": []string{"https://www.deepl.com/"},
|
||||||
"Accept-Encoding": []string{"gzip, deflate, br"}, // Keep this!
|
"Sec-Fetch-Dest": []string{"empty"},
|
||||||
"X-App-Device": []string{"iPhone16,2"},
|
"Sec-Fetch-Mode": []string{"cors"},
|
||||||
"Referer": []string{"https://www.deepl.com/"},
|
"Sec-Fetch-Site": []string{"same-site"},
|
||||||
"X-Product": []string{"translator"},
|
"User-Agent": []string{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0"},
|
||||||
"X-App-Build": []string{"1627620"},
|
|
||||||
"X-App-Version": []string{"25.1"},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if dlSession != "" {
|
if dlSession != "" {
|
||||||
@@ -77,17 +74,27 @@ func makeRequest(postData *PostData, proxyURL string, dlSession string) (gjson.R
|
|||||||
return gjson.Result{}, err
|
return gjson.Result{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for blocked status like TypeScript version
|
||||||
|
if resp.StatusCode == 429 {
|
||||||
|
return gjson.Result{}, fmt.Errorf("too many requests, your IP has been blocked by DeepL temporarily, please don't request it frequently in a short time")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for other error status codes
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return gjson.Result{}, fmt.Errorf("request failed with status code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
var bodyReader io.Reader
|
var bodyReader io.Reader
|
||||||
contentEncoding := resp.Header.Get("Content-Encoding")
|
contentEncoding := resp.Header.Get("Content-Encoding")
|
||||||
switch contentEncoding {
|
switch contentEncoding {
|
||||||
case "br":
|
case "br":
|
||||||
bodyReader = brotli.NewReader(resp.Body)
|
bodyReader = brotli.NewReader(resp.Body)
|
||||||
case "gzip":
|
case "gzip":
|
||||||
bodyReader, err = gzip.NewReader(resp.Body) // Use gzip.NewReader
|
bodyReader, err = gzip.NewReader(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gjson.Result{}, fmt.Errorf("failed to create gzip reader: %w", err)
|
return gjson.Result{}, fmt.Errorf("failed to create gzip reader: %w", err)
|
||||||
}
|
}
|
||||||
case "deflate": // Less common, but good to handle
|
case "deflate":
|
||||||
bodyReader = flate.NewReader(resp.Body)
|
bodyReader = flate.NewReader(resp.Body)
|
||||||
default:
|
default:
|
||||||
bodyReader = resp.Body
|
bodyReader = resp.Body
|
||||||
@@ -109,182 +116,86 @@ func TranslateByDeepLX(sourceLang, targetLang, text string, tagHandling string,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagHandling == "" {
|
// Get detected language if source language is auto
|
||||||
tagHandling = "plaintext"
|
if sourceLang == "auto" || sourceLang == "" {
|
||||||
|
sourceLang = strings.ToUpper(whatlanggo.DetectLang(text).Iso6391())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split text by newlines and store them for later reconstruction
|
// Prepare translation request using new LMT_handle_texts method
|
||||||
textParts := strings.Split(text, "\n")
|
id := getRandomNumber()
|
||||||
var translatedParts []string
|
iCount := getICount(text)
|
||||||
var allAlternatives [][]string // Store alternatives for each part
|
timestamp := getTimeStamp(iCount)
|
||||||
|
|
||||||
for _, part := range textParts {
|
postData := &PostData{
|
||||||
if strings.TrimSpace(part) == "" {
|
Jsonrpc: "2.0",
|
||||||
translatedParts = append(translatedParts, "")
|
Method: "LMT_handle_texts",
|
||||||
allAlternatives = append(allAlternatives, []string{""})
|
ID: id,
|
||||||
continue
|
Params: Params{
|
||||||
}
|
Splitting: "newlines",
|
||||||
|
Lang: Lang{
|
||||||
// Get detected language if source language is auto
|
SourceLangUserSelected: sourceLang,
|
||||||
if sourceLang == "auto" || sourceLang == "" {
|
TargetLang: targetLang,
|
||||||
sourceLang = strings.ToUpper(whatlanggo.DetectLang(part).Iso6391())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare jobs from split result
|
|
||||||
var jobs []Job
|
|
||||||
|
|
||||||
jobs = append(jobs, Job{
|
|
||||||
Kind: "default",
|
|
||||||
PreferredNumBeams: 4,
|
|
||||||
RawEnContextBefore: []string{},
|
|
||||||
RawEnContextAfter: []string{},
|
|
||||||
Sentences: []Sentence{{
|
|
||||||
Prefix: "",
|
|
||||||
Text: text,
|
|
||||||
ID: 0,
|
|
||||||
}},
|
|
||||||
})
|
|
||||||
|
|
||||||
hasRegionalVariant := false
|
|
||||||
targetLangCode := targetLang
|
|
||||||
targetLangParts := strings.Split(targetLang, "-")
|
|
||||||
if len(targetLangParts) > 1 {
|
|
||||||
targetLangCode = targetLangParts[0]
|
|
||||||
hasRegionalVariant = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare translation request
|
|
||||||
id := getRandomNumber()
|
|
||||||
|
|
||||||
postData := &PostData{
|
|
||||||
Jsonrpc: "2.0",
|
|
||||||
Method: "LMT_handle_jobs",
|
|
||||||
ID: id,
|
|
||||||
Params: Params{
|
|
||||||
CommonJobParams: CommonJobParams{
|
|
||||||
Mode: "translate",
|
|
||||||
Formality: "undefined",
|
|
||||||
TranscribeAs: "romanize",
|
|
||||||
AdvancedMode: false,
|
|
||||||
TextType: tagHandling,
|
|
||||||
WasSpoken: false,
|
|
||||||
},
|
|
||||||
Lang: Lang{
|
|
||||||
SourceLangUserSelected: "auto",
|
|
||||||
TargetLang: strings.ToUpper(targetLangCode),
|
|
||||||
SourceLangComputed: strings.ToUpper(sourceLang),
|
|
||||||
},
|
|
||||||
Jobs: jobs,
|
|
||||||
Timestamp: getTimeStamp(getICount(part)),
|
|
||||||
},
|
},
|
||||||
}
|
Texts: []TextItem{{
|
||||||
|
Text: text,
|
||||||
if hasRegionalVariant {
|
RequestAlternatives: 3,
|
||||||
postData = &PostData{
|
}},
|
||||||
Jsonrpc: "2.0",
|
Timestamp: timestamp,
|
||||||
Method: "LMT_handle_jobs",
|
},
|
||||||
ID: id,
|
|
||||||
Params: Params{
|
|
||||||
CommonJobParams: CommonJobParams{
|
|
||||||
Mode: "translate",
|
|
||||||
Formality: "undefined",
|
|
||||||
TranscribeAs: "romanize",
|
|
||||||
AdvancedMode: false,
|
|
||||||
TextType: tagHandling,
|
|
||||||
WasSpoken: false,
|
|
||||||
RegionalVariant: targetLang,
|
|
||||||
},
|
|
||||||
Lang: Lang{
|
|
||||||
SourceLangUserSelected: "auto",
|
|
||||||
TargetLang: strings.ToUpper(targetLangCode),
|
|
||||||
SourceLangComputed: strings.ToUpper(sourceLang),
|
|
||||||
},
|
|
||||||
Jobs: jobs,
|
|
||||||
Timestamp: getTimeStamp(getICount(part)),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make translation request
|
|
||||||
result, err := makeRequest(postData, proxyURL, dlSession)
|
|
||||||
if err != nil {
|
|
||||||
return DeepLXTranslationResult{
|
|
||||||
Code: http.StatusServiceUnavailable,
|
|
||||||
Message: err.Error(),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process translation results
|
|
||||||
var partTranslation string
|
|
||||||
var partAlternatives []string
|
|
||||||
|
|
||||||
translations := result.Get("result.translations").Array()
|
|
||||||
if len(translations) > 0 {
|
|
||||||
// Process main translation
|
|
||||||
for _, translation := range translations {
|
|
||||||
partTranslation += translation.Get("beams.0.sentences.0.text").String() + " "
|
|
||||||
}
|
|
||||||
partTranslation = strings.TrimSpace(partTranslation)
|
|
||||||
|
|
||||||
// Process alternatives
|
|
||||||
numBeams := len(translations[0].Get("beams").Array())
|
|
||||||
for i := 1; i < numBeams; i++ { // Start from 1 since 0 is the main translation
|
|
||||||
var altText string
|
|
||||||
for _, translation := range translations {
|
|
||||||
beams := translation.Get("beams").Array()
|
|
||||||
if i < len(beams) {
|
|
||||||
altText += beams[i].Get("sentences.0.text").String() + " "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if altText != "" {
|
|
||||||
partAlternatives = append(partAlternatives, strings.TrimSpace(altText))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if partTranslation == "" {
|
|
||||||
return DeepLXTranslationResult{
|
|
||||||
Code: http.StatusServiceUnavailable,
|
|
||||||
Message: "Translation failed",
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
translatedParts = append(translatedParts, partTranslation)
|
|
||||||
allAlternatives = append(allAlternatives, partAlternatives)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join all translated parts with newlines
|
// Format and apply body manipulation method like TypeScript
|
||||||
translatedText := strings.Join(translatedParts, "\n")
|
postStr := formatPostString(postData)
|
||||||
|
postStr = handlerBodyMethod(id, postStr)
|
||||||
|
|
||||||
// Combine alternatives with proper newline handling
|
// Make translation request
|
||||||
var combinedAlternatives []string
|
result, err := makeRequestWithBody(postStr, proxyURL, dlSession)
|
||||||
maxAlts := 0
|
if err != nil {
|
||||||
for _, alts := range allAlternatives {
|
return DeepLXTranslationResult{
|
||||||
if len(alts) > maxAlts {
|
Code: http.StatusServiceUnavailable,
|
||||||
maxAlts = len(alts)
|
Message: err.Error(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process translation results using new format
|
||||||
|
textsArray := result.Get("result.texts").Array()
|
||||||
|
if len(textsArray) == 0 {
|
||||||
|
return DeepLXTranslationResult{
|
||||||
|
Code: http.StatusServiceUnavailable,
|
||||||
|
Message: "Translation failed",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get main translation
|
||||||
|
mainText := textsArray[0].Get("text").String()
|
||||||
|
if mainText == "" {
|
||||||
|
return DeepLXTranslationResult{
|
||||||
|
Code: http.StatusServiceUnavailable,
|
||||||
|
Message: "Translation failed",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get alternatives
|
||||||
|
var alternatives []string
|
||||||
|
alternativesArray := textsArray[0].Get("alternatives").Array()
|
||||||
|
for _, alt := range alternativesArray {
|
||||||
|
altText := alt.Get("text").String()
|
||||||
|
if altText != "" {
|
||||||
|
alternatives = append(alternatives, altText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create combined alternatives preserving line structure
|
// Get detected source language from response
|
||||||
for i := 0; i < maxAlts; i++ {
|
detectedLang := result.Get("result.lang").String()
|
||||||
var altParts []string
|
if detectedLang != "" {
|
||||||
for j, alts := range allAlternatives {
|
sourceLang = detectedLang
|
||||||
if i < len(alts) {
|
|
||||||
altParts = append(altParts, alts[i])
|
|
||||||
} else if len(translatedParts[j]) == 0 {
|
|
||||||
altParts = append(altParts, "") // Keep empty lines
|
|
||||||
} else {
|
|
||||||
altParts = append(altParts, translatedParts[j]) // Use main translation if no alternative
|
|
||||||
}
|
|
||||||
}
|
|
||||||
combinedAlternatives = append(combinedAlternatives, strings.Join(altParts, "\n"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DeepLXTranslationResult{
|
return DeepLXTranslationResult{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
ID: getRandomNumber(), // Using new ID for the complete translation
|
ID: id,
|
||||||
Data: translatedText,
|
Data: mainText,
|
||||||
Alternatives: combinedAlternatives,
|
Alternatives: alternatives,
|
||||||
SourceLang: sourceLang,
|
SourceLang: sourceLang,
|
||||||
TargetLang: targetLang,
|
TargetLang: targetLang,
|
||||||
Method: map[bool]string{true: "Pro", false: "Free"}[dlSession != ""],
|
Method: map[bool]string{true: "Pro", false: "Free"}[dlSession != ""],
|
||||||
|
|||||||
+33
-1
@@ -46,8 +46,22 @@ type Job struct {
|
|||||||
Sentences []Sentence `json:"sentences"`
|
Sentences []Sentence `json:"sentences"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TextItem represents a text item for translation
|
||||||
|
type TextItem struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
RequestAlternatives int `json:"requestAlternatives"`
|
||||||
|
}
|
||||||
|
|
||||||
// Params represents parameters for translation requests
|
// Params represents parameters for translation requests
|
||||||
type Params struct {
|
type Params struct {
|
||||||
|
Splitting string `json:"splitting"`
|
||||||
|
Lang Lang `json:"lang"`
|
||||||
|
Texts []TextItem `json:"texts"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LegacyParams represents the old parameters structure for jobs (kept for compatibility)
|
||||||
|
type LegacyParams struct {
|
||||||
CommonJobParams CommonJobParams `json:"commonJobParams"`
|
CommonJobParams CommonJobParams `json:"commonJobParams"`
|
||||||
Lang Lang `json:"lang"`
|
Lang Lang `json:"lang"`
|
||||||
Jobs []Job `json:"jobs"`
|
Jobs []Job `json:"jobs"`
|
||||||
@@ -62,8 +76,26 @@ type PostData struct {
|
|||||||
Params Params `json:"params"`
|
Params Params `json:"params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TranslationResponse represents the response from translation
|
// TextResponse represents a single text response
|
||||||
|
type TextResponse struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
Alternatives []struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
} `json:"alternatives"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TranslationResponse represents the response from LMT_handle_texts
|
||||||
type TranslationResponse struct {
|
type TranslationResponse struct {
|
||||||
|
Jsonrpc string `json:"jsonrpc"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Result struct {
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
Texts []TextResponse `json:"texts"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LegacyTranslationResponse represents the old response format (kept for compatibility)
|
||||||
|
type LegacyTranslationResponse struct {
|
||||||
Jsonrpc string `json:"jsonrpc"`
|
Jsonrpc string `json:"jsonrpc"`
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Result struct {
|
Result struct {
|
||||||
|
|||||||
+11
-9
@@ -28,7 +28,7 @@ func getICount(translateText string) int64 {
|
|||||||
func getRandomNumber() int64 {
|
func getRandomNumber() int64 {
|
||||||
src := rand.NewSource(time.Now().UnixNano())
|
src := rand.NewSource(time.Now().UnixNano())
|
||||||
rng := rand.New(src)
|
rng := rand.New(src)
|
||||||
num := rng.Int63n(99999) + 8300000
|
num := rng.Int63n(99999) + 100000
|
||||||
return num * 1000
|
return num * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ func getTimeStamp(iCount int64) int64 {
|
|||||||
ts := time.Now().UnixMilli()
|
ts := time.Now().UnixMilli()
|
||||||
if iCount != 0 {
|
if iCount != 0 {
|
||||||
iCount = iCount + 1
|
iCount = iCount + 1
|
||||||
return ts - ts%iCount + iCount
|
return ts - (ts % iCount) + iCount
|
||||||
}
|
}
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
@@ -46,12 +46,14 @@ func getTimeStamp(iCount int64) int64 {
|
|||||||
func formatPostString(postData *PostData) string {
|
func formatPostString(postData *PostData) string {
|
||||||
postBytes, _ := json.Marshal(postData)
|
postBytes, _ := json.Marshal(postData)
|
||||||
postStr := string(postBytes)
|
postStr := string(postBytes)
|
||||||
|
|
||||||
if (postData.ID+5)%29 == 0 || (postData.ID+3)%13 == 0 {
|
|
||||||
postStr = strings.Replace(postStr, `"method":"`, `"method" : "`, 1)
|
|
||||||
} else {
|
|
||||||
postStr = strings.Replace(postStr, `"method":"`, `"method": "`, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return postStr
|
return postStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handlerBodyMethod manipulates the request body based on random number calculation
|
||||||
|
func handlerBodyMethod(random int64, body string) string {
|
||||||
|
calc := (random+5)%29 == 0 || (random+3)%13 == 0
|
||||||
|
if calc {
|
||||||
|
return strings.Replace(body, `"method":"`, `"method" : "`, 1)
|
||||||
|
}
|
||||||
|
return strings.Replace(body, `"method":"`, `"method": "`, 1)
|
||||||
|
}
|
||||||
|
|||||||
Executable
+55
@@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
red='\033[0;31m'
|
||||||
|
green='\033[0;32m'
|
||||||
|
yellow='\033[0;33m'
|
||||||
|
plain='\033[0m'
|
||||||
|
|
||||||
|
# Check for root privileges
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo -e "${red}This script must be run as root.${plain}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
uninstall_deeplx() {
|
||||||
|
echo -e "${green}Starting DeepLX uninstallation...${plain}"
|
||||||
|
|
||||||
|
# 1. Stop and disable the DeepLX service
|
||||||
|
if systemctl is-active --quiet deeplx; then
|
||||||
|
echo -e "${yellow}Stopping DeepLX service...${plain}"
|
||||||
|
systemctl stop deeplx
|
||||||
|
else
|
||||||
|
echo -e "${yellow}DeepLX service is not running or not found.${plain}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if systemctl is-enabled --quiet deeplx; then
|
||||||
|
echo -e "${yellow}Disabling DeepLX service from starting on boot...${plain}"
|
||||||
|
systemctl disable deeplx
|
||||||
|
else
|
||||||
|
echo -e "${yellow}DeepLX service is not enabled.${plain}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2. Remove the systemd service file
|
||||||
|
if [ -f /etc/systemd/system/deeplx.service ]; then
|
||||||
|
echo -e "${yellow}Removing DeepLX systemd service file (/etc/systemd/system/deeplx.service)...${plain}"
|
||||||
|
rm -f /etc/systemd/system/deeplx.service
|
||||||
|
systemctl daemon-reload
|
||||||
|
echo -e "${green}Systemd daemon reloaded.${plain}"
|
||||||
|
else
|
||||||
|
echo -e "${yellow}DeepLX systemd service file not found, skipping removal.${plain}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3. Remove the DeepLX executable
|
||||||
|
if [ -f /usr/bin/deeplx ]; then
|
||||||
|
echo -e "${yellow}Removing DeepLX executable (/usr/bin/deeplx)...${plain}"
|
||||||
|
rm -f /usr/bin/deeplx
|
||||||
|
else
|
||||||
|
echo -e "${yellow}DeepLX executable not found, skipping removal.${plain}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${green}DeepLX uninstallation complete.${plain}"
|
||||||
|
echo -e "${green}If you wish to reinstall, please run the install script again.${plain}"
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_deeplx
|
||||||
Reference in New Issue
Block a user