Skip to content

Commit

Permalink
use BIDU OCR service
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzamx committed Apr 5, 2024
1 parent 494ed86 commit c3b8104
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.2b(2024/4/6)
- 又改回验证码分支了,需要自行架设一个百度的服务,参考 https://cloud.baidu.com/doc/OCR/s/dk3iqnq51

v0.2(2023/5/30)
- Merged https://github.com/pizzamx/zimuku_for_kodi/pull/18(感谢 @lm317379829 解决了验证码,以及好厉害的服务)

Expand Down
6 changes: 5 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.subtitles.zimukux" name="ZiMuKuX" version="0.2.0" provider-name="pizzamx">
<addon id="script.subtitles.zimukux" name="ZiMuKuX" version="0.2.0b" provider-name="pizzamx">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.beautifulsoup4" version="4.6.2"/>
Expand All @@ -20,6 +20,10 @@
<fanart>resources/fanart.png</fanart>
</assets>
<news>
v0.2b(2024/4/6)
- Need to resolve Captcha issue again
- Do change OCR service URL to your own, ref: https://cloud.baidu.com/doc/OCR/s/dk3iqnq51

v0.2.0(2023/5/30)
- Merged https://github.com/pizzamx/zimuku_for_kodi/pull/18 (big thanks to lm317379829 for solving the captcha issue)
- Let's bump version a bit
Expand Down
19 changes: 11 additions & 8 deletions resources/lib/zimuku_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class Zimuku_Agent:
def __init__(self, base_url, dl_location, logger, unpacker, settings, ocrUrl='https://ddddocr.lm317379829.repl.co/'):
def __init__(self, base_url, dl_location, logger, unpacker, settings, ocrUrl):
self.ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'
self.ZIMUKU_BASE = base_url
# self.ZIMUKU_API = '%s/search?q=%%s&vertoken=%%s' % base_url
Expand Down Expand Up @@ -126,16 +126,20 @@ def verify(self, url, append):
if content is not None:
# 处理编码
ocrurl = self.ocrUrl
payload = {'imgdata': content}
payload = {'image': content}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36'
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
}
response = requests.request(
"POST", ocrurl, headers=headers, json=payload)
"POST", ocrurl, headers=headers, data=payload)
result_json = json.loads(response.text)
text = ''
if result_json['code'] == 1:
text = result_json['result']
try:
text = result_json['words_result'][0]['words']
except Exception as e:
self.logger.log(sys._getframe().f_code.co_name, "ERROR CHALLENGING CAPTCHA(SERVICE CODE: %s, MSG: %s" % (result_json['error_code'], result_json['error_msg']), level=3)
return
str1 = ''
i = 0
for ch in text:
Expand All @@ -144,7 +148,6 @@ def verify(self, url, append):
else:
str1 += hex(ord(text[i]))
i = i + 1

# 使用带验证码的访问
get_cookie_url = '%s%s&%s' % (
url, append, 'security_verify_img=' + str1.replace('0x', ''))
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<control type="edit" format="string">
<heading>301011</heading>
</control>
<default>https://ddddocr.lm317379829.repl.co/</default>
<default>https://aip.baidubce.com/rest/2.0/ocr/v1/numbers?access_token=YOUR_BAIDU_ACCESS_TOKEN</default>
<constraints>
<allowempty>false</allowempty>
</constraints>
Expand Down

0 comments on commit c3b8104

Please sign in to comment.