From d37df2ee54020fad7b059969193996f2b17accf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=8B=E9=9B=A8?= <1299172402@qq.com> Date: Tue, 18 Oct 2022 16:27:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=93=94=E5=93=A9=E5=93=94?= =?UTF-8?q?=E5=93=A9=E6=BC=AB=E7=94=BB=E4=B8=8B=E8=BD=BD=E7=9B=B8=E5=85=B3?= =?UTF-8?q?api=20(#508)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update Comic.md * 添加漫画下载api * fix: json format * Update Comic.md * add: unlock index.data * Update unlock_index_data.md * Update unlock_index_data.md * Update unlock_index_data.md * 修改【data.index解析】 Co-authored-by: 社会易姐QwQ <45892418+SocialSisterYi@users.noreply.github.com> --- README.md | 4 +- manga/Comic.md | 16 ++- manga/Download.md | 256 ++++++++++++++++++++++++++++++++++++++++ manga/index_file.md | 277 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 549 insertions(+), 4 deletions(-) create mode 100644 manga/Download.md create mode 100644 manga/index_file.md diff --git a/README.md b/README.md index 4e7c58a..633ea62 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,9 @@ PS:所有 rest api 均可使用 https,文档中为了统一写作`http`( - [x] [积分商城](manga/point_shop.md) - [x] [漫画操作](manga/Comic.md) - [x] [漫读券/已购相关](manga/User.md) - + - [x] [下载](manga/Download.md) + - [x] [data.index解析](manga/index_file.md) + - [ ] 哔哩哔哩游戏 - [ ] 轻视频 - [ ] [终端网络查询](clientinfo) diff --git a/manga/Comic.md b/manga/Comic.md index d73a966..af9d4bb 100644 --- a/manga/Comic.md +++ b/manga/Comic.md @@ -29,10 +29,11 @@ | 参数名 | 类型 | 内容 | 必要性 | 备注 | | -------- | ---- | ------------------------ | ------ | ------------------------------------------------- | | epId | num | 章节id | 必要 | | -| buyMethod | num | 购买方式 | 必要 | 2:漫读券
5:通用券 | +| buyMethod | num | 购买方式 | 必要 | 2:漫读券
4:新人等免
5:通用券 | | couponId | num | 漫读券id | 必要 | | -| autoPayGoldStatus | num | 2 | 必要 | | -| isPresale | num | 0 | 必要 | | +| comicId | num | 漫画id | 可选 | buyMethod:4为必要| +| autoPayGoldStatus | num | 2 | 可选 | buyMethod:2,5 为必要
buyMethod:4为不必要 | +| isPresale | num | 0 | 可选 | buyMethod:2,5 为必要
buyMethod:4为不必要 | 漫读券购买 @@ -46,6 +47,15 @@ } ``` +等就免费(新人等免) +``` +{ + "ep_id": 321913, + "comic_id": 26564, + "buy_method": 4 +} +``` + 通用券购买 ``` diff --git a/manga/Download.md b/manga/Download.md new file mode 100644 index 0000000..07b0a97 --- /dev/null +++ b/manga/Download.md @@ -0,0 +1,256 @@ +# 获取当前话全部图片地址 + +> https://manga.bilibili.com/twirp/comic.v1.Comic/GetImageIndex + +*请求方式:POST* + +认证方式:Cookie(SESSDATA)/ APP + +**URL参数:** + +| 参数名 | 类型 | 内容 | 必要性 | 备注 | +| ---------- | ---- | ------------------------ | -------------- | ------------------------------------------------------------ | +| access_key | str | APP登录凭证 | 必要 | 使用APP鉴权方式时必填 | +| appkey | str | cc8617fd6961e070 | 非必要 | | +| mobi_app | str | android_comic | 非必要 | | +| version | str | 4.21.0 | 非必要 | | +| build | str | 36421000 | 非必要 | | +| channel | str | bilicomic | 非必要 | | +| platform | str | android | 非必要 | | +| device | str | android | 非必要 | | +| buvid | str | XY118701XXXXXXXXX104911DXXXXXCAEXXXXE | 非必要 | 长度为37 | +| machine | str | | 非必要 | 手机品牌+型号 | +| is_teenager | num | 0 | 非必要 | | +| no_recommend | num | 0 | 非必要 | | +| ts | num | 秒级时间戳 | 非必要 | + +**正文参数( application/json ):** + +| 参数名 | 类型 | 内容 | 必要性 | 备注 | +| -------- | ---- | ------------------------ | ------ | ------------------------------------------------- | +| epId(ep_id) | num | 当前话的id | 必要 | | + +**json回复:** + +根对象: + +| 字段 | 类型 | 内容 | 备注 | +| ------- | ---- | -------- | ------------------------------------------------------------ | +| code | num | 返回值 | 0:成功 | +| msg | str | 错误信息 | | +| data | obj | | | + +`data` 对象: + +| 字段 | 类型 | 内容 | 备注 | +| ------- | ---- | -------- | ------------------------------------------------------------ | +| path | str | .index 文件路径 | 解密详见[此处](./unlock_index_data.md) | +| images | array | 本话图片信息 | | +| last_modified | str | 本话信息最后修改时间 | | +| host | str | `https://manga.hdslb.com` | | +| video | obj | | | + +`images` 数组中的对象: + +| 字段 | 类型 | 内容 | 备注 | +| ------- | ---- | -------- | ------------------------------------------------------------ | +| path | str | 图片的路径 | 不包含host | +| x | num | 图片宽度 | 单位:像素px | +| y | num | 图片高度 | 单位:像素px | +| video_path | str | | | +| video_size | str | | | + +`video` 对象: + +| 字段 | 类型 | 内容 | 备注 | +| ------- | ---- | -------- | ------------------------------------------------------------ | +| svid | str | | | +| filename | str | | | +| route | str | | | +| resource | array | | | +| raw_width | str | | | +| raw_height | str | | | +| raw_rotate | str | | | +| img_urls | array | | | +| bin_url | str | | | +| img_x_len | num | | | +| img_x_size | num | | | +| img_y_len | num | | | +| img_y_size | num | | | + + +**示例:** + +```bash +curl -L -X POST 'https://manga.bilibili.com/twirp/comic.v1.Comic/GetImageIndex' \ +-H 'Cookie: SESSDATA=xxx;' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "ep_id": 321912 +}' +``` + +
+查看响应示例: + + +```json +{ + "code": 0, + "msg": "", + "data": { + "path": "/bfs/manga/26564/321912/data.index?token=80eab62fef85c1c134a6399f817a938f&ts=63404145", + "images": [ + { + "path": "/bfs/manga/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg", + "x": 1600, + "y": 2268, + "video_path": "", + "video_size": "0" + }, + { + "path": "/bfs/manga/bf1c48540b68f473b429317d8f6fa8cdb6eed3a5.jpg", + "x": 1600, + "y": 2268, + "video_path": "", + "video_size": "0" + }, + { + "path": "/bfs/manga/a46cfe90cfb49c67a4dbfc0002e5bc3d87d02963.jpg", + "x": 1600, + "y": 2268, + "video_path": "", + "video_size": "0" + } + ], + "last_modified": "2019-05-13 21:15:53", + "host": "https://manga.hdslb.com", + "video": { + "svid": "", + "filename": "", + "route": "", + "resource": [], + "raw_width": "0", + "raw_height": "0", + "raw_rotate": "0", + "img_urls": [], + "bin_url": "", + "img_x_len": 10, + "img_x_size": 160, + "img_y_len": 10, + "img_y_size": 90 + } + } +} +``` + +
+ +# 获取某一图片的token + +> https://manga.bilibili.com/twirp/comic.v1.Comic/ImageToken + +*请求方式:POST* + +认证方式:Cookie(SESSDATA)/ APP + +**URL参数:** + +| 参数名 | 类型 | 内容 | 必要性 | 备注 | +| ------------ | ---- | ------------------------------------- | ------ | --------------------- | +| access_key | str | APP登录凭证 | 必要 | 使用APP鉴权方式时必填 | +| appkey | str | cc8617fd6961e070 | 非必要 | | +| mobi_app | str | android_comic | 非必要 | | +| version | str | 4.21.0 | 非必要 | | +| build | str | 36421000 | 非必要 | | +| channel | str | bilicomic | 非必要 | | +| platform | str | android | 非必要 | | +| device | str | android | 非必要 | | +| buvid | str | XY118701XXXXXXXXX104911DXXXXXCAEXXXXE | 非必要 | 长度为37 | +| machine | str | samsung+SM-G9730 | 非必要 | 手机品牌+型号 | +| is_teenager | num | 0 | 非必要 | | +| no_recommend | num | 0 | 非必要 | | +| ts | num | 秒级时间戳 | 非必要 | | + +**正文参数( application/json ):** + +| 参数名 | 类型 | 内容 | 必要性 | 备注 | +| ------ | ---- | ------------------- | ------ | ------------------------------------------------------------ | +| urls | str | 请求token的图片地址 | 必要 | `[\"https://i0.hdslb.com{path}\"]`
{path}代表图片的相对网站路径,支持jpg和webp | + +**json回复:** + +根对象: + +| 字段 | 类型 | 内容 | 备注 | +| ---- | ----- | -------- | ------- | +| code | num | 返回值 | 0:成功 | +| msg | str | 错误信息 | | +| data | array | | | + +`data` 数组中的对象: + +| 字段 | 类型 | 内容 | 备注 | +| ----- | ---- | ------------------- | ------------------------------------ | +| url | str | 图片下载的地址 | 此时网址开头 https://manga.hdslb.com | +| token | str | 图片下载需要的token | | + +**示例:** + +```bash +curl -L -X POST 'https://manga.bilibili.com/twirp/comic.v1.Comic/ImageToken' \ +-H 'Cookie: SESSDATA=xxx;' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "urls": "[\"https://i0.hdslb.com/bfs/manga/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg\"]" +}' +``` + +
+查看响应示例: + + + +```json +{ + "code": 0, + "msg": "", + "data": [ + { + "url": "https://manga.hdslb.com/bfs/manga/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg", + "token": "36931815abb35857627a22c347dc1c86&ts=634045c2" + } + ] +} +``` + +
+ +# 下载图片 + +*请求方式:GET* + +在上一步获取token的基础上,构建如下的url + +例如获取到此token + +``` +{ + "code": 0, + "msg": "", + "data": [ + { + "url": "https://manga.hdslb.com/bfs/manga/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg", + "token": "36931815abb35857627a22c347dc1c86&ts=634045c2" + } + ] +} +``` + +则访问以下网址即可,注意需要添加`?token=`。此网址有效期较短 + +``` +https://manga.hdslb.com/bfs/manga/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg?token=36931815abb35857627a22c347dc1c86&ts=634045c2 +``` + +备注:若访问 `https://i0(或i1).hdslb.com/bfs/manga(或new_dyn或archive)/11e404e602fa9f709bfb89d692ac56d2e17f974d.jpg` 均无法获取 diff --git a/manga/index_file.md b/manga/index_file.md new file mode 100644 index 0000000..e6f9c39 --- /dev/null +++ b/manga/index_file.md @@ -0,0 +1,277 @@ +# data.index + +- [data.index文件解析](#data.index文件解析) + - [获取data.index](#获取data.index) + - [文件解密算法](#文件解密算法) + - [进行解密操作](#进行解密操作) +- [data.index内容](#data.index内容) + +--- + +## data.index文件解析 + +本解密及数据解析例程以《在魔王城说晚安 第 1 话 不眠之城的公主》为例 + +本话链接:https://manga.bilibili.com/mc26731/329893 (mcid=`26731`, epid=`329893`) + +使用 Python 语言为例 + +### 获取data.index + +直接使用 GET 方法请求该话对应的 data.index 文件地址,就会得到一个二进制文件 + +```bash +curl -s 'https://manga.hdslb.com/bfs/manga/26731/329893/data.index?token=4b93ced19dc5ade671064804232ef4f5&ts=634e1943' | hexdump -C +``` + +data.index 文件内容的 HEX 如下 + +首部有 9 Byte 作为 File Magic 内容是 ASCII 编码的 `BILICOMIC` + +``` +00000000 42 49 4c 49 43 4f 4d 49 43 f5 43 06 04 7f 68 08 |BILICOMIC.C...h.| +00000010 00 ad 08 05 00 6b 68 00 00 a5 08 05 00 6b 68 00 |.....kh......kh.| +00000020 00 a5 08 0c 00 6b 68 69 6e c1 6d 7d 2e 0f 09 74 |.....khin.m}...t| +00000030 ec 33 c3 8f 5c 2c 64 86 df 40 a4 82 58 9c 42 f5 |.3..\,d..@..X.B.| +00000040 ab 21 51 4d aa f9 f1 e0 84 84 9b 40 12 58 87 1e |.!QM.......@.X..| +00000050 ba 28 29 7d ce 89 04 03 d9 91 8d fd 7e 31 1d be |.()}........~1..| +00000060 ba d8 35 ef cb a0 83 db 71 5e f1 ee f1 90 19 43 |..5.....q^.....C| +00000070 03 dd 32 f7 b8 7a b7 07 7f b9 3f 7d 3a d5 54 7e |..2..z....?}:.T~| +00000080 5f fa e2 bd c1 90 bb 0f 9c 7d 34 e4 f0 49 2f 17 |_........}4..I/.| +00000090 39 1b c0 cc 45 25 47 72 76 34 13 12 b9 12 f9 f3 |9...E%Grv4......| +000000a0 8b b9 56 13 72 be 60 5e 55 27 5f 98 e0 3e 41 78 |..V.r.`^U'_..>Ax| +000000b0 d5 af 56 d0 82 3c d5 e0 55 94 70 d0 0c 16 5f 33 |..V..<..U.p..._3| +000000c0 c5 bb 14 d7 e9 e5 4a 7c 7f db 04 ea 7b 9b 90 94 |......J|....{...| +000000d0 fd 53 e1 d2 f8 86 1b 7c ea 97 dd 0b 22 33 75 39 |.S.....|...."3u9| +000000e0 24 76 39 38 6d 58 a4 ed b4 14 8f 71 49 95 9c cb |$v98mX.....qI...| +000000f0 eb 42 eb ec df a2 22 ae 39 0c 3d 03 95 43 27 55 |.B....".9.=..C'U| +00000100 c1 c8 b2 37 2c 01 b0 f4 22 7c 51 1a 93 b5 ab 6d |...7,..."|Q....m| +00000110 72 95 0c 33 9a ed 2d d6 22 f0 08 b6 5c bb f6 b5 |r..3..-."...\...| +00000120 07 5f cf a1 3a 66 c8 30 41 29 31 dd 17 63 46 85 |._..:f.0A)1..cF.| +00000130 ea 53 20 a0 aa 89 65 91 78 37 ac 4b 06 e6 59 7a |.S ...e.x7.K..Yz| +00000140 c2 b7 10 56 cc a0 2e 85 94 09 01 89 83 43 82 a4 |...V.........C..| +00000150 db 60 91 89 15 83 aa 45 aa d6 5f fd 6a 64 f9 1c |.`.....E.._.jd..| +00000160 9d ef c3 6c 34 85 e7 49 8a a7 c3 bc 32 09 eb b8 |...l4..I....2...| +00000170 ef 70 ab d6 6a d2 7f f6 96 b1 9a 75 eb f8 47 34 |.p..j......u..G4| +00000180 db 1d 99 78 57 58 04 4e e0 c4 a4 58 d8 81 f5 02 |...xWX.N...X....| +00000190 3c 42 7e 1c 27 98 3c 70 df 04 13 33 fa ff 21 3b | +查看json内容: + +```json +{ + "clips": [ + {"r": 1600, "b": 2300, "t": 0, "l": 0, "pic": 0}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 1}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 2}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 3}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 4}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 5}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 6}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 7}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 8}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 9}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 10}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 11}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 12}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 13}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 14}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 15}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 16}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 17}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 18}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 19}, + {"r": 1600, "b": 2468, "t": 0, "l": 0, "pic": 20}, + {"r": 846, "b": 1200, "t": 0, "l": 0, "pic": 21} + ], + "pics": [ + "/bfs/manga/fc655fa220dfab74bb91b9b6e308e92e1f74fc4b.jpg", + "/bfs/manga/cb3c882f5a72c45385541e65dba6ac7689c24ebc.jpg", + "/bfs/manga/9f79683a30a1f165a6abcd2550066bd0f9bce719.jpg", + "/bfs/manga/592702a6411a8739d041d50cff9ac52ccc3e0ab1.jpg", + "/bfs/manga/52fb305a77f80d4078469c67ca4c4d8031722acc.jpg", + "/bfs/manga/d3bb31ca1943c2558eca9df9a44b7fb52d927f1e.jpg", + "/bfs/manga/2ac06b8dbaae0499edf7fb6cd99c1fe4b424a96f.jpg", + "/bfs/manga/98f63f139ecf30e3b037635fc1f59fb40388e947.jpg", + "/bfs/manga/55099ea5e0e198482ea6d216a5e41b02835701b7.jpg", + "/bfs/manga/ee60daaf9ca659bb0df7d45402c86c79a1f64739.jpg", + "/bfs/manga/8620f9742fddc97d4179f18fd2b9f1b1420138dd.jpg", + "/bfs/manga/0490a9d8bdb6312ac56baa24ed0595a2465d98dc.jpg", + "/bfs/manga/bc3234cb0ba2be2b724b1a640a418f1db7b2ac43.jpg", + "/bfs/manga/0d16c5e9779f187916e4b173e7a6447b14707ece.jpg", + "/bfs/manga/58f3985afc3f2cf57052725dfea47af5634ac1c8.jpg", + "/bfs/manga/de09b30d952566c2c1308f5da59a2ffb3b2deb5c.jpg", + "/bfs/manga/36ecc5565340605883cb000f513b49bfc91e0d3e.jpg", + "/bfs/manga/120f3174def02b3dd908ee69b427d094506b884d.jpg", + "/bfs/manga/fdbe3bd0d446c0129557bd19037785456e55f12c.jpg", + "/bfs/manga/813a1bb68c3f89616583c8662fa81984d6a907db.jpg", + "/bfs/manga/fd3a53f04831e577707e4c873e2fc205e71d5cde.jpg", + "/bfs/manga/50e1c513336e0685ca01723d64c712294e534ca0.jpg" + ], + "sizes": [ + {"cx": 1600, "cy": 2300}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 1600, "cy": 2468}, + {"cx": 846, "cy": 1200} + ] +} +``` + + + +## data.index内容 + +以下内容为解密后的 JSON 数据定义 + +根对象: + +| 字段 | 类型 | 内容 | 备注 | +| ----- | ----- | -------- | ---- | +| clips | array | 尺寸信息 | | +| pics | array | 图片路径 | | +| sizes | array | 尺寸信息 | | + +根对象中的`clips`数组: + +| 项 | 类型 | 内容 | 备注 | +| ---- | ---- | --------------- | ---- | +| 0 | obj | 第 1 页信息 | | +| n | obj | 第 (n+1) 页信息 | | +| …… | obj | …… | …… | + +`clips`数组中的对象: + +| 字段 | 类型 | 内容 | 备注 | +| ---- | ---- | ------------ | ------------- | +| r | num | 图片宽度 | | +| b | num | 图片高度 | | +| t | num | (?) | | +| l | num | (?) | | +| pic | num | 图片页码序号 | 从 0 开始递增 | + +根对象中的`pics`数组: + +| 项 | 类型 | 内容 | 备注 | +| ---- | ---- | ----------------- | ------------------------------ | +| 0 | str | 第 1 图片路径 | 图片不能直接访问,需要二次鉴权 | +| n | str | 第 (n+1) 图片路径 | | +| …… | str | …… | …… | + +根对象中的`sizes`数组: + +| 项 | 类型 | 内容 | 备注 | +| ---- | ---- | --------------- | ---- | +| 0 | obj | 第 1 页信息 | | +| n | obj | 第 (n+1) 页信息 | | +| …… | obj | …… | …… | + +`clips`数组中的对象: + +| 字段 | 类型 | 内容 | 备注 | +| ---- | ---- | -------- | ---- | +| cx | num | 图片宽度 | | +| cy | num | 图片高度 | |