Skip to content

Commit

Permalink
feat: filter regex
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifengle committed Oct 15, 2022
1 parent 07846e6 commit 6f51667
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gcookie = "0.0.3"
log = "0.4.0"
env_logger = "0.9.0"
once_cell = "1.15.0"
regex = "1"

[profile.release]
lto = true
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- [x] proxy 配置
- ~~目前写死在 build_proxy_client 里面~~
- 读取 ALL_PROXY 或者 HTTPS_PROXY 环境变量
- [ ] 正则过滤 filter
- [x] 正则过滤 filter
- [ ] Windows 定时任务
- ~~懒得写了,我是手动配置的~~
- [x] 不同网站的并发任务
Expand Down Expand Up @@ -57,7 +57,7 @@ rss2pan -u "https://mikanani.me/RSS/Bangumi?bangumiId=2739&subgroupid=12"
"mikanani.me": [
{
"name": "test",
"filter": "简体内嵌",
"filter": "/简体|1080p/",
"url": "https://mikanani.me/RSS/Bangumi?bangumiId=2739&subgroupid=12"
}
],
Expand All @@ -73,7 +73,8 @@ rss2pan -u "https://mikanani.me/RSS/Bangumi?bangumiId=2739&subgroupid=12"
```

配置了 `filter` 后,标题包含该文字的会被离线。不设置 `filter` 默认离线全部
> 正则功能还没写

`/简体|\\d{3-4}[pP]/` 使用斜线包裹的正则规则。注意转义规则

cid 是离线到指定的文件夹的 id 。
获取方法: 浏览器打开 115 的文件,地址栏像 `https://115.com/?cid=2479224057885794455&offset=0&tab=&mode=wangpan`
Expand Down
24 changes: 23 additions & 1 deletion src/rss_site/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod dmhy;
mod mikanani;
mod nyaa;

use regex::Regex;
use reqwest::Method;
use rss::{Channel, Item};
use std::io::BufReader;
Expand Down Expand Up @@ -75,7 +76,17 @@ pub async fn get_magnetitem_list(config: &RssConfig) -> Vec<MagnetItem> {
let m = site.get_magnet_item(item);
let mut flag = true;
if let Some(pat) = &config.filter {
flag = m.title.contains(pat);
if pat.starts_with("/") && pat.ends_with("/") {
let re = Regex::new(&pat[1..pat.len() - 1]);
match re {
Ok(re) => {
flag = re.is_match(&m.title);
}
Err(_) => {}
}
} else {
flag = m.title.contains(pat);
}
}
if flag {
item_list.push(m)
Expand Down Expand Up @@ -116,4 +127,15 @@ mod tests {
let res = service.save_items(&items, true);
assert!(res.is_ok());
}
#[test]
fn test_re() {
let str_list = [
"[7月新番][传颂之物 二人的白皇][Utawarerumono - Futari no Hakuoro][09][1080P][MP4][GB][简中] [241.72 MB]",
"【幻樱字幕组】【7月新番】【传颂之物 二人白皇 Utawarerumono-Futari no Hakuoro-】【16】【BIG5_MP4】【1920X1080】 [321.13 MB]",
"[动漫国字幕组&澄空学园&LoliHouse] 传颂之物 二人的白皇 / Utawarerumono Futari no Hakuoro - 16 [WebRip 1080p HEVC-10bit AAC][简繁外挂字幕] [485.4 MB]"
];
let pat = "/澄空学园|幻樱|\\d{4}[p]/";
let re = Regex::new(&pat[1..pat.len() - 1]).unwrap();
assert_eq!(str_list.map(|s| re.is_match(s)), [true, true, true]);
}
}

0 comments on commit 6f51667

Please sign in to comment.