├── .babelrc ├── .eslintrc ├── .gitignore ├── .npmignore ├── LICENSE.md ├── Procfile ├── README.md ├── jsconfig.json ├── package-lock.json ├── package.json ├── screenshots ├── appstore.png ├── screen1.jpg ├── screen3.jpg ├── screen4.jpg └── unblock.png ├── server_config ├── nginx.conf.sample └── sniproxy.conf.sample └── src ├── app.js ├── bin ├── run.js └── unblockneteasemusic.js ├── config └── index.js ├── controllers ├── index.js ├── modify │ ├── dead.js │ ├── download.js │ ├── forward.js │ ├── index.js │ └── player.js └── pair │ ├── get.js │ ├── index.js │ ├── list.js │ ├── recent.js │ ├── save.js │ └── unpair.js ├── middleware ├── index.js ├── permission │ └── index.js └── proxy │ └── index.js ├── models ├── index.js ├── pair.js ├── recent.js └── song.js └── utils ├── common ├── crypto.js └── index.js ├── index.js ├── netease └── index.js └── plugins ├── kugou.js └── qq.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "transform-runtime", 4 | [ 5 | "transform-object-rest-spread", { "useBuiltIns": true } 6 | ] 7 | ], 8 | "presets": [ 9 | "env" 10 | ] 11 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb" 4 | ], 5 | "parser": "babel-eslint", 6 | "rules": { 7 | "strict": 0, 8 | "no-restricted-syntax": 0, 9 | "func-names": 0, 10 | "no-param-reassign": 0, 11 | "no-console": 0, 12 | "no-mixed-operators": 0, 13 | "no-continue": 0, 14 | "no-await-in-loop": 0 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | test.js 4 | unblock.sqlite 5 | .DS_Store 6 | dist 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /src 2 | /server_config 3 | .babelrc 4 | .eslintrc 5 | .gitignore 6 | jsconfig.json 7 | screenshot.png 8 | unblock.sqlite 9 | node_modules 10 | 11 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 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 General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: npm i && npm run build && npm start 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnblockNeteaseMusic 2 | 3 | > 一个基于 koa 的网易云音乐的代理,用于海外解锁及替换版权歌曲的播放地址 4 | 5 | 1. 替换版权曲目播放地址 6 | 2. 禁止客户端更新 7 | 8 | [![NPM](https://nodei.co/npm/unblock-netease-music.png?downloads=true&downloadRank=true)](https://nodei.co/npm/unblock-netease-music/) 9 | 10 | # 依赖 11 | 12 | 1. Node.js 8.x+ 13 | 2. Nginx with subs-filter module configured. 14 | 15 | # 注意 16 | 17 | 从 2.0 版本开始,本代理仅支持与 nginx 一同部署。standalone 分支已停止更新,无法使用。 18 | 19 | ## Ubuntu/Debian 用户请注意 20 | 21 | 请使用 `npm config get prefix` 命令查看 npm 的默认目录,如果为 `/usr` 将导致无法正常安装。 22 | 23 | 请按照以下官方教程修复。 24 | [Fixing npm permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions) 25 | 26 | # 使用方法 27 | 1. 安装 Node.js 28 | 2. 安装本代理 `sudo npm install unblock-netease-music -g` 29 | 3. 后台运行 `nohup unblockneteasemusic &` 30 | 4. 完成! 31 | 32 | ## 手动匹配歌曲 33 | Get it on App Store 34 | 35 | ![Screen 1](./screenshots/screen1.jpg) 36 | ![Screen 2](./screenshots/screen4.jpg) 37 | ![Screen 3](./screenshots/screen3.jpg) 38 | 39 | ## 配置参数 40 | 41 | ``` 42 | unblockneteasemusic -h 43 | 44 | Usage: unblockneteasemusic [options] 45 | 46 | 47 | Options: 48 | 49 | -V, --version output the version number 50 | -p, --port Specific server port. 51 | -f, --force-ip Force the netease server ip. 52 | -r, --rewrite-url Rewrite music download url, let client download file through proxy. 53 | --username The username of Web API. 54 | --password The password of Web API. 55 | --database-path Specific the path to store database file. 56 | -v, --verbose Display errors. 57 | -h, --help output usage information 58 | ``` 59 | 60 | ## 支持客户端 61 | 62 | ~~向 hosts 文件中添加一行:` music.163.com`~~ 63 | 64 | ### OSX 用户 65 | 66 | #### 旧版本客户端 1.4.3 67 | ~~直接使用。 [下载链接](http://s1.music.126.net/download/osx/NeteaseMusic_1.4.3_452_web.dmg)~~ 68 | 69 | #### 最新客户端 70 | 配合插件使用,详见 [NeteaseMusicPlugin](https://github.com/ITJesse/NeteaseMusicPlugin) 71 | 72 | ### Windows 用户 73 | ~~请务必不要更新客户端到 2.0.2 以上的版本。 [下载链接](http://s1.music.126.net/download/pc/cloudmusicsetup_2_0_2[128316].exe)~~ 74 | 已无法使用。 75 | 76 | ### Linux 用户 77 | 直接使用。 78 | 79 | ### 其他用户 80 | 81 | 新版客户端现在可以使用该代理解决海外限制,但是无法替换版权歌曲的播放地址。 82 | 83 | # 预览 84 | 85 | ![Screenshot](./screenshots/unblock.png) 86 | 87 | # 感谢 88 | 89 | 1. 这个项目最初的想法及实现来源于 EraserKing 的 [CloudMusicGear](https://github.com/EraserKing/CloudMusicGear). 90 | 2. 感谢 yanunon 的 API 文档 [API documents](https://github.com/yanunon/NeteaseCloudMusic/wiki/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90API%E5%88%86%E6%9E%90). 91 | 3. 感谢 Chion82 的配置文件 92 | 4. 感谢 [NeteaseCloudMusicApi](https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/util/crypto.js) 93 | 94 | # License 95 | 96 | GPLv3 97 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017" 4 | }, 5 | "exclude": [ 6 | "node_modules", 7 | "**/node_modules/*" 8 | ] 9 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unblock-netease-music", 3 | "version": "3.1.5", 4 | "scripts": { 5 | "start": "node dist/bin/unblockneteasemusic -p 8123 --username unblock --password unblock --proxy 101.96.10.58 -v", 6 | "dev": "babel-node -- src/bin/unblockneteasemusic -p 8123 --username unblock --password unblock --proxy 101.96.10.58 -v", 7 | "build": "rm -rf dist && babel src --out-dir dist" 8 | }, 9 | "bin": { 10 | "unblockneteasemusic": "dist/bin/unblockneteasemusic.js" 11 | }, 12 | "dependencies": { 13 | "babel-cli": "^6.26.0", 14 | "babel-runtime": "^6.11.6", 15 | "babel-core": "^6.26.3", 16 | "babel-eslint": "^8.2.6", 17 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 18 | "babel-plugin-transform-runtime": "^6.23.0", 19 | "babel-polyfill": "^6.26.0", 20 | "babel-preset-env": "^1.7.0", 21 | "big-integer": "^1.6.36", 22 | "colors": "^1.3.2", 23 | "commander": "^2.19.0", 24 | "kcors": "^2.2.2", 25 | "koa": "^2.6.1", 26 | "koa-basic-auth": "^2.0.0", 27 | "koa-bodyparser": "^4.2.1", 28 | "koa-logger": "^3.2.0", 29 | "koa-router": "^7.4.0", 30 | "md5": "^2.1.0", 31 | "pkginfo": "^0.4.1", 32 | "remote-file-size": "^3.0.5", 33 | "request": "^2.88.0", 34 | "request-promise": "^4.2.2", 35 | "sequelize": "^4.41.0", 36 | "sqlite3": "^4.0.3" 37 | }, 38 | "keywords": [ 39 | "netease", 40 | "neteasemusic", 41 | "unblock", 42 | "neteaseunblock" 43 | ], 44 | "description": "A proxy server for Netease Music...", 45 | "main": "dist/bin/unblockneteasemusic.js", 46 | "devDependencies": { 47 | "ajv": "^5.5.2", 48 | "eslint": "^3.19.0", 49 | "eslint-config-airbnb": "^14.1.0", 50 | "eslint-plugin-es-beautifier": "^1.0.1", 51 | "eslint-plugin-import": "^2.14.0", 52 | "eslint-plugin-jsx-a11y": "^3.0.2", 53 | "eslint-plugin-react": "^6.9.0" 54 | }, 55 | "repository": { 56 | "type": "git", 57 | "url": "git+https://github.com/ITJesse/UnblockNeteaseMusic.git" 58 | }, 59 | "author": "itjesse", 60 | "license": "GPL-3.0", 61 | "bugs": { 62 | "url": "https://github.com/ITJesse/UnblockNeteaseMusic/issues" 63 | }, 64 | "homepage": "https://github.com/ITJesse/UnblockNeteaseMusic#readme" 65 | } 66 | -------------------------------------------------------------------------------- /screenshots/appstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/screenshots/appstore.png -------------------------------------------------------------------------------- /screenshots/screen1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/screenshots/screen1.jpg -------------------------------------------------------------------------------- /screenshots/screen3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/screenshots/screen3.jpg -------------------------------------------------------------------------------- /screenshots/screen4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/screenshots/screen4.jpg -------------------------------------------------------------------------------- /screenshots/unblock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/screenshots/unblock.png -------------------------------------------------------------------------------- /server_config/nginx.conf.sample: -------------------------------------------------------------------------------- 1 | proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g; 2 | server { 3 | listen 80; 4 | server_name music.163.com; 5 | resolver 114.114.114.114 223.5.5.5; 6 | 7 | set $backend "http://music.163.com"; 8 | 9 | location /* { 10 | if ($http_host !~* ^(music.163.com)$){ 11 | return 500; 12 | } 13 | } 14 | 15 | location / { 16 | proxy_pass $backend; 17 | proxy_connect_timeout 6s; 18 | proxy_send_timeout 6s; 19 | proxy_read_timeout 6s; 20 | proxy_set_header Host $host; 21 | proxy_set_header X-Real-IP ""; 22 | proxy_set_header Accept-Encoding ""; 23 | subs_filter_types *; 24 | subs_filter '"st":-.+?,' '"st":0,' ir; 25 | subs_filter '"pl":0' '"pl":320000'; 26 | subs_filter '"dl":0' '"dl":320000'; 27 | subs_filter '"sp":0' '"sp":7'; 28 | subs_filter '"cp":0' '"cp":1'; 29 | subs_filter '"subp":0' '"subp":1'; 30 | subs_filter '"fl":0' '"fl":320000'; 31 | subs_filter '"fee":.+?,' '"fee":0,' ir; 32 | subs_filter '"abroad":1,' ''; 33 | subs_filter '"updateFiles":\[.*\]' '"updateFiles":[]' ir; 34 | proxy_cache STATIC; 35 | proxy_cache_valid 200 1d; 36 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 37 | } 38 | 39 | location /eapi/song/enhance/player/url { 40 | proxy_set_header X-Real-IP ""; 41 | proxy_pass http://localhost:8123; 42 | proxy_cache STATIC; 43 | proxy_cache_valid 200 1d; 44 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 45 | } 46 | 47 | location /eapi/song/enhance/download/url { 48 | proxy_set_header X-Real-IP ""; 49 | proxy_pass http://localhost:8123; 50 | proxy_cache STATIC; 51 | proxy_cache_valid 200 1d; 52 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 53 | } 54 | 55 | # For linux 56 | location /api/linux/forward { 57 | proxy_set_header X-Real-IP ""; 58 | proxy_pass http://localhost:8123; 59 | subs_filter_types *; 60 | subs_filter '"st":-.+?,' '"st":0,' ir; 61 | subs_filter '"pl":0' '"pl":320000'; 62 | subs_filter '"dl":0' '"dl":320000'; 63 | subs_filter '"sp":0' '"sp":7'; 64 | subs_filter '"cp":0' '"cp":1'; 65 | subs_filter '"subp":0' '"subp":1'; 66 | subs_filter '"fl":0' '"fl":320000'; 67 | subs_filter '"fee":.+?,' '"fee":0,' ir; 68 | subs_filter '"abroad":1,' ''; 69 | subs_filter '"updateFiles":\[.*\]' '"updateFiles":[]' ir; 70 | proxy_cache STATIC; 71 | proxy_cache_valid 200 1d; 72 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 73 | } 74 | 75 | location /kugou { 76 | rewrite '^/kugou/(.*)' /$1 break; 77 | proxy_set_header X-Real-IP ""; 78 | proxy_pass http://fs.web.kugou.com; 79 | proxy_set_header Host fs.web.kugou.com; 80 | proxy_cache STATIC; 81 | proxy_cache_valid 200 1d; 82 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 83 | } 84 | 85 | location /qqmusic { 86 | rewrite '^/qqmusic/(.*)' /$1 break; 87 | proxy_set_header X-Real-IP ""; 88 | proxy_pass http://dl.stream.qqmusic.qq.com; 89 | proxy_set_header "User-Agent" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; 90 | proxy_set_header Host dl.stream.qqmusic.qq.com; 91 | proxy_cache STATIC; 92 | proxy_cache_valid 200 1d; 93 | proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /server_config/sniproxy.conf.sample: -------------------------------------------------------------------------------- 1 | user daemon 2 | pidfile /var/run/sniproxy.pid 3 | 4 | error_log { 5 | syslog daemon 6 | priority notice 7 | } 8 | 9 | listen :443 { 10 | proto tls 11 | table https_hosts 12 | 13 | access_log { 14 | filename /var/log/sniproxy/https_access.log 15 | priority notice 16 | } 17 | fallback 127.0.0.1:443 18 | } 19 | 20 | table https_hosts { 21 | music.163.com 223.252.199.7:443 22 | } -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import Koa from 'koa'; 3 | import logger from 'koa-logger'; 4 | import Router from 'koa-router'; 5 | import auth from 'koa-basic-auth'; 6 | import bodyParser from 'koa-bodyparser'; 7 | import cors from 'kcors'; 8 | 9 | import config from './config'; 10 | import { proxy } from './middleware'; 11 | import { modify, pair } from './controllers'; 12 | import { Netease } from './utils'; 13 | 14 | const errorHandler = async (ctx, next) => { 15 | const data = ctx.body; 16 | let json = ''; 17 | try { 18 | json = JSON.parse(ctx.body.toString()); 19 | } catch (error) { 20 | console.log('Pares failed. Maybe encrypted.'); 21 | ctx.body = data; 22 | return; 23 | } 24 | if (Array.isArray(json.data)) { 25 | json.data = json.data.map(e => Netease.fixJsonData(e)); 26 | } else if (json.data) { 27 | json.data = Netease.fixJsonData(json.data); 28 | } else { 29 | json = Netease.fixJsonData(json); 30 | } 31 | try { 32 | ctx.body = json; 33 | await next(); 34 | } catch (err) { 35 | if (config.verbose) { 36 | console.log(err); 37 | } 38 | ctx.body = json; 39 | console.log('Modify failed.'.red); 40 | } 41 | }; 42 | 43 | const app = new Koa(); 44 | app.use(logger()); 45 | app.use(cors()); 46 | app.use(bodyParser()); 47 | 48 | const router = Router(); 49 | 50 | // Route for native netease client 51 | router.post( 52 | '/eapi/song/enhance/player/url', 53 | proxy, 54 | errorHandler, 55 | modify.player, 56 | ); 57 | router.post( 58 | '/api/plugin/player', 59 | proxy, 60 | errorHandler, 61 | modify.player, 62 | ); 63 | router.post( 64 | '/eapi/song/enhance/download/url', 65 | proxy, 66 | errorHandler, 67 | modify.download, 68 | ); 69 | router.post( 70 | '/api/plugin/download', 71 | proxy, 72 | errorHandler, 73 | modify.download, 74 | ); 75 | router.post( 76 | '/api/linux/forward', 77 | proxy, 78 | errorHandler, 79 | modify.forward, 80 | ); 81 | 82 | // Route for Unblock Netease Music Server itself 83 | if (config.webApi) { 84 | router.use('/api/pair/*', auth({ 85 | name: config.username, 86 | pass: config.password, 87 | })); 88 | 89 | router 90 | .get('/api/pair/check', pair.check) 91 | .get('/api/pair/recent', pair.recent) 92 | .get('/api/pair', pair.list) 93 | .put('/api/pair', pair.save) 94 | .delete('/api/pair/:songId', pair.unpair) 95 | .get('/api/pair/:songId', pair.get); 96 | } 97 | 98 | app 99 | .use(router.routes()) 100 | .use(router.allowedMethods()); 101 | 102 | export default app; 103 | -------------------------------------------------------------------------------- /src/bin/run.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies. 3 | */ 4 | 5 | import http from 'http'; 6 | import 'colors'; 7 | 8 | import app from '../app'; 9 | import config from '../config'; 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | const port = process.env.PORT || config.port || '8123'; 16 | 17 | /** 18 | * Create HTTP server. 19 | */ 20 | 21 | const server = http.createServer(app.callback()); 22 | 23 | /** 24 | * Event listener for HTTP server "error" event. 25 | */ 26 | 27 | function onError(error) { 28 | if (error.syscall !== 'listen') { 29 | throw error; 30 | } 31 | 32 | const bind = typeof port === 'string' 33 | ? `Pipe ${port}` 34 | : `Port ${port}`; 35 | 36 | // handle specific listen errors with friendly messages 37 | switch (error.code) { 38 | case 'EACCES': 39 | console.error(`${bind} requires elevated privileges`); 40 | process.exit(1); 41 | break; 42 | case 'EADDRINUSE': 43 | console.error(`${bind} is already in use`); 44 | process.exit(1); 45 | break; 46 | default: 47 | throw error; 48 | } 49 | } 50 | 51 | /** 52 | * Event listener for HTTP server "listening" event. 53 | */ 54 | 55 | function onListening() { 56 | const addr = server.address(); 57 | const bind = typeof addr === 'string' 58 | ? `pipe ${addr}` 59 | : `port ${addr.port}`; 60 | console.log('Listening on '.yellow + bind.yellow); 61 | } 62 | 63 | /** 64 | * Listen on provided port, on all network interfaces. 65 | */ 66 | 67 | server.listen(port); 68 | server.on('error', onError); 69 | server.on('listening', onListening); 70 | -------------------------------------------------------------------------------- /src/bin/unblockneteasemusic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const version = process.version.replace('v', '').split('.'); 4 | if (version[0] < 8) { 5 | console.log(`Unsupported nodejs version ${process.version}. Please upgrade.`); 6 | } else { 7 | require('./run'); 8 | } 9 | -------------------------------------------------------------------------------- /src/config/index.js: -------------------------------------------------------------------------------- 1 | import program from 'commander'; 2 | import pkginfo from 'pkginfo'; 3 | import 'colors'; 4 | 5 | pkginfo(module); 6 | 7 | program 8 | .version(module.exports.version) 9 | .option('-p, --port ', 'Specific server port.') 10 | .option('-f, --force-ip ', 'Force the netease server ip.') 11 | .option('-r, --rewrite-url', 'Rewrite music download url, let client download file through proxy.') 12 | .option('--username ', 'The username of Web API.') 13 | .option('--password ', 'The password of Web API.') 14 | .option('--database-path', 'Specific the path to store database file.') 15 | .option('--proxy ', 'Specific a proxy for plugins.') 16 | .option('-v, --verbose', 'Display errors.') 17 | .parse(process.argv); 18 | 19 | if (program.kugou || program.qq) { 20 | console.log('The option --kugou and --qq is no longer support.'.yellow); 21 | } 22 | 23 | if (program.port && (program.port < 1 || program.port > 65535)) { 24 | console.log('Port must be higher than 0 and lower than 65535.'.red); 25 | process.exit(1); 26 | } 27 | 28 | if (program.forceIp && !/\d+\.\d+\.\d+\.\d+/.test(program.forceIp)) { 29 | console.log('Please check the ip address.'.red); 30 | process.exit(1); 31 | } 32 | 33 | if (program.rewriteUrl) { 34 | console.log('Rewrite music download url.'.green); 35 | } 36 | 37 | if (!program.username || !program.password) { 38 | console.log('Please set the username and password to enable the Web API.'.yellow); 39 | program.webApi = false; 40 | } 41 | if (program.username && program.password) { 42 | console.log('Web API enabled.'.green); 43 | program.webApi = true; 44 | } 45 | 46 | if (program.proxy) { 47 | console.log('Using proxy:'.green, program.proxy); 48 | } 49 | 50 | export default program; 51 | -------------------------------------------------------------------------------- /src/controllers/index.js: -------------------------------------------------------------------------------- 1 | import * as modify from './modify'; 2 | import * as pair from './pair'; 3 | 4 | export { modify, pair }; 5 | -------------------------------------------------------------------------------- /src/controllers/modify/dead.js: -------------------------------------------------------------------------------- 1 | import { Recent, Song, Pair } from '../../models'; 2 | import { Utils, Netease } from '../../utils'; 3 | 4 | const utils = new Utils(); 5 | 6 | export const handleDeadMusic = (songId, songInfo) => { 7 | const { songName, artist, album, albumPic } = songInfo; 8 | Song.findOrCreate({ 9 | where: { songId }, 10 | defaults: { 11 | songId, 12 | artist, 13 | album, 14 | albumPic, 15 | name: songName, 16 | }, 17 | }).then().catch(err => console.log(err)); 18 | Recent.upsert({ 19 | songId, 20 | }).then().catch(err => console.log(err)); 21 | }; 22 | 23 | export const checkPairMusic = async (songId) => { 24 | let pair; 25 | try { 26 | pair = await Pair.findOne({ where: { songId } }); 27 | } catch (err) { 28 | throw new Error(err); 29 | } 30 | if (pair) { 31 | let urlInfo; 32 | try { 33 | urlInfo = await utils.getUrlInfoForPair(pair.dataValues); 34 | } catch (err) { 35 | throw new Error(err); 36 | } 37 | return urlInfo; 38 | } 39 | return null; 40 | }; 41 | 42 | export default handleDeadMusic; 43 | -------------------------------------------------------------------------------- /src/controllers/modify/download.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import { Utils, Netease } from '../../utils'; 3 | import { handleDeadMusic, checkPairMusic } from './dead'; 4 | 5 | const utils = new Utils(); 6 | 7 | export const download = async (ctx, next) => { 8 | const data = ctx.body; 9 | 10 | if (Netease.getDownloadReturnCode(data) === 200) { 11 | return console.log('The song URL is '.green + data.data.url); 12 | } 13 | 14 | const songId = Netease.getDownloadSongId(data); 15 | let pair; 16 | try { 17 | pair = await checkPairMusic(songId); 18 | } catch (err) { 19 | console.log(err); 20 | throw new Error(err); 21 | } 22 | if (pair) { 23 | try { 24 | data.data = await Netease.modifyPlayerApiCustom(pair, data.data); 25 | } catch (error) { 26 | console.log('No resource.'.red); 27 | throw new Error(error); 28 | } 29 | } else { 30 | let songInfo; 31 | try { 32 | songInfo = await Utils.getSongInfo(songId); 33 | } catch (err) { 34 | console.log(err); 35 | throw new Error(err); 36 | } 37 | let urlInfo; 38 | try { 39 | urlInfo = await utils.getUrlInfo(songInfo); 40 | } catch (err) { 41 | console.log(err); 42 | throw new Error(err); 43 | } 44 | if (urlInfo) { 45 | try { 46 | data.data = await Netease.modifyDownloadApiCustom(urlInfo, data.data); 47 | } catch (error) { 48 | console.log('No resource.'.red); 49 | throw new Error(error); 50 | } 51 | } else { 52 | console.log('No resource.'.red); 53 | handleDeadMusic(songId, songInfo); 54 | } 55 | } 56 | 57 | ctx.body = JSON.stringify(data); 58 | return next(); 59 | }; 60 | 61 | export default download; 62 | -------------------------------------------------------------------------------- /src/controllers/modify/forward.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import { player } from './player'; 3 | import { Netease } from '../../utils/netease'; 4 | 5 | export const forward = async (ctx, next) => { 6 | const req = ctx.request; 7 | if (!Object.prototype.hasOwnProperty.call(req, 'body')) { 8 | return next(); 9 | } 10 | let url; 11 | try { 12 | const body = Netease.decryptLinuxForwardApi(req.body.eparams); 13 | const json = JSON.parse(body); 14 | url = json.url; 15 | } catch (err) { 16 | console.log('Parse body failed.'); 17 | throw new Error(err); 18 | } 19 | console.log('API:'.green, url); 20 | if (url !== 'http://music.163.com/api/song/enhance/player/url') { 21 | return next(); 22 | } 23 | return player(ctx, next); 24 | }; 25 | 26 | export default forward; 27 | -------------------------------------------------------------------------------- /src/controllers/modify/index.js: -------------------------------------------------------------------------------- 1 | export { player } from './player'; 2 | export { download } from './download'; 3 | export { forward } from './forward'; 4 | -------------------------------------------------------------------------------- /src/controllers/modify/player.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import { Utils, Netease } from '../../utils'; 3 | import { handleDeadMusic, checkPairMusic } from './dead'; 4 | 5 | const utils = new Utils(); 6 | 7 | export const player = async (ctx, next) => { 8 | const data = ctx.body; 9 | 10 | const playbackReturnCode = data.data[0].code; 11 | const songId = data.data[0].id; 12 | 13 | if (playbackReturnCode === 200) { 14 | console.log('The song URL is '.green + data.data[0].url); 15 | return next(); 16 | } 17 | 18 | let pair; 19 | try { 20 | pair = await checkPairMusic(songId); 21 | } catch (err) { 22 | console.log(err); 23 | throw new Error(err); 24 | } 25 | if (pair) { 26 | try { 27 | data.data[0] = await Netease.modifyPlayerApiCustom(pair, data.data[0]); 28 | } catch (error) { 29 | console.log('No resource.'.red); 30 | throw new Error(error); 31 | } 32 | } else { 33 | let songInfo; 34 | try { 35 | songInfo = await Utils.getSongInfo(songId); 36 | } catch (err) { 37 | console.log(err); 38 | throw new Error(err); 39 | } 40 | let urlInfo; 41 | try { 42 | urlInfo = await utils.getUrlInfo(songInfo); 43 | } catch (err) { 44 | console.log(err); 45 | throw new Error(err); 46 | } 47 | if (urlInfo) { 48 | try { 49 | data.data[0] = await Netease.modifyPlayerApiCustom(urlInfo, data.data[0]); 50 | } catch (error) { 51 | console.log('No resource.'.red); 52 | throw new Error(error); 53 | } 54 | } else { 55 | console.log('No resource.'.red); 56 | handleDeadMusic(songId, songInfo); 57 | } 58 | } 59 | 60 | ctx.body = JSON.stringify(data); 61 | return next(); 62 | }; 63 | 64 | export default player; 65 | -------------------------------------------------------------------------------- /src/controllers/pair/get.js: -------------------------------------------------------------------------------- 1 | import { Pair, Song } from '../../models'; 2 | 3 | export const get = async (ctx) => { 4 | const { songId } = ctx.params; 5 | if (!/^\d+$/.test(songId)) { 6 | ctx.body = { 7 | error: -1, 8 | }; 9 | } else { 10 | const pair = await Pair.findOne({ 11 | include: [{ 12 | as: 'song', 13 | model: Song, 14 | }], 15 | order: [ 16 | ['updatedAt', 'DESC'], 17 | ], 18 | }); 19 | if (pair) { 20 | ctx.body = { 21 | error: 0, 22 | result: pair, 23 | }; 24 | } else { 25 | ctx.body = { 26 | error: -2, 27 | }; 28 | } 29 | } 30 | }; 31 | 32 | export default get; 33 | -------------------------------------------------------------------------------- /src/controllers/pair/index.js: -------------------------------------------------------------------------------- 1 | export { recent } from './recent'; 2 | export { list } from './list'; 3 | export { save } from './save'; 4 | export { get } from './get'; 5 | export { unpair } from './unpair'; 6 | 7 | export const check = (ctx) => { 8 | ctx.body = { 9 | error: 0, 10 | result: 'ok', 11 | }; 12 | }; 13 | -------------------------------------------------------------------------------- /src/controllers/pair/list.js: -------------------------------------------------------------------------------- 1 | import { Pair, Song } from '../../models'; 2 | 3 | export const list = async (ctx) => { 4 | const pairs = await Pair.findAll({ 5 | include: [{ 6 | as: 'song', 7 | model: Song, 8 | }], 9 | order: [ 10 | ['updatedAt', 'DESC'], 11 | ], 12 | }); 13 | ctx.body = { 14 | error: 0, 15 | result: pairs.map(e => e.dataValues), 16 | }; 17 | }; 18 | 19 | export default list; 20 | -------------------------------------------------------------------------------- /src/controllers/pair/recent.js: -------------------------------------------------------------------------------- 1 | import { Recent, Song } from '../../models'; 2 | 3 | export const recent = async (ctx) => { 4 | const recents = await Recent.findAll({ 5 | include: [{ 6 | as: 'song', 7 | model: Song, 8 | }], 9 | order: [ 10 | ['updatedAt', 'DESC'], 11 | ], 12 | limit: 50, 13 | }); 14 | ctx.body = { 15 | error: 0, 16 | result: recents.map(e => e.dataValues), 17 | }; 18 | }; 19 | 20 | export default recent; 21 | -------------------------------------------------------------------------------- /src/controllers/pair/save.js: -------------------------------------------------------------------------------- 1 | import { Recent, Pair } from '../../models'; 2 | 3 | export const save = async (ctx) => { 4 | const req = ctx.request; 5 | const result = {}; 6 | const { songId, plugin, hash, name, artist, album, albumPic } = req.body; 7 | if (!/^QQ Music|Kugou$/.test(plugin)) { 8 | result.error = -1; 9 | ctx.body = result; 10 | } else if (!/^\d+$/.test(songId)) { 11 | result.error = -1; 12 | ctx.body = result; 13 | } else if (!/^[0-9,a-z,A-Z]+$/.test(songId)) { 14 | result.error = -1; 15 | ctx.body = result; 16 | } else { 17 | Pair.upsert({ 18 | songId, plugin, hash, name, artist, album, albumPic, 19 | }).then().catch(err => console.log(err)); 20 | Recent.destroy({ 21 | where: { songId }, 22 | }).then().catch(err => console.log(err)); 23 | result.error = 0; 24 | ctx.body = result; 25 | } 26 | }; 27 | 28 | export default save; 29 | -------------------------------------------------------------------------------- /src/controllers/pair/unpair.js: -------------------------------------------------------------------------------- 1 | import { Pair } from '../../models'; 2 | 3 | export const unpair = async (ctx) => { 4 | const { songId } = ctx.params; 5 | const result = {}; 6 | Pair.destroy({ 7 | where: { songId }, 8 | }).then().catch(err => console.log(err)); 9 | result.error = 0; 10 | ctx.body = result; 11 | }; 12 | 13 | export default unpair; 14 | 15 | -------------------------------------------------------------------------------- /src/middleware/index.js: -------------------------------------------------------------------------------- 1 | import { proxy } from './proxy'; 2 | import { permission } from './permission'; 3 | 4 | export { proxy, permission }; 5 | -------------------------------------------------------------------------------- /src/middleware/permission/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ITJesse/UnblockNeteaseMusic/b9c08bd0039012da0cf43c0edea5026a3168c2dc/src/middleware/permission/index.js -------------------------------------------------------------------------------- /src/middleware/proxy/index.js: -------------------------------------------------------------------------------- 1 | import zlib from 'zlib'; 2 | 3 | import config from '../../config'; 4 | import { sendRequest } from '../../utils'; 5 | 6 | export const proxy = async function (ctx, next) { 7 | const req = ctx.request; 8 | 9 | if (req.url.indexOf('/api/plugin') !== -1) { 10 | ctx.body = req.rawBody; 11 | await next(); 12 | } else if (req.method === 'POST') { 13 | const ip = config.forceIp ? config.forceIp : '223.252.199.7'; 14 | const url = `http://${ip}${req.url}`; 15 | 16 | const newHeader = { 17 | ...req.headers, 18 | host: 'music.163.com', 19 | 'x-real-ip': `202.114.79.${Math.floor(Math.random() * 255) + 1}`, 20 | }; 21 | 22 | const options = { 23 | url, 24 | headers: newHeader, 25 | method: 'post', 26 | encoding: null, 27 | gzip: true, 28 | }; 29 | if (req.rawBody) { 30 | options.body = req.rawBody; 31 | } 32 | let result; 33 | try { 34 | result = await sendRequest(options); 35 | } catch (err) { 36 | console.log('Cannot get orignal response.'.red); 37 | throw new Error(err); 38 | } 39 | 40 | const headers = result.headers; 41 | const body = result.body; 42 | ctx.body = body.toString(); 43 | // console.log(ctx.body); 44 | await next(); 45 | 46 | if (typeof ctx.body === 'object') { 47 | ctx.body = JSON.stringify(ctx.body); 48 | } 49 | if (typeof ctx.body === 'string') { 50 | ctx.compress = true; 51 | const stream = zlib.createGzip(); 52 | stream.end(ctx.body); 53 | ctx.body = stream; 54 | headers['content-encoding'] = 'gzip'; 55 | } else { 56 | delete headers['content-encoding']; 57 | } 58 | // console.log(headers); 59 | ctx.set(headers); 60 | // console.log(ctx.body); 61 | } 62 | }; 63 | 64 | export default proxy; 65 | -------------------------------------------------------------------------------- /src/models/index.js: -------------------------------------------------------------------------------- 1 | import Sequelize from 'sequelize'; 2 | 3 | import config from '../config'; 4 | import song from './song'; 5 | import recent from './recent'; 6 | import pair from './pair'; 7 | 8 | const sequelize = new Sequelize('unblock', 'unblock', 'unblock', { 9 | dialect: 'sqlite', 10 | storage: config.databasePath ? config.databasePath : './unblock.sqlite', 11 | logging: config.verbose ? console.log : false, 12 | }); 13 | 14 | 15 | export const Song = song(sequelize, Sequelize); 16 | export const Recent = recent(sequelize, Sequelize); 17 | export const Pair = pair(sequelize, Sequelize); 18 | 19 | Recent.associate(Song); 20 | Pair.associate(Song); 21 | 22 | Song.sync(); 23 | Recent.sync(); 24 | Pair.sync(); 25 | 26 | export default sequelize; 27 | -------------------------------------------------------------------------------- /src/models/pair.js: -------------------------------------------------------------------------------- 1 | export default (sequelize, DataTypes) => { 2 | const Pair = sequelize.define('Pair', { 3 | songId: { 4 | type: DataTypes.INTEGER, 5 | primaryKey: true, 6 | }, 7 | plugin: DataTypes.STRING, 8 | name: DataTypes.STRING, 9 | artist: DataTypes.STRING, 10 | album: DataTypes.STRING, 11 | albumPic: DataTypes.STRING, 12 | hash: DataTypes.STRING, 13 | createdAt: DataTypes.DATE, 14 | updatedAt: DataTypes.DATE, 15 | }); 16 | 17 | Pair.associate = (Song) => { 18 | Pair.hasOne(Song, { 19 | foreignKey: 'songId', 20 | as: 'song', 21 | }); 22 | }; 23 | 24 | return Pair; 25 | }; 26 | -------------------------------------------------------------------------------- /src/models/recent.js: -------------------------------------------------------------------------------- 1 | export default (sequelize, DataTypes) => { 2 | const Recent = sequelize.define('Recent', { 3 | songId: { 4 | type: DataTypes.INTEGER, 5 | primaryKey: true, 6 | }, 7 | }); 8 | 9 | Recent.associate = (Song) => { 10 | Recent.hasOne(Song, { 11 | foreignKey: 'songId', 12 | as: 'song', 13 | }); 14 | }; 15 | 16 | return Recent; 17 | }; 18 | -------------------------------------------------------------------------------- /src/models/song.js: -------------------------------------------------------------------------------- 1 | export default (sequelize, DataTypes) => { 2 | const Song = sequelize.define('Song', { 3 | songId: { 4 | type: DataTypes.INTEGER, 5 | primaryKey: true, 6 | }, 7 | name: DataTypes.STRING, 8 | artist: DataTypes.STRING, 9 | album: DataTypes.STRING, 10 | albumPic: DataTypes.STRING, 11 | }); 12 | 13 | return Song; 14 | }; 15 | -------------------------------------------------------------------------------- /src/utils/common/crypto.js: -------------------------------------------------------------------------------- 1 | // 参考 https://github.com/darknessomi/musicbox/wiki/ 2 | 3 | 'use strict'; 4 | 5 | import crypto from 'crypto'; 6 | import bigInt from 'big-integer'; 7 | 8 | const modulus = 9 | '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'; 10 | const nonce = '0CoJUm6Qyw8W8jud'; 11 | const pubKey = '010001'; 12 | 13 | function createSecretKey(size) { 14 | const keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; 15 | let key = ''; 16 | for (let i = 0; i < size; i += 1) { 17 | let pos = Math.random() * keys.length; 18 | pos = Math.floor(pos); 19 | key += keys.charAt(pos); 20 | } 21 | return key; 22 | } 23 | 24 | function aesEncrypt(text, secKey) { 25 | const lv = Buffer.from('0102030405060708', 'binary'); 26 | const secKeyBin = Buffer.from(secKey, 'binary'); 27 | const cipher = crypto.createCipheriv('AES-128-CBC', secKeyBin, lv); 28 | let encrypted = cipher.update(text, 'utf8', 'base64'); 29 | encrypted += cipher.final('base64'); 30 | return encrypted; 31 | } 32 | 33 | function zfill(str, size) { 34 | while (str.length < size) str = `0${str}`; 35 | return str; 36 | } 37 | 38 | function rsaEncrypt(text) { 39 | const reverseText = text.split('').reverse().join(''); 40 | const biText = bigInt(Buffer.from(reverseText).toString('hex'), 16); 41 | const biEx = bigInt(pubKey, 16); 42 | const biMod = bigInt(modulus, 16); 43 | const biRet = biText.modPow(biEx, biMod); 44 | return zfill(biRet.toString(16), 256); 45 | } 46 | 47 | function Encrypt(obj) { 48 | const text = JSON.stringify(obj); 49 | const secKey = createSecretKey(16); 50 | const encText = aesEncrypt(aesEncrypt(text, nonce), secKey); 51 | const encSecKey = rsaEncrypt(secKey, pubKey, modulus); 52 | return { 53 | params: encText, 54 | encSecKey, 55 | }; 56 | } 57 | 58 | export default Encrypt; 59 | -------------------------------------------------------------------------------- /src/utils/common/index.js: -------------------------------------------------------------------------------- 1 | import request from 'request-promise'; 2 | import querystring from 'querystring'; 3 | import Encrypt from './crypto'; 4 | 5 | export function randomUserAgent() { 6 | const userAgentList = [ 7 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 8 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 9 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', 10 | 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', 11 | 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', 12 | 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', 13 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper', 14 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4', 15 | 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1', 16 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 17 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0', 18 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0', 19 | 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', 20 | 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)', 21 | 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', 22 | 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)', 23 | 'Mozilla/5.0 (Windows NT 6.3; Win64, x64; Trident/7.0; rv:11.0) like Gecko', 24 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586', 25 | 'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1', 26 | ]; 27 | const num = Math.floor(Math.random() * userAgentList.length); 28 | return userAgentList[num]; 29 | } 30 | 31 | export async function sendRequest(options) { 32 | const defaults = { 33 | method: 'get', 34 | followRedirect: true, 35 | timeout: 10000, 36 | resolveWithFullResponse: true, 37 | }; 38 | options = { 39 | ...defaults, 40 | ...options, 41 | }; 42 | let result; 43 | try { 44 | result = await request(options); 45 | } catch (err) { 46 | throw new Error(err); 47 | } 48 | return result; 49 | } 50 | 51 | export async function createWebAPIRequest( 52 | url, 53 | method, 54 | data, 55 | ) { 56 | const cryptoreq = Encrypt(data); 57 | const options = { 58 | url, 59 | method, 60 | headers: { 61 | Accept: '*/*', 62 | Connection: 'keep-alive', 63 | Referer: 'http://music.163.com', 64 | Cookie: '', 65 | 'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4', 66 | 'Content-Type': 'application/x-www-form-urlencoded', 67 | 'User-Agent': randomUserAgent(), 68 | }, 69 | body: querystring.stringify({ 70 | params: cryptoreq.params, 71 | encSecKey: cryptoreq.encSecKey, 72 | }), 73 | }; 74 | let result; 75 | try { 76 | result = await request(options); 77 | } catch (err) { 78 | throw new Error(err); 79 | } 80 | return result; 81 | } 82 | 83 | export default sendRequest; 84 | -------------------------------------------------------------------------------- /src/utils/index.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import fs from 'fs'; 3 | import path from 'path'; 4 | 5 | import { Netease } from './netease'; 6 | import config from '../config'; 7 | 8 | export class Utils { 9 | constructor() { 10 | const ip = config.forceIp ? config.forceIp : '223.252.199.7'; 11 | this.netease = new Netease(ip); 12 | this.plugins = []; 13 | this.initPlugins(); 14 | } 15 | 16 | initPlugins() { 17 | fs.readdirSync(path.resolve(__dirname, 'plugins')).forEach((file) => { 18 | // eslint-disable-next-line 19 | const Plugin = require(path.resolve(__dirname, 'plugins', file)); 20 | this.plugins.push(new Plugin()); 21 | }); 22 | this.plugins.sort((a, b) => a.order - b.order); 23 | // console.log(this.plugins); 24 | } 25 | 26 | async batchSeachMusic(songName, artist, album) { 27 | const result = []; 28 | for (const plugin of this.plugins) { 29 | console.log(`Search from ${plugin.name}`.green); 30 | const keyword = `${artist} ${songName} ${album}`; 31 | let searchResult; 32 | try { 33 | searchResult = await plugin.search(keyword); 34 | } catch (error) { 35 | console.log(`Cannot search from ${plugin.name}`.red); 36 | console.log(error); 37 | continue; 38 | } 39 | if (searchResult.length > 0) { 40 | // console.log(searchResult); 41 | const searchName = searchResult[0].name.replace(/ /g, '').toLowerCase(); 42 | const trueName = songName.replace(/ /g, '').toLowerCase(); 43 | if (searchName.indexOf(trueName) !== -1) { 44 | result.push({ 45 | plugin, 46 | searchResult: searchResult[0], 47 | }); 48 | } else { 49 | console.log(`No resource found from ${plugin.name}`.yellow); 50 | } 51 | } else { 52 | console.log(`No resource found from ${plugin.name}`.yellow); 53 | } 54 | } 55 | return result; 56 | } 57 | 58 | static async getSongInfo(songId) { 59 | let detail; 60 | try { 61 | detail = await Netease.getSongDetail(songId); 62 | } catch (err) { 63 | console.log('Cannot get song info from netease.'.red); 64 | throw new Error(err); 65 | } 66 | const songName = Netease.getSongName(detail); 67 | const artist = Netease.getArtistName(detail); 68 | const album = Netease.getAlbumName(detail); 69 | const albumPic = Netease.getAlbumPic(detail); 70 | console.log('Song name: '.green + songName); 71 | console.log('Artist: '.green + artist); 72 | console.log('Album: '.green + album); 73 | return { 74 | songName, artist, album, albumPic, 75 | }; 76 | } 77 | 78 | /* 79 | Get song url. 80 | */ 81 | async getUrlInfo(songInfo) { 82 | const { songName, artist, album } = songInfo; 83 | let result; 84 | try { 85 | result = await this.batchSeachMusic(songName, artist, album); 86 | } catch (err) { 87 | console.log('Batch search failed.'.red); 88 | throw new Error(err); 89 | } 90 | result = result.sort((a, b) => { 91 | if (!a) { 92 | return 1; 93 | } 94 | if (!b) { 95 | return -1; 96 | } 97 | if (parseInt(a.searchResult.bitrate, 10) > parseInt(b.searchResult.bitrate, 10)) { 98 | return -1; 99 | } 100 | if (parseInt(a.searchResult.bitrate, 10) < parseInt(b.searchResult.bitrate, 10)) { 101 | return 1; 102 | } 103 | if (a.searchResult.bitrate === b.searchResult.bitrate) { 104 | return a.searchResult.order - b.searchResult.order; 105 | } 106 | return 0; 107 | }); 108 | if (result[0]) { 109 | const plugin = result[0].plugin; 110 | const data = result[0].searchResult; 111 | songInfo = { 112 | bitrate: data.bitrate, 113 | filesize: data.filesize, 114 | hash: data.hash, 115 | type: data.type, 116 | }; 117 | let url; 118 | try { 119 | url = await plugin.getUrl(data); 120 | } catch (err) { 121 | console.log('Cannot get song url'.red); 122 | throw new Error(err); 123 | } 124 | songInfo.origUrl = null; 125 | // 魔改 URL 应对某司防火墙 126 | if (config.rewriteUrl) { 127 | songInfo.origUrl = url; 128 | url = url.replace(plugin.baseUrl, `music.163.com/${plugin.name.replace(/ /g, '').toLowerCase()}`); 129 | } 130 | songInfo.url = url; 131 | return songInfo; 132 | } 133 | return null; 134 | } 135 | 136 | async getUrlInfoForPair(pair) { 137 | let plugin; 138 | for (const p of this.plugins) { 139 | if (p.name === pair.plugin) { 140 | plugin = p; 141 | break; 142 | } 143 | } 144 | let url; 145 | try { 146 | await plugin.init(); 147 | url = plugin.getUrl({ 148 | prefix: 'M800', 149 | type: 'mp3', 150 | mid: pair.hash, 151 | }); 152 | } catch (err) { 153 | throw new Error(err); 154 | } 155 | return { 156 | hash: '', 157 | bitrate: '320000', 158 | type: 'mp3', 159 | url, 160 | }; 161 | } 162 | } 163 | 164 | export { Netease } from './netease'; 165 | export { sendRequest } from './common'; 166 | -------------------------------------------------------------------------------- /src/utils/netease/index.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | import request from 'request'; 3 | import crypto from 'crypto'; 4 | import remoteFilesize from 'remote-file-size'; 5 | import { createWebAPIRequest } from '../common'; 6 | 7 | export class Netease { 8 | constructor(ip) { 9 | this.baseUrl = `http://${ip}`; 10 | } 11 | 12 | static getDownloadReturnCode(body) { 13 | return body.data.code; 14 | } 15 | 16 | static getDownloadUrl(body) { 17 | return body.data.url; 18 | } 19 | 20 | static getSongName(body) { 21 | body = JSON.parse(body); 22 | return body.songs[0].name; 23 | } 24 | 25 | static getArtistName(body) { 26 | body = JSON.parse(body); 27 | return body.songs[0].ar[0].name; 28 | } 29 | 30 | static getAlbumName(body) { 31 | body = JSON.parse(body); 32 | return body.songs[0].al.name; 33 | } 34 | 35 | static getAlbumPic(body) { 36 | body = JSON.parse(body); 37 | return body.songs[0].al.picUrl; 38 | } 39 | 40 | static getDownloadSongId(body) { 41 | return body.data.id; 42 | } 43 | 44 | static getFilesize(url) { 45 | console.log('Getting filesize.'.yellow); 46 | return new Promise((resolve, reject) => { 47 | remoteFilesize(url, (err, size) => { 48 | if (err) return reject(err); 49 | console.log('Filesize:'.green, size); 50 | return resolve(size); 51 | }); 52 | }); 53 | } 54 | 55 | static getFileInfo(url) { 56 | console.log('Getting file info.'.yellow); 57 | return new Promise((resolve, reject) => { 58 | const hash = crypto.createHash('md5'); 59 | hash.setEncoding('hex'); 60 | let filesize = 0; 61 | let md5 = ''; 62 | request.get(url) 63 | .on('error', err => reject(err)) 64 | .on('response', (res) => { 65 | filesize = parseInt(res.headers['content-length'], 10); 66 | console.log('Filesize:'.green, filesize); 67 | }) 68 | .pipe(hash) 69 | .on('finish', () => { 70 | hash.end(); 71 | md5 = hash.read(); 72 | console.log('MD5:'.green, md5); 73 | return resolve({ 74 | filesize, 75 | md5, 76 | }); 77 | }); 78 | }); 79 | } 80 | 81 | static fixJsonData(body) { 82 | if (body.code === 200) { 83 | return body; 84 | } 85 | return { 86 | ...body, 87 | url: null, 88 | type: null, 89 | md5: null, 90 | uf: null, 91 | }; 92 | } 93 | 94 | static async modifyPlayerApiCustom(urlInfo, body) { 95 | console.log('Player API Injected'.green); 96 | console.log('New URL is '.green + urlInfo.url); 97 | body.url = urlInfo.url; 98 | body.br = urlInfo.bitrate; 99 | body.code = 200; 100 | body.type = urlInfo.type; 101 | body.md5 = urlInfo.hash; 102 | if (!urlInfo.filesize) { 103 | try { 104 | const filesize = await Netease.getFilesize(urlInfo.origUrl || urlInfo.url); 105 | body.size = filesize; 106 | } catch (error) { 107 | console.log('Cannot get file size.'.red); 108 | throw new Error(error); 109 | } 110 | } else { 111 | body.size = urlInfo.filesize; 112 | } 113 | return body; 114 | } 115 | 116 | static async modifyDownloadApiCustom(urlInfo, body) { 117 | console.log('Download API Injected'.green); 118 | console.log('New URL is '.green + urlInfo.url); 119 | body.url = urlInfo.url; 120 | body.br = urlInfo.bitrate; 121 | body.code = 200; 122 | body.type = urlInfo.type; 123 | body.md5 = urlInfo.hash; 124 | body.expi = 1200; 125 | if (!urlInfo.filesize || !urlInfo.md5) { 126 | try { 127 | const { 128 | filesize, 129 | md5, 130 | } = await Netease.getFileInfo(urlInfo.origUrl || urlInfo.url); 131 | body.size = filesize; 132 | body.md5 = md5; 133 | } catch (error) { 134 | throw new Error(error); 135 | } 136 | } else { 137 | body.size = urlInfo.filesize; 138 | body.md5 = urlInfo.md5; 139 | } 140 | return body; 141 | } 142 | 143 | static async getSongDetail(songId) { 144 | const data = { 145 | c: JSON.stringify([{ id: songId }]), 146 | ids: `[${songId}]`, 147 | csrf_token: '', 148 | }; 149 | let result; 150 | try { 151 | result = await createWebAPIRequest( 152 | 'http://music.163.com/weapi/v3/song/detail', 153 | 'POST', 154 | data, 155 | ); 156 | } catch (err) { 157 | throw new Error(err); 158 | } 159 | return result; 160 | } 161 | 162 | static decryptLinuxForwardApi(eparams) { 163 | const key = new Buffer('7246674226682325323F5E6544673A51', 'hex'); 164 | const decipher = crypto.createDecipheriv('aes-128-ecb', key, ''); 165 | decipher.setAutoPadding(true); 166 | const cipherChunks = []; 167 | cipherChunks.push(decipher.update(eparams, 'hex')); 168 | cipherChunks.push(decipher.final()); 169 | 170 | let totalLength = 0; 171 | for (const e of cipherChunks) { 172 | totalLength += e.length; 173 | } 174 | return Buffer.concat(cipherChunks, totalLength); 175 | } 176 | } 177 | 178 | export default Netease; 179 | -------------------------------------------------------------------------------- /src/utils/plugins/kugou.js: -------------------------------------------------------------------------------- 1 | import md5 from 'md5'; 2 | 3 | import * as common from '../common'; 4 | 5 | class Kugou { 6 | constructor() { 7 | this.name = 'Kugou'; 8 | this.order = 2; 9 | this.baseUrl = 'fs.web.kugou.com'; 10 | } 11 | 12 | getPluginInfo() { 13 | return { 14 | name: this.name, 15 | order: this.order, 16 | }; 17 | } 18 | 19 | // eslint-disable-next-line 20 | async search(keyword) { 21 | const options = { 22 | url: `http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword=${encodeURIComponent(keyword)}&page=1&pagesize=1&showtype=1`, 23 | }; 24 | let data; 25 | try { 26 | const result = await common.sendRequest(options); 27 | data = JSON.parse(result.body); 28 | } catch (err) { 29 | throw new Error(err); 30 | } 31 | const result = []; 32 | if (data.status === 1 && data.data.info.length > 0) { 33 | for (const e of data.data.info) { 34 | let filesize; 35 | let hash; 36 | let bitrate; 37 | // if (Object.prototype.hasOwnProperty.call(e, 'sqhash')) { 38 | // bitrate = '999000'; 39 | // filesize = e.sqfilesize; 40 | // hash = e.sqhash; 41 | // type = 'flac'; 42 | // } else if (Object.prototype.hasOwnProperty.call(e, '320hash')) { 43 | 44 | if (Object.prototype.hasOwnProperty.call(e, '320hash') && e['320hash'].lenght > 0) { 45 | bitrate = '320000'; 46 | filesize = e['320filesize']; 47 | hash = e['320hash']; 48 | } else if (Object.prototype.hasOwnProperty.call(e, 'hash') && e.hash.lenght > 0) { 49 | bitrate = '128000'; 50 | filesize = e.filesize; 51 | hash = e.hash; 52 | } else { 53 | continue; 54 | } 55 | result.push({ 56 | name: e.filename, 57 | artist: e.singername, 58 | type: 'mp3', 59 | filesize, 60 | bitrate, 61 | hash, 62 | }); 63 | } 64 | } 65 | return result; 66 | } 67 | 68 | // eslint-disable-next-line 69 | async getUrl(searchResult) { 70 | const hash = searchResult.hash; 71 | const key = md5(`${hash}kgcloud`); 72 | const options = { 73 | url: `http://trackercdn.kugou.com/i/?acceptMp3=1&cmd=4&pid=6&hash=${hash}&key=${key}`, 74 | }; 75 | 76 | let data; 77 | try { 78 | const result = await common.sendRequest(options); 79 | data = JSON.parse(result.body); 80 | } catch (err) { 81 | throw new Error(err); 82 | } 83 | 84 | let url; 85 | if (data.error || data.status !== 1) { 86 | url = null; 87 | } else { 88 | url = data.url; 89 | } 90 | return url; 91 | } 92 | } 93 | 94 | module.exports = Kugou; 95 | -------------------------------------------------------------------------------- /src/utils/plugins/qq.js: -------------------------------------------------------------------------------- 1 | import 'colors'; 2 | 3 | import * as common from '../common'; 4 | import config from '../../config'; 5 | 6 | class QQ { 7 | constructor() { 8 | this.name = 'QQ Music'; 9 | this.order = 1; 10 | this.baseUrl = 'isure.stream.qqmusic.qq.com'; 11 | if (config.proxy && config.proxy.length > 0) { 12 | this.baseSearchApi = `http://${config.proxy}/c.y.qq.com`; 13 | this.baseVKeyApi = `http://${config.proxy}/u.y.qq.com`; 14 | } else { 15 | this.baseSearchApi = 'https://c.y.qq.com'; 16 | this.baseVKeyApi = 'https://u.y.qq.com'; 17 | } 18 | } 19 | 20 | static getGUid() { 21 | const currentMs = new Date().getUTCMilliseconds(); 22 | return `${(Math.round(2147483647 * Math.random()) * currentMs) % 1e10}`; 23 | } 24 | 25 | async search(keyword) { 26 | const options = { 27 | url: `${ 28 | this.baseSearchApi 29 | }/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&t=0&aggr=1&cr=1&catZhida=1&lossless=1&flag_qc=0&p=1&n=1&w=${encodeURIComponent( 30 | keyword, 31 | )}&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0`, 32 | }; 33 | let data; 34 | try { 35 | const result = await common.sendRequest(options); 36 | data = JSON.parse(result.body); 37 | } catch (err) { 38 | throw new Error(err); 39 | } 40 | const result = []; 41 | if (data.code === 0 && data.data.song.list.length > 0) { 42 | for (const e of data.data.song.list) { 43 | const list = e.file; 44 | let prefix; 45 | let bitrate; 46 | let filesize; 47 | let type; 48 | let fromtag; 49 | if (list.size_128 && list.size_128 > 0) { 50 | prefix = 'M500'; 51 | type = 'mp3'; 52 | bitrate = 128000; 53 | filesize = list.size_128; 54 | fromtag = 30; 55 | } 56 | if (list.size_320 && list.size_320 > 0) { 57 | prefix = 'M800'; 58 | type = 'mp3'; 59 | bitrate = 320000; 60 | filesize = list.size_320; 61 | fromtag = 30; 62 | } 63 | if (list.size_flac && list.size_flac > 0) { 64 | prefix = 'F000'; 65 | type = 'flac'; 66 | bitrate = 999000; 67 | filesize = list.size_flac; 68 | fromtag = 53; 69 | } 70 | result.push({ 71 | name: e.name || 'V.A.', 72 | artist: e.singer.name || 'V.A.', 73 | filesize, 74 | hash: '', 75 | songmid: e.mid, 76 | mid: list.media_mid, 77 | bitrate: String(bitrate), 78 | prefix, 79 | type, 80 | fromtag, 81 | }); 82 | } 83 | } 84 | return result; 85 | } 86 | 87 | async getUrl(data) { 88 | const guid = QQ.getGUid(); 89 | const url = `${this.baseVKeyApi}/cgi-bin/musicu.fcg?loginUin=0&data=${encodeURIComponent( 90 | JSON.stringify({ 91 | req: { 92 | module: 'vkey.GetVkeyServer', 93 | method: 'CgiGetVkey', 94 | param: { 95 | guid, 96 | songmid: [data.songmid], 97 | songtype: [0], 98 | uin: '0', 99 | loginflag: 1, 100 | platform: '20', 101 | }, 102 | }, 103 | comm: { uin: 0, format: 'json', ct: 20, cv: 0 }, 104 | }), 105 | )}`; 106 | const res = await common.sendRequest({ url }); 107 | const { vkey } = JSON.parse(res.body).req.data.midurlinfo[0]; 108 | if (!vkey) { 109 | return null; 110 | } 111 | return `http://${this.baseUrl}/${data.prefix}${data.mid}.${ 112 | data.type 113 | }?vkey=${vkey}&guid=${guid}&uin=0&fromtag=${data.fromtag}`; 114 | } 115 | } 116 | 117 | module.exports = QQ; 118 | --------------------------------------------------------------------------------