Skip to content

Commit

Permalink
Merge pull request #500 from ChowDPa02k/main
Browse files Browse the repository at this point in the history
Mikanani: Add support for subcategory
  • Loading branch information
gitautomator[bot] authored Apr 16, 2024
2 parents d2667c6 + 7f4033b commit 2479a8c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .config/source_provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mikanani_source_provider:
# 将以下rss链接更换为自己的mikan订阅链接
# 格式为 https://mikanani.me/RSS/MyBangumi?token=***mytoken***
rss_link: https://mikanani.me/Home/Classic
use_sub_category: false
custom_category_mapping:
ani_source_provider:
type: ani_source_provider
enable: false
Expand Down
12 changes: 12 additions & 0 deletions docs/zh/user_guide/mikanani_source_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mikanani_source_provider:
tags:
- mikanani
filter: ^((?!先行).)*$
use_sub_category: true
custom_category_mapping:
```
* `type`:订阅源类型,需为`meijutt_source_provider`。
Expand All @@ -35,6 +37,16 @@ mikanani_source_provider:
* `downloader`:指定使用的下载器,格式为数组,内容需要精确地跟 `downloader_provider.yaml` 中声明的名称一样;下载优先级将由数组顺序决定。
* `download_param`:下载时传给下载器的额外参数,具体参数需要参考下载器定义。
* `filter`:用于过滤标题名的正则表达式。
* `use_sub_category`:qBittorrent的子分类支持,有助于高效管理番剧内容,这里使用的分类名是Mikan Project动画详情中左上角的标题。
![img](images/4.png)
* `custom_category_mapping`:qBittorrent的子分类映射,用于适配用户自己的内容管理模式,例如:

```yaml
custom_category_mapping:
'无职转生Ⅱ ~到了异世界就拿出真本事~ 第2部分': '无职转生/Season 02'
'鲁邦三世 PART6': '鲁邦三世/Season 06'
'黑执事 -寄宿学校篇-': '黑执事/Season 04'
```

## 启用配置
设置好后,直接重启Kubespider即可。
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions kubespider/source_provider/mikanani_source_provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, name: str, config_reader: AbsConfigReader) -> None:
self.rss_link = ''
self.tmp_file_path = '/tmp/'
self.provider_name = name
self.custom_category_mapping = {}
self.use_sub_category = False

def get_provider_name(self) -> str:
return self.provider_name
Expand Down Expand Up @@ -95,12 +97,16 @@ def get_links_from_xml(self, tmp_xml, pattern: str) -> list[Resource]:
logging.info('mikanani find %s', helper.format_long_string(anime_name))
url = i.find('./enclosure').attrib['url']
if path is not None and item_title is not None:
ret.append(Resource(
res = Resource(
url=url,
path=path,
file_type=types.FILE_TYPE_VIDEO_TV,
link_type=self.get_link_type(),
))
)
if self.use_sub_category:
res.put_extra_params({'sub_category': self.get_subcategory(path)})
logging.info("Using subcategory: %s", res.extra_param('sub_category'))
ret.append(res)
else:
logging.warning("Skip %s, %s", anime_name, item_title)
return ret
Expand All @@ -127,13 +133,49 @@ def check_anime_title(self, title, pattern: Pattern) -> str:
logging.warning("Episode %s will not be downloaded, filtered by %s", title, pattern)
return None

def get_subcategory(self, title: str) -> str:
# Custom subcategory mapping will cover any generated data
for x in self.custom_category_mapping:
if x in title:
return self.custom_category_mapping[x]
# Get Season
season = 1
keyword = None
mapper = {
"第二季": 2,
"第三季": 3,
"第四季": 4,
"第五季": 5,
"第六季": 6,
"第七季": 7,
"第八季": 8,
"第九季": 9,
"第十季": 10
}
# The user-defined season_mapping has higher priority
for kw, s in mapper.items():
if kw in title:
season = s
keyword = kw
# Avoid '/' appear in original Anime title
# This will be misleading for qbittorrent
sub_category = title.replace('/', '_')
if season > 1:
s_ = str(season).zfill(2)
sub_category = sub_category.replace(f" {keyword}", '') + f"/Season {s_}"
if sub_category[-1] in "<>:\"/\\|?* ":
sub_category = sub_category[:-1] + "_"
return sub_category

def update_config(self, event: Event) -> None:
pass

def load_config(self) -> None:
cfg = self.config_reader.read()
logging.info('mikanani rss link is:%s', cfg['rss_link'])
self.rss_link = cfg['rss_link']
self.custom_category_mapping = cfg.get('custom_category_mapping', {})
self.use_sub_category = cfg.get('use_sub_category', False)

def get_file_title(self, link: str) -> str:
# example: https://mikanani.me/Home/Episode/5350b283db7d8e4665a08dda24d0d0c66259fc71
Expand Down

0 comments on commit 2479a8c

Please sign in to comment.