Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

bug fix for parse_episode() #83

Merged
merged 2 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,25 @@ script:
- bgmi filter $BANGUMI_2 --subtitle "" --exclude "MKV" --regex "720p|720P"
- bgmi fetch $BANGUMI_2
- bgmi search "为美好的世界献上祝福!" --regex-filter '.*动漫国字幕组.*为美好的世界献上祝福!].*720P.*'
- echo 'test mikan'
- export BANGUMI_1=捏造陷阱
- export BANGUMI_2=咲良田重置
- export BANGUMI_3=人马小姐不迷茫
- rm ~/.bgmi -r
- bgmi -h
- bgmi config DATA_SOURCE mikan_project
- bgmi cal
- bgmi config DOWNLOAD_DELEGATE 'rr!'
- bgmi add $BANGUMI_1 $BANGUMI_2 $BANGUMI_3
- bgmi update
- bgmi delete --name $BANGUMI_3
- bgmi delete --clear-all --batch
- bgmi add $BANGUMI_2 --episode 1
- bgmi list
- bgmi config ARIA2_RPC_TOKEN 'token:233'
- bgmi download --list
- bgmi mark $BANGUMI_2 1
- bgmi update $BANGUMI_2
- bgmi filter $BANGUMI_2 --subtitle "" --exclude "MKV" --regex "720p|720P"
- bgmi fetch $BANGUMI_2
- bgmi search "末日时在做什么" --regex-filter '.*极影.*'
41 changes: 4 additions & 37 deletions bgmi/website/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import time
from collections import defaultdict
from itertools import chain

import bgmi.config
from bgmi.config import MAX_PAGE
from bgmi.models import Bangumi, Filter, Subtitle, STATUS_FOLLOWED, STATUS_UPDATED
Expand All @@ -34,52 +33,21 @@ def parse_episode(episode_title):
:rtype: int
"""

def cn2int(cn):
cn_num = {
u'零': 0,
u'〇': 0,
u'一': 1,
u'二': 2,
u'三': 3,
u'四': 4,
u'五': 5,
u'六': 6,
u'七': 7,
u'八': 8,
u'九': 9,
}
li = list(cn)
if len(li) == 2:
ret = 10
char = li[-1]
ret += cn_num[char]
else:
char = cn
ret = cn_num[char]
return ret

FETCH_EPISODE_ZH = re.compile("[第]\s?(\d{1,2})\s?[話话集]")
FETCH_EPISODE_ALL_ZH = re.compile('[第]([\u4e00-\u9fa5]*)[話话集]')
FETCH_EPISODE_WITH_BRACKETS = re.compile('[【\[](\d+)\s?(?:END)?[】]')
FETCH_EPISODE_ZH = re.compile("第?\s?(\d{1,3})\s?[話话集]")
FETCH_EPISODE_WITH_BRACKETS = re.compile('[【\[](\d+)\s?(?:END)?[】\]]')
FETCH_EPISODE_ONLY_NUM = re.compile('^([\d]{2,})$')
FETCH_EPISODE_RANGE = re.compile('[\d]{2,}\s?-\s?([\d]{2,})')
FETCH_EPISODE_OVA_OAD = re.compile('([\d]{2,})\s?\((?:OVA|OAD)\)]')
FETCH_EPISODE_WITH_VERSION = re.compile('[【\[](\d+)\s? *v\d(?:END)?[】]')
FETCH_EPISODE_WITH_VERSION = re.compile('[【\[](\d+)\s? *v\d(?:END)?[】\]]')
FETCH_EPISODE = (
FETCH_EPISODE_ZH, FETCH_EPISODE_ALL_ZH, FETCH_EPISODE_WITH_BRACKETS, FETCH_EPISODE_ONLY_NUM,
FETCH_EPISODE_ZH, FETCH_EPISODE_WITH_BRACKETS, FETCH_EPISODE_ONLY_NUM,
FETCH_EPISODE_RANGE,
FETCH_EPISODE_OVA_OAD, FETCH_EPISODE_WITH_VERSION)

_ = FETCH_EPISODE_ZH.findall(episode_title)
if _ and _[0].isdigit():
return int(_[0])

_ = FETCH_EPISODE_ALL_ZH.findall(episode_title)
if _:
if re.compile('.*合集.*').findall(episode_title):
return
return cn2int(_[0])

_ = FETCH_EPISODE_WITH_BRACKETS.findall(episode_title)
if _ and _[0].isdigit():
return int(_[0])
Expand All @@ -102,7 +70,6 @@ def search(self, keyword='', count=1, filter_=None):
match_title = re.compile(filter_)

result = self.search_by_keyword(keyword, count)

# filter
filtered_result = []
for episode in result:
Expand Down