mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 14:57:52 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffdba23b03 | ||
|
|
a3778c05fb | ||
|
|
81c94afb55 | ||
|
|
48151fec8f | ||
|
|
154fb27895 | ||
|
|
08fd328e9d | ||
|
|
d8fbb7e07e | ||
|
|
d16d74b3e9 | ||
|
|
8b0953e9f7 | ||
|
|
43565812b5 | ||
|
|
7aa936e888 |
@@ -2,7 +2,7 @@
|
|||||||
* @Author: Vincent Young
|
* @Author: Vincent Young
|
||||||
* @Date: 2022-10-18 07:32:29
|
* @Date: 2022-10-18 07:32:29
|
||||||
* @LastEditors: Vincent Young
|
* @LastEditors: Vincent Young
|
||||||
* @LastEditTime: 2023-02-18 19:46:10
|
* @LastEditTime: 2023-02-24 21:36:36
|
||||||
* @FilePath: /DeepLX/README.md
|
* @FilePath: /DeepLX/README.md
|
||||||
* @Telegram: https://t.me/missuo
|
* @Telegram: https://t.me/missuo
|
||||||
*
|
*
|
||||||
@@ -32,10 +32,16 @@ Permanently free DeepL API written in Golang
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Run on Linux Server
|
||||||
|
```bash
|
||||||
|
bash <(curl -Ls https://cpp.li/deeplx)
|
||||||
|
```
|
||||||
|
|
||||||
### Run on Mac
|
### Run on Mac
|
||||||
1. Download the latest release of DeepL X.
|
1. Download the latest release of DeepL X.
|
||||||
```bash
|
```bash
|
||||||
sudo mv deeplx_darwin_amd64 /usr/local/bin/deeplx
|
sudo mv deeplx_darwin_amd64 /usr/local/bin/deeplx
|
||||||
|
sudo chmod +x /usr/local/bin/deeplx
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Download the `me.missuo.deeplx.plist` to `~/Library/LaunchAgents`.
|
2. Download the `me.missuo.deeplx.plist` to `~/Library/LaunchAgents`.
|
||||||
@@ -48,15 +54,29 @@ launchctl load ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
|||||||
launchctl start ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
launchctl start ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Install from AUR
|
||||||
|
```bash
|
||||||
|
paru -S deeplx-bin
|
||||||
|
```
|
||||||
|
|
||||||
|
After installation, start the daemon with the following command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable deeplx
|
||||||
|
|
||||||
|
```
|
||||||
## Setup on [Bob App](https://bobtranslate.com/)
|
## Setup on [Bob App](https://bobtranslate.com/)
|
||||||
1. Install [bob-plugin-deeplx](https://github.com/clubxdev/bob-plugin-deeplx) on Bob.
|
1. Install [bob-plugin-deeplx](https://github.com/clubxdev/bob-plugin-deeplx) on Bob.
|
||||||
|
|
||||||
2. Setup the API.
|
2. Setup the API.
|
||||||

|

|
||||||
|
|
||||||
## Docker Backup for zu1k
|
## Backup the Docker Image of zu1k
|
||||||
```shell
|
```shell
|
||||||
docker run -itd -p 7373:80 missuo/deeplx-bk
|
docker run -itd -p 1188:80 missuo/deeplx-bk
|
||||||
```
|
```
|
||||||
|
**This docker image is not related to this project, as the original author deleted the image, it is only for backup.**
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
**DeepL X** © [Vincent Young](https://github.com/missuo) & [Leo Shen](https://github.com/sjlleo), Released under the [MIT](./LICENSE) License.<br>
|
**DeepL X** © [Vincent Young](https://github.com/missuo) & [Leo Shen](https://github.com/sjlleo), Released under the [MIT](./LICENSE) License.<br>
|
||||||
|
|||||||
+3
-5
@@ -1,14 +1,12 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=DeepLX Service
|
Description=DeepLX Service
|
||||||
After=network.target nss-lookup.target
|
After=network.target
|
||||||
Wants=network.target
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=root
|
|
||||||
Group=root
|
|
||||||
Type=simple
|
Type=simple
|
||||||
|
Restart=always
|
||||||
WorkingDirectory=/usr/bin/
|
WorkingDirectory=/usr/bin/
|
||||||
ExecStart=/usr/bin/deeplx
|
ExecStart=/usr/bin/deeplx
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
+2
-1
@@ -22,6 +22,7 @@ install_deeplx(){
|
|||||||
wget -q -N --no-check-certificate -O /etc/systemd/system/deeplx.service https://raw.githubusercontent.com/OwO-Network/DeepLX/main/deeplx.service
|
wget -q -N --no-check-certificate -O /etc/systemd/system/deeplx.service https://raw.githubusercontent.com/OwO-Network/DeepLX/main/deeplx.service
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable deeplx
|
systemctl enable deeplx
|
||||||
|
systemctl start deeplx
|
||||||
echo -e "Installed successfully, listening at 0.0.0.0:1188"
|
echo -e "Installed successfully, listening at 0.0.0.0:1188"
|
||||||
}
|
}
|
||||||
install_deeplx
|
install_deeplx
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
}
|
||||||
|
|
||||||
type Lang struct {
|
type Lang struct {
|
||||||
SourceLangUserSelected string `json:"source_lang_user_selected"`
|
SourceLangUserSelected string `json:"source_lang_user_selected"`
|
||||||
TargetLang string `json:"target_lang"`
|
TargetLang string `json:"target_lang"`
|
||||||
@@ -46,15 +50,15 @@ type PostData struct {
|
|||||||
Params Params `json:"params"`
|
Params Params `json:"params"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init_data(source_lang string, target_lang string) *PostData {
|
func initData(sourceLang string, targetLang string) *PostData {
|
||||||
return &PostData{
|
return &PostData{
|
||||||
Jsonrpc: "2.0",
|
Jsonrpc: "2.0",
|
||||||
Method: "LMT_handle_texts",
|
Method: "LMT_handle_texts",
|
||||||
Params: Params{
|
Params: Params{
|
||||||
Splitting: "newlines",
|
Splitting: "newlines",
|
||||||
Lang: Lang{
|
Lang: Lang{
|
||||||
SourceLangUserSelected: source_lang,
|
SourceLangUserSelected: sourceLang,
|
||||||
TargetLang: target_lang,
|
TargetLang: targetLang,
|
||||||
},
|
},
|
||||||
CommonJobParams: CommonJobParams{
|
CommonJobParams: CommonJobParams{
|
||||||
WasSpoken: false,
|
WasSpoken: false,
|
||||||
@@ -65,8 +69,8 @@ func init_data(source_lang string, target_lang string) *PostData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_i_count(translate_text string) int64 {
|
func getICount(translateText string) int64 {
|
||||||
return int64(strings.Count(translate_text, "i"))
|
return int64(strings.Count(translateText, "i"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRandomNumber() int64 {
|
func getRandomNumber() int64 {
|
||||||
@@ -75,21 +79,20 @@ func getRandomNumber() int64 {
|
|||||||
return num * 1000
|
return num * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTimeStamp(i_count int64) int64 {
|
func getTimeStamp(iCount int64) int64 {
|
||||||
ts := time.Now().UnixMilli()
|
ts := time.Now().UnixMilli()
|
||||||
if i_count != 0 {
|
if iCount != 0 {
|
||||||
i_count = i_count + 1
|
iCount = iCount + 1
|
||||||
return ts - ts%i_count + i_count
|
return ts - ts%iCount + iCount
|
||||||
} else {
|
} else {
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResData struct {
|
type ResData struct {
|
||||||
Trans_Text string `json:"text"`
|
TransText string `json:"text"`
|
||||||
Source_Lang string `json:"source_lang"`
|
SourceLang string `json:"source_lang"`
|
||||||
Target_Lang string `json:"target_lang"`
|
TargetLang string `json:"target_lang"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -106,8 +109,8 @@ func main() {
|
|||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/", func(c *gin.Context) {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"msg": "DeepL API, Made by sjlleo and missuo. Go to /translate with POST.",
|
"message": "DeepL Free API, Made by sjlleo and missuo. Go to /translate with POST. http://github.com/OwO-Network/DeepLX",
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
@@ -115,41 +118,47 @@ func main() {
|
|||||||
r.POST("/translate", func(c *gin.Context) {
|
r.POST("/translate", func(c *gin.Context) {
|
||||||
reqj := ResData{}
|
reqj := ResData{}
|
||||||
c.BindJSON(&reqj)
|
c.BindJSON(&reqj)
|
||||||
source_lang := reqj.Source_Lang
|
|
||||||
target_lang := reqj.Target_Lang
|
sourceLang := reqj.SourceLang
|
||||||
if source_lang == "" {
|
targetLang := reqj.TargetLang
|
||||||
source_lang = "ZH"
|
if sourceLang == "" {
|
||||||
|
sourceLang = "ZH"
|
||||||
}
|
}
|
||||||
if target_lang == "" {
|
if targetLang == "" {
|
||||||
target_lang = "EN"
|
targetLang = "EN"
|
||||||
}
|
}
|
||||||
translate_text := reqj.Trans_Text
|
translateText := reqj.TransText
|
||||||
// fmt.Printf("%v", translate_text)
|
// fmt.Printf("%v", translateText)
|
||||||
if translate_text != "" {
|
if translateText == "" {
|
||||||
|
c.JSON(http.StatusNotFound, gin.H{
|
||||||
|
"code": http.StatusNotFound,
|
||||||
|
"message": "No Translate Text Found",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
url := "https://www2.deepl.com/jsonrpc"
|
url := "https://www2.deepl.com/jsonrpc"
|
||||||
id = id + 1
|
id = id + 1
|
||||||
post_data := init_data(source_lang, target_lang)
|
postData := initData(sourceLang, targetLang)
|
||||||
text := Text{
|
text := Text{
|
||||||
Text: translate_text,
|
Text: translateText,
|
||||||
RequestAlternatives: 3,
|
RequestAlternatives: 3,
|
||||||
}
|
}
|
||||||
// set id
|
// set id
|
||||||
post_data.ID = id
|
postData.ID = id
|
||||||
// set text
|
// set text
|
||||||
post_data.Params.Texts = append(post_data.Params.Texts, text)
|
postData.Params.Texts = append(postData.Params.Texts, text)
|
||||||
// set timestamp
|
// set timestamp
|
||||||
post_data.Params.Timestamp = getTimeStamp(get_i_count(translate_text))
|
postData.Params.Timestamp = getTimeStamp(getICount(translateText))
|
||||||
post_byte, _ := json.Marshal(post_data)
|
post_byte, _ := json.Marshal(postData)
|
||||||
post_str := string(post_byte)
|
postStr := string(post_byte)
|
||||||
|
|
||||||
// add space if necessary
|
// add space if necessary
|
||||||
if (id+5)%29 == 0 || (id+3)%13 == 0 {
|
if (id+5)%29 == 0 || (id+3)%13 == 0 {
|
||||||
post_str = strings.Replace(post_str, "\"method\":\"", "\"method\" : \"", -1)
|
postStr = strings.Replace(postStr, "\"method\":\"", "\"method\" : \"", -1)
|
||||||
} else {
|
} else {
|
||||||
post_str = strings.Replace(post_str, "\"method\":\"", "\"method\": \"", -1)
|
postStr = strings.Replace(postStr, "\"method\":\"", "\"method\": \"", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
post_byte = []byte(post_str)
|
post_byte = []byte(postStr)
|
||||||
reader := bytes.NewReader(post_byte)
|
reader := bytes.NewReader(post_byte)
|
||||||
request, err := http.NewRequest("POST", url, reader)
|
request, err := http.NewRequest("POST", url, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -177,38 +186,33 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
res := gjson.ParseBytes(body)
|
res := gjson.ParseBytes(body)
|
||||||
// display response
|
// display response
|
||||||
fmt.Println(res)
|
// fmt.Println(res)
|
||||||
if res.Get("error.code").String() == "-32600" {
|
if res.Get("error.code").String() == "-32600" {
|
||||||
log.Println(res.Get("error").String())
|
log.Println(res.Get("error").String())
|
||||||
c.JSON(406, gin.H{
|
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||||
"code": 406,
|
"code": http.StatusNotAcceptable,
|
||||||
"msg": "Invalid target_lang",
|
"message": "Invalid targetLang",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
if resp.StatusCode == 429 {
|
|
||||||
c.JSON(429, gin.H{
|
|
||||||
"code": 429,
|
|
||||||
"message": "Too Many Requests",
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
c.JSON(200, gin.H{
|
|
||||||
"code": 200,
|
|
||||||
"id": id,
|
|
||||||
"data": res.Get("result.texts.0.text").String(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.JSON(404, gin.H{
|
if resp.StatusCode == http.StatusTooManyRequests {
|
||||||
"code": 404,
|
c.JSON(http.StatusTooManyRequests, gin.H{
|
||||||
"message": "No Text Found",
|
"code": http.StatusTooManyRequests,
|
||||||
})
|
"message": "Too Many Requests",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": http.StatusOK,
|
||||||
|
"id": id,
|
||||||
|
"data": res.Get("result.texts.0.text").String(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
r.Run(":1188") // listen and serve on 0.0.0.0:1188
|
r.Run(":1188") // listen and serve on 0.0.0.0:1188
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user