├── .gitignore
├── LICENSE
├── README.md
├── __init__.py
├── api
├── MusicooApi.py
└── __init__.py
├── common
├── Response.py
└── __init__.py
├── config
├── Getter.py
├── Setting.py
└── __init__.py
├── exception
└── NeteaseResolverException.py
├── model
├── Album.py
├── Playlist.py
├── Privilege.py
├── Song.py
└── __init__.py
├── netease
├── Api.py
├── Encrypt.py
├── Setting.py
├── __init__.py
└── __test__.py
├── requirements.txt
├── resolve
├── NeteaseResolver.py
├── __init__.py
└── __test__.py
├── service
├── MusicooService.py
└── __init__.py
├── start
├── Musicoo.py
└── __init__.py
└── util
├── ClassUtils.py
├── LogHandler.py
└── __init__.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Python template
3 | # Byte-compiled / optimized / DLL files
4 | __pycache__/
5 | *.py[cod]
6 | *$py.class
7 |
8 | # C extensions
9 | *.so
10 |
11 | # Distribution / packaging
12 | .Python
13 | build/
14 | develop-eggs/
15 | dist/
16 | downloads/
17 | eggs/
18 | .eggs/
19 | lib/
20 | lib64/
21 | parts/
22 | sdist/
23 | var/
24 | wheels/
25 | pip-wheel-metadata/
26 | share/python-wheels/
27 | *.egg-info/
28 | .installed.cfg
29 | *.egg
30 | MANIFEST
31 |
32 | # PyInstaller
33 | # Usually these files are written by a python script from a template
34 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
35 | *.manifest
36 | *.spec
37 |
38 | # Installer logs
39 | pip-log.txt
40 | pip-delete-this-directory.txt
41 |
42 | # Unit test / coverage reports
43 | htmlcov/
44 | .tox/
45 | .nox/
46 | .coverage
47 | .coverage.*
48 | .cache
49 | nosetests.xml
50 | coverage.xml
51 | *.cover
52 | .hypothesis/
53 | .pytest_cache/
54 |
55 | # Translations
56 | *.mo
57 | *.pot
58 |
59 | # Django stuff:
60 | *.log
61 | local_settings.py
62 | db.sqlite3
63 | db.sqlite3-journal
64 |
65 | # Flask stuff:
66 | instance/
67 | .webassets-cache
68 |
69 | # Scrapy stuff:
70 | .scrapy
71 |
72 | # Sphinx documentation
73 | docs/_build/
74 |
75 | # PyBuilder
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | .python-version
87 |
88 | # pipenv
89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
92 | # install all needed dependencies.
93 | #Pipfile.lock
94 |
95 | # celery beat schedule file
96 | celerybeat-schedule
97 |
98 | # SageMath parsed files
99 | *.sage.py
100 |
101 | # Environments
102 | .env
103 | .venv
104 | env/
105 | venv/
106 | ENV/
107 | env.bak/
108 | venv.bak/
109 |
110 | # Spyder project settings
111 | .spyderproject
112 | .spyproject
113 |
114 | # Rope project settings
115 | .ropeproject
116 |
117 | # mkdocs documentation
118 | /site
119 |
120 | # mypy
121 | .mypy_cache/
122 | .dmypy.json
123 | dmypy.json
124 |
125 | # Pyre type checker
126 | .pyre/
127 |
128 | ### JetBrains template
129 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
130 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
131 |
132 | # User-specific stuff
133 | .idea/**/workspace.xml
134 | .idea/**/tasks.xml
135 | .idea/**/usage.statistics.xml
136 | .idea/**/dictionaries
137 | .idea/**/shelf
138 |
139 | # Generated files
140 | .idea/**/contentModel.xml
141 |
142 | # Sensitive or high-churn files
143 | .idea/**/dataSources/
144 | .idea/**/dataSources.ids
145 | .idea/**/dataSources.local.xml
146 | .idea/**/sqlDataSources.xml
147 | .idea/**/dynamic.xml
148 | .idea/**/uiDesigner.xml
149 | .idea/**/dbnavigator.xml
150 |
151 | # Gradle
152 | .idea/**/gradle.xml
153 | .idea/**/libraries
154 |
155 | # Gradle and Maven with auto-import
156 | # When using Gradle or Maven with auto-import, you should exclude module files,
157 | # since they will be recreated, and may cause churn. Uncomment if using
158 | # auto-import.
159 | # .idea/modules.xml
160 | # .idea/*.iml
161 | # .idea/modules
162 | # *.iml
163 | # *.ipr
164 |
165 | # CMake
166 | cmake-build-*/
167 |
168 | # Mongo Explorer plugin
169 | .idea/**/mongoSettings.xml
170 |
171 | # File-based project format
172 | *.iws
173 |
174 | # IntelliJ
175 | out/
176 |
177 | # mpeltonen/sbt-idea plugin
178 | .idea_modules/
179 |
180 | # JIRA plugin
181 | atlassian-ide-plugin.xml
182 |
183 | # Cursive Clojure plugin
184 | .idea/replstate.xml
185 |
186 | # Crashlytics plugin (for Android Studio and IntelliJ)
187 | com_crashlytics_export_strings.xml
188 | crashlytics.properties
189 | crashlytics-build.properties
190 | fabric.properties
191 |
192 | # Editor-based Rest Client
193 | .idea/httpRequests
194 |
195 | # Android studio 3.1+ serialized cache file
196 | .idea/caches/build_file_checksums.ser
197 |
198 | /ignore/
199 | /.idea/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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 |
635 | Copyright (C)
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 | Copyright (C)
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Musicoo
2 |
3 | [](https://github.com/hanhuoer/Musicoo)
4 | [](https://github.com/hanhuoer/Musicoo)
5 | [](https://github.com/hanhuoer/Musicoo)
6 | [](https://github.com/hanhuoer/Musicoo)
7 | [](https://github.com/hanhuoer/Musicoo)
8 |
9 | ```
10 |
11 | ____
12 | ,' , `.
13 | ,-+-,.' _ | ,--, .--, .--, .--,
14 | ,-+-. ; , || ,--, ,--.'| ,---. ,---. |\ \ |\ \ |\ \
15 | ,--.'|' | ;| ,'_ /| .--.--. | |, ' ,'\ ' ,'\` \ `` \ `` \ `
16 | | | ,', | ': .--. | | : / / ' `--'_ ,---. / / | / / |\ \ \\ \ \\ \ \
17 | | | / | | ||,'_ /| : . | | : /`./ ,' ,'| / \. ; ,. :. ; ,. : , \ \, \ \, \ \
18 | ' | : | : |,| ' | | . . | : ;_ ' | | / / '' | |: :' | |: : / /` // /` // /` /
19 | ; . | ; |--' | | ' | | | \ \ `. | | : . ' / ' | .; :' | .; :` / /` / /` / /
20 | | : | | , : | : ; ; | `----. \' : |__ ' ; :__| : || : | . /| . /| . /
21 | | : ' |/ ' : `--' \ / /`--' /| | '.'|' | '.'|\ \ / \ \ /./__/ ./__/ ./__/
22 | ; | |`-' : , .-./'--'. / ; : ;| : : `----' `----'
23 | | ;/ `--`----' `--'---' | , / \ \ /
24 | '---' ---`-' `----'
25 | ```
26 |
27 | 开放接口信息请查看 [Wiki](https://github.com/hanhuoer/Musicoo/wiki/Web-%E5%BC%80%E6%94%BE%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3)
28 |
29 | ## 安装
30 |
31 | 1.**克隆项目**
32 |
33 | ```
34 | > git clone https://github.com/hanhuoer/Musicoo.git
35 | ```
36 |
37 | 2.**安装依赖**
38 |
39 | ```
40 | > pip install -r requirements.txt
41 | ```
42 |
43 | ## 使用
44 |
45 | 1.**修改配置 `config.Setting`**
46 |
47 | ```
48 | # config/Setting.py
49 |
50 | # 配置 Web 服务
51 | WEB_SERVER = {
52 | "HOST": "127.0.0.1",
53 | "PORT": 8888
54 | }
55 |
56 | # 以上配置在项目启动后的访问地址为 http://127.0.0.1:8888
57 | ```
58 |
59 | 2.**启动项目**
60 |
61 | 进入项目 `start` 目录
62 |
63 | ```
64 | # 启动项目之前确保项目依赖全部安装
65 |
66 | # 启动服务
67 | > python Musicoo.py run
68 | # 启动时指定 host, port 将使用 setting 中的配置
69 | > python Musicoo.py run --host 0.0.0.0
70 | # 启动时指定 port, host 将使用 setting 中的配置
71 | > python Musicoo.py run --port 8888
72 | # 启动时指定 host port
73 | > python Musicoo.py run --host 0.0.0.0 --port 8888
74 | ```
75 |
76 | ## 更新日志
77 |
78 | 2019-12-02 版本 1.0.1 添加日志、异常处理和项目启动可选参数
79 |
80 | 2019-12-02 版本 1.0.0 首次发布
81 |
82 | ## 开源协议
83 |
84 | [GPL](https://github.com/hanhuoer/Musicoo/blob/master/LICENSE) © hanhuoer
85 |
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/__init__.py
--------------------------------------------------------------------------------
/api/MusicooApi.py:
--------------------------------------------------------------------------------
1 | """
2 | -------------------------------------------------
3 | File Name : MusicooApi.py
4 | Description : Web Api
5 | Author : H
6 | Date : 2019/12/1
7 | -------------------------------------------------
8 | """
9 |
10 | import platform
11 |
12 | from flask import Flask, request
13 |
14 | from common.Response import Response
15 | from config.Getter import config
16 | from service.MusicooService import MusicooService
17 | from util.LogHandler import LogHandler
18 |
19 | app = Flask(__name__)
20 |
21 | log = LogHandler('Musicoo')
22 |
23 |
24 | @app.route('/', methods=['GET'])
25 | def index():
26 | return 'index'
27 |
28 |
29 | @app.route('/netease/song//url', methods=['GET'])
30 | def song_url(song_id):
31 | """
32 | 获取音乐链接
33 | /netease/song/1379444316/url
34 | :param song_id:
35 | :return:
36 | """
37 | try:
38 | if song_id is None or song_id is '' or len(song_id) is 0:
39 | return Response.error(song_id, message='song_id can not be null.')
40 | if song_id.isdigit() is False:
41 | return Response.error(song_id, message='song_id must be digit.')
42 |
43 | return Response.success(MusicooService.song_url(song_id).to_json())
44 | except Exception as e:
45 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
46 | log.info('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
47 | log.debug('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
48 | log.warning('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
49 | return Response.error()
50 |
51 |
52 | @app.route('/netease/song//lyric', methods=['GET'])
53 | def song_lyric(song_id):
54 | """
55 | 获取音乐歌词
56 | /netease/song/1379444316/lyric
57 | :param song_id:
58 | :return:
59 | """
60 | try:
61 | if song_id is None or song_id is '' or len(song_id) is 0:
62 | return Response.error(song_id, message='song_id can not be null.')
63 | if song_id.isdigit() is False:
64 | return Response.error(song_id, message='song_id must be digit.')
65 |
66 | return Response.success(MusicooService.song_lyric(song_id).to_json())
67 | except Exception as e:
68 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
69 | return Response.error()
70 |
71 |
72 | @app.route('/netease/song//search', methods=['GET'])
73 | def song_search(keyword):
74 | """
75 | 搜索音乐
76 | /netease/song/keyword/search
77 | :return:
78 | """
79 | try:
80 | if keyword is None or keyword is '' or len(keyword) is 0:
81 | return Response.error(keyword, message='keyword can not be null.')
82 |
83 | return Response.success(MusicooService.song_search(keyword).to_json())
84 | except Exception as e:
85 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
86 | return Response.error()
87 |
88 |
89 | @app.route('/netease/songs//search//', methods=['GET'])
90 | def songs_search(keyword, offset, limit):
91 | """
92 | 搜索音乐们
93 | /netease/songs/keyword/search
94 | :param keyword 关键字
95 | :param offset 页数
96 | :param limit 数量
97 | :return:
98 | """
99 | try:
100 | if keyword is None or keyword is '' or len(keyword) is 0:
101 | return Response.error(keyword, message='keyword can not be null.')
102 |
103 | return Response.success(MusicooService.songs_search(keyword, offset=offset, limit=limit))
104 | except Exception as e:
105 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
106 | return Response.error()
107 |
108 |
109 | @app.route('/netease/song//detail')
110 | def song_detail(song_id=''):
111 | """
112 | 获取音乐详情
113 | /netease/song/1379444316/detail
114 | :param song_id: eg 1379444316
115 | :return:
116 | """
117 | try:
118 | if song_id is None or song_id is '' or len(song_id) is 0:
119 | return Response.error(song_id, message='song_id can not be null.')
120 | if song_id.isdigit() is False:
121 | return Response.error(song_id, message='song_id must be digit.')
122 |
123 | return Response.success(MusicooService.song_detail(song_id).to_json())
124 | except Exception as e:
125 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
126 | return Response.error()
127 |
128 |
129 | @app.route('/netease/song/', methods=['GET'])
130 | def song(keyword):
131 | """
132 | url,歌词,detail
133 | /netease/song/1379444316
134 | /netease/song/差不多姑娘
135 | :param keyword:
136 | :return:
137 | """
138 | try:
139 | if keyword is None or keyword is '' or len(keyword) is 0:
140 | return Response.error(keyword, message='keyword can not be null.')
141 |
142 | return Response.success(MusicooService.song(keyword).to_json())
143 | except Exception as e:
144 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
145 | return Response.error()
146 |
147 |
148 | @app.route('/netease/playlist//songs')
149 | def playlist_songs(playlist_id=''):
150 | """
151 | 获取歌单列表,音乐 id、音乐名等等
152 | /netease/playlist/3778678/songs
153 | :param playlist_id: eg 3778678
154 | :return:
155 | """
156 | try:
157 | if playlist_id is None or playlist_id is '' or len(playlist_id) is 0:
158 | return Response.error(playlist_id, message='playlist_id can not be null.')
159 | if playlist_id.isdigit() is False:
160 | return Response.error(playlist_id, message='song_id must be digit.')
161 |
162 | return Response.success(MusicooService.playlist_songs(playlist_id).to_json())
163 | except Exception as e:
164 | log.error('[Musicoo] ip: {};\t\terror: {}'.format(request.remote_addr, e))
165 | return Response.error()
166 |
167 |
168 | """
169 | ------------------------------------------------------------------------------------------------------------------------
170 | > <
171 | > The start <
172 | > <
173 | 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
174 | """
175 |
176 | if platform.system() != "Windows":
177 | import gunicorn.app.base
178 | from gunicorn.six import iteritems
179 |
180 |
181 | class StandaloneApplication(gunicorn.app.base.BaseApplication):
182 |
183 | def __init__(self, app, options=None):
184 | self.options = options or {}
185 | self.application = app
186 | super(StandaloneApplication, self).__init__()
187 |
188 | def load_config(self):
189 | _config = dict([(key, value) for key, value in iteritems(self.options)
190 | if key in self.cfg.settings and value is not None])
191 | for key, value in iteritems(_config):
192 | self.cfg.set(key.lower(), value)
193 |
194 | def load(self):
195 | return self.application
196 |
197 |
198 | def run(host, port):
199 | if host is None:
200 | host = config.host_ip
201 | if port is None:
202 | port = config.host_port
203 | app.run(host=host, port=port)
204 |
205 |
206 | def run_(host, port):
207 | if host is None:
208 | host = config.host_ip
209 | if port is None:
210 | port = config.host_port
211 | _options = {
212 | 'bind': '%s:%s' % (host, port),
213 | 'workers': 4,
214 | 'accesslog': '-',
215 | 'access_log_format': '%(h)s %(l)s %(t)s "%(r)s" %(s)s "%(a)s"'
216 | }
217 | StandaloneApplication(app, _options).run()
218 |
219 |
220 | if __name__ == '__main__':
221 | if platform.system() == "Windows":
222 | run(config.host_ip, config.host_port)
223 | else:
224 | run_(config.host_ip, config.host_port)
225 |
--------------------------------------------------------------------------------
/api/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/api/__init__.py
--------------------------------------------------------------------------------
/common/Response.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 |
4 | class Response(object):
5 | """
6 | 封装 response
7 | """
8 |
9 | def __init__(self, data, message, code):
10 | self.data = data
11 | self.message = message
12 | self.code = code
13 |
14 | def to_string(self):
15 | return json.dumps({
16 | 'data': self.data,
17 | 'message': self.message,
18 | 'code': self.code
19 | }, ensure_ascii=False)
20 |
21 | def to_json(self):
22 | return {
23 | 'data': self.data,
24 | 'message': self.message,
25 | 'code': self.code
26 | }
27 |
28 | @staticmethod
29 | def error(data=None, message='error', code=-1):
30 | return json.dumps(Response(data, message, code).to_json(), ensure_ascii=False)
31 |
32 | @staticmethod
33 | def fail(data=None, message='fail', code=0):
34 | return json.dumps(Response(data, message, code).to_json(), ensure_ascii=False)
35 |
36 | @staticmethod
37 | def success(data=None, message='success', code=1):
38 | return json.dumps(Response(data, message, code).to_json(), ensure_ascii=False)
39 |
--------------------------------------------------------------------------------
/common/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/common/__init__.py
--------------------------------------------------------------------------------
/config/Getter.py:
--------------------------------------------------------------------------------
1 | from config.Setting import *
2 | from util.ClassUtils import LazyProperty
3 |
4 |
5 | class ConfigGetter(object):
6 | """
7 | config getter
8 | """
9 |
10 | def __init__(self):
11 | pass
12 |
13 | @LazyProperty
14 | def host_ip(self):
15 | return WEB_SERVER.get("HOST", "127.0.0.1")
16 |
17 | @LazyProperty
18 | def host_port(self):
19 | return WEB_SERVER.get("PORT", "8888")
20 |
21 |
22 | config = ConfigGetter()
23 |
24 | if __name__ == '__main__':
25 | print(config.host_ip)
26 | print(config.host_port)
27 |
--------------------------------------------------------------------------------
/config/Setting.py:
--------------------------------------------------------------------------------
1 | """
2 |
3 | """
4 |
5 | BANNER = """
6 | >> <<
7 | >> ____ <<
8 | >> ,' , `. <<
9 | >> ,-+-,.' _ | ,--, .--, .--, .--, <<
10 | >> ,-+-. ; , || ,--, ,--.'| ,---. ,---. |\ \ |\ \ |\ \ <<
11 | >> ,--.'|' | ;| ,'_ /| .--.--. | |, ' ,'\ ' ,'\` \ `` \ `` \ ` <<
12 | >> | | ,', | ': .--. | | : / / ' `--'_ ,---. / / | / / |\ \ \\\\ \ \\\\ \ \ <<
13 | >> | | / | | ||,'_ /| : . | | : /`./ ,' ,'| / \. ; ,. :. ; ,. : , \ \, \ \, \ \ <<
14 | >> ' | : | : |,| ' | | . . | : ;_ ' | | / / '' | |: :' | |: : / /` // /` // /` / <<
15 | >> ; . | ; |--' | | ' | | | \ \ `. | | : . ' / ' | .; :' | .; :` / /` / /` / / <<
16 | >> | : | | , : | : ; ; | `----. \\' : |__ ' ; :__| : || : | . /| . /| . / <<
17 | >> | : ' |/ ' : `--' \ / /`--' /| | '.'|' | '.'|\ \ / \ \ /./__/ ./__/ ./__/ <<
18 | >> ; | |`-' : , .-./'--'. / ; : ;| : : `----' `----' <<
19 | >> | ;/ `--`----' `--'---' | , / \ \ / <<
20 | >> '---' ---`-' `----' <<
21 | """
22 |
23 | # 配置 Web 服务
24 | WEB_SERVER = {
25 | "HOST": "0.0.0.0",
26 | "PORT": 8888
27 | }
28 |
--------------------------------------------------------------------------------
/config/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/config/__init__.py
--------------------------------------------------------------------------------
/exception/NeteaseResolverException.py:
--------------------------------------------------------------------------------
1 | class NeteaseResolverException(Exception):
2 | """
3 | NeteaseResolverException
4 | """
5 |
6 | def __init__(self, *args):
7 | self.args = args
8 |
9 |
10 | if __name__ == '__main__':
11 | try:
12 | raise NeteaseResolverException('e')
13 | except NeteaseResolverException as e:
14 | print(e)
15 |
--------------------------------------------------------------------------------
/model/Album.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 |
4 | class Album(object):
5 | """
6 | 专辑实体类
7 | """
8 |
9 | def __init__(self):
10 | self.id = None
11 | self.name = None
12 | self.artist = None
13 | self.picture_url = None
14 |
15 | def get_id(self):
16 | return self.id
17 |
18 | def get_name(self):
19 | return self.name
20 |
21 | def get_artist(self):
22 | return self.artist
23 |
24 | def get_picture_url(self):
25 | return self.picture_url
26 |
27 | def set_id(self, id):
28 | self.id = id
29 |
30 | def set_name(self, name):
31 | self.name = name
32 |
33 | def set_artist(self, artist):
34 | self.artist = artist
35 |
36 | def set_picture_url(self, picture_url):
37 | self.picture_url = picture_url
38 |
39 | def to_string(self):
40 | return json.dumps({
41 | 'id': self.get_id(),
42 | 'name': self.get_name(),
43 | 'artist': self.get_artist(),
44 | 'picture_url': self.get_picture_url()
45 | }, ensure_ascii=False)
46 |
47 | def to_json(self):
48 | return {
49 | 'id': self.get_id(),
50 | 'name': self.get_name(),
51 | 'artist': self.get_artist(),
52 | 'picture_url': self.get_picture_url()
53 | }
54 |
55 | def dict_to_object(dictObject: dict, object):
56 | for k, v in dictObject.items():
57 | object.__dict__[k] = v
58 | return object
--------------------------------------------------------------------------------
/model/Playlist.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 |
4 | class Playlist(object):
5 |
6 | def __init__(self):
7 | self.id = None
8 | self.name = None
9 | self.tracks = []
10 |
11 | def set_id(self, id):
12 | self.id = id
13 |
14 | def get_id(self):
15 | return self.id
16 |
17 | def set_name(self, name):
18 | self.name = name
19 |
20 | def get_name(self):
21 | return self.name
22 |
23 | def set_tracks(self, tracks):
24 | self.tracks = tracks
25 |
26 | def get_tracks(self):
27 | return self.tracks
28 |
29 | def to_string(self):
30 | return json.dumps({
31 | 'id': self.get_id(),
32 | 'name': self.get_name(),
33 | 'tracks': self.get_tracks(),
34 | }, ensure_ascii=False)
35 |
36 | def to_json(self):
37 | return {
38 | 'id': self.get_id(),
39 | 'name': self.get_name(),
40 | 'tracks': self.get_tracks(),
41 | }
42 |
43 |
44 | def generate_setter_getter():
45 | playlist = Playlist()
46 | print(playlist.__dict__)
47 | for k in playlist.__dict__:
48 | print("def set_" + k + "(self," + k + "):")
49 | print("\tself." + k, "=" + k)
50 | print("def get_" + k + "(self):")
51 | print("\treturn self." + k)
52 |
53 |
54 | def generate_to_string():
55 | playlist = Playlist()
56 | print(playlist.__dict__)
57 | result = 'def to_string(self):\n'
58 | result += '\treturn json.dumps({\n'
59 | for k in playlist.__dict__:
60 | result += "\t\t'" + k + "'" + ":" + " self.get_" + k + "(),\n"
61 | result += "\t}, ensure_ascii=False)"
62 | print(result)
63 |
64 |
65 | def generate_to_json():
66 | playlist = Playlist()
67 | print(playlist.__dict__)
68 | result = 'def to_json(self):\n'
69 | result += '\treturn {\n'
70 | for k in playlist.__dict__:
71 | result += "\t\t'" + k + "'" + ":" + " self.get_" + k + "(),\n"
72 | result += "\t}"
73 | print(result)
74 |
75 |
76 | # def test_dict_to_object():
77 | # playlist_dict = {'id': 514235010, 'fee': 4, 'payed': 5, 'st': 0, 'pl': 999000, 'dl': 999000, 'sp': 7, 'cp': 1,
78 | # 'subp': 1, 'cs': False, 'maxbr': 999000, 'fl': 0, 'toast': False, 'flag': 0}
79 | # playlist = Playlist.dict_to_object(playlist_dict, Playlist())
80 | # print(playlist.to_json())
81 | # print(playlist.to_string())
82 |
83 |
84 | if __name__ == '__main__':
85 | # generate_setter_getter()
86 | # generate_to_string()
87 | # generate_to_json()
88 | # test_dict_to_object()
89 | pass
90 |
--------------------------------------------------------------------------------
/model/Privilege.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 |
4 | class Privilege(object):
5 |
6 | def __init__(self):
7 | self.id = None
8 | self.fee = None
9 | self.payed = None
10 | self.st = None
11 | self.pl = None
12 | self.dl = None
13 | self.sp = None
14 | self.cp = None
15 | self.subp = None
16 | self.cs = None
17 | self.maxbr = None
18 | self.fl = None
19 | self.toast = None
20 | self.flag = None
21 |
22 | def set_id(self, id):
23 | self.id = id
24 |
25 | def get_id(self):
26 | return self.id
27 |
28 | def set_fee(self, fee):
29 | self.fee = fee
30 |
31 | def get_fee(self):
32 | return self.fee
33 |
34 | def set_payed(self, payed):
35 | self.payed = payed
36 |
37 | def get_payed(self):
38 | return self.payed
39 |
40 | def set_st(self, st):
41 | self.st = st
42 |
43 | def get_st(self):
44 | return self.st
45 |
46 | def set_pl(self, pl):
47 | self.pl = pl
48 |
49 | def get_pl(self):
50 | return self.pl
51 |
52 | def set_dl(self, dl):
53 | self.dl = dl
54 |
55 | def get_dl(self):
56 | return self.dl
57 |
58 | def set_sp(self, sp):
59 | self.sp = sp
60 |
61 | def get_sp(self):
62 | return self.sp
63 |
64 | def set_cp(self, cp):
65 | self.cp = cp
66 |
67 | def get_cp(self):
68 | return self.cp
69 |
70 | def set_subp(self, subp):
71 | self.subp = subp
72 |
73 | def get_subp(self):
74 | return self.subp
75 |
76 | def set_cs(self, cs):
77 | self.cs = cs
78 |
79 | def get_cs(self):
80 | return self.cs
81 |
82 | def set_maxbr(self, maxbr):
83 | self.maxbr = maxbr
84 |
85 | def get_maxbr(self):
86 | return self.maxbr
87 |
88 | def set_fl(self, fl):
89 | self.fl = fl
90 |
91 | def get_fl(self):
92 | return self.fl
93 |
94 | def set_toast(self, toast):
95 | self.toast = toast
96 |
97 | def get_toast(self):
98 | return self.toast
99 |
100 | def set_flag(self, flag):
101 | self.flag = flag
102 |
103 | def get_flag(self):
104 | return self.flag
105 |
106 | def dict_to_object(dictObject: dict, object):
107 | for k, v in dictObject.items():
108 | object.__dict__[k] = v
109 | return object
110 |
111 | def to_string(self):
112 | return json.dumps({
113 | 'id': self.get_id(),
114 | 'fee': self.get_fee(),
115 | 'payed': self.get_payed(),
116 | 'st': self.get_st(),
117 | 'pl': self.get_pl(),
118 | 'dl': self.get_dl(),
119 | 'sp': self.get_sp(),
120 | 'cp': self.get_cp(),
121 | 'subp': self.get_subp(),
122 | 'cs': self.get_cs(),
123 | 'maxbr': self.get_maxbr(),
124 | 'fl': self.get_fl(),
125 | 'toast': self.get_toast(),
126 | 'flag': self.get_flag(),
127 | }, ensure_ascii=False)
128 |
129 | def to_json(self):
130 | return {
131 | 'id': self.get_id(),
132 | 'fee': self.get_fee(),
133 | 'payed': self.get_payed(),
134 | 'st': self.get_st(),
135 | 'pl': self.get_pl(),
136 | 'dl': self.get_dl(),
137 | 'sp': self.get_sp(),
138 | 'cp': self.get_cp(),
139 | 'subp': self.get_subp(),
140 | 'cs': self.get_cs(),
141 | 'maxbr': self.get_maxbr(),
142 | 'fl': self.get_fl(),
143 | 'toast': self.get_toast(),
144 | 'flag': self.get_flag(),
145 | }
146 |
147 |
148 | def generate_setter_getter():
149 | privilege = Privilege()
150 | print(privilege.__dict__)
151 | for k in privilege.__dict__:
152 | print("def set_" + k + "(self," + k + "):")
153 | print("\tself." + k, "=" + k)
154 | print("def get_" + k + "(self):")
155 | print("\treturn self." + k)
156 |
157 |
158 | def generate_to_string():
159 | privilege = Privilege()
160 | print(privilege.__dict__)
161 | result = 'def to_string(self):\n'
162 | result += '\treturn json.dumps({\n'
163 | for k in privilege.__dict__:
164 | result += "\t\t'" + k + "'" + ":" + " self.get_" + k + "(),\n"
165 | result += "\t}, ensure_ascii=False)"
166 | print(result)
167 |
168 |
169 | def generate_to_json():
170 | privilege = Privilege()
171 | print(privilege.__dict__)
172 | result = 'def to_json(self):\n'
173 | result += '\treturn {\n'
174 | for k in privilege.__dict__:
175 | result += "\t\t'" + k + "'" + ":" + " self.get_" + k + "(),\n"
176 | result += "\t}"
177 | print(result)
178 |
179 |
180 | def test_dict_to_object():
181 | privilege_dict = {'id': 514235010, 'fee': 4, 'payed': 5, 'st': 0, 'pl': 999000, 'dl': 999000, 'sp': 7, 'cp': 1,
182 | 'subp': 1, 'cs': False, 'maxbr': 999000, 'fl': 0, 'toast': False, 'flag': 0}
183 | privilege = Privilege.dict_to_object(privilege_dict, Privilege())
184 | print(privilege.to_json())
185 | print(privilege.to_string())
186 |
187 |
188 | if __name__ == '__main__':
189 | # generate_setter_getter()
190 | # generate_to_string()
191 | # generate_to_json()
192 | test_dict_to_object()
193 |
--------------------------------------------------------------------------------
/model/Song.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | from model.Album import Album
4 | from model.Privilege import Privilege
5 |
6 |
7 | class Song(object):
8 | """
9 | 音乐实体类,存放音乐信息
10 | """
11 |
12 | def __init__(self):
13 | self.id = None
14 | self.name = None
15 | self.url = None
16 | self.duration = None
17 | self.lyric = None
18 | self.picture_url = None
19 | self.artist = None
20 | self.album = Album()
21 | self.privilege = Privilege()
22 |
23 | def get_id(self):
24 | return self.id
25 |
26 | def get_name(self):
27 | return self.name
28 |
29 | def get_url(self):
30 | return self.url
31 |
32 | def get_duration(self):
33 | return self.duration
34 |
35 | def get_lyric(self):
36 | return self.lyric
37 |
38 | def get_picture_url(self):
39 | return self.picture_url
40 |
41 | def get_artist(self):
42 | return self.artist
43 |
44 | def get_album(self):
45 | return self.album
46 |
47 | def get_privilege(self):
48 | return self.privilege
49 |
50 | def set_id(self, id):
51 | self.id = id
52 |
53 | def set_name(self, name):
54 | self.name = name
55 |
56 | def set_url(self, url):
57 | self.url = url
58 |
59 | def set_duration(self, duration):
60 | self.duration = duration
61 |
62 | def set_lyric(self, lyric):
63 | self.lyric = lyric
64 |
65 | def set_picture_url(self, picture_url):
66 | self.picture_url = picture_url
67 |
68 | def set_artist(self, artist):
69 | self.artist = artist
70 |
71 | def set_album(self, album):
72 | self.album = album
73 |
74 | def set_privilege(self, privilege):
75 | self.privilege = privilege
76 |
77 | def to_string(self):
78 | return json.dumps({
79 | 'id': self.get_id(),
80 | 'name': self.get_name(),
81 | 'artist': self.get_artist(),
82 | 'url': self.get_url(),
83 | 'duration': self.get_duration(),
84 | 'lyric': self.get_lyric(),
85 | 'picture_url': self.get_picture_url(),
86 | 'album': self.get_album().to_string(),
87 | 'privilege': self.get_privilege().to_string()
88 | }, ensure_ascii=False)
89 |
90 | def to_json(self):
91 | return {
92 | 'id': self.get_id(),
93 | 'name': self.get_name(),
94 | 'artist': self.get_artist(),
95 | 'url': self.get_url(),
96 | 'duration': self.get_duration(),
97 | 'lyric': self.get_lyric(),
98 | 'picture_url': self.get_picture_url(),
99 | 'album': self.get_album().to_json(),
100 | 'privilege': self.get_privilege().to_json()
101 | }
102 |
103 | def dict_to_object(dictObject: dict, object):
104 | for k, v in dictObject.items():
105 | if k is 'album':
106 | object.__dict__[k] = Album.dict_to_object(v, Album())
107 | elif k is 'privilege':
108 | object.__dict__[k] = Privilege.dict_to_object(v, Privilege())
109 | else:
110 | object.__dict__[k] = v
111 | return object
112 |
--------------------------------------------------------------------------------
/model/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/model/__init__.py
--------------------------------------------------------------------------------
/netease/Api.py:
--------------------------------------------------------------------------------
1 | """
2 | -------------------------------------------------
3 | File Name : Api.py
4 | Description : netease api,请求方式,加密方式都在这里
5 | Author : H
6 | Date : 2019/11/30
7 | -------------------------------------------------
8 | """
9 |
10 | import json
11 |
12 | import requests
13 |
14 | import netease.Encrypt as netease
15 | from util.LogHandler import LogHandler
16 |
17 | BASE_URL = "http://music.163.com"
18 | DEFAULT_TIMEOUT = 10
19 |
20 | POST = "POST"
21 | GET = "GET"
22 |
23 |
24 | class NetEase(object):
25 |
26 | def __init__(self):
27 | """
28 | 构造默认 header request session
29 | """
30 | self.header = {
31 | "Accept": "*/*",
32 | "Accept-Encoding": "gzip,deflate,sdch",
33 | "Accept-Language": "zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4",
34 | "Connection": "keep-alive",
35 | "Content-Type": "application/x-www-form-urlencoded",
36 | "Host": "music.163.com",
37 | "Referer": "http://music.163.com",
38 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
39 | }
40 | self.session = requests.session()
41 | self.log = LogHandler('NeteaseApi')
42 |
43 | def _raw_request(self, method, url, data=None):
44 | """
45 | 实际发起请求方法
46 | :param method: POST | GET
47 | :param url: url
48 | :param data: 请求携带的数据
49 | :return: response
50 | """
51 | if method == "GET":
52 | response = self.session.get(
53 | url, params=data, headers=self.header, timeout=DEFAULT_TIMEOUT
54 | )
55 | elif method == "POST":
56 | response = self.session.post(
57 | url, data=data, headers=self.header, timeout=DEFAULT_TIMEOUT
58 | )
59 | return response
60 |
61 | def _get_form_data(self, encrypt_data):
62 | """
63 | 获取加密后的 form data 参数
64 | :param encrypt_data: 待加密的参数
65 | :return: 加密后的参数 {"params":"", "encSecKey":""}
66 | """
67 | key = netease.create_key(16)
68 | return {
69 | "params": netease.aes(netease.aes(encrypt_data, netease.NONCE), key),
70 | "encSecKey": netease.rsa(key, netease.PUBKEY, netease.MODULUS)
71 | }
72 |
73 | def request(self, method, path, data={}, default={"code": -1}):
74 | """
75 | 统一请求方法
76 | :param method: POST | GET
77 | :param path: 路径
78 | :param data: 未加密的 data
79 | :param default: 默认的 response
80 | :return: response
81 | """
82 | url = "{}{}".format(BASE_URL, path)
83 | response = default
84 | csrf_token = ""
85 |
86 | data.update({"csrf_token": csrf_token})
87 | params = self._get_form_data(json.dumps(data).encode('utf-8'))
88 | try:
89 | self.log.debug('[Netease api] url: {};\trequest data: {};\tparams: {}'.format(url, data, params))
90 | response = self._raw_request(method, url, params)
91 | response = response.json()
92 | self.log.debug('[Netease api] url: {};\tresponse data: {}'.format(url, response))
93 | except requests.exceptions.RequestException as e:
94 | self.log.error('[Netease api] request error: {}'.format(e))
95 | except ValueError as e:
96 | self.log.error("[Netease api] request error; Path: {}, response: {}".format(path, response.text[:200]))
97 | finally:
98 | return response
99 |
100 | def songs_url(self, song_id):
101 | """
102 | 获取音乐的实际 url,外链
103 | {ids: "[514235010]", level: "standard", encodeType: "aac", csrf_token: ""}
104 | :param song_id: 音乐 id
105 | :return: 带有外链的 json 串
106 | """
107 | path = "/weapi/song/enhance/player/url/v1?csrf_token="
108 | params = {
109 | 'ids': '[' + str(song_id) + ']',
110 | 'level': 'standard',
111 | 'encodeType': 'aac',
112 | 'csrf_token': ''
113 | }
114 | return self.request(POST, path, params)
115 |
116 | def songs_lyric(self, song_id):
117 | """
118 | 获取音乐歌词
119 | {id: "186453", lv: -1, tv: -1, csrf_token: ""}
120 | :param song_id:
121 | :return:
122 | """
123 | path = "/weapi/song/lyric?csrf_token="
124 | params = {
125 | 'id': str(song_id),
126 | 'lv': -1,
127 | 'tv': -1,
128 | 'csrf_token': ''
129 | }
130 | return self.request(POST, path, params)
131 |
132 | def songs_search(self, keyword, offset=0, limit=30):
133 | """
134 | 搜索音乐
135 | 按照关键字搜索一般就用这个
136 | {hlpretag: "", hlposttag: "", s: "春夏秋冬 张国荣", type: "1", offset: "0", …}
137 | :return:
138 | """
139 | path = '/weapi/cloudsearch/get/web?csrf_token='
140 | params = {
141 | 'csrf_token': '',
142 | 'hlposttag': '',
143 | 'hlpretag': '',
144 | 'limit': str(limit),
145 | 'offset': str(offset),
146 | 's': str(keyword),
147 | 'total': 'true',
148 | 'type': '1'
149 | }
150 | return self.request(POST, path, params)
151 |
152 | def songs_search_(self, song):
153 | """
154 | 搜索音乐,搜索框联动接口,不常用
155 | {s: "春夏秋冬", limit: "8", csrf_token: ""}
156 | :return:
157 | """
158 | path = "/weapi/search/suggest/web?csrf_token="
159 | params = {
160 | 's': str(song),
161 | 'limit': 8,
162 | 'csrf_token': ''
163 | }
164 | return self.request(POST, path, params)
165 |
166 | def songs_detail(self, song_id):
167 | """
168 | 获取歌曲详情
169 | 给定 song id
170 | {id: "186453", c: "[{"id":"186453"}]", csrf_token: ""}
171 | :param song_id: 必传参数,song id
172 | :return: Song
173 | """
174 | path = "/weapi/v3/song/detail?csrf_token="
175 | params = {
176 | 'id': str(song_id),
177 | 'c': "[{'id': " + str(song_id) + "}]",
178 | 'csrf_token': ''
179 | }
180 | return self.request(POST, path, params)
181 |
182 | def playlist_detail(self, playlist_id):
183 | """
184 | 获取歌单详情
185 | :param playlist_id: 歌单 id
186 | :return: json
187 | """
188 | path = "/weapi/playlist/detail"
189 | params = {
190 | 'id': str(playlist_id),
191 | 'ids': "[" + str(playlist_id) + "]",
192 | 'limit': 10000,
193 | 'offset': 0,
194 | 'csrf_token': ''
195 | }
196 | return self.request(POST, path, params)
197 |
198 |
199 | """
200 | ------------------------------------------------------------------------------------------------------------------------
201 | > <
202 | > The test case <
203 | > <
204 | 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
205 | """
206 |
207 |
208 | def start():
209 | pass
210 |
211 |
212 | if __name__ == '__main__':
213 | start()
214 |
--------------------------------------------------------------------------------
/netease/Encrypt.py:
--------------------------------------------------------------------------------
1 | """
2 | https://github.com/darknessomi/musicbox/wiki/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90API%E5%88%86%E6%9E%90
3 | """
4 |
5 | import base64
6 | import binascii
7 | import hashlib
8 | import json
9 | import os
10 |
11 | from Crypto.Cipher import AES
12 |
13 | MODULUS = (
14 | "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7"
15 | "b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280"
16 | "104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932"
17 | "575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b"
18 | "3ece0462db0a22b8e7"
19 | )
20 | PUBKEY = "010001"
21 | NONCE = b"0CoJUm6Qyw8W8jud"
22 |
23 |
24 | # encrypt
25 | def encrypt_data(text):
26 | data = json.dumps(text).encode("utf-8")
27 | secret = create_key(16)
28 | params = aes(aes(data, NONCE), secret)
29 | encseckey = rsa(secret, PUBKEY, MODULUS)
30 | return {"params": params, "encSecKey": encseckey}
31 |
32 |
33 | def aes(text, key):
34 | """
35 | @text: text
36 | @key: self.NONCE
37 | """
38 | pad = 16 - len(text) % 16
39 | text = text + bytearray([pad] * pad)
40 | encryptor = AES.new(key, 2, b"0102030405060708")
41 | ciphertext = encryptor.encrypt(text)
42 | return base64.b64encode(ciphertext)
43 |
44 |
45 | def rsa(text, pubkey, modulus):
46 | """
47 | @text: self.create_key()
48 | @pubkey: PUBKEY
49 | @modulus: MODULUS
50 | """
51 | text = text[::-1]
52 | rs = pow(int(binascii.hexlify(text), 16), int(pubkey, 16), int(modulus, 16))
53 | return format(rs, "x").zfill(256)
54 |
55 |
56 | def create_key(size):
57 | return binascii.hexlify(os.urandom(size))[:16]
58 |
59 |
60 | def encrypted_id(id):
61 | magic = bytearray("3go8&$8*3*3h0k(2)2", "u8")
62 | song_id = bytearray(id, "u8")
63 | magic_len = len(magic)
64 | for i, sid in enumerate(song_id):
65 | song_id[i] = sid ^ magic[i % magic_len]
66 | m = hashlib.md5(song_id)
67 | result = m.digest()
68 | result = base64.b64encode(result).replace(b"/", b"_").replace(b"+", b"-")
69 | return result.decode("utf-8")
70 |
--------------------------------------------------------------------------------
/netease/Setting.py:
--------------------------------------------------------------------------------
1 | SONGS_ID = [
2 | "36270426",
3 | "418602088",
4 | "519265246",
5 | "536243886",
6 | "29459692",
7 | "545947135",
8 | "36990266",
9 | "515452048",
10 | "526472185",
11 | "29910080",
12 | "515540639",
13 | "528273377",
14 | "1333160781",
15 | "478056436",
16 | "515453363",
17 | "476324207",
18 | "472141627",
19 | "506092035",
20 | "507134193",
21 | "1347814906",
22 | "1355149745",
23 | "1296410418",
24 | "529557738",
25 | "1312710726",
26 | "29732106",
27 | "415792222",
28 | "26292065",
29 | "493394429",
30 | "1309975421",
31 | "538470558",
32 | "540333737",
33 | "31877683",
34 | "543987451",
35 | "31010713",
36 | "1310022346",
37 | "572763271",
38 | "447925342",
39 | "1338119851",
40 | "437909145",
41 | "546722490",
42 | "1301572562",
43 | "1348792318",
44 | "1344353899",
45 | "1347684016",
46 | "1314777725",
47 | "1331192365",
48 | "441116579",
49 | "543203947",
50 | "1320908673",
51 | "33522489",
52 | "522353191",
53 | "1334248838",
54 | "487375361",
55 | "547976140",
56 | "29497338",
57 | "347230",
58 | "186436",
59 | "191232",
60 | "212233",
61 | "298880",
62 | "316938",
63 | "66282",
64 | "32705017",
65 | "110146",
66 | "65766",
67 | "65800",
68 | "513791211",
69 | "166432",
70 | "409916250",
71 | "518781004",
72 | "477933952",
73 | "571553649",
74 | "1355197518",
75 | "468513829",
76 | "1369798757",
77 | "27888500",
78 | "479422643",
79 | "526412160",
80 | "28250504",
81 | "420125895",
82 | "406318298",
83 | "392605",
84 | "97357",
85 | "167975",
86 | "1381049131",
87 | "1397674264",
88 | "86369",
89 | "569213220",
90 | "1359595520",
91 | "1363948882",
92 | "1399533630",
93 | "411214279",
94 | "347230",
95 | "31654343",
96 | "1392990601",
97 | "529823971",
98 | "1305366556",
99 | "1334295185",
100 | "65766",
101 | "1396973729",
102 | "426291544",
103 | "36270426",
104 | "1362247767",
105 | "1361348080",
106 | "482988834",
107 | "25706282",
108 | "483671599",
109 | "191528",
110 | "1330348068",
111 | "65800",
112 | "522510615",
113 | "1313354324",
114 | "31445554",
115 | "518725853",
116 | "442869203",
117 | "167876",
118 | "29019227",
119 | "169185",
120 | "1376142151",
121 | "202373",
122 | "1335350269",
123 | "28639182",
124 | "63650",
125 | "542690276",
126 | "1357785909",
127 | "1296583188",
128 | "502043537",
129 | "1365898499",
130 | "490407216",
131 | "410801653",
132 | "25727803",
133 | "1365221826",
134 | "1308818967",
135 | "1391639224",
136 | "472045959",
137 | "1300994613",
138 | "29947420",
139 | "1395252835",
140 | "536502758",
141 | "1313107065",
142 | "509313150",
143 | "1357999894",
144 | "333750",
145 | "480353",
146 | "1384570191",
147 | "1355147933",
148 | "501133798",
149 | "1383927341",
150 | "308353",
151 | "1381761209",
152 | "1386056380",
153 | "1325896149",
154 | "1359356908",
155 | "224000",
156 | "287063",
157 | "28907016",
158 | "26830207",
159 | "27946894",
160 | "5308028",
161 | "33937527",
162 | "4341314",
163 | "31654455",
164 | "38019092",
165 | "29717271",
166 | "22212233",
167 | "2866921",
168 | "4940920",
169 | "4017240",
170 | "1385367710",
171 | "513791211",
172 | "1383001696",
173 | "5260494",
174 | "1373228477",
175 | "2740360",
176 | "450853439",
177 | "1381755293",
178 | "424264505",
179 | "461083054",
180 | "506196018",
181 | "557584658",
182 | "31654478",
183 | "440208476",
184 | "452986458",
185 | "33211676",
186 | "461347998",
187 | "26092806",
188 | "505449407",
189 | "3935139",
190 | "26199445",
191 | "139774",
192 | "37653063",
193 | "31356499",
194 | "29750825",
195 | "19542337",
196 | "536622304",
197 | "38592976",
198 | "33911781",
199 | "586299",
200 | "496869422",
201 | "423228325",
202 | "472361096"
203 | ]
204 |
205 | SONG_NAME = [
206 | "春夏秋冬"
207 | ]
--------------------------------------------------------------------------------
/netease/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/netease/__init__.py
--------------------------------------------------------------------------------
/netease/__test__.py:
--------------------------------------------------------------------------------
1 | """
2 | -------------------------------------------------
3 | File Name : __test__.py
4 | Description : Api.py 的测试用例
5 | Author : H
6 | Date : 2019/12/1
7 | -------------------------------------------------
8 | """
9 |
10 | import math
11 | import random
12 | import time
13 |
14 | from netease.Api import NetEase
15 | from netease.Setting import *
16 |
17 | SONGS_ID = SONGS_ID
18 | SONG_NAME = SONG_NAME
19 |
20 |
21 | def test_song_url():
22 | netease = NetEase()
23 | for i in SONGS_ID:
24 | response = netease.songs_url(i)
25 | if response.get('code') is not None and response.get('code') is -1:
26 | print('error')
27 | break
28 | random_number = math.floor(random.random() * 5) + 1
29 | print('第 {} 首音乐,代码 {},休眠 {} 秒钟后继续,response {}'.format(SONGS_ID.index(i) + 1, i, random_number, response))
30 | time.sleep(random_number)
31 |
32 |
33 | def test_song_lyric(SONGS_ID=['186453', '316686']):
34 | netease = NetEase()
35 | for i in SONGS_ID:
36 | response = netease.songs_lyric(i)
37 | if response.get('code') is not None and response.get('code') is -1:
38 | print('error')
39 | break
40 | random_number = math.floor(random.random() * 5) + 1
41 | print('第 {} 首音乐,代码 {},休眠 {} 秒钟后继续,response {}'.format(SONGS_ID.index(i) + 1, i, random_number, response))
42 | time.sleep(random_number)
43 |
44 |
45 | def test_song_search():
46 | netease = NetEase()
47 | for i in SONG_NAME:
48 | response = netease.songs_search(i)
49 | if response.get('code') is not None and response.get('code') is -1:
50 | print('error')
51 | break
52 | random_number = math.floor(random.random() * 5) + 1
53 | print('第 {} 首音乐,代码 {},休眠 {} 秒钟后继续,response {}'.format(SONG_NAME.index(i) + 1, i, random_number, response))
54 | time.sleep(random_number)
55 |
56 |
57 | def test_songs_detail():
58 | netease = NetEase()
59 | response = netease.songs_detail('1379444316')
60 | print(response)
61 |
62 |
63 | def start():
64 | # test_song_url()
65 | test_song_lyric(['1379444316'])
66 | # test_song_search()
67 | # test_songs_detail()
68 |
69 |
70 | if __name__ == '__main__':
71 | start()
72 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Click==7.0
2 | Flask==0.12
3 | requests==2.20.0
4 | gunicorn==19.9.0
5 | pycryptodome==3.9.4
--------------------------------------------------------------------------------
/resolve/NeteaseResolver.py:
--------------------------------------------------------------------------------
1 | """
2 | -------------------------------------------------
3 | File Name : NeteaseResolver.py
4 | Description : netease api 解析
5 | Author : H
6 | Date : 2019/12/2
7 | -------------------------------------------------
8 | """
9 | from exception.NeteaseResolverException import NeteaseResolverException
10 | from model.Album import Album
11 | from model.Song import Song
12 | from model.Privilege import Privilege
13 | from model.Playlist import Playlist
14 |
15 |
16 | class NeteaseResolver(object):
17 | """netease 解析器"""
18 |
19 | def __init__(self):
20 | pass
21 |
22 | @staticmethod
23 | def song_url_resolver(song=Song(), json={}):
24 | """
25 | 解析 netease 歌曲 api 的响应结果
26 | 解析目标:音乐 id,音乐 url
27 | :param song: 解析结果
28 | :param json: netease api 响应 json 串
29 | :return: Song
30 | """
31 | try:
32 | json = json.get('data')
33 |
34 | if isinstance(json, list) and len(json) < 1:
35 | return song
36 |
37 | if isinstance(json, list) and len(json) > 0:
38 | json = json[0]
39 |
40 | song.set_id(json.get('id'))
41 | song.set_url(json.get('url'))
42 | except Exception as e:
43 | raise NeteaseResolverException('resolver exception; song: {}, json: {}'.format(song, json))
44 | finally:
45 | return song
46 |
47 | @staticmethod
48 | def song_lyric_resolver(song=Song(), json={}):
49 | """
50 | 解析 netease 歌词 api 的响应结果
51 | 可以拿到:原生歌词信息
52 | :param song: 解析结果
53 | :param json: netease api 响应 json 串
54 | :return: Song
55 | """
56 | try:
57 | lrc_json = json.get('lrc')
58 | if json is None or json.get('nolyric') is True:
59 | song.set_lyric(None)
60 | else:
61 | song.set_lyric(lrc_json.get('lyric'))
62 | except Exception as e:
63 | raise NeteaseResolverException('resolver exception; song: {}, json: {}'.format(song, json))
64 | finally:
65 | return song
66 |
67 | @staticmethod
68 | def song_search_resolver(song=Song(), json={}):
69 | """
70 | 解析音乐的搜索结果
71 | 重点拿到 id 就好了,其余的交给 detail 去解析
72 | :param song:
73 | :param json:
74 | :return:
75 | """
76 | try:
77 | json = json.get('result')
78 | json = json.get('songs')
79 | if isinstance(json, list) and len(json) > 0:
80 | json = json[0]
81 |
82 | song.set_id(json.get('id'))
83 | except Exception as e:
84 | raise NeteaseResolverException('resolver exception; song: {}, json: {}'.format(song, json))
85 | finally:
86 | return song
87 |
88 | @staticmethod
89 | def songs_search_resolver(json={}):
90 | """
91 | 解析音乐的搜索结果
92 | 重点拿到 id 就好了,其余的交给 detail 去解析
93 | :param song:
94 | :param json:
95 | :return:
96 | """
97 | result = {
98 | 'data': [],
99 | 'count': 0
100 | }
101 |
102 | try:
103 | if json.get('code') is 200:
104 | songs = json.get('result').get('songs')
105 | count = json.get('result').get('songCount')
106 | result['count'] = count
107 |
108 | for item in songs:
109 | song = Song()
110 | song.set_id(item.get('id'))
111 | song.set_name(item.get('name'))
112 | song.set_picture_url(item.get('al').get('picUrl'))
113 | song.set_duration(item.get('dt'))
114 | name = ''
115 | ars = item.get('ar')
116 | for ar in ars:
117 | if len(ars) - 1 is ars.index(ar):
118 | name += ar.get('name')
119 | else:
120 | name += ar.get('name') + '/'
121 | song.set_artist(name)
122 |
123 | album = Album()
124 | album.set_id(item.get('al').get('id'))
125 | album.set_name(item.get('al').get('name'))
126 | album.set_picture_url(item.get('al').get('picUrl'))
127 |
128 | song.set_album(album)
129 |
130 | privilege = Privilege.dict_to_object(item.get('privilege'), Privilege())
131 | song.set_privilege(privilege)
132 |
133 | result.get('data').append(song.to_json())
134 |
135 | except Exception as e:
136 | raise NeteaseResolverException('resolver exception; json: {}'.format(json))
137 | finally:
138 | return result
139 |
140 | @staticmethod
141 | def song_detail_resolver(song=Song(), json={}):
142 | """
143 | 解析歌曲详情
144 | 这里可以拿到:音乐名,音乐id,音乐时长,艺人,专辑名,专辑图片,专辑id
145 | :param song:
146 | :param json:
147 | :return:
148 | """
149 | try:
150 | json = json.get('songs')
151 |
152 | if isinstance(json, list) and len(json) > 0:
153 | json = json[0]
154 |
155 | album_json = json.get('al')
156 | artist_json = json.get('ar')
157 | if isinstance(artist_json, list) and len(artist_json) > 0:
158 | artist_json = artist_json[0]
159 |
160 | song.set_name(json.get('name'))
161 | song.set_id(json.get('id'))
162 | song.set_duration(json.get('dt'))
163 | song.set_picture_url(album_json.get('picUrl'))
164 | song.set_artist(artist_json.get('name'))
165 |
166 | album = Album()
167 | album.set_id(album_json.get('id'))
168 | album.set_name(album_json.get('name'))
169 | album.set_artist(artist_json.get('name'))
170 | album.set_picture_url(album_json.get('picUrl'))
171 | song.set_album(album)
172 |
173 | except Exception as e:
174 | raise NeteaseResolverException('resolver exception; song: {}, json: {}'.format(song, json))
175 | finally:
176 | return song
177 |
178 | @staticmethod
179 | def playlist_songs_resolver(json={}):
180 | """
181 | 解析歌单音乐列表
182 | :param json:
183 | :return:
184 | """
185 | playlist = Playlist()
186 | print(json)
187 |
188 | if json.get('code') is 200:
189 | playlist.set_id(json.get('result').get('id'))
190 | playlist.set_name(json.get('result').get('name'))
191 | playlist.set_tracks(json.get('result').get('tracks'))
192 |
193 | return playlist
194 |
--------------------------------------------------------------------------------
/resolve/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/resolve/__init__.py
--------------------------------------------------------------------------------
/resolve/__test__.py:
--------------------------------------------------------------------------------
1 | """
2 | ------------------------------------------------------------------------------------------------------------------------
3 | > <
4 | > The test case <
5 | > <
6 | 👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇
7 | """
8 |
9 | from model.Song import Song
10 | from resolve.NeteaseResolver import NeteaseResolver
11 |
12 | SONG_URL_RESULT = {
13 | 'data': [{
14 | 'id': 36270426,
15 | 'url': 'http://m801.music.126.net/20191202003049/ea0c355e919bd40caac1546f8f782cf9/jdyyaac/0358/0709/5352/421539417c0cc8347406d8c3f0391dfd.m4a',
16 | 'br': 96000,
17 | 'size': 2989749,
18 | 'md5': '421539417c0cc8347406d8c3f0391dfd',
19 | 'code': 200,
20 | 'expi': 1200,
21 | 'type': 'm4a',
22 | 'gain': 0.0,
23 | 'fee': 8,
24 | 'uf': None,
25 | 'payed': 0,
26 | 'flag': 0,
27 | 'canExtend': False,
28 | 'freeTrialInfo': None,
29 | 'level': 'standard',
30 | 'encodeType': 'aac'
31 | }],
32 | 'code': 200
33 | }
34 |
35 | SONG_LYRICS_RESULT = {
36 | 'sgc': False,
37 | 'sfy': False,
38 | 'qfy': False,
39 | 'lyricUser': {
40 | 'id': 186453,
41 | 'status': 99,
42 | 'demand': 0,
43 | 'userid': 404241265,
44 | 'nickname': 'Monica12956',
45 | 'uptime': 1499330955480
46 | },
47 | 'lrc': {
48 | 'version': 10,
49 | 'lyric': '[by:Monica12956]\n[00:00.000] 作曲 : 叶良俊\n[00:01.000] 作词 : 林振强\n[00:06.00]编曲:陈伟文\n[00:14.00]秋天该很好 你若尚在场\n[00:22.00]秋风即使带凉 亦漂亮\n[00:29.00]深秋中的你填密我梦想\n[00:36.00]就像落叶飞 轻敲我窗\n[00:43.00]冬天该很好 你若尚在场\n[00:50.00]天空多灰 我们亦放亮\n[00:57.00]一起坐坐谈谈来日动向\n[01:04.00]漠视外间低温 这样唱\n[02:27.00][01:10.00]能同途偶遇在这星球上\n[02:33.00][01:16.00]燃亮飘渺人生\n[02:37.00][01:20.00]我多么够运\n[02:41.00][01:24.00]无人如你逗留我思潮上\n[02:47.00][01:30.00]从没再疑问\n[02:50.00][01:34.00]这个世界好得很\n[01:40.00]暑天该很好 你若尚在场\n[01:46.00]火一般的太阳在脸上\n[01:53.00]烧得肌肤如情 痕极又痒\n[02:00.00]滴着汗的一双 笑着唱\n[02:55.00]能同途偶遇在这星球上\n[03:02.00]是某种缘份\n[03:06.00]我多么庆幸\n[03:09.00]如离别 你亦长处心灵上\n[03:15.00]宁愿有遗憾\n[03:19.00]亦愿和你远亦近\n[03:25.00]春天该很好 你若尚 在场\n[03:32.00]春风仿佛爱情\n[03:35.00]在蕴酝\n[03:39.00]初春中的你 撩动我幻想\n[03:46.00]就像嫩绿草使\n[03:52.00]春雨香\n'
50 | },
51 | 'tlyric': {
52 | 'version': 0
53 | },
54 | 'code': 200
55 | }
56 |
57 | SONG_SEARCH_RESULT = {
58 | 'result': {
59 | 'songs': [{
60 | 'name': '春夏秋冬',
61 | 'id': 186453,
62 | 'pst': 0,
63 | 't': 0,
64 | 'ar': [{
65 | 'id': 6457,
66 | 'name': '张国荣',
67 | 'tns': [],
68 | 'alias': []
69 | }],
70 | 'alia': [],
71 | 'pop': 100.0,
72 | 'st': 0,
73 | 'rt': '',
74 | 'fee': 8,
75 | 'v': 208,
76 | 'crbt': None,
77 | 'cf': '',
78 | 'al': {
79 | 'id': 18937,
80 | 'name': 'I Am What I Am',
81 | 'picUrl': 'http://p2.music.126.net/2YIpNoCzXfYgz4zIw3s0Vg==/73667279073787.jpg',
82 | 'tns': [],
83 | 'pic': 73667279073787
84 | },
85 | 'dt': 250586,
86 | 'h': {
87 | 'br': 320000,
88 | 'fid': 0,
89 | 'size': 10025839,
90 | 'vd': 7200.0
91 | },
92 | 'm': {
93 | 'br': 192000,
94 | 'fid': 0,
95 | 'size': 6015520,
96 | 'vd': 9700.0
97 | },
98 | 'l': {
99 | 'br': 128000,
100 | 'fid': 0,
101 | 'size': 4010361,
102 | 'vd': 11399.0
103 | },
104 | 'a': None,
105 | 'cd': '1',
106 | 'no': 13,
107 | 'rtUrl': None,
108 | 'ftype': 0,
109 | 'rtUrls': [],
110 | 'djId': 0,
111 | 'copyright': 1,
112 | 's_id': 0,
113 | 'mark': 8192,
114 | 'rtype': 0,
115 | 'rurl': None,
116 | 'mst': 9,
117 | 'cp': 7003,
118 | 'mv': 5570704,
119 | 'publishTime': 1269273600000,
120 | 'privilege': {
121 | 'id': 186453,
122 | 'fee': 8,
123 | 'payed': 0,
124 | 'st': 0,
125 | 'pl': 128000,
126 | 'dl': 0,
127 | 'sp': 7,
128 | 'cp': 1,
129 | 'subp': 1,
130 | 'cs': False,
131 | 'maxbr': 999000,
132 | 'fl': 128000,
133 | 'toast': False,
134 | 'flag': 4
135 | }
136 | }],
137 | 'songCount': '600'
138 | },
139 | 'code': '200'
140 | }
141 |
142 | SONG_DETAIL_RESULT = a = {
143 | 'songs': [{
144 | 'name': '差不多姑娘',
145 | 'id': 1379444316,
146 | 'pst': 0,
147 | 't': 0,
148 | 'ar': [{
149 | 'id': 7763,
150 | 'name': 'G.E.M.邓紫棋',
151 | 'tns': [],
152 | 'alias': []
153 | }],
154 | 'alia': [],
155 | 'pop': 100.0,
156 | 'st': 0,
157 | 'rt': '',
158 | 'fee': 0,
159 | 'v': 7,
160 | 'crbt': None,
161 | 'cf': '',
162 | 'al': {
163 | 'id': 80536158,
164 | 'name': '差不多姑娘',
165 | 'picUrl': 'http://p1.music.126.net/9K3XB_8nwqQwbWdt-Suj-w==/109951164231366714.jpg',
166 | 'tns': [],
167 | 'pic_str': '109951164231366714',
168 | 'pic': 109951164231366714
169 | },
170 | 'dt': 230008,
171 | 'h': {
172 | 'br': 320000,
173 | 'fid': 0,
174 | 'size': 9202460,
175 | 'vd': -39996.0
176 | },
177 | 'm': {
178 | 'br': 192000,
179 | 'fid': 0,
180 | 'size': 5521493,
181 | 'vd': -37471.0
182 | },
183 | 'l': {
184 | 'br': 128000,
185 | 'fid': 0,
186 | 'size': 3681010,
187 | 'vd': -35861.0
188 | },
189 | 'a': None,
190 | 'cd': '01',
191 | 'no': 1,
192 | 'rtUrl': None,
193 | 'ftype': 0,
194 | 'rtUrls': [],
195 | 'djId': 0,
196 | 'copyright': 0,
197 | 's_id': 0,
198 | 'mark': 16,
199 | 'mst': 9,
200 | 'cp': 1416446,
201 | 'mv': 10880291,
202 | 'rtype': 0,
203 | 'rurl': None,
204 | 'publishTime': 0
205 | }],
206 | 'privileges': [{
207 | 'id': 1379444316,
208 | 'fee': 0,
209 | 'payed': 0,
210 | 'st': 0,
211 | 'pl': 320000,
212 | 'dl': 0,
213 | 'sp': 7,
214 | 'cp': 1,
215 | 'subp': 1,
216 | 'cs': False,
217 | 'maxbr': 320000,
218 | 'fl': 999000,
219 | 'toast': False,
220 | 'flag': 0,
221 | 'preSell': False
222 | }],
223 | 'code': 200
224 | }
225 |
226 |
227 | def test_song_url_resolver(song=Song()):
228 | resolver = NeteaseResolver.song_url_resolver(song, SONG_URL_RESULT)
229 | print(resolver.to_string())
230 | return resolver
231 |
232 |
233 | def test_song_lyric_resolver(song=Song()):
234 | resolver = NeteaseResolver.song_lyric_resolver(song, SONG_LYRICS_RESULT)
235 | print(resolver.to_string())
236 | return resolver
237 |
238 |
239 | def test_song_search_resolver(song=Song()):
240 | resolver = NeteaseResolver.song_search_resolver(song, SONG_SEARCH_RESULT)
241 | print(resolver.to_string())
242 | return resolver
243 |
244 |
245 | def test_song_detail_resolver(song=Song()):
246 | resolver = NeteaseResolver.song_detail_resolver(song, SONG_DETAIL_RESULT)
247 | print(resolver.to_string())
248 | return resolver
249 |
250 |
251 | def start():
252 | song = Song()
253 | song = test_song_search_resolver(song)
254 | song = test_song_url_resolver(song)
255 | song = test_song_lyric_resolver(song)
256 | song = test_song_detail_resolver(song)
257 | print(song.to_string())
258 |
259 |
260 | if __name__ == '__main__':
261 | start()
262 |
--------------------------------------------------------------------------------
/service/MusicooService.py:
--------------------------------------------------------------------------------
1 | """
2 | -------------------------------------------------
3 | File Name : MusicooService.py
4 | Description : 接口业务具体处理
5 | Author : H
6 | Date : 2019/12/2
7 | -------------------------------------------------
8 | """
9 |
10 | from model.Song import Song
11 | from netease.Api import NetEase
12 | from resolve.NeteaseResolver import NeteaseResolver
13 |
14 |
15 | class MusicooService(object):
16 |
17 | @staticmethod
18 | def song_url(song_id, song=Song()):
19 | """
20 | song url service
21 | 获取音乐链接
22 | https://github.com/hanhuoer/Musicoo/wiki/web-api#1-%E8%8E%B7%E5%8F%96%E9%9F%B3%E4%B9%90%E9%93%BE%E6%8E%A5
23 | :param song_id:
24 | :param song:
25 | :return:
26 | """
27 | netease = NetEase()
28 | result = netease.songs_url(str(song_id))
29 | song = NeteaseResolver.song_url_resolver(song, result)
30 | return song
31 |
32 | @staticmethod
33 | def song_lyric(song_id, song=Song()):
34 | """
35 | song lyric service
36 | 获取歌词
37 | https://github.com/hanhuoer/Musicoo/wiki/web-api#2-%E6%AD%8C%E8%AF%8D
38 | :param song_id:
39 | :param song:
40 | :return:
41 | """
42 | netease = NetEase()
43 | result = netease.songs_lyric(str(song_id))
44 | song = NeteaseResolver.song_lyric_resolver(song, result)
45 | song.set_id(song_id)
46 | return song
47 |
48 | @staticmethod
49 | def song_search(keyword, song=Song()):
50 | """
51 | song search service
52 | 搜索音乐
53 | https://github.com/hanhuoer/Musicoo/wiki/web-api#3-%E9%9F%B3%E4%B9%90%E8%AF%A6%E6%83%85
54 | :param keyword:
55 | :param song:
56 | :return:
57 | """
58 | netease = NetEase()
59 | result = netease.songs_search(keyword)
60 | song = NeteaseResolver.song_search_resolver(song, result)
61 | return song
62 |
63 | @staticmethod
64 | def songs_search(keyword, offset=0, limit=30):
65 | """
66 | songs search service
67 | 搜索音乐
68 | https://github.com/hanhuoer/Musicoo/wiki/web-api#3-%E9%9F%B3%E4%B9%90%E8%AF%A6%E6%83%85
69 | :param limit:
70 | :param offset:
71 | :param keyword:
72 | :param song:
73 | :return:
74 | """
75 |
76 | netease = NetEase()
77 | result = netease.songs_search(keyword, offset=offset, limit=limit)
78 | return NeteaseResolver.songs_search_resolver(result)
79 |
80 | @staticmethod
81 | def song_detail(song_id, song=Song()):
82 | """
83 | song detail service
84 | 获取音乐信息
85 | https://github.com/hanhuoer/Musicoo/wiki/web-api#4-%E9%9F%B3%E4%B9%90%E6%90%9C%E7%B4%A2
86 | :param song_id:
87 | :param song: [optional]
88 | :return:
89 | """
90 | netease = NetEase()
91 | result = netease.songs_detail(song_id)
92 | song = NeteaseResolver.song_detail_resolver(song, result)
93 | return song
94 |
95 | @staticmethod
96 | def song(keyword, song=Song()):
97 | """
98 | song service
99 | 获取音乐
100 | https://github.com/hanhuoer/Musicoo/wiki/web-api#5-%E8%8E%B7%E5%8F%96%E9%9F%B3%E4%B9%90
101 | :param keyword: 关键字
102 | :param song: [optional]
103 | :return:
104 | """
105 | search_results = MusicooService.songs_search(keyword, 0, 10)
106 | if search_results.get('count') > 0:
107 | song = Song.dict_to_object(search_results.get('data')[0], Song())
108 | song = MusicooService.song_url(song.get_id(), song)
109 | song = MusicooService.song_lyric(song.get_id(), song)
110 | song = MusicooService.song_detail(song.get_id(), song)
111 | else:
112 | pass
113 | return song
114 |
115 | @staticmethod
116 | def playlist_songs(playlist_id):
117 | """
118 | playlist songs
119 | 获取歌单音乐列表
120 | :param playlist_id: 歌单 id
121 | :return: See: Playlist.py
122 | """
123 |
124 | netease = NetEase()
125 | result = netease.playlist_detail(playlist_id)
126 | return NeteaseResolver.playlist_songs_resolver(result)
127 |
--------------------------------------------------------------------------------
/service/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/service/__init__.py
--------------------------------------------------------------------------------
/start/Musicoo.py:
--------------------------------------------------------------------------------
1 | import platform
2 | import sys
3 |
4 | import click
5 |
6 | sys.path.append('../')
7 |
8 | from api.MusicooApi import run, run_
9 | from config.Setting import BANNER
10 | from config.Getter import ConfigGetter
11 |
12 | CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
13 |
14 |
15 | @click.group(context_settings=CONTEXT_SETTINGS)
16 | @click.version_option(version='2.0.0')
17 | def cli():
18 | """Musicoo tool"""
19 |
20 |
21 | @cli.command(name="run")
22 | @click.option('--host', default=None, help='Number of greetings.')
23 | @click.option('--port', default=None, help='Number of greetings.')
24 | def server(host, port):
25 | """start the web server"""
26 | click.echo(BANNER)
27 | if platform.system() == "Windows":
28 | run(host, port)
29 | else:
30 | run_(host, port)
31 |
32 |
33 | if __name__ == '__main__':
34 | cli()
35 |
--------------------------------------------------------------------------------
/start/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/start/__init__.py
--------------------------------------------------------------------------------
/util/ClassUtils.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # !/usr/bin/env python
3 |
4 | """
5 |
6 | """
7 |
8 |
9 | class LazyProperty(object):
10 | """
11 | LazyProperty
12 | explain: http://www.spiderpy.cn/blog/5/
13 | """
14 |
15 | def __init__(self, func):
16 | self.func = func
17 |
18 | def __get__(self, instance, owner):
19 | if instance is None:
20 | return self
21 | else:
22 | value = self.func(instance)
23 | setattr(instance, self.func.__name__, value)
24 | return value
25 |
26 |
27 | class Singleton(type):
28 | """
29 | Singleton Metaclass
30 | """
31 |
32 | _inst = {}
33 |
34 | def __call__(cls, *args, **kwargs):
35 | if cls not in cls._inst:
36 | cls._inst[cls] = super(Singleton, cls).__call__(*args)
37 | return cls._inst[cls]
38 |
--------------------------------------------------------------------------------
/util/LogHandler.py:
--------------------------------------------------------------------------------
1 | """
2 | Author: JHao
3 | """
4 |
5 | import logging
6 | import os
7 | from logging.handlers import TimedRotatingFileHandler
8 |
9 | # 日志级别
10 | CRITICAL = 50
11 | FATAL = CRITICAL
12 | ERROR = 40
13 | WARNING = 30
14 | WARN = WARNING
15 | INFO = 20
16 | DEBUG = 10
17 | NOTSET = 0
18 |
19 | CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
20 | ROOT_PATH = os.path.join(CURRENT_PATH, os.pardir)
21 | LOG_PATH = os.path.join(ROOT_PATH, 'log')
22 |
23 | if not os.path.exists(LOG_PATH):
24 | os.mkdir(LOG_PATH)
25 |
26 |
27 | class LogHandler(logging.Logger):
28 | """
29 | LogHandler
30 | """
31 |
32 | def __init__(self, name, level=DEBUG, stream=True, file=True):
33 | self.name = name
34 | self.level = level
35 | logging.Logger.__init__(self, self.name, level=level)
36 | if stream:
37 | self.__setStreamHandler__()
38 | if file:
39 | self.__setFileHandler__()
40 |
41 | def __setFileHandler__(self, level=None):
42 | """
43 | set file handler
44 | :param level:
45 | :return:
46 | """
47 | file_name = os.path.join(LOG_PATH, '{name}.log'.format(name=self.name))
48 | # 设置日志回滚, 保存在log目录, 一天保存一个文件, 保留15天
49 | file_handler = TimedRotatingFileHandler(filename=file_name, when='D', interval=1, backupCount=15)
50 | file_handler.suffix = '%Y%m%d.log'
51 | if not level:
52 | file_handler.setLevel(self.level)
53 | else:
54 | file_handler.setLevel(level)
55 | formatter = logging.Formatter(
56 | '%(asctime)s\t%(levelname)s\t---\t[\t\t\t\t%(filename)s:%(lineno)d]\t\t\t\t: %(message)s')
57 |
58 | file_handler.setFormatter(formatter)
59 | self.file_handler = file_handler
60 | self.addHandler(file_handler)
61 |
62 | def __setStreamHandler__(self, level=None):
63 | """
64 | set stream handler
65 | :param level:
66 | :return:
67 | """
68 | stream_handler = logging.StreamHandler()
69 | formatter = logging.Formatter(
70 | '%(asctime)s\t%(levelname)s\t---\t[\t\t\t\t%(filename)s:%(lineno)d]\t\t\t\t: %(message)s')
71 | stream_handler.setFormatter(formatter)
72 | if not level:
73 | stream_handler.setLevel(self.level)
74 | else:
75 | stream_handler.setLevel(level)
76 | self.addHandler(stream_handler)
77 |
78 | def reset_name(self, name):
79 | """
80 | reset name
81 | :param name:
82 | :return:
83 | """
84 | self.name = name
85 | self.removeHandler(self.file_handler)
86 | self.__setFileHandler__()
87 |
88 |
89 | if __name__ == '__main__':
90 | log = LogHandler('netease')
91 | for i in range(0, 10):
92 | log.info('netease')
93 | log.error('error')
94 | log.debug('debug')
95 | log.warning('warning')
96 |
--------------------------------------------------------------------------------
/util/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hanhuoer/Musicoo/fcb660ec15702f836cfd4534951f3b831483fd5d/util/__init__.py
--------------------------------------------------------------------------------