Skip to content

Commit 282bd48

Browse files
committed
修改算法
1 parent ad8f529 commit 282bd48

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

getComic.py

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def isLegelUrl(url):
3434
legal_url_list = [
3535
re.compile(r'^http://ac.qq.com/Comic/[Cc]omicInfo/id/\d+/?$'),
3636
re.compile(r'^http://m.ac.qq.com/Comic/[Cc]omicInfo/id/\d+/?$'),
37+
re.compile(r'^http://m.ac.qq.com/comic/index/id/\d+/?$'),
3738
re.compile(r'^http://ac.qq.com/\w+/?$'),
38-
re.compile(r'^http://pad.ac.qq.com/Comic/[Cc]omicInfo/id/\d+/?$')
3939
]
4040

4141
for legal_url in legal_url_list:
@@ -85,38 +85,61 @@ def getContent(id):
8585
break
8686
return (comicName, comicIntrd, count, sortedContentList)
8787

88-
def getImgList(contentJson, id):
88+
def getImgList(contentJson, comic_id):
8989
cid = list(contentJson.keys())[0]
90-
eid = contentJson.get(cid).get('eid')
91-
getPicHashURL = 'http://m.ac.qq.com/View/mGetPicHash?id={}&eid={}'.format(id, eid)
92-
requestSession.headers.update({'Referer': 'http://m.ac.qq.com/Comic/view/id/{}/cid/{}'.format(id,cid)})
93-
try:
94-
picJsonPage = requestSession.get(getPicHashURL).text
95-
except:
96-
sleep(2)
97-
picJsonPage = requestSession.get(getPicHashURL).text
98-
picJson = json.loads(picJsonPage)
99-
count = picJson['pCount'] #统计图片数量
100-
pHash = picJson['pHash']
101-
sortedImgDictList = []
102-
for i in range(1, count + 1):
103-
for item in pHash:
104-
if pHash[item]['seq'] == i:
105-
sortedImgDictList.append(pHash[item])
106-
break
90+
cid_page = requestSession.get('http://m.ac.qq.com/chapter/index/id/{0}/cid/{1}'.format(comic_id, cid)).text
91+
base64data = re.findall(r"data:\s*'(.+?)'", cid_page)[0][1:]
92+
img_detail_json = json.loads(__decode_base64_data(base64data))
10793
imgList = []
108-
for imgDict in sortedImgDictList:
109-
k = imgDict['cid']
110-
m = imgDict['pid']
111-
j = int(id)
112-
uin = max(j + k + m, 10001)
113-
l = [j % 1000 // 100, j % 100, j, k]
114-
n = '/mif800/' + '/'.join(str(j) for j in l) + '/'
115-
h = str(m) + '.mif2'
116-
g="http://ac.tc.qq.com/store_file_download?buid=15017&uin="+str(uin)+"&dir_path="+n+"&name="+h
117-
imgList.append(g)
94+
for img_url in img_detail_json.get('picture'):
95+
imgList.append(img_url['url'])
11896
return imgList
11997

98+
def __decode_base64_data(base64data):
99+
base64DecodeChars = [- 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1]
100+
data_length = len(base64data)
101+
i = 0
102+
out = ""
103+
c1 = c2 = c3 = c4 = 0
104+
while i < data_length:
105+
while True:
106+
c1 = base64DecodeChars[ord(base64data[i]) & 255]
107+
i += 1
108+
if not (i < data_length and c1 == -1):
109+
break
110+
if c1 == -1:
111+
break
112+
while True:
113+
c2 = base64DecodeChars[ord(base64data[i]) & 255]
114+
i += 1
115+
if not (i < data_length and c2 == -1):
116+
break
117+
if c2 == -1:
118+
break
119+
out += chr(c1 << 2 | (c2 & 48) >> 4)
120+
while True:
121+
c3 = ord(base64data[i]) & 255
122+
i += 1
123+
if c3 == 61:
124+
return out
125+
c3 = base64DecodeChars[c3]
126+
if not (i < data_length and c3 == - 1):
127+
break
128+
if c3 == -1:
129+
break
130+
out += chr((c2 & 15) << 4 | (c3 & 60) >> 2)
131+
while True:
132+
c4 = ord(base64data[i]) & 255
133+
i += 1
134+
if c4 == 61:
135+
return out
136+
c4 = base64DecodeChars[c4]
137+
if not (i < data_length and c4 == - 1):
138+
break
139+
out += chr((c3 & 3) << 6 | c4)
140+
return out
141+
142+
120143
def downloadImg(imgUrlList, contentPath, one_folder=False):
121144
count = len(imgUrlList)
122145
print('该集漫画共计{}张图片'.format(count))
@@ -296,4 +319,4 @@ def main(url, path, lst=None, one_folder=False):
296319
if not path:
297320
path = defaultPath
298321

299-
main(url, path, lst, one_folder)
322+
main(url, path, lst, one_folder)

0 commit comments

Comments
 (0)