Skip to content

Commit

Permalink
Fix: seemh server detection (#362)
Browse files Browse the repository at this point in the history
* Fix: seemh server detection

* Fix: support tw
  • Loading branch information
eight04 authored Dec 24, 2023
1 parent 3ea99c7 commit 41fe0ec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
6 changes: 4 additions & 2 deletions comiccrawler/mods/seemh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from lzstring import LZString

from ..core import Episode, grabhtml
from ..util import balance

domain = ["seemh.com", "ikanman.com", "manhuagui.com", "www.mhgui.com"]
name = "看漫畫"
Expand Down Expand Up @@ -107,8 +108,9 @@ def get_images(html, url):
corejs = grabhtml(urljoin(url, corejs_url), referer=url)

# cache server list
servs = re.search(r"var servs=(.+)", configjs).group(1)
servs = eval(servs)
m = re.search(r"自动|自動", configjs)
s = balance(configjs, m.start(), "[", "]")
servs = eval(s)
servs = [host["h"] for category in servs for host in category["hosts"]]

global servers
Expand Down
41 changes: 36 additions & 5 deletions comiccrawler/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def create_safefilepath_table():
":": ":",
"\"": """,
"*": "*"
})
})
table.update({
c: None for c in set(chr(i) for i in range(128)).difference(string.printable)
})
})
table.update({
chr(i): " " for i in range(32) if chr(i) not in table
})
})
return str.maketrans(table)

safefilepath_table = create_safefilepath_table()
dot_table = str.maketrans({".": "."})

Expand Down Expand Up @@ -71,8 +71,39 @@ def clean_tags(html):
class MinimumAny:
def __le__(self, other):
return True

def __eq__(self, other):
return self is other

MIN = MinimumAny()

def balance(s: str, index: int, left="(", right=")", skip=0):
"""Return the string inside (including) matched left and right brackets."""
# backward search
count = 0
for i in range(index, -1, -1):
if s[i] == right:
count += 1
elif s[i] == left:
if count == -skip:
break
count -= 1
else:
raise ValueError(f"Unbalanced brackets: {s}")
start = i

# forward search
count = 0
for j in range(index, len(s)):
if s[j] == left:
count += 1
elif s[j] == right:
if count == -skip:
break
count -= 1
else:
raise ValueError(f"Unbalanced brackets: {s}")
end = j + 1

return s[start:end]

0 comments on commit 41fe0ec

Please sign in to comment.