-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unified the lanzou hosename and remove download client.
- Loading branch information
Showing
6 changed files
with
136 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package lanzou | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/bookstairs/bookhunter/internal/client" | ||
"github.com/bookstairs/bookhunter/internal/log" | ||
) | ||
|
||
type Drive struct { | ||
client *client.Client | ||
} | ||
|
||
// hostname is used to return a valid lanzou host. | ||
func hostname() string { | ||
// We may add a roundrobin list in the future. | ||
return "lanzoux.com" | ||
} | ||
|
||
func NewDrive(config *client.Config) (*Drive, error) { | ||
cl, err := client.New(&client.Config{ | ||
HTTPS: true, | ||
Host: hostname(), | ||
UserAgent: config.UserAgent, | ||
Proxy: config.Proxy, | ||
ConfigRoot: config.ConfigRoot, | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cl.Client. | ||
SetHeader("Accept-Language", "zh-CN,zh;q=0.9"). | ||
SetHeader("Referer", cl.BaseURL) | ||
|
||
return &Drive{client: cl}, nil | ||
} | ||
|
||
func (l Drive) DownloadFile(downloadURL string) (io.ReadCloser, int64, error) { | ||
log.Debugf("Start to download file from aliyun drive: %s", downloadURL) | ||
|
||
resp, err := l.client.R(). | ||
SetDoNotParseResponse(true). | ||
Get(downloadURL) | ||
response := resp.RawResponse | ||
|
||
return response.Body, response.ContentLength, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package lanzou | ||
|
||
import "regexp" | ||
|
||
var ( | ||
lxReg = regexp.MustCompile(`'lx':(\d+),`) | ||
fidReg = regexp.MustCompile(`'fid':(\d+),`) | ||
uidReg = regexp.MustCompile(`'uid':'(\d+)',`) | ||
repReg = regexp.MustCompile(`'rep':'(\d+)',`) | ||
upReg = regexp.MustCompile(`'up':(\d+),`) | ||
lsReg = regexp.MustCompile(`'ls':(\d+),`) | ||
tVar = regexp.MustCompile(`'t':(\S+),`) | ||
kVar = regexp.MustCompile(`'k':(\S+),`) | ||
|
||
dirURLRe = regexp.MustCompile(`(?m)https?://[a-zA-Z0-9-]*?\.?lanzou[a-z]\.com/(/s/)?b[a-zA-Z0-9]{7,}/?`) | ||
fileURLRe = regexp.MustCompile(`(?m)https?://[a-zA-Z0-9-]*?\.?lanzou[a-z]\.com/(/s/)?i[a-zA-Z0-9]{7,}/?`) | ||
|
||
find1Re = regexp.MustCompile(`(?m)url\s:\s+'(.*?)',\n\t+data\s:\s+'(.*?)'\+pwd,`) | ||
find2Re = regexp.MustCompile(`(?m)<iframe.*?src="(/fn\?\w{10,})"\s.*>`) | ||
find2TitleRe = regexp.MustCompile(`(?m)<title>(.*?)\s-\s蓝奏云</title>`) | ||
|
||
htmlNoteRe = regexp.MustCompile(`(?m)<!--.+?-->|\s+//\s*.+`) | ||
jsNoteRe = regexp.MustCompile(`(?m)(.+?[,;])\s*//.+`) | ||
) | ||
|
||
type ( | ||
Response struct { | ||
Code int64 `json:"code"` | ||
Data ResponseData `json:"data"` | ||
Msg string `json:"msg"` | ||
} | ||
|
||
ResponseData struct { | ||
Name string `json:"name"` | ||
URL string `json:"url"` | ||
} | ||
|
||
Dom struct { | ||
Zt int `json:"zt"` | ||
Dom string `json:"dom"` | ||
URL string `json:"url"` | ||
Inf interface{} `json:"inf"` | ||
} | ||
|
||
FileList struct { | ||
Zt int `json:"zt"` | ||
Info string `json:"info"` | ||
Text []struct { | ||
Icon string `json:"icon"` | ||
T int `json:"t"` | ||
ID string `json:"id"` | ||
NameAll string `json:"name_all"` | ||
Size string `json:"size"` | ||
Time string `json:"time"` | ||
Duan string `json:"duan"` | ||
PIco int `json:"p_ico"` | ||
} `json:"text"` | ||
} | ||
) |
Oops, something went wrong.