├── .editorconfig ├── .eslintrc.cjs ├── .gitignore ├── .npmignore ├── .prettierrc.js ├── .vscode └── settings.json ├── LICENSE.txt ├── README.md ├── bin └── index.js ├── docs ├── example.gif ├── example_2.gif ├── logo.png └── site.md ├── package-lock.json ├── package.json ├── patches └── cli-progress+3.12.0.patch ├── src ├── cli.ts ├── core.ts ├── index.ts ├── lib.d.ts ├── lib │ ├── ProgressBar.ts │ ├── download.ts │ └── parse │ │ ├── baimangu │ │ └── index.ts │ │ ├── baozi │ │ └── index.ts │ │ ├── base │ │ └── index.ts │ │ ├── dmzj │ │ ├── crypto.ts │ │ └── index.ts │ │ ├── godamanga │ │ └── index.ts │ │ ├── ikuku │ │ └── index.ts │ │ └── index.ts ├── update.ts └── utils │ ├── index.ts │ ├── log.ts │ └── ua.ts ├── test ├── lib.test.ts ├── parse │ ├── Ikuku.test.ts │ ├── __snapshots__ │ │ └── baozi.test.ts.snap │ ├── baimangu.test.ts │ ├── baozi.test.ts │ ├── dmzj.test.ts │ └── godamanga.test.ts └── utils.test.ts ├── tsconfig.build.json ├── tsconfig.json └── vitest.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | # 最后一行换行 取消掉 11 | insert_final_newline = false 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | insert_final_newline = false 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ignorePatterns: [ 3 | 'dist', 4 | 'types', 5 | 'node_modules', 6 | 'bin', 7 | 'test', 8 | 'docs', 9 | 'temp' 10 | ], 11 | env: { 12 | node: true, 13 | }, 14 | parser: '@typescript-eslint/parser', 15 | plugins: [ 16 | '@typescript-eslint', 17 | ], 18 | extends: [ 19 | 'eslint:recommended', 20 | 'plugin:@typescript-eslint/recommended', 21 | ], 22 | rules: { 23 | semi: ['error', 'never'], 24 | quotes: ['error', 'single'], 25 | 'no-console': 'off', 26 | 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], 27 | '@typescript-eslint/no-explicit-any': 'off', 28 | '@typescript-eslint/no-non-null-assertion': 'off' 29 | }, 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | .DS_Store 133 | test/.temp 134 | temp 135 | types 136 | comic-book -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | node_modules 3 | test 4 | temp 5 | assets 6 | .vscode 7 | .np-config.js 8 | .eslintrc.js 9 | .eslintignore 10 | .editorconfig 11 | *.log 12 | .prettierrc.js 13 | .eslintrc.cjs 14 | docs 15 | comic-book -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | export default { 2 | semi: false, 3 | endOfLine: 'lf', 4 | singleQuote: true, 5 | tabWidth: 2, 6 | useTabs: false, 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "Applebot", 4 | "Baimangu", 5 | "baozi", 6 | "baozimh", 7 | "colamanga", 8 | "dmzj", 9 | "Epub", 10 | "fzmanga", 11 | "Gener", 12 | "Godamanga", 13 | "Ikuku", 14 | "manhuagui", 15 | "plusplus" 16 | ] 17 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # comic-book-dl 2 | 3 | ![logo](https://socialify.git.ci/gxr404/comic-book-dl/image?font=Source%20Code%20Pro&logo=https%3A%2F%2Fgithub.com%2Fgxr404%2Fcomic-book-dl%2Fraw%2Fmain%2Fdocs%2Flogo.png&name=1&pattern=Circuit%20Board&theme=Light) 4 | 5 | 6 | 7 |

8 | 一款漫画下载器(搭配comic-book-browser使用)
9 | 开源 | 高效 | 易用

10 | npm 11 | Static Badge 12 | GitHub License 13 |
14 |

15 | 16 | ## 安装 17 | 18 | ```bash 19 | npm i -g comic-book-dl 20 | ``` 21 | 22 | ## 用法 23 | 24 | ```bash 25 | $ comic-book-dl --help 26 | 27 | Usage: 28 | $ comic-book-dl 29 | 30 | Commands: 31 | update 更新已下载的漫画 32 | 漫画目录页url 33 | 34 | For more info, run any command with the `--help` flag: 35 | $ comic-book-dl update --help 36 | $ comic-book-dl --help 37 | 38 | Options: 39 | -d, --distPath 下载的目录 eg: -d comic-book (default: comic-book) 40 | -h, --help Display this message 41 | -v, --version Display version number 42 | ``` 43 | 44 | ## Start 45 | 46 | 开始新下载一部漫画到本地,会在当前目录创建 comic-book目录存放漫画的图片 47 | 48 | > PS: 目前支持的站点[查看](./docs/site.md), 后续尝试其他站点 49 | 50 | ```bash 51 | # url 为对应想下载漫画目录 52 | comic-book-dl "https://cn.baozimh.com/comic/mengoushia-feiniaocheng" 53 | ``` 54 | 55 | ![example](./docs/example.gif) 56 | 57 | 下载仅是下载漫画的图片,安装 [`comic-book-browser`](https://github.com/gxr404/comic-book-browser) 开始沉浸式的阅读体验 58 | 59 | ## 更新 60 | 61 | 如果漫画后续有更新,可使用 `update` 命令更新 62 | 63 | ```bash 64 | comic-book-dl update 65 | ``` 66 | 67 | ![example_2](./docs/example_2.gif) 68 | 69 | ## 功能与建议 70 | 71 | - [x] 支持下载中断继续 72 | - [x] 支持漫画更新 73 | - [ ] 更多站点支持🤔 74 | 75 | 目前项目处于开发初期, 如果你对该项目有任何功能与建议,欢迎在 Issues 中提出 76 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | function run() { 4 | return import('../dist/cli.js') 5 | } 6 | run() -------------------------------------------------------------------------------- /docs/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gxr404/comic-book-dl/a04bb2ad4441b8405088a27c96c1eb5d4ec1fc8e/docs/example.gif -------------------------------------------------------------------------------- /docs/example_2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gxr404/comic-book-dl/a04bb2ad4441b8405088a27c96c1eb5d4ec1fc8e/docs/example_2.gif -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gxr404/comic-book-dl/a04bb2ad4441b8405088a27c96c1eb5d4ec1fc8e/docs/logo.png -------------------------------------------------------------------------------- /docs/site.md: -------------------------------------------------------------------------------- 1 | # 支持的网站 2 | 3 | - [包子漫画](https://cn.baozimh.com/)-- [其他域名](https://cn.fzmanga.com) 4 | - 其他备用域名: 5 | - "cn.baozimh.com" 6 | - "tw.baozimh.com" 7 | - "www.baozimh.com" 8 | - "cn.webmota.com" 9 | - "tw.webmota.com" 10 | - "www.webmota.com" 11 | - "cn.kukuc.co" 12 | - "tw.kukuc.co" 13 | - "www.kukuc.co" 14 | - "cn.czmanga.com" 15 | - "tw.czmanga.com" 16 | - "www.czmanga.com" 17 | - "cn.dinnerku.com" 18 | - "tw.dinnerku.com" 19 | - "www.dinnerku.com" 20 | 21 | ```bash 22 | comic-book-dl "https://cn.baozimh.com/comic/mengoushia-feiniaocheng" 23 | ``` 24 | 25 | > ⚠️ cloudflare 403报错, 改用其他域名试试 26 | 27 | - 动漫之家([mobile](https://m.idmzj.com/)/[pc](https://cn.baozimh.com/)) 28 | 29 | ```bash 30 | comic-book-dl "https://m.idmzj.com/info/qishishiyimeizuijinchuxiandeyilididiguoyuqinmile.html" 31 | ``` 32 | 33 | - [百漫谷](https://www.darpou.com) 34 | 35 | ```bash 36 | comic-book-dl "https://www.darpou.com/book/116645.html" 37 | ``` 38 | 39 | - [GoDa](https://cn.godamanga.com)(需科学上网) 40 | - [另一个域名](https://cn.baozimh.one/)(仿包子漫画实际是goda) 41 | 42 | ```bash 43 | comic-book-dl "https://cn.baozimh.one/manga/bianfuxiaqunyinghuiv3" 44 | ``` 45 | 46 | - [Ikuku](https://m.ikuku.cc) 47 | 48 | 49 | ```bash 50 | comic-book-dl "https://m.ikuku.cc/comiclist/2262/" 51 | ``` 52 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "comic-book-dl", 3 | "version": "0.0.43", 4 | "description": "漫画下载器", 5 | "keywords": [ 6 | "manga", 7 | "comic", 8 | "nodejs", 9 | "download", 10 | "comic-dl", 11 | "comic-book-dl", 12 | "comic-downloader", 13 | "cli" 14 | ], 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/gxr404/comic-book-dl.git" 18 | }, 19 | "license": "ISC", 20 | "author": "gxr404", 21 | "type": "module", 22 | "main": "dist/index.js", 23 | "types": "types/index.d.ts", 24 | "bin": { 25 | "comic-book-dl": "bin/index.js" 26 | }, 27 | "scripts": { 28 | "dev": "tsc -p tsconfig.build.json && (concurrently \"tsc -p tsconfig.build.json -w\" \"tsc-alias -p tsconfig.build.json -w\")", 29 | "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", 30 | "test": "run-s test:clean test:run", 31 | "test:run": "vitest run", 32 | "test:clean": "rimraf test/.temp", 33 | "eslintLog": "eslint . > eslint.log", 34 | "clean": "rimraf dist types", 35 | "np": "np", 36 | "release": "run-s clean build np", 37 | "postinstall": "patch-package", 38 | "sort-package-json": "npx sort-package-json" 39 | }, 40 | "dependencies": { 41 | "@inquirer/prompts": "^7.4.0", 42 | "cac": "^6.7.14", 43 | "cheerio": "^1.0.0", 44 | "cli-progress": "3.12.0", 45 | "got": "^14.4.6", 46 | "log4js": "^6.9.1", 47 | "node-rsa": "^1.1.1", 48 | "p-limit": "^6.2.0", 49 | "patch-package": "^8.0.0", 50 | "protobufjs": "^7.4.0", 51 | "rand-user-agent": "2.0.81", 52 | "rimraf": "^6.0.1" 53 | }, 54 | "devDependencies": { 55 | "@types/cli-progress": "^3.11.6", 56 | "@types/node-rsa": "^1.1.4", 57 | "@typescript-eslint/eslint-plugin": "^8.27.0", 58 | "@typescript-eslint/parser": "^8.27.0", 59 | "concurrently": "^9.1.2", 60 | "np": "^10.2.0", 61 | "npm-run-all": "^4.1.5", 62 | "tsc-alias": "^1.8.11", 63 | "typescript": "^5.8.2", 64 | "vitest": "^3.0.9" 65 | }, 66 | "engines": { 67 | "node": ">=16.14.0" 68 | }, 69 | "np": { 70 | "tests": true, 71 | "2fa": false 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /patches/cli-progress+3.12.0.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/cli-progress/lib/multi-bar.js b/node_modules/cli-progress/lib/multi-bar.js 2 | index d40ccfc..39db839 100644 3 | --- a/node_modules/cli-progress/lib/multi-bar.js 4 | +++ b/node_modules/cli-progress/lib/multi-bar.js 5 | @@ -114,7 +114,7 @@ module.exports = class MultiBar extends _EventEmitter{ 6 | this.bars.splice(index, 1); 7 | 8 | // force update 9 | - this.update(); 10 | + this.update(true); 11 | 12 | // clear bottom 13 | this.terminal.newline(); 14 | @@ -124,7 +124,7 @@ module.exports = class MultiBar extends _EventEmitter{ 15 | } 16 | 17 | // internal update routine 18 | - update(){ 19 | + update(forceRendering=false){ 20 | // stop timer 21 | if (this.timer){ 22 | clearTimeout(this.timer); 23 | @@ -158,7 +158,7 @@ module.exports = class MultiBar extends _EventEmitter{ 24 | } 25 | 26 | // render 27 | - this.bars[i].render(); 28 | + this.bars[i].render(forceRendering); 29 | } 30 | 31 | // trigger event 32 | -------------------------------------------------------------------------------- /src/cli.ts: -------------------------------------------------------------------------------- 1 | import { readFileSync } from 'node:fs' 2 | import { cac } from 'cac' 3 | import { main } from '@/index' 4 | import { logger } from '@/utils' 5 | import { update } from '@/update' 6 | 7 | const cli = cac('comic-book-dl') 8 | 9 | export interface IOptions { 10 | distPath: string; 11 | } 12 | 13 | // 不能直接使用 import {version} from '../package.json' 14 | // 否则declaration 生成的d.ts 会多一层src目录 15 | const { version } = JSON.parse( 16 | readFileSync(new URL('../package.json', import.meta.url)).toString(), 17 | ) 18 | 19 | cli.command('update', '更新已下载的漫画') 20 | .option('-d, --distPath ', '下载的目录 eg: -d /xx/comic-book', { 21 | default: 'comic-book', 22 | }) 23 | .action(async (options: IOptions) => { 24 | try { 25 | await update({ 26 | bookPath: options.distPath 27 | }) 28 | } catch (err) { 29 | console.log(err) 30 | logger.error(err.message || 'unknown exception') 31 | } 32 | }) 33 | 34 | cli 35 | .command('', '漫画目录页url') 36 | .option('-d, --distPath ', '下载的目录 eg: -d comic-book', { 37 | default: 'comic-book', 38 | }) 39 | .action(async (url, options: IOptions) => { 40 | try { 41 | await main({ 42 | targetUrl: url, 43 | bookPath: options.distPath, 44 | ignoreConsole: false 45 | }) 46 | } catch (err) { 47 | console.log(err) 48 | logger.error(err.message || 'unknown exception') 49 | } 50 | }) 51 | 52 | cli.help() 53 | cli.version(version) 54 | 55 | try { 56 | cli.parse() 57 | } catch (err) { 58 | logger.error(err.message || 'unknown exception') 59 | process.exit(1) 60 | } 61 | -------------------------------------------------------------------------------- /src/core.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import pLimit from 'p-limit' 3 | import ProgressBar from './lib/ProgressBar' 4 | import type { IProgressItem } from './lib/ProgressBar' 5 | import { existsMkdir } from './utils' 6 | import { matchParse } from './lib/parse/index' 7 | import { writeBookInfoFile } from './lib/download' 8 | import type { ChaptersItem } from './lib/parse/base' 9 | 10 | interface RunHooks { 11 | // 漫画url解析错误 12 | parseErr?: () => void, 13 | // 下载中断 14 | downloadInterrupted?: () => void, 15 | // 开始下载 16 | start?: (bookName: string) => void, 17 | // 下载结束存在错误 18 | error?: (bookName: string, chaptersList: ChaptersItem[], errorList: ErrorChapterItem[]) => void, 19 | // 下载结束 成功未有错误 20 | success?: (bookName: string, distPath: string, chaptersList: ChaptersItem[] | null) => void, 21 | } 22 | 23 | export interface ErrorChapterItem { 24 | bookName: string, 25 | /** 图片获取失败则所有图片都算失败 无指定的图片 */ 26 | imgUrl?: string, 27 | chapter: ChaptersItem 28 | } 29 | 30 | interface IgnoreBook { 31 | name: string, 32 | chapter?: string[] 33 | } 34 | 35 | export interface UserConfig { 36 | ignore?: IgnoreBook[] 37 | } 38 | export interface Config { 39 | bookPath: string, 40 | targetUrl: string, 41 | ignoreConsole?: boolean, 42 | userConfig?: UserConfig 43 | } 44 | 45 | // process.on('warning', e => { 46 | // writeFile('./warn.log', JSON.stringify(e.stack, null, 2)) 47 | // console.warn(e.stack?.at(-1)) 48 | // }) 49 | 50 | export async function run(config: Config, hooks: RunHooks) { 51 | const match = matchParse(config.targetUrl) 52 | if (!match) { 53 | if (hooks.parseErr) hooks.parseErr() 54 | return 55 | } 56 | const { preHandleUrl, getInstance } = match 57 | if (typeof preHandleUrl === 'function') { 58 | config.targetUrl = preHandleUrl(config.targetUrl) 59 | } 60 | const parseInstance = getInstance(config.targetUrl) 61 | const bookInfo = await parseInstance.parseBookInfo() 62 | if (!bookInfo) { 63 | if (hooks.parseErr) hooks.parseErr() 64 | return 65 | } 66 | 67 | const bookName = bookInfo.name 68 | const bookDistPath = path.resolve(config.bookPath, bookInfo.pathName) 69 | existsMkdir(bookDistPath) 70 | 71 | const total = bookInfo.chapters.length 72 | const progressBar = new ProgressBar(bookDistPath, total, config.ignoreConsole) 73 | await progressBar.init() 74 | 75 | // 已完成 无需再继续 76 | if (progressBar.curr === total) { 77 | if (hooks.success) hooks.success(bookName, bookDistPath, null) 78 | return 79 | } 80 | 81 | let chaptersList = bookInfo.chapters 82 | 83 | // 存在用户配置 忽略本漫画的某些章节 84 | if (config.userConfig?.ignore) { 85 | const ignoreInfo = config.userConfig?.ignore.find(item => item.name === bookName) 86 | if (ignoreInfo) { 87 | const ignoreChapter = ignoreInfo.chapter ?? [] 88 | chaptersList = chaptersList.filter(chaptersItem => { 89 | return !ignoreChapter.includes(chaptersItem.name) 90 | }) 91 | // 已完成 无需再继续 92 | if (progressBar.curr === total - ignoreChapter.length) { 93 | if (hooks.success) { 94 | progressBar.bar?.stop() 95 | hooks.success(bookName, bookDistPath, null) 96 | } 97 | return 98 | } 99 | } 100 | } 101 | 102 | if (hooks.start) hooks.start(bookName) 103 | 104 | 105 | // 下载中断 重新获取下载进度数据 106 | if (progressBar.isDownloadInterrupted) { 107 | if (hooks.downloadInterrupted) hooks?.downloadInterrupted() 108 | // 根据匹配chaptersList 重新更新 progressInfo 仅保留符合chaptersList 109 | // 因为有种情况 漫画更新 url一致 但对应的内容由于更新变化了 110 | const updateProgressInfo: IProgressItem[] = [] 111 | 112 | // 从process.json中读取已下载的数据 对 chaptersList 回填 已下载的数据 113 | // 并过滤出 chaptersList中未下载的 114 | chaptersList = chaptersList.filter((chaptersItem) => { 115 | return !progressBar.progressInfo.some(item => { 116 | try { 117 | let isSameHref = item.href === chaptersItem.href 118 | const isUrlReg = /(http|https):\/\// 119 | if (!isSameHref && isUrlReg.test(item.href) && isUrlReg.test(chaptersItem.href)) { 120 | isSameHref = new URL(item.href).pathname === new URL(chaptersItem.href).pathname 121 | } 122 | const isSameName = item.rawName == chaptersItem.rawName 123 | if (isSameHref && isSameName) { 124 | chaptersItem.imageList = item.imageList 125 | chaptersItem.imageListPath = item.imageListPath 126 | updateProgressInfo.push(item) 127 | } 128 | return isSameHref && isSameName 129 | } catch(e) { 130 | return false 131 | } 132 | }) 133 | }) 134 | // ! 漫画更新 url一致 但对应的内容由于更新变化了 重新更新符合的progressInfo 135 | progressBar.resetProgressInfo(updateProgressInfo) 136 | } 137 | 138 | const LIMIT_MAX = 6 139 | 140 | const limit = pLimit(LIMIT_MAX) 141 | 142 | const errorList: ErrorChapterItem[] = [] 143 | 144 | const promiseList = chaptersList.map(item => { 145 | return limit(async () => { 146 | const chaptersItemPath = `${bookDistPath}/chapters/${item.name}` 147 | existsMkdir(chaptersItemPath) 148 | let getImageListSuccess = true 149 | const imageList = await parseInstance.getImgList(item.href) 150 | .catch(() => { 151 | getImageListSuccess = false 152 | errorList.push({ 153 | bookName, 154 | chapter: item 155 | }) 156 | return [] as string[] 157 | }) 158 | let imageListPath: string[] = [] 159 | const curBar = progressBar.multiBarCreate({ 160 | total: imageList.length, 161 | file: `下载「${item.name}」中的图片...` 162 | }) 163 | 164 | let isAllSuccess = true 165 | imageListPath = await parseInstance.saveImgList( 166 | chaptersItemPath, 167 | imageList, 168 | (imgUrl: string, isSuccess: boolean) => { 169 | if (!isSuccess) { 170 | isAllSuccess = false 171 | errorList.push({ 172 | bookName, 173 | imgUrl, 174 | chapter: item 175 | }) 176 | } 177 | progressBar.multiBarUpdate(curBar) 178 | } 179 | ) 180 | imageListPath = imageListPath.map((itemPath) => { 181 | return `chapters/${item.name}/${itemPath}` 182 | }) 183 | item.imageList = imageList 184 | item.imageListPath = imageListPath 185 | progressBar.multiBarRemove(curBar) 186 | await progressBar.updateProgress({ 187 | name: item.name, 188 | rawName: item.rawName, 189 | path: chaptersItemPath, 190 | href: item.href, 191 | index: item.index, 192 | imageList, 193 | imageListPath 194 | }, isAllSuccess && getImageListSuccess) 195 | return isAllSuccess && getImageListSuccess 196 | }) 197 | }) 198 | 199 | const isAllSuccess = await Promise.all(promiseList) 200 | 201 | await writeBookInfoFile(bookInfo, bookDistPath, parseInstance) 202 | 203 | if (errorList.length > 0) { 204 | if (hooks.error) hooks.error(bookName, chaptersList, errorList) 205 | } else if (progressBar.curr === total && isAllSuccess) { 206 | if (hooks.success) hooks.success(bookName, bookDistPath, chaptersList) 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { logger } from '@/utils' 2 | import { run } from '@/core' 3 | import { scanFolder } from '@/lib/download' 4 | import type { Config, ErrorChapterItem } from '@/core' 5 | import type { ChaptersItem } from '@/lib/parse/base' 6 | 7 | interface ChapterErrorMsgItem { 8 | chapterName: string, 9 | imgList: string[] 10 | } 11 | 12 | export function echoErrorMsg( 13 | bookName: string, 14 | chaptersList: ChaptersItem[], 15 | errorList: ErrorChapterItem[], 16 | isShowDetails: boolean = false 17 | ) { 18 | const errChaptersMsg: ChapterErrorMsgItem[] = [] 19 | errorList.forEach((item)=>{ 20 | const errChapter = errChaptersMsg.find(msg => { 21 | return msg.chapterName === item.chapter.name 22 | }) 23 | if (errChapter && item.imgUrl) { 24 | errChapter.imgList.push(item.imgUrl) 25 | } else { 26 | errChaptersMsg.push({ 27 | chapterName: item.chapter.name, 28 | imgList: item.imgUrl ? [item.imgUrl] : [] 29 | }) 30 | } 31 | }) 32 | 33 | logger.error(`《${bookName}》本次执行总数${chaptersList.length}话,✕ 失败${errChaptersMsg.length}话`) 34 | for (const errInfo of errChaptersMsg) { 35 | logger.error(` └── ✕ ${errInfo.chapterName}`) 36 | if (isShowDetails) { 37 | errInfo.imgList.forEach(imgUrl => { 38 | logger.error(` └── ${imgUrl}`) 39 | }) 40 | } 41 | } 42 | } 43 | 44 | export async function main(config: Config) { 45 | const bookInfoList = await scanFolder(config.bookPath) 46 | const existedBookInfo = bookInfoList.find(bookInfo => { 47 | return bookInfo.rawUrl === config.targetUrl 48 | }) 49 | if (existedBookInfo) config.targetUrl = existedBookInfo.url 50 | const {ignoreConsole} = config 51 | await run(config, { 52 | parseErr() { 53 | if (ignoreConsole) return 54 | logger.error('× 请输入正确的url... o(╥﹏╥)o') 55 | }, 56 | start(bookName) { 57 | if (ignoreConsole) return 58 | logger.info(`开始下载 《${bookName}》`) 59 | }, 60 | downloadInterrupted() { 61 | if (ignoreConsole) return 62 | logger.info('根据上次数据继续断点下载') 63 | }, 64 | error(...args) { 65 | if (ignoreConsole) return 66 | echoErrorMsg(...args, true) 67 | logger.error('o(╥﹏╥)o 由于网络波动或链接失效以上下载失败,可重新执行命令重试(PS:不会影响已下载成功的数据)') 68 | }, 69 | success(bookName, bookDistPath) { 70 | if (ignoreConsole) return 71 | logger.info(`√ 已完成: ${bookDistPath}`) 72 | logger.info('(つ•̀ω•́)つ 欢迎star: https://github.com/gxr404/comic-book-dl') 73 | } 74 | }) 75 | process.exit(0) 76 | } 77 | -------------------------------------------------------------------------------- /src/lib.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'rand-user-agent' -------------------------------------------------------------------------------- /src/lib/ProgressBar.ts: -------------------------------------------------------------------------------- 1 | import fs from 'node:fs/promises' 2 | import cliProgress, { SingleBar } from 'cli-progress' 3 | import { rimraf } from 'rimraf' 4 | 5 | export interface IProgressItem { 6 | name: string, 7 | rawName: string, 8 | index: number, 9 | path: string, 10 | href: string, 11 | imageList: string[], 12 | imageListPath: string[] 13 | } 14 | export type IProgress = IProgressItem[] 15 | 16 | export default class ProgressBar { 17 | bookPath: string = '' 18 | progressFilePath: string = '' 19 | progressInfo: IProgress = [] 20 | curr: number = 0 21 | total: number = 0 22 | /** 是否中断下载 */ 23 | isDownloadInterrupted: boolean = false 24 | multiBar: cliProgress.MultiBar | null = null 25 | bar: cliProgress.SingleBar | null = null 26 | completePromise: Promise | null = null 27 | /** 忽略打印(如果忽略打印则 bar multiBar 一直为null) */ 28 | ignoreConsole: boolean = false 29 | 30 | constructor (bookPath: string, total: number, ignoreConsole: boolean = false) { 31 | this.bookPath = bookPath 32 | this.progressFilePath = `${bookPath}/progress.json` 33 | this.total = total 34 | this.ignoreConsole = ignoreConsole 35 | } 36 | 37 | async init() { 38 | this.progressInfo = await this.getProgress() 39 | this.curr = this.progressInfo.length 40 | 41 | if (this.curr === this.total) return 42 | 43 | this.isDownloadInterrupted = this.curr > 0 && this.curr !== this.total 44 | 45 | if (this.ignoreConsole) return 46 | 47 | this.multiBar = new cliProgress.MultiBar({ 48 | format: ' {bar} | {file} | {value}/{total}', 49 | hideCursor: true, 50 | barCompleteChar: '\u2588', 51 | barIncompleteChar: '\u2591', 52 | clearOnComplete: true, 53 | stopOnComplete: true, 54 | noTTYOutput: true 55 | }) 56 | 57 | this.bar = this.multiBar.create(this.total, this.curr, {}, { 58 | ...cliProgress.Presets.legacy, 59 | format: 'Download [{bar}] {percentage}% | {value}/{total}', 60 | }) 61 | } 62 | 63 | async getProgress(): Promise { 64 | let progressInfo = [] 65 | try { 66 | const progressInfoStr = await fs.readFile(this.progressFilePath, {encoding: 'utf8'}) 67 | progressInfo = JSON.parse(progressInfoStr) 68 | } catch (err) { 69 | if (err && err.code === 'ENOENT') { 70 | await fs.writeFile( 71 | this.progressFilePath, 72 | JSON.stringify(progressInfo), 73 | {encoding: 'utf8'} 74 | ) 75 | } 76 | } 77 | return progressInfo 78 | } 79 | 80 | async updateProgress(progressItem: IProgressItem, isSuccess: boolean) { 81 | this.curr = this.curr + 1 82 | // 成功才写入 progress.json 以便重新执行时重新下载 83 | if (isSuccess) { 84 | this.progressInfo.push(progressItem) 85 | await fs.writeFile( 86 | this.progressFilePath, 87 | JSON.stringify(this.progressInfo, null, 2), 88 | {encoding: 'utf8'} 89 | ) 90 | } 91 | if (this.bar) { 92 | this.bar.update(this.curr > this.total ? this.total : this.curr) 93 | if (this.curr >= this.total) { 94 | this.clearLine(1) 95 | this.bar.render() 96 | this.bar.stop() 97 | console.log('') 98 | } 99 | } 100 | } 101 | 102 | async resetProgressInfo(updateProgressInfo: IProgressItem[]) { 103 | if (updateProgressInfo.length < this.progressInfo.length) { 104 | const needDeleteList = this.progressInfo.filter((oldData) => { 105 | return !updateProgressInfo.some(item => { 106 | return item.href == oldData.href && 107 | item.name === oldData.name && 108 | item.rawName === oldData.rawName 109 | }) 110 | }) 111 | this.progressInfo = updateProgressInfo 112 | if (this.bar) this.bar.update(updateProgressInfo.length) 113 | this.curr = updateProgressInfo.length 114 | // 删除已下载但已经不符合最新漫画目录的文件夹 115 | const promiseList = needDeleteList.map(needDel => { 116 | return rimraf(needDel.path, {preserveRoot: true}) 117 | }) 118 | await Promise.all(promiseList) 119 | } 120 | 121 | } 122 | 123 | multiBarCreate(params: {total: number, file: string}) { 124 | if (this.ignoreConsole) return 125 | return this.multiBar?.create(params.total, 0, { 126 | file: params.file 127 | }) 128 | } 129 | 130 | multiBarUpdate(curBar: SingleBar | undefined) { 131 | if (curBar) curBar.increment() 132 | } 133 | 134 | multiBarRemove(curBar: SingleBar| undefined) { 135 | if (curBar) this.multiBar?.remove(curBar) 136 | } 137 | 138 | // 暂停进度条的打印 139 | pause () { 140 | if (this.bar) this.bar.stop() 141 | } 142 | // 继续进度条的打印 143 | continue(line: number) { 144 | this.clearLine(line) 145 | this.bar?.start(this.total, this.curr) 146 | } 147 | // 清理n行终端显示 148 | clearLine(line: number) { 149 | if (line <= 0) return 150 | process.stderr.cursorTo(0) 151 | for (let i = 0; i< line;i++){ 152 | process.stderr.moveCursor(0, -1) 153 | process.stderr.clearLine(1) 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /src/lib/download.ts: -------------------------------------------------------------------------------- 1 | import { writeFileSync } from 'node:fs' 2 | import { readdir, stat, readFile } from 'node:fs/promises' 3 | import { join } from 'node:path' 4 | import pLimit from 'p-limit' 5 | import { logger, notEmpty } from '@/utils' 6 | import { Base } from '@/lib/parse/base' 7 | import type { BookInfo } from '@/lib/parse/base' 8 | import { UserConfig } from '@/core' 9 | 10 | export async function writeBookInfoFile(bookInfo: BookInfo, bookDistPath: string, parseInstance: Base) { 11 | const coverPicPath = await parseInstance.saveImg(bookDistPath, bookInfo.coverUrl, 'cover').catch(e => { 12 | logger.error('封面图下载失败', e.message) 13 | return '' 14 | }) 15 | bookInfo.coverPath = coverPicPath 16 | writeFileSync(`${bookDistPath}/bookInfo.json`, JSON.stringify(bookInfo, null, 2)) 17 | } 18 | 19 | export async function scanFolder(distPath: string) { 20 | const LIMIT_MAX = 6 21 | let folderList: string[] 22 | try { 23 | folderList = await readdir(distPath) 24 | } catch (e) { 25 | folderList = [] 26 | } 27 | const limit = pLimit(LIMIT_MAX) 28 | const promiseList = folderList.map((folder) => { 29 | return limit(async () => { 30 | const curBookPath = join(distPath, folder) 31 | const itemStat = await stat(curBookPath) 32 | if (!itemStat.isDirectory()) return null 33 | try { 34 | const bookInfoStr = await readFile(`${curBookPath}/bookInfo.json`, {encoding: 'utf-8'}) 35 | const bookInfo: BookInfo = JSON.parse(bookInfoStr) 36 | return bookInfo 37 | } catch (e) { 38 | return null 39 | } 40 | }) 41 | }) 42 | const bookInfoList = await Promise.all(promiseList) 43 | return bookInfoList.filter(notEmpty) 44 | } 45 | 46 | export async function readConfig(distPath: string) { 47 | try { 48 | const configStr = await readFile(`${distPath}/config.json`, {encoding: 'utf-8'}) 49 | const config: UserConfig = JSON.parse(configStr) 50 | return config 51 | } catch (e) { 52 | return {} 53 | } 54 | } -------------------------------------------------------------------------------- /src/lib/parse/baimangu/index.ts: -------------------------------------------------------------------------------- 1 | import vm from 'node:vm' 2 | import got, { Response } from 'got' 3 | import pLimit from 'p-limit' 4 | import { load } from 'cheerio' 5 | import { Base } from '@/lib/parse/base' 6 | import type { BookInfo, ChaptersItem, TSaveImgCallback } from '@/lib/parse/base' 7 | import { UA, fixPathName } from '@/utils' 8 | 9 | export class Baimangu extends Base { 10 | override readonly type = 'Baimangu' 11 | 12 | async parseBookInfo(): Promise { 13 | const url = this.bookUrl 14 | const rawUrl = url 15 | let response: Response 16 | try { 17 | response = await got.get(url, this.genReqOptions()) 18 | } catch (e) { 19 | return false 20 | } 21 | if (!response || response.statusCode !== 200) { 22 | return false 23 | } 24 | const $ = load(response.body) 25 | const name = $('.fed-deta-content .fed-part-eone.fed-font-xvi').text().trim() 26 | const desc = $('.fed-deta-content li.fed-col-xs12:nth-child(6) .fed-part-esan').text().trim() 27 | const author = $('.fed-deta-content li.fed-col-xs12:nth-child(1) a').text().trim() 28 | const coverUrl = $('.fed-main-info .fed-deta-info .fed-list-pics').attr('data-original')?.trim() ?? '' 29 | // 全部章节 30 | const chaptersEl = $('.fed-drop-boxs.fed-drop-btms.fed-matp-v ul:nth-child(2) li') 31 | 32 | let chapters: ChaptersItem[] = [] 33 | chaptersEl.toArray().forEach((el: any, index: number) => { 34 | const target = $(el) 35 | const name = target.find('a').text().trim() 36 | const href = target.find('a').attr('href')?.trim() ?? '' 37 | chapters.push({ 38 | name: `${index}_${fixPathName(name)}`, 39 | rawName: name, 40 | href, 41 | imageList: [], 42 | imageListPath: [], 43 | index 44 | }) 45 | }) 46 | if (!name || chapters.length === 0) { 47 | return false 48 | } 49 | 50 | // 生成上一话/下一话信息 51 | chapters = chapters.map((item, index) => { 52 | const newItem = {...item} 53 | if (index !== 0) { 54 | newItem.preChapter = { 55 | name: chapters[index - 1].name, 56 | rawName: chapters[index - 1].rawName, 57 | href: chapters[index - 1].href, 58 | index: chapters[index - 1].index 59 | } 60 | } 61 | if (index !== chapters.length - 1){ 62 | newItem.nextChapter = { 63 | name: chapters[index + 1].name, 64 | rawName: chapters[index + 1].rawName, 65 | href: chapters[index + 1].href, 66 | index: chapters[index + 1].index 67 | } 68 | } 69 | return newItem 70 | }) 71 | 72 | return { 73 | name, 74 | pathName: fixPathName(name), 75 | author, 76 | desc, 77 | coverUrl, 78 | coverPath: '', 79 | chapters, 80 | url, 81 | language: '简体', 82 | rawUrl 83 | } 84 | } 85 | 86 | async getImgList(chapterUrl: string): Promise { 87 | const response = await got(chapterUrl, this.genReqOptions()) 88 | 89 | const reg = /var oScript=document\.createElement\('script'\);(.*)oScript\.src=txt_url;/s 90 | const jsStr = reg.exec(response.body)?.[1] ?? '' 91 | if (!jsStr) return [] 92 | const context: any = {} 93 | 94 | try { 95 | vm.createContext(context) 96 | vm.runInContext(jsStr, context) 97 | } catch (e) { 98 | return [] 99 | } 100 | 101 | const txtUrl = context['txt_url'] || '' 102 | if (!txtUrl) return [] 103 | 104 | const resImgTxt = await got.get(txtUrl, this.genReqOptions()) 105 | const imgReg = /.*?src="(.*?)"/mg 106 | let imgList: string[] = [] 107 | let res = imgReg.exec(resImgTxt.body) 108 | while(res) { 109 | if (res[1]) { 110 | imgList.push(res[1]) 111 | } 112 | res = imgReg.exec(resImgTxt.body) 113 | } 114 | imgList = imgList.map(img =>{ 115 | return img 116 | .replace(/(.*)img.manga8.xyz(.*)/g, '$1img3.manga8.xyz$2') 117 | .replace(/(.*)img2.manga8.xyz(.*)/g, '$1img4.manga8.xyz$2') 118 | }) 119 | 120 | return [...new Set(imgList)] 121 | } 122 | 123 | override genReqOptions() { 124 | return { 125 | headers: { 126 | 'referrer': 'https://www.darpou.com/', 127 | 'user-agent': UA 128 | } 129 | } 130 | } 131 | 132 | override async saveImgList( 133 | path: string, 134 | imgList: string[], 135 | saveImgCallback?: TSaveImgCallback) { 136 | const limit = pLimit(6) 137 | 138 | const promiseList = imgList.map((imgUrl, index) => limit(async () => { 139 | let isSuccess = true 140 | // let imgPath = '' 141 | let imgFileName = '' 142 | try { 143 | // baimangu 特殊的 保存文件名 非顺序的数字 自定义index 去命名 144 | imgFileName = await this.saveImg(path, imgUrl, String(index+1)) 145 | } catch(err) { 146 | isSuccess = false 147 | } 148 | if (typeof saveImgCallback === 'function') saveImgCallback(imgUrl, isSuccess) 149 | return imgFileName 150 | })) 151 | return await Promise.all(promiseList) 152 | } 153 | } -------------------------------------------------------------------------------- /src/lib/parse/baozi/index.ts: -------------------------------------------------------------------------------- 1 | import got, {Response} from 'got' 2 | import { load } from 'cheerio' 3 | 4 | import { Base } from '@/lib/parse/base' 5 | import type { BookInfo, ChaptersItem } from '@/lib/parse/base' 6 | import { fixPathName } from '@/utils' 7 | 8 | export class Baozi extends Base { 9 | override readonly type = 'baozi' 10 | async getImgList(chapterUrl: string): Promise { 11 | const response = await got(chapterUrl, this.genReqOptions()) 12 | const $ = load(response.body) 13 | const ampState = $('.comic-contain amp-state') 14 | 15 | let imgList = ampState.toArray().map((el: any) => { 16 | const scriptText = $(el).find('script').text() 17 | const jsonData = JSON.parse(scriptText) 18 | return jsonData?.url as string ?? '' 19 | }) 20 | 21 | const nextChapterList = $('.comic-chapter .next_chapter').toArray() 22 | const findIndex = nextChapterList.length > 1 ? 1 : 0 23 | const nextChapterEl = $(nextChapterList[findIndex]).find('a') 24 | const nextChapterHref = nextChapterEl.attr('href') 25 | const nextChapterText = nextChapterEl.text() 26 | // baozi 页数超过50则会有下一页, 递归执行直到没有下一页 27 | if (/下一頁|下一页/g.test(nextChapterText) && nextChapterHref) { 28 | const nextImgList = await this.getImgList(nextChapterHref) 29 | imgList = imgList.concat(nextImgList) 30 | } 31 | return [...new Set(imgList)] 32 | } 33 | 34 | async parseBookInfo(): Promise { 35 | let url = this.bookUrl 36 | const rawUrl = url 37 | let response: Response 38 | try { 39 | response = await got.get(url, this.genReqOptions()) 40 | } catch (e) { 41 | return false 42 | } 43 | if (!response || response.statusCode !== 200) { 44 | return false 45 | } 46 | const $ = load(response.body) 47 | const name = $('.comics-detail__info .comics-detail__title').text().trim() 48 | const desc = $('.comics-detail__info .comics-detail__desc').text().trim() 49 | const author = $('.comics-detail__info .comics-detail__author').text().trim() 50 | const coverUrl = $('.l-content .pure-g.de-info__box amp-img').attr('src')?.trim() ?? '' 51 | // 全部章节 52 | const chaptersEl = $('#chapter-items a.comics-chapters__item, #chapters_other_list a.comics-chapters__item') 53 | 54 | let language = $('.header .home-menu .pure-menu-list:nth-of-type(2) .pure-menu-item:nth-of-type(2) > a').text()?.trim() ?? '' 55 | const realLanguage = language === '繁體' ? '简体' : '繁體' 56 | language = language && realLanguage 57 | 58 | if (language) { 59 | const hostnameMap = new Map([ 60 | ['繁體', 'tw'], 61 | ['简体', 'cn'] 62 | ]) 63 | const newHostName = hostnameMap.get(language) 64 | if (newHostName) { 65 | // xxx.aaa.com -> cn.aaa.com 66 | // aaa.com -> cn.aaa.com 67 | url = url.replace(/(http|https):\/\/(www\.)?([^.\s]+)\.(com)/, `$1://${newHostName}.$3.$4`) 68 | // 不管繁体简体都用 cn.xx.com 69 | // 因为墙内也没法访问tw域名也会转cn域名 70 | // tw.xx.com -> cn.xxx.com 71 | url = url.replace(/tw\./, 'cn.') 72 | } 73 | } 74 | 75 | let chapters: ChaptersItem[] = [] 76 | const {origin} = new URL(url) 77 | 78 | chaptersEl.toArray().forEach((el: any, index: number) => { 79 | const target = $(el) 80 | const name = target.find('span').text().trim() 81 | const href = target.attr('href')?.trim() ?? '' 82 | chapters.push({ 83 | name: `${index}_${fixPathName(name)}`, 84 | rawName: name, 85 | href: `${origin}${href}`, 86 | imageList: [], 87 | imageListPath: [], 88 | index 89 | }) 90 | }) 91 | 92 | // 没有全部章节 尝试取最新章节(新上架的漫画仅有 最新章节, 没有全部章节) 93 | if (chapters.length === 0) { 94 | let chaptersEl = $('#layout > div.comics-detail > div:nth-child(3) > div > div:nth-child(4) a.comics-chapters__item') 95 | if (chaptersEl.length === 0) { 96 | chaptersEl = $('#layout > div.comics-detail > div:nth-child(3) > div .comics-chapters > a.comics-chapters__item') 97 | } 98 | chaptersEl.toArray().forEach((el: any, index: number) => { 99 | const target = $(el) 100 | const name = target.find('span').text().trim() 101 | const href = target.attr('href')?.trim() ?? '' 102 | chapters.unshift({ 103 | name: `${index}_${fixPathName(name)}`, 104 | rawName: name, 105 | href: `${origin}${href}`, 106 | imageList: [], 107 | imageListPath: [], 108 | index 109 | }) 110 | }) 111 | // fix index name 112 | chapters = chapters.map((item, index) => { 113 | return { 114 | ...item, 115 | name: `${index}_${fixPathName(item.rawName)}`, 116 | index, 117 | } 118 | }) 119 | } 120 | 121 | if (!name || chapters.length === 0) { 122 | return false 123 | } 124 | 125 | // 生成上一话/下一话信息 126 | chapters = chapters.map((item, index) => { 127 | const newItem = {...item} 128 | if (index !== 0) { 129 | newItem.preChapter = { 130 | name: chapters[index - 1].name, 131 | rawName: chapters[index - 1].rawName, 132 | href: chapters[index - 1].href, 133 | index: chapters[index - 1].index 134 | } 135 | } 136 | if (index !== chapters.length - 1){ 137 | newItem.nextChapter = { 138 | name: chapters[index + 1].name, 139 | rawName: chapters[index + 1].rawName, 140 | href: chapters[index + 1].href, 141 | index: chapters[index + 1].index 142 | } 143 | } 144 | return newItem 145 | }) 146 | 147 | return { 148 | name, 149 | pathName: fixPathName(name), 150 | author, 151 | desc, 152 | coverUrl, 153 | coverPath: '', 154 | chapters, 155 | url, 156 | language, 157 | rawUrl 158 | } 159 | } 160 | } -------------------------------------------------------------------------------- /src/lib/parse/base/index.ts: -------------------------------------------------------------------------------- 1 | import { pipeline } from 'node:stream/promises' 2 | import { createWriteStream } from 'node:fs' 3 | import got from 'got' 4 | import pLimit from 'p-limit' 5 | import { UA, getUrlFileName } from '@/utils' 6 | 7 | export type TSaveImgCallback = (imgUrl: string, isSuccess: boolean) => void 8 | 9 | export interface ChaptersItem { 10 | name: string, 11 | rawName: string, 12 | index: number, 13 | href: string, 14 | imageList: string[], 15 | imageListPath: string[] 16 | preChapter?: { 17 | name: string, 18 | href: string, 19 | rawName: string, 20 | index: number 21 | }, 22 | nextChapter?: { 23 | name: string, 24 | href: string, 25 | rawName: string, 26 | index: number 27 | }, 28 | other?: { 29 | [key: string]: any 30 | } 31 | } 32 | 33 | export interface BookInfo { 34 | name: string, 35 | pathName: string, 36 | author: string, 37 | desc: string, 38 | coverUrl: string, 39 | coverPath: string, 40 | chapters: ChaptersItem[], 41 | url: string, 42 | language: string, 43 | rawUrl: string, 44 | /** 是否完结 */ 45 | isEnd?: boolean 46 | } 47 | 48 | export abstract class Base { 49 | readonly type: string = 'base' 50 | /* 漫画目录url */ 51 | bookUrl: string 52 | constructor(bookUrl?: string) { 53 | this.bookUrl = bookUrl ?? '' 54 | } 55 | /** got请求配置 */ 56 | genReqOptions() { 57 | return { 58 | headers: { 59 | 'user-agent': UA 60 | } 61 | } 62 | } 63 | /** 通用保存图片列表方法 */ 64 | async saveImgList( 65 | path: string, 66 | imgList: string[], 67 | saveImgCallback?: TSaveImgCallback) { 68 | const limit = pLimit(6) 69 | 70 | const promiseList = imgList.map(imgUrl => limit(async () => { 71 | let isSuccess = true 72 | // let imgPath = '' 73 | let imgFileName = '' 74 | try { 75 | imgFileName = await this.saveImg(path, imgUrl) 76 | } catch(err) { 77 | // console.error(`save img Error: ${imgUrl}`) 78 | // console.error(err) 79 | isSuccess = false 80 | } 81 | if (typeof saveImgCallback === 'function') saveImgCallback(imgUrl, isSuccess) 82 | return imgFileName 83 | })) 84 | return await Promise.all(promiseList) 85 | } 86 | /** 通用保存图片方法 */ 87 | async saveImg(path: string, imgUrl: string, fixFileName?: string, fixSuffix?: string) { 88 | if (!imgUrl) return '' 89 | let imgName = getUrlFileName(imgUrl) ?? '' 90 | imgName = decodeURIComponent(imgName) 91 | if (fixFileName) { 92 | const suffix = imgName?.split('.')?.[1] ?? 'jpg' 93 | imgName = `${fixFileName}.${fixSuffix ?? suffix}` 94 | } 95 | await pipeline( 96 | got.stream(imgUrl, this.genReqOptions()), 97 | createWriteStream(`${path}/${imgName}`) 98 | ) 99 | return imgName 100 | } 101 | /** 102 | * 抽象方法需有继承类实现 103 | * 获取图片列表 104 | */ 105 | abstract getImgList(chapterUrl: string): Promise 106 | /** 107 | * 抽象方法需有继承类实现 108 | * 解析漫画信息 109 | */ 110 | abstract parseBookInfo(): Promise 111 | } -------------------------------------------------------------------------------- /src/lib/parse/dmzj/crypto.ts: -------------------------------------------------------------------------------- 1 | import protobuf from 'protobufjs' 2 | import NodeRSA from 'node-rsa' 3 | 4 | const key = 'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAK8nNR1lTnIfIes6oRWJNj3mB6OssDGx0uGMpgpbVCpf6+VwnuI2stmhZNoQcM417Iz7WqlPzbUmu9R4dEKmLGEEqOhOdVaeh9Xk2IPPjqIu5TbkLZRxkY3dJM1htbz57d/roesJLkZXqssfG5EJauNc+RcABTfLb4IiFjSMlTsnAgMBAAECgYEAiz/pi2hKOJKlvcTL4jpHJGjn8+lL3wZX+LeAHkXDoTjHa47g0knYYQteCbv+YwMeAGupBWiLy5RyyhXFoGNKbbnvftMYK56hH+iqxjtDLnjSDKWnhcB7089sNKaEM9Ilil6uxWMrMMBH9v2PLdYsqMBHqPutKu/SigeGPeiB7VECQQDizVlNv67go99QAIv2n/ga4e0wLizVuaNBXE88AdOnaZ0LOTeniVEqvPtgUk63zbjl0P/pzQzyjitwe6HoCAIpAkEAxbOtnCm1uKEp5HsNaXEJTwE7WQf7PrLD4+BpGtNKkgja6f6F4ld4QZ2TQ6qvsCizSGJrjOpNdjVGJ7bgYMcczwJBALvJWPLmDi7ToFfGTB0EsNHZVKE66kZ/8Stx+ezueke4S556XplqOflQBjbnj2PigwBN/0afT+QZUOBOjWzoDJkCQClzo+oDQMvGVs9GEajS/32mJ3hiWQZrWvEzgzYRqSf3XVcEe7PaXSd8z3y3lACeeACsShqQoc8wGlaHXIJOHTcCQQCZw5127ZGs8ZDTSrogrH73Kw/HvX55wGAeirKYcv28eauveCG7iyFR0PFB/P/EDZnyb+ifvyEFlucPUI0+Y87F' 5 | 6 | const ChapterImageProtoDefinition = ` 7 | // https://github.com/tachiyomiorg/tachiyomi-extensions/blob/master/src/zh/dmzj/API.md 8 | 9 | syntax = "proto3"; 10 | 11 | package dmzj.chapter_images; 12 | 13 | message ResponseDto { 14 | int32 Errno = 1; 15 | string Errmsg = 2; 16 | ChapterImagesDto Data= 3; 17 | } 18 | 19 | message ChapterImagesDto { 20 | int32 Id = 1; 21 | int32 MangaId = 2; 22 | string Name= 3; 23 | int32 Order= 4; 24 | int32 Direction= 5; 25 | repeated string LowResImages= 6; 26 | int32 PageCount= 7; 27 | repeated string Images= 8; 28 | int32 CommentCount= 9; 29 | } 30 | ` 31 | 32 | const ChapterListProtoDefinition = ` 33 | syntax = "proto3"; 34 | 35 | package dmzj.comic; 36 | 37 | 38 | message ComicDetailResponse { 39 | int32 Errno = 1; 40 | string Errmsg = 2; 41 | ComicDetailInfoResponse Data= 3; 42 | } 43 | 44 | message ComicDetailInfoResponse { 45 | int32 Id = 1; 46 | string Title = 2; 47 | int32 Direction=3; 48 | int32 Islong=4; 49 | int32 IsDmzj=5; 50 | string Cover=6; 51 | string Description=7; 52 | int64 LastUpdatetime=8; 53 | string LastUpdateChapterName=9; 54 | int32 Copyright=10; 55 | string FirstLetter=11; 56 | string ComicPy=12; 57 | int32 Hidden=13; 58 | int32 HotNum=14; 59 | int32 HitNum=15; 60 | int32 Uid=16; 61 | int32 IsLock=17; 62 | int32 LastUpdateChapterId=18; 63 | repeated ComicDetailTypeItemResponse Types=19; 64 | repeated ComicDetailTypeItemResponse Status=20; 65 | repeated ComicDetailTypeItemResponse Authors=21; 66 | int32 SubscribeNum=22; 67 | repeated ComicDetailChapterResponse Chapters=23; 68 | int32 IsNeedLogin=24; 69 | //object UrlLinks=25; 70 | int32 IsHideChapter=26; 71 | //object DhUrlLinks=27; 72 | } 73 | 74 | message ComicDetailTypeItemResponse { 75 | int32 TagId = 1; 76 | string TagName = 2; 77 | } 78 | 79 | message ComicDetailChapterResponse { 80 | string Title = 1; 81 | repeated ComicDetailChapterInfoResponse Data=2; 82 | } 83 | message ComicDetailChapterInfoResponse { 84 | int32 ChapterId = 1; 85 | string ChapterTitle = 2; 86 | int64 Updatetime=3; 87 | int32 Filesize=4; 88 | int32 ChapterOrder=5; 89 | } 90 | ` 91 | 92 | // 需要注意buffer的长度 不要有为空为0的 否则 protobuf 解码会失败 93 | export function ApiV4Decrypt(data: string): Buffer { 94 | const keyByte = Buffer.from(key, 'base64') 95 | // const privateKey = crypto.createPrivateKey({ 96 | // key: keyByte, 97 | // format: 'der', 98 | // type: 'pkcs8' 99 | // }) 100 | // const decryptedRequestData = privateKey 101 | // .decrypt(encryptedBody) 102 | // .toString("utf8"); 103 | const tempData = Buffer.from(data, 'base64') 104 | const privateKey = new NodeRSA(keyByte, 'pkcs8-der', {}) 105 | privateKey.setOptions({ encryptionScheme: 'pkcs1', environment: 'browser' }) 106 | const MAX_DECRYPT_BLOCK = 128 107 | const inputLen = tempData.length 108 | let result = new Uint8Array(inputLen) 109 | let chunk = 0 110 | // 该循环是为了分段解码 每128位解码一次 111 | for (let offset = 0; offset < inputLen; offset += MAX_DECRYPT_BLOCK) { 112 | // min 是为了结尾时不多取buffer位数 113 | const blockLen = Math.min(MAX_DECRYPT_BLOCK, inputLen - offset) 114 | const encryptedData = tempData.subarray(offset, offset + blockLen) 115 | // console.log(encryptedData.length) 116 | // const decryptData = crypto.privateDecrypt({ 117 | // key: privateKey, 118 | // padding: crypto.constants.RSA_PKCS1_PADDING, 119 | // }, encryptedData) 120 | const decryptData = privateKey.decrypt(encryptedData) 121 | // 注意这里不能使用 offset 而需使用计算的chunk, 122 | // 因为 128位进行解码后不一定是 128 是不定长度的 123 | // 所以手动计算chunk位数 124 | result.set(decryptData, chunk) 125 | chunk = chunk + decryptData.length 126 | } 127 | result = result.subarray(0, chunk) 128 | return Buffer.from(result) 129 | } 130 | 131 | interface ApiV4ChapterImageData { 132 | Id: number, 133 | MangaId: number, 134 | Name: string, 135 | Order: number, 136 | Direction: number, 137 | LowResImages: string[] 138 | PageCount: number, 139 | Images: string[], 140 | CommentCount: number 141 | } 142 | 143 | export function ApiV4ChapterImageParse(data: Buffer): ApiV4ChapterImageData | null{ 144 | const root = protobuf.parse(ChapterImageProtoDefinition, { 145 | keepCase: true 146 | }).root 147 | 148 | const ResponseDto = root.lookupType('ResponseDto') 149 | const decodedRes = ResponseDto.decode(data) 150 | const decodedObject = ResponseDto.toObject(decodedRes, { 151 | longs: String, 152 | enums: String, 153 | bytes: String 154 | }) 155 | if (!decodedObject) { 156 | return null 157 | } 158 | return decodedObject?.Data as ApiV4ChapterImageData 159 | } 160 | 161 | interface ApiV4ChapterItem { 162 | ChapterId: number, 163 | ChapterOrder: number, 164 | ChapterTitle: string, 165 | Filesize: number 166 | } 167 | 168 | interface ApiV4ChapterList { 169 | Chapters: { 170 | Title: string 171 | Data: ApiV4ChapterItem[] 172 | }[] 173 | [key: string]: any 174 | } 175 | export function ApiV4ChapterListParse(data: Buffer): ApiV4ChapterList | null{ 176 | const root = protobuf.parse(ChapterListProtoDefinition, { 177 | keepCase: true 178 | }).root 179 | 180 | const ResponseDto = root.lookupType('ComicDetailResponse') 181 | const decodedRes = ResponseDto.decode(data) 182 | const decodedObject = ResponseDto.toObject(decodedRes, { 183 | longs: String, 184 | enums: String, 185 | bytes: String 186 | }) 187 | if (!decodedObject) { 188 | return null 189 | } 190 | return decodedObject?.Data as ApiV4ChapterList 191 | } -------------------------------------------------------------------------------- /src/lib/parse/dmzj/index.ts: -------------------------------------------------------------------------------- 1 | import got, {Response} from 'got' 2 | import { load } from 'cheerio' 3 | 4 | import { UA, fixPathName } from '@/utils' 5 | import { Base } from '@/lib/parse/base' 6 | import type { BookInfo, ChaptersItem } from '@/lib/parse/base' 7 | import { ApiV4ChapterImageParse, ApiV4ChapterListParse, ApiV4Decrypt } from './crypto' 8 | 9 | const api = { 10 | v4Chapter: 'https://nnv4api.dmzj.com/comic/chapter/', 11 | v3Chapter: 'https://m.idmzj.com/chapinfo/', 12 | v3Api: 'https://api.dmzj.com', 13 | v4Api: 'https://nnv4api.dmzj.com' 14 | } 15 | 16 | interface MobileTempChapterItem { 17 | chapter_name: string, 18 | chapter_order: number, 19 | chaptertype: number, 20 | comic_id: number, 21 | id: number, 22 | sort: number, 23 | title: string 24 | } 25 | 26 | interface PcTempChapterItem { 27 | chapter_id: number, 28 | chapter_title: string, 29 | updatetime: number, 30 | filesize: number, 31 | chapter_order: number, 32 | is_fee: boolean 33 | } 34 | 35 | export class Dmzj extends Base { 36 | override readonly type = 'Dmzj' 37 | async parseBookInfo(): Promise { 38 | const url = this.bookUrl 39 | const rawUrl = url 40 | 41 | let response: Response 42 | try { 43 | response = await got.get(url, this.genReqOptions()) 44 | } catch (e) { 45 | // console.log(e) 46 | return false 47 | } 48 | if (!response || response.statusCode !== 200) { 49 | return false 50 | } 51 | 52 | const isMobile = /m\.idmzj/.test(url) 53 | let parseResult 54 | if (isMobile) { 55 | parseResult = this.mSite(url, response.body) 56 | } else { 57 | parseResult = await this.pcSite(url, response.body) 58 | } 59 | if (!parseResult) return false 60 | const name = parseResult?.name 61 | const author = parseResult?.author 62 | const desc = parseResult?.desc 63 | const coverUrl = parseResult?.coverUrl 64 | let chapters: ChaptersItem[] = parseResult?.chapters || [] 65 | 66 | if (!name || chapters.length === 0) { 67 | return false 68 | } 69 | // 章节默认是升序改为降序 70 | chapters = chapters.reverse() 71 | 72 | // 生成上一话/下一话信息 73 | chapters = chapters.map((item, index) => { 74 | const newItem = {...item} 75 | if (index !== 0) { 76 | newItem.preChapter = { 77 | name: chapters[index - 1].name, 78 | rawName: chapters[index - 1].rawName, 79 | href: chapters[index - 1].href, 80 | index: chapters[index - 1].index 81 | } 82 | } 83 | if (index !== chapters.length - 1){ 84 | newItem.nextChapter = { 85 | name: chapters[index + 1].name, 86 | rawName: chapters[index + 1].rawName, 87 | href: chapters[index + 1].href, 88 | index: chapters[index + 1].index 89 | } 90 | } 91 | return newItem 92 | }) 93 | 94 | return { 95 | name, 96 | pathName: fixPathName(name), 97 | author, 98 | desc, 99 | coverUrl, 100 | coverPath: '', 101 | chapters, 102 | url, 103 | language: '简体', 104 | rawUrl 105 | } 106 | } 107 | async getImgList(url: string): Promise { 108 | // urlPath = comic_id/id 109 | const urlPath = /.*view\/(.*).html/g.exec(url)?.[1] 110 | if (!urlPath) return [] 111 | // https://m.idmzj.com/view/62324/140451.html 112 | const response = await got(`${api.v4Chapter}${urlPath}`, this.genReqOptions()) 113 | let imgList: string[] = [] 114 | try { 115 | const data = ApiV4ChapterImageParse(ApiV4Decrypt(response.body)) 116 | imgList = data?.Images ?? [] 117 | imgList = imgList.map(img => decodeURIComponent(img)) 118 | } catch(e) { 119 | const response = await got(`${api.v3Chapter}${urlPath}.html`,this.genReqOptions()) 120 | let data: any = {} 121 | try { 122 | data = JSON.parse(response.body) 123 | } catch (e) { 124 | console.log(e) 125 | } 126 | imgList = data['page_url'] 127 | } 128 | 129 | return imgList 130 | } 131 | // mobile https://m.idmzj.com/index.html 132 | mSite(url: string, body: string) { 133 | const $ = load(body) 134 | const name = $('#comicName').text().trim() 135 | const desc = $('.txtDesc.autoHeight').text().trim() 136 | const author = $('.introName').toArray().map(el => $(el).text()).join('/').trim() 137 | const coverUrl = $('#Cover img').attr('src')?.trim() ?? '' 138 | // 全部章节 139 | const chaptersReg = /initIntroData\((.*?)\)/gm 140 | const chaptersJSONstr = chaptersReg.exec(body)?.[1] ?? '' 141 | let tempChapters: MobileTempChapterItem[] = [] 142 | try { 143 | tempChapters = JSON.parse(chaptersJSONstr) 144 | } catch (e) { 145 | // console.log(e) 146 | return null 147 | } 148 | if (!Array.isArray(tempChapters)) tempChapters = [] 149 | tempChapters = tempChapters.map((item: any) => item?.data ?? null) 150 | tempChapters = tempChapters.flat() 151 | 152 | const chapters: ChaptersItem[] = [] 153 | const {origin} = new URL(url) 154 | 155 | tempChapters.forEach((item, index) => { 156 | const chapterIndex = item['chapter_order'] ?? index 157 | // /view/comic_id/id.html 158 | chapters.push({ 159 | name: `${chapterIndex}_${fixPathName(item['chapter_name'])}`, 160 | rawName: item['chapter_name'], 161 | href: `${origin}/view/${item['comic_id']}/${item.id}.html`, 162 | imageList: [], 163 | imageListPath: [], 164 | index: chapterIndex, 165 | other: item 166 | }) 167 | }) 168 | return { 169 | name, 170 | author, 171 | desc, 172 | coverUrl, 173 | chapters, 174 | } 175 | } 176 | // pc https://www.idmzj.com/info/yaoshenji.html 177 | async pcSite(url: string, body: string) { 178 | const reg = /.*\/(.*?)$/ 179 | const params: any = {} 180 | let comicName = url.match(reg)?.[1] ?? '' 181 | comicName = comicName.replace(/\.html/, '') 182 | params['comic_py'] = comicName 183 | const api = 'https://www.idmzj.com/api/v1/comic1/comic/detail' 184 | const nuxtDataStr = body.match(/window\.__NUXT__=\((.*)\)/gm)?.[0] ?? '' 185 | const fieldGroup = ['channel', 'app_name', 'version', 'timestamp'] 186 | fieldGroup.forEach((field, i) => { 187 | const fieldReg = new RegExp(`${field}:(.*?),`) 188 | const key = fieldGroup[i] 189 | params[key] = nuxtDataStr.match(fieldReg)?.[1] ?? '' 190 | }) 191 | const queryStr = new URLSearchParams(params).toString() 192 | const response = await got.get(`${api}?${queryStr}`, this.genReqOptions()) 193 | let resJSON: any = null 194 | try { 195 | resJSON = JSON.parse(response.body) 196 | resJSON = resJSON?.data?.comicInfo || {} 197 | } catch (e) { 198 | console.log(e) 199 | return null 200 | } 201 | // const $ = load(body) 202 | // const name = $('.comic_deCon > h1 > a').text().trim() 203 | // const desc = $('.comic_deCon .comic_deCon_d').text().trim() 204 | // const author = $('.comic_deCon .comic_deCon_liO > li:nth-child(1)').text().trim() 205 | // const coverUrl = $('#Cover img').attr('src')?.trim() ?? '' 206 | const author = resJSON?.authorInfo?.authorName || '' 207 | const name = resJSON?.title || '' 208 | const desc = resJSON?.description || '' 209 | const coverUrl = resJSON?.cover || '' 210 | const chapters: ChaptersItem[] = [] 211 | let tempChapters: PcTempChapterItem[] = resJSON?.chapterList || [] 212 | if (tempChapters.length <= 0) { 213 | const comicId = resJSON?.id 214 | tempChapters = await this.commonFetchChaptersList(comicId) 215 | } else { 216 | tempChapters = tempChapters.map((item: any) => item?.data ?? null) 217 | tempChapters = tempChapters.flat() 218 | } 219 | 220 | // const {origin} = new URL(url) 221 | tempChapters.forEach((item, index) => { 222 | const chapterIndex = item['chapter_order'] ?? index 223 | // /view/comic_id/id.html 224 | chapters.push({ 225 | name: `${chapterIndex}_${fixPathName(item['chapter_title'])}`, 226 | rawName: item['chapter_title'], 227 | href: `https://m.idmzj.com/view/${resJSON?.id}/${item['chapter_id']}.html`, 228 | imageList: [], 229 | imageListPath: [], 230 | index: chapterIndex, 231 | other: item 232 | }) 233 | }) 234 | return { 235 | name, 236 | author, 237 | desc, 238 | coverUrl, 239 | chapters, 240 | } 241 | 242 | } 243 | 244 | /** 可公用的 获取章节 前提是需要 comic id */ 245 | async commonFetchChaptersList(id: string) { 246 | if (!id) return [] 247 | const url = `${api.v4Api}/comic/detail/${id}?uid=2665531` 248 | const response = await got.get(url, this.genReqOptions()) 249 | let chapterList: any[] = [] 250 | try { 251 | const data = ApiV4ChapterListParse(ApiV4Decrypt(response.body)) 252 | const tempChapterList = data?.Chapters ?? [] 253 | const dataFieldList = tempChapterList.map(item => item.Data) 254 | chapterList = dataFieldList.flat().map(item => { 255 | return { 256 | ['chapter_order']: item.ChapterOrder, 257 | ['chapter_title']: item.ChapterTitle, 258 | ['chapter_id']: item.ChapterId 259 | } 260 | }) 261 | } catch (e) { 262 | // v3接口一直为空 暂时忽略 263 | // const v3Url = `${api.v3Api}/dynamic/comicinfo/${id}.json` 264 | return [] 265 | } 266 | return chapterList.reverse() 267 | } 268 | 269 | override genReqOptions() { 270 | return { 271 | headers: { 272 | 'user-agent': UA 273 | }, 274 | http2: true 275 | } 276 | } 277 | } -------------------------------------------------------------------------------- /src/lib/parse/godamanga/index.ts: -------------------------------------------------------------------------------- 1 | import got, {Response} from 'got' 2 | import { load } from 'cheerio' 3 | import pLimit from 'p-limit' 4 | import { Base } from '@/lib/parse/base' 5 | import { fixPathName, sleep } from '@/utils' 6 | import { UA } from '@/utils' 7 | import type { BookInfo, ChaptersItem, TSaveImgCallback } from '@/lib/parse/base' 8 | 9 | export class Godamanga extends Base { 10 | override readonly type = 'Godamanga' 11 | 12 | async parseBookInfo(): Promise { 13 | const url = this.bookUrl 14 | const rawUrl = url 15 | let response: Response 16 | try { 17 | response = await got.get(url, this.genReqOptions()) 18 | } catch (e) { 19 | return false 20 | } 21 | if (!response || response.statusCode !== 200) { 22 | return false 23 | } 24 | let $ = load(response.body) 25 | let name = $('#info .gap-unit-xs .text-xl').text().trim() 26 | const _name = $('#info .gap-unit-xs .text-xl .text-xs').text().trim() 27 | name = name.replace(_name, '').trim() 28 | const desc = $('#info .block .text-medium').text().trim() 29 | const author = $('#info .block div:nth-child(2) a span').text().trim() 30 | const coverUrl = $('#MangaCard > div > div:nth-child(1) img').attr('src')?.trim() ?? '' 31 | // 全部章节需 点击全部章节按钮 请求另一个页面 32 | const chaptersAllUrl = $('.my-unit-sm a').attr('href') 33 | let chapters: ChaptersItem[] = [] 34 | const {origin} = new URL(url) 35 | 36 | // 如果有全部章节则 点击,没有则直接在当前页取 因为章节太少的可能会没有全部章节页 37 | if (chaptersAllUrl) { 38 | const chaptersAllHref = new URL(chaptersAllUrl, origin).href 39 | const res = await got.get(chaptersAllHref, this.genReqOptions()).catch(() => ({body: ''})) 40 | $ = load(res.body) 41 | } 42 | const chaptersElSelector = chaptersAllUrl ? 43 | '#allchapters' : 44 | '.peer-checked\\:block #chapterlists .chapteritem' 45 | const chaptersEl = $(chaptersElSelector) 46 | const mid = chaptersEl.data('mid') 47 | if (!mid) return false 48 | let chaptersList = [] as any 49 | let chaptersHrefPrefix = '' 50 | try { 51 | // 2024-10-10接口变更 52 | // const chaptersAPI = `https://api-get.mgsearcher.com/api/manga/get?mid=${mid}&mode=all` 53 | const chaptersAPI = `https://api-get-v2.mgsearcher.com/api/manga/get?mid=${mid}&mode=all` 54 | const response = await fetch(chaptersAPI, { 55 | headers: this.genReqOptions().headers, 56 | method: 'GET' 57 | }) 58 | const bodyText = await response.text() 59 | const data = JSON.parse(bodyText) 60 | // const response = await got.get(chaptersAPI, this.genReqOptions()) 61 | // const data = JSON.parse(response.body) 62 | if (data.status && Array.isArray(data?.data?.chapters)) { 63 | chaptersList = data?.data?.chapters 64 | chaptersHrefPrefix = `/manga/${data?.data?.slug}` 65 | } 66 | } catch (e) { 67 | // console.log(e) 68 | return false 69 | } 70 | 71 | chaptersList.forEach((data: any, index: number) => { 72 | const name = data?.attributes?.title?.trim() || '' 73 | const slug = data?.attributes?.slug?.trim() || '' 74 | const href = `${chaptersHrefPrefix}/${slug}` 75 | chapters.push({ 76 | name: `${index}_${fixPathName(name)}`, 77 | rawName: name, 78 | href: `${origin}${href}`, 79 | imageList: [], 80 | imageListPath: [], 81 | index 82 | }) 83 | }) 84 | if (!name || chapters.length === 0) { 85 | return false 86 | } 87 | 88 | // 生成上一话/下一话信息 89 | chapters = chapters.map((item, index) => { 90 | const newItem = {...item} 91 | if (index !== 0) { 92 | newItem.preChapter = { 93 | name: chapters[index - 1].name, 94 | rawName: chapters[index - 1].rawName, 95 | href: chapters[index - 1].href, 96 | index: chapters[index - 1].index 97 | } 98 | } 99 | if (index !== chapters.length - 1){ 100 | newItem.nextChapter = { 101 | name: chapters[index + 1].name, 102 | rawName: chapters[index + 1].rawName, 103 | href: chapters[index + 1].href, 104 | index: chapters[index + 1].index 105 | } 106 | } 107 | return newItem 108 | }) 109 | return { 110 | name, 111 | pathName: fixPathName(name), 112 | author, 113 | desc, 114 | coverUrl, 115 | coverPath: '', 116 | chapters, 117 | url, 118 | language: '简体', 119 | rawUrl 120 | } 121 | } 122 | async getImgList(chapterUrl: string): Promise { 123 | const response = await got(chapterUrl, this.genReqOptions()) 124 | const $ = load(response.body) 125 | const domInfo = $('#chapterContent') 126 | const mid = domInfo.data('ms') 127 | const cid = domInfo.data('cs') 128 | let imgList: string[] = [] 129 | try { 130 | // 2024-10-10接口变更 131 | // const chaptersAPI = `https://api-get.mgsearcher.com/api/chapter/getinfo?m=${mid}&c=${cid}` 132 | const chaptersAPI = `https://api-get-v2.mgsearcher.com/api/chapter/getinfo?m=${mid}&c=${cid}` 133 | // const response = await got.get(chaptersAPI, this.genReqOptions()) 134 | // const data = JSON.parse(response.body) 135 | const response = await fetch(chaptersAPI, { 136 | headers: this.genReqOptions().headers, 137 | method: 'GET' 138 | }) 139 | const bodyText = await response.text() 140 | const data = JSON.parse(bodyText) 141 | if (data?.status && Array.isArray(data?.data?.info?.images?.images)) { 142 | imgList = data?.data?.info?.images?.images.map((item: any) => { 143 | const imgHost = data?.data?.info?.images?.line === 2 ? 'https://f40-1-4.g-mh.online' : 'https://t40-1-4.g-mh.online' 144 | return `${imgHost}${item?.url}` || '' 145 | }) 146 | } 147 | } catch (e) { 148 | console.log(e) 149 | return [] 150 | } 151 | return [...new Set(imgList)] 152 | } 153 | 154 | override async saveImgList( 155 | path: string, 156 | imgList: string[], 157 | saveImgCallback?: TSaveImgCallback) { 158 | const limit = pLimit(6) 159 | 160 | const promiseList = imgList.map((imgUrl, index) => limit(async () => { 161 | let isSuccess = true 162 | // let imgPath = '' 163 | let imgFileName = '' 164 | try { 165 | // baimangu 特殊的 保存文件名 非顺序的数字 自定义index 去命名 166 | imgFileName = await this.saveImg(path, imgUrl, String(index+1), 'jpg') 167 | } catch(err) { 168 | isSuccess = false 169 | } 170 | if (typeof saveImgCallback === 'function') saveImgCallback(imgUrl, isSuccess) 171 | return imgFileName 172 | })) 173 | return await Promise.all(promiseList) 174 | } 175 | // ! 有访问限制 不能太快 176 | override async saveImg(path: string, imgUrl: string, fixFileName?: string | undefined, fixSuffix?: string | undefined): Promise { 177 | await sleep(600) 178 | const res = await super.saveImg(path, imgUrl, fixFileName, fixSuffix) 179 | await sleep(600) 180 | return res 181 | } 182 | 183 | override genReqOptions() { 184 | return { 185 | headers: { 186 | 'user-agent': UA, 187 | referer: 'https://m.baozimh.one/' 188 | }, 189 | http2: true 190 | } 191 | } 192 | } -------------------------------------------------------------------------------- /src/lib/parse/ikuku/index.ts: -------------------------------------------------------------------------------- 1 | import got, {Response} from 'got' 2 | import { load } from 'cheerio' 3 | import pLimit from 'p-limit' 4 | import { Base } from '@/lib/parse/base' 5 | import { fixPathName, isHasHost, sleep, toReversed } from '@/utils' 6 | import type { BookInfo, ChaptersItem, TSaveImgCallback } from '@/lib/parse/base' 7 | 8 | export class Ikuku extends Base { 9 | override readonly type = 'Ikuku' 10 | 11 | async parseBookInfo(): Promise { 12 | const url = this.bookUrl 13 | const rawUrl = url 14 | let response: Response 15 | try { 16 | response = await got.get(url, this.genReqOptions()) 17 | } catch (e) { 18 | return false 19 | } 20 | if (!response || response.statusCode !== 200) { 21 | return false 22 | } 23 | const decoder = new TextDecoder('gbk') 24 | const $ = load(decoder.decode(response.rawBody)) 25 | const name = $('#comicName').text().trim() 26 | const desc =$('.txtDesc').text().trim() 27 | const author = $('.Introduct_Sub .txtItme:nth-child(1)').text().trim() 28 | const coverUrl = $('#Cover img').attr('src')?.trim() ?? '' 29 | 30 | let chapters: ChaptersItem[] = [] 31 | // const {origin} = new URL(url) 32 | const chaptersEl = $('#list li') 33 | toReversed(chaptersEl.toArray()).forEach((el: any, index: number) => { 34 | const target = $(el) 35 | const aEl = target.find('a') 36 | const name = aEl.text().trim() 37 | const href = aEl.attr('href')?.trim() ?? '' 38 | chapters.push({ 39 | name: `${index}_${fixPathName(name)}`, 40 | rawName: name, 41 | href, 42 | imageList: [], 43 | imageListPath: [], 44 | index 45 | }) 46 | }) 47 | 48 | if (!name || chapters.length === 0) { 49 | return false 50 | } 51 | 52 | // 生成上一话/下一话信息 53 | chapters = chapters.map((item, index) => { 54 | const newItem = {...item} 55 | if (index !== 0) { 56 | newItem.preChapter = { 57 | name: chapters[index - 1].name, 58 | rawName: chapters[index - 1].rawName, 59 | href: chapters[index - 1].href, 60 | index: chapters[index - 1].index 61 | } 62 | } 63 | if (index !== chapters.length - 1){ 64 | newItem.nextChapter = { 65 | name: chapters[index + 1].name, 66 | rawName: chapters[index + 1].rawName, 67 | href: chapters[index + 1].href, 68 | index: chapters[index + 1].index 69 | } 70 | } 71 | return newItem 72 | }) 73 | 74 | return { 75 | name, 76 | pathName: fixPathName(name), 77 | author, 78 | desc, 79 | coverUrl, 80 | coverPath: '', 81 | chapters, 82 | url, 83 | language: '简体', 84 | rawUrl 85 | } 86 | } 87 | 88 | async getImgList(chapterUrl: string): Promise { 89 | const {origin} = new URL(this.bookUrl) 90 | const reqUrl = isHasHost(chapterUrl) ? chapterUrl : `${origin}${chapterUrl}` 91 | const response = await got(reqUrl, this.genReqOptions()) 92 | const decoder = new TextDecoder('gbk') 93 | const bodyStr = decoder.decode(response.rawBody) 94 | const reg = /document\.write\("/g 95 | const [, nextImgUrlPath, tempCurImgPath ] = reg.exec(bodyStr) ?? [] 96 | if (!nextImgUrlPath || !tempCurImgPath) return [] 97 | const nextImgUrl = `${origin}${nextImgUrlPath}` 98 | const isEnd = nextImgUrlPath.includes('exit') 99 | const imgHostMap = {} as {[key: string]: string} 100 | const scriptReg = /