Skip to content

Commit

Permalink
v1.1 新增站点适配器
Browse files Browse the repository at this point in the history
  • Loading branch information
Juszoe committed Aug 17, 2019
1 parent 63bd0cb commit f0d005a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 56 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ C:\Users\<YOURUSER>\flexget\plugins\ # Windows

## 使用
1. 编辑flexget配置文件,添加nexusphp选项,按照需要进行配置
``` yaml
```yaml
nexusphp:
cookie: 'you_cookie' # 必填
discount: # 优惠信息 选填
Expand All @@ -37,9 +37,16 @@ nexusphp:
max: 100
max_complete: 0.8
hr: no # 是否下载HR 选填
adapter: # 站点适配器
free: free
2x: twoup
2xfree: twoupfree
30%: thirtypercent
50%: halfdown
2x50%: twouphalfdown
```
2. 为rss的other_fields字段添加link属性
``` yaml
```yaml
rss:
url: https://www.example.com/rss.xml
other_fields:
Expand Down Expand Up @@ -79,7 +86,7 @@ flexget execute

## 完整配置示例
### 免费热种
``` yaml
```yaml
tasks:
my-free-task:
rss:
Expand All @@ -100,7 +107,7 @@ tasks:
download: ~/flexget/torrents/
```
### 热种
``` yaml
```yaml
tasks:
my-hot-task:
rss:
Expand All @@ -116,7 +123,7 @@ tasks:
download: ~/flexget/torrents/
```
### 避免HR
``` yaml
```yaml
tasks:
no-hr-task:
rss:
Expand Down
126 changes: 75 additions & 51 deletions nexusphp.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ class NexusPHP(object):
'max_complete': {'type': 'number', 'minimum': 0, 'maximum': 1, 'default': 1}
}
},
'hr': {'type': 'boolean'}
'hr': {'type': 'boolean'},
'adapter': {
'type': 'object',
'properties': {
'free': {'type': 'string', 'default': 'free'},
'2x': {'type': 'string', 'default': 'twoup'},
'2xfree': {'type': 'string', 'default': 'twoupfree'},
'30%': {'type': 'string', 'default': 'thirtypercent'},
'50%': {'type': 'string', 'default': 'halfdown'},
'2x50%': {'type': 'string', 'default': 'twouphalfdown'}
}
}
},
'required': ['cookie']
}
Expand All @@ -67,6 +78,7 @@ def build_config(config):
config.setdefault('seeders', {'min': 0, 'max': 100000})
config.setdefault('leechers', {'min': 0, 'max': 100000, 'max_complete': 1})
config.setdefault('hr', True)
config.setdefault('adaptor', None)
return config

def on_task_filter(self, task, config):
Expand All @@ -77,7 +89,7 @@ def on_task_filter(self, task, config):
task.requests.mount('https://', adapter)

def consider_entry(_entry, _link):
discount, seeders, leechers, hr = NexusPHP._get_info(task, _link, config['cookie'])
discount, seeders, leechers, hr = NexusPHP._get_info(task, _link, config['cookie'], config['adapter'])
seeder_max = config['seeders']['max']
seeder_min = config['seeders']['min']
leecher_max = config['leechers']['max']
Expand Down Expand Up @@ -125,22 +137,8 @@ def consider_entry(_entry, _link):

@staticmethod
# 解析页面,获取优惠、做种者信息、下载者信息
def info_from_page(detail_page, peer_page, discount_fn=None, hr_fn=None):
def info_from_page(detail_page, peer_page, discount_fn, hr_fn=None):
try:
if discount_fn is None:
def discount_fn(page):
convert = {
'free': 'free',
'twoup': '2x',
'twoupfree': '2xfree',
'thirtypercent': '30%',
'halfdown': '50%',
'twouphalfdown': '2x50%'
}
for key, value in convert.items():
if key in page.text:
return value
return None
discount = discount_fn(detail_page)
except Exception:
discount = None # 无优惠
Expand All @@ -149,7 +147,11 @@ def discount_fn(page):
if hr_fn:
hr = hr_fn(detail_page)
else:
hr = ('hitandrun' in detail_page.text)
hr = False
for item in ['hitandrun', 'hit_run.gif', 'Hit and Run', 'Hit & Run']:
if item in detail_page.text:
hr = True
break
except Exception:
hr = False # 无HR

Expand Down Expand Up @@ -204,7 +206,7 @@ def get_peers(table):
return peers

@staticmethod
def _get_info(task, link, cookie):
def _get_info(task, link, cookie, adapter):
headers = {
'cookie': cookie,
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
Expand All @@ -217,39 +219,61 @@ def _get_info(task, link, cookie):
if 'login' in detail_page.url or 'login' in peer_page.url:
raise plugin.PluginError("Can't access the site. Your cookie may be wrong!")

if 'chdbits' in link:
def discount_fn(page):
convert = {
'pro_free': 'free',
'pro_2up': '2x',
'pro_free2up': '2xfree',
'pro_30pctdown': '30%',
'pro_50pctdown': '50%',
'pro_50pctdown2up': '2x50%'
}
for key, value in convert.items():
if key in page.text:
return value
return None
if adapter:
convert = {value: key for key, value in adapter.items()}
discount_fn = NexusPHP.generate_discount_fn(convert)
return NexusPHP.info_from_page(detail_page, peer_page, discount_fn)
if 'u2.dmhy' in link:
def discount_fn(page):
convert = {
'pro_free': 'free',
'pro_2up': '2x',
'pro_free2up': '2xfree',
'pro_30pctdown': '30%',
'pro_50pctdown': '50%',
'pro_50pctdown2up': '2x50%',
'pro_custom': '2x'
}
for key, value in convert.items():
if key in page.text:
return value
return None
return NexusPHP.info_from_page(detail_page, peer_page, discount_fn)
else:
return NexusPHP.info_from_page(detail_page, peer_page)

sites_discount = {
'chdbits': {
'pro_free': 'free',
'pro_2up': '2x',
'pro_free2up': '2xfree',
'pro_30pctdown': '30%',
'pro_50pctdown': '50%',
'pro_50pctdown2up': '2x50%'
},
'u2.dmhy': {
'pro_free': 'free',
'pro_2up': '2x',
'pro_free2up': '2xfree',
'pro_30pctdown': '30%',
'pro_50pctdown': '50%',
'pro_50pctdown2up': '2x50%',
'pro_custom': '2x'
},
'yingk': {
'span_frees': 'free',
'span_twoupls': '2x',
'span_twoupfreels': '2xfree',
'span_thirtypercentls': '30%',
'span_halfdowns': '50%',
'span_twouphalfdownls': '2x50%'
}
}
for site, convert in sites_discount.items():
if site in link:
discount_fn = NexusPHP.generate_discount_fn(convert)
return NexusPHP.info_from_page(detail_page, peer_page, discount_fn)
discount_fn = NexusPHP.generate_discount_fn({
'free': 'free',
'twoup': '2x',
'twoupfree': '2xfree',
'thirtypercent': '30%',
'halfdown': '50%',
'twouphalfdown': '2x50%'
})
return NexusPHP.info_from_page(detail_page, peer_page, discount_fn)

@staticmethod
def generate_discount_fn(convert):
def fn(page):
for key, value in convert.items():
if key in page.text:
return value
return None

return fn


@event('plugin.register')
Expand Down
23 changes: 23 additions & 0 deletions site.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ REJECTED: `XXX` by nexusphp plugin because none does not match discount
- 该站点结构和其他站点区别较大,可能不支持

# 适配站点
## 自行适配
1. 在详情页面的HTML代码中寻找相关信息,如:
```html
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="free">免费</font>]</b></h1>
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="twoup">2X</font>]</b></h1>
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="twoupfree">2X免费</font>]</b></h1>
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="thirtypercent">30%</font>]</b></h1>
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="halfdown">50%</font>]</b></h1>
<h1 align="center" id="top">XXX 2006 1080p<b>[<font class="twouphalfdown">2X50%</font>]</b></h1>
```
选择其中的类名作为标识,即 `free twoup twoupfree thirtypercent halfdown twouphalfdown`
2. 在配置文件添加适配选项adopter
```yaml
nexusphp:
adopter:
free: free
2x: twoup
2xfree: twoupfree
30%: thirtypercent
50%: halfdown
2x50%: twouphalfdown
```
## 开发者适配
请联系开发者并提供以下信息:
- 站点名
- Flexget相关输出日志
Expand Down

0 comments on commit f0d005a

Please sign in to comment.