Skip to content

Commit

Permalink
feat: Add new book sources and remove invalid ones!
Browse files Browse the repository at this point in the history
Signed-off-by: Fang Yuan <wojiushifangyuanlove@gmail.com>
  • Loading branch information
767829413 committed Dec 24, 2024
1 parent d422f9e commit dd32516
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 121 deletions.
1 change: 0 additions & 1 deletion frontend/src/components/ViewConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const ViewConfig: React.FC = () => {
options={[
{ value: 1, label: '1' },
{ value: 2, label: '2' },
{ value: 3, label: '3' }
]}
style={{ width: '100%' }}
/>
Expand Down
58 changes: 50 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,72 @@ func GetConf() Info {

func SetConf(conf string) error {
var newConf Info
// Parsing a JSON string
currentConf := GetConf()

// Parse the input JSON string
if err := json.Unmarshal([]byte(conf), &newConf); err != nil {
return fmt.Errorf("failed to unmarshal config: %w", err)
}

// Updating the in-memory configuration
confValue.Store(newConf)
// Compare and update configuration
updated := false

// Update Base fields
if newConf.Base.SourceID != 0 && newConf.Base.SourceID != currentConf.Base.SourceID {
currentConf.Base.SourceID = newConf.Base.SourceID
updated = true
}
if newConf.Base.DownloadPath != "" &&
newConf.Base.DownloadPath != currentConf.Base.DownloadPath {
currentConf.Base.DownloadPath = newConf.Base.DownloadPath
updated = true
}
if newConf.Base.Extname != "" && newConf.Base.Extname != currentConf.Base.Extname {
currentConf.Base.Extname = newConf.Base.Extname
updated = true
}
if newConf.Base.LogLevel != "" && newConf.Base.LogLevel != currentConf.Base.LogLevel {
currentConf.Base.LogLevel = newConf.Base.LogLevel
updated = true
}

// Update Crawl fields
if newConf.Crawl.Threads != 0 && newConf.Crawl.Threads != currentConf.Crawl.Threads {
currentConf.Crawl.Threads = newConf.Crawl.Threads
updated = true
}

// Update Retry fields
if newConf.Retry.MaxAttempts != 0 &&
newConf.Retry.MaxAttempts != currentConf.Retry.MaxAttempts {
currentConf.Retry.MaxAttempts = newConf.Retry.MaxAttempts
updated = true
}

// If no updates, return early
if !updated {
return nil
}

// Update the in-memory configuration
confValue.Store(currentConf)

// Write the new configuration to a user-defined configuration file
// Write the new configuration to the user-defined configuration file
expandedPath := os.ExpandEnv(customConfigPath)

// Make sure the catalog exists
// Ensure the directory exists
dir := filepath.Dir(expandedPath)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create config directory: %w", err)
}

// Converting Configuration to JSON
jsonData, err := json.MarshalIndent(newConf, "", " ")
// Convert configuration to JSON
jsonData, err := json.MarshalIndent(currentConf, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal config to JSON: %w", err)
}

// write to a file
// Write to file
if err := os.WriteFile(expandedPath, jsonData, 0644); err != nil {
return fmt.Errorf("failed to write config file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/default_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
base:
# 启用书源 (只能选一个, 当前可选值:1、2、3)
# 启用书源 (只能选一个, 当前可选值:1、2)
source-id: 3
# 下载路径, 绝对相对均可 (Windows 路径分隔符不要用 \ , 用 / 或 \)
download-path: "downloads"
Expand Down
27 changes: 14 additions & 13 deletions internal/source/rule/rule1.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"id": "1",
"url": "http://www.xbiqugu.net",
"name": "香书小说",
"url": "http://www.mcmssc.la/",
"name": "梦书中文",
"comment": "无限流",
"type": "html",
"search": {
"url": "http://www.xbiqugu.net/modules/article/waps.php",
"url": "http://www.mcmssc.la/search.html",
"method": "post",
"body": {
"kw": "searchkey"
"kw": "name"
},
"cookies": {},
"pagination": false,
"result": "#checkform > table > tbody > tr",
"bookName": "td.even > a",
"author": "td:nth-of-type(3)",
"latestChapter": "td.odd > a",
"update": "td:nth-of-type(4)"
"nextPage": "",
"result": ".novelslist2 > ul > li",
"bookName": "span.s2.wid > a",
"author": "span.s4.wid > a",
"latestChapter": "span.s3.wid3 > a",
"update": "span.s6.wid6"
},
"book": {
"url": "http://www.xbiqugu.net/0/%s/",
"url": "http://www.mcmssc.la/%s/",
"bookName": "meta[property=\"og:novel:book_name\"]",
"author": "meta[property=\"og:novel:author\"]",
"intro": "meta[property=\"og:description\"]",
Expand All @@ -29,17 +30,17 @@
"latestUpdate": "",
"isEnd": "",
"catalog": "#list > dl > dd > a",
"catalogOffset": 0
"catalogOffset": 12
},
"chapter": {
"url": "http://www.xbiqugu.net/0/%s/%s.html",
"url": "http://www.mcmssc.la/%s/%s.html",
"pagination": false,
"chapterNo": 0,
"title": "",
"content": "#content",
"paragraphTagClosed": false,
"paragraphTag": "<br><br>",
"filterTxt": "一秒记住【文学巴士&nbsp;】,精彩无弹窗免费阅读!|(www.xbiquge.la 新笔趣阁),高速全文字在线阅读!",
"filterTxt": "天才一秒记住本站地址:[梦书中文] .+最快更新!无广告!|(www.xbiquge.la 新笔趣阁),高速全文字在线阅读!",
"filterTag": "div p script"
}
}
93 changes: 42 additions & 51 deletions internal/source/rule/rule2.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
{
"id": "2",
"url": "https://www.shuhaige.net/",
"name": "书海阁小说网",
"comment": "搜索有反爬机制,爬取过快会丢包",
"type": "html",
"search": {
"url": "https://www.shuhaige.net/search.html",
"method": "post",
"body": {
"kw": "searchkey",
"searchtype": "all"
},
"cookies": {
"waf_sc": "",
"HMACCOUNT": ""
},
"pagination": true,
"nextPage": "#pagelink > a:not(.pgroup):not(.ngroup)",
"result": "#sitembox > dl",
"bookName": "dd > h3 > a",
"author": "dd:nth-child(3) > span:nth-child(1)",
"latestChapter": "dd:nth-child(5) > a",
"update": "dd:nth-child(5) > span"
},
"book": {
"url": "https://www.shuhaige.net/%s/",
"bookName": "meta[property=\"og:novel:book_name\"]",
"author": "meta[property=\"og:novel:author\"]",
"intro": "meta[property=\"og:description\"]",
"category": "meta[property=\"og:novel:category\"]",
"coverUrl": "#fmimg > img",
"latestChapter": "",
"latestUpdate": "",
"isEnd": "",
"catalog": "#list > dl > dd > a",
"catalogOffset": 12
},
"chapter": {
"url": "https://www.shuhaige.net/%s/%s.html",
"pagination": true,
"nextPage": "#pager_next",
"chapterNo": 0,
"title": ".bookname > h1",
"content": "#content",
"paragraphTagClosed": true,
"paragraphTag": "p",
"filterTxt": "本小章还未完,请点击下一页继续阅读后面精彩内容!|小主,这个章节后面还有哦,请点击下一页继续阅读,后面更精彩!|这章没有结束,请点击下一页继续阅读!|喜欢.*?请大家收藏:(.*?).*?书海阁小说网更新速度全网最快。",
"filterTag": ""
}
}
{
"id": "2",
"url": "http://www.99xs.info/",
"name": "鸟书网",
"comment": "书很全,有15w+;无反爬",
"type": "html",
"search": {
"url": "http://www.99xs.info/read/search/",
"method": "post",
"body": {"kw": "searchkey"},
"cookies": {},
"pagination": false,
"result": "div.wrap > div > div > div",
"bookName": "div.bookinfo > h4 > a",
"author": "div.bookinfo > div.author",
"latestChapter": "div.bookinfo > div.update > a"
},
"book": {
"url": "http://www.99xs.info/tag/%s/",
"bookName": "meta[property=\"og:novel:book_name\"]",
"author": "meta[property=\"og:novel:author\"]",
"intro": "meta[property=\"og:description\"]",
"category": "meta[property=\"og:novel:category\"]",
"coverUrl": "div.cover > img",
"latestChapter": "",
"latestUpdate": "",
"isEnd": "",
"catalog": "div.listmain > dl > dd > a",
"catalogOffset": 12
},
"chapter": {
"url": "http://www.99xs.info/tag/%s/%s.html",
"pagination": false,
"chapterNo": 0,
"title": "",
"content": "#content",
"paragraphTagClosed": false,
"paragraphTag": "<br><br>",
"filterTxt": "请记住本书首发域名:.+。鸟书网手机版阅读网址:.+|7017k",
"filterTag": ""
}
}
46 changes: 0 additions & 46 deletions internal/source/rule/rule3.json

This file was deleted.

2 changes: 1 addition & 1 deletion internal/tools/concurrency/concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetConcurrencyNum(target int) int {
once.Do(func() {
defaultConcurrency = runtime.NumCPU()
})
if target == -1 {
if target == -1 || target == 0 {
target = defaultConcurrency * 2
}
if target >= maxThreads {
Expand Down

0 comments on commit dd32516

Please sign in to comment.