├── .gitattributes ├── .gitignore ├── DataStucture.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── LICENSE ├── LICENSE-Zony ├── LyricProcessor.cs ├── MusicBeeInterface.cs ├── NeteaseApi.cs ├── NeteaseLyrics.cs ├── NeteaseLyrics.csproj ├── NeteaseLyrics.sln ├── NeteaseMusicEncryptionHandler.cs ├── Properties └── AssemblyInfo.cs ├── README.MD ├── SearchMatch.cs ├── SearchMatchLegacy.cs ├── app.config └── packages.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # Build result!!!!!!!!!!!!!!!! 7 | pkg/ 8 | 9 | # User-specific files 10 | *.suo 11 | *.user 12 | *.userosscache 13 | *.sln.docstates 14 | 15 | # User-specific files (MonoDevelop/Xamarin Studio) 16 | *.userprefs 17 | 18 | # Build results 19 | [Dd]ebug/ 20 | [Dd]ebugPublic/ 21 | [Rr]elease/ 22 | [Rr]eleases/ 23 | x64/ 24 | x86/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # .NET Core 49 | project.lock.json 50 | project.fragment.lock.json 51 | artifacts/ 52 | **/Properties/launchSettings.json 53 | 54 | *_i.c 55 | *_p.c 56 | *_i.h 57 | *.ilk 58 | *.meta 59 | *.obj 60 | *.pch 61 | *.pdb 62 | *.pgc 63 | *.pgd 64 | *.rsp 65 | *.sbr 66 | *.tlb 67 | *.tli 68 | *.tlh 69 | *.tmp 70 | *.tmp_proj 71 | *.log 72 | *.vspscc 73 | *.vssscc 74 | .builds 75 | *.pidb 76 | *.svclog 77 | *.scc 78 | 79 | # Chutzpah Test files 80 | _Chutzpah* 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opendb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | *.VC.db 91 | *.VC.VC.opendb 92 | 93 | # Visual Studio profiler 94 | *.psess 95 | *.vsp 96 | *.vspx 97 | *.sap 98 | 99 | # TFS 2012 Local Workspace 100 | $tf/ 101 | 102 | # Guidance Automation Toolkit 103 | *.gpState 104 | 105 | # ReSharper is a .NET coding add-in 106 | _ReSharper*/ 107 | *.[Rr]e[Ss]harper 108 | *.DotSettings.user 109 | 110 | # JustCode is a .NET coding add-in 111 | .JustCode 112 | 113 | # TeamCity is a build add-in 114 | _TeamCity* 115 | 116 | # DotCover is a Code Coverage Tool 117 | *.dotCover 118 | 119 | # Visual Studio code coverage results 120 | *.coverage 121 | *.coveragexml 122 | 123 | # NCrunch 124 | _NCrunch_* 125 | .*crunch*.local.xml 126 | nCrunchTemp_* 127 | 128 | # MightyMoose 129 | *.mm.* 130 | AutoTest.Net/ 131 | 132 | # Web workbench (sass) 133 | .sass-cache/ 134 | 135 | # Installshield output folder 136 | [Ee]xpress/ 137 | 138 | # DocProject is a documentation generator add-in 139 | DocProject/buildhelp/ 140 | DocProject/Help/*.HxT 141 | DocProject/Help/*.HxC 142 | DocProject/Help/*.hhc 143 | DocProject/Help/*.hhk 144 | DocProject/Help/*.hhp 145 | DocProject/Help/Html2 146 | DocProject/Help/html 147 | 148 | # Click-Once directory 149 | publish/ 150 | 151 | # Publish Web Output 152 | *.[Pp]ublish.xml 153 | *.azurePubxml 154 | # TODO: Comment the next line if you want to checkin your web deploy settings 155 | # but database connection strings (with potential passwords) will be unencrypted 156 | *.pubxml 157 | *.publishproj 158 | 159 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 160 | # checkin your Azure Web App publish settings, but sensitive information contained 161 | # in these scripts will be unencrypted 162 | PublishScripts/ 163 | 164 | # NuGet Packages 165 | *.nupkg 166 | # The packages folder can be ignored because of Package Restore 167 | **/packages/* 168 | # except build/, which is used as an MSBuild target. 169 | !**/packages/build/ 170 | # Uncomment if necessary however generally it will be regenerated when needed 171 | #!**/packages/repositories.config 172 | # NuGet v3's project.json files produces more ignorable files 173 | *.nuget.props 174 | *.nuget.targets 175 | 176 | # Microsoft Azure Build Output 177 | csx/ 178 | *.build.csdef 179 | 180 | # Microsoft Azure Emulator 181 | ecf/ 182 | rcf/ 183 | 184 | # Windows Store app package directories and files 185 | AppPackages/ 186 | BundleArtifacts/ 187 | Package.StoreAssociation.xml 188 | _pkginfo.txt 189 | 190 | # Visual Studio cache files 191 | # files ending in .cache can be ignored 192 | *.[Cc]ache 193 | # but keep track of directories ending in .cache 194 | !*.[Cc]ache/ 195 | 196 | # Others 197 | ClientBin/ 198 | ~$* 199 | *~ 200 | *.dbmdl 201 | *.dbproj.schemaview 202 | *.jfm 203 | *.pfx 204 | *.publishsettings 205 | orleans.codegen.cs 206 | 207 | # Since there are multiple workflows, uncomment next line to ignore bower_components 208 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 209 | #bower_components/ 210 | 211 | # RIA/Silverlight projects 212 | Generated_Code/ 213 | 214 | # Backup & report files from converting an old project file 215 | # to a newer Visual Studio version. Backup files are not needed, 216 | # because we have git ;-) 217 | _UpgradeReport_Files/ 218 | Backup*/ 219 | UpgradeLog*.XML 220 | UpgradeLog*.htm 221 | 222 | # SQL Server files 223 | *.mdf 224 | *.ldf 225 | *.ndf 226 | 227 | # Business Intelligence projects 228 | *.rdl.data 229 | *.bim.layout 230 | *.bim_*.settings 231 | 232 | # Microsoft Fakes 233 | FakesAssemblies/ 234 | 235 | # GhostDoc plugin setting file 236 | *.GhostDoc.xml 237 | 238 | # Node.js Tools for Visual Studio 239 | .ntvs_analysis.dat 240 | node_modules/ 241 | 242 | # Typescript v1 declaration files 243 | typings/ 244 | 245 | # Visual Studio 6 build log 246 | *.plg 247 | 248 | # Visual Studio 6 workspace options file 249 | *.opt 250 | 251 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 252 | *.vbw 253 | 254 | # Visual Studio LightSwitch build output 255 | **/*.HTMLClient/GeneratedArtifacts 256 | **/*.DesktopClient/GeneratedArtifacts 257 | **/*.DesktopClient/ModelManifest.xml 258 | **/*.Server/GeneratedArtifacts 259 | **/*.Server/ModelManifest.xml 260 | _Pvt_Extensions 261 | 262 | # Paket dependency manager 263 | .paket/paket.exe 264 | paket-files/ 265 | 266 | # FAKE - F# Make 267 | .fake/ 268 | 269 | # JetBrains Rider 270 | .idea/ 271 | *.sln.iml 272 | 273 | # CodeRush 274 | .cr/ 275 | 276 | # Python Tools for Visual Studio (PTVS) 277 | __pycache__/ 278 | *.pyc 279 | 280 | # Cake - Uncomment if you are using it 281 | # tools/** 282 | # !tools/packages.config 283 | 284 | # Telerik's JustMock configuration file 285 | *.jmconfig 286 | 287 | # BizTalk build output 288 | *.btp.cs 289 | *.btm.cs 290 | *.odx.cs 291 | *.xsd.cs 292 | -------------------------------------------------------------------------------- /DataStucture.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | #pragma warning disable 649 // Suppresses: ___ is never assigned to 3 | 4 | // ReSharper disable All 5 | 6 | namespace MusicBeePlugin 7 | { 8 | internal class SearchResult 9 | { 10 | public SearchResultResult result; 11 | public int code; 12 | } 13 | 14 | internal class SearchResultResult 15 | { 16 | public int songCount; 17 | public IEnumerable songs; 18 | } 19 | 20 | internal class SearchResultSong 21 | { 22 | public string name; 23 | public long id; 24 | public long duration; // in ms 25 | public SearchResultAlbum album; 26 | public SearchResultArtist[] artists; 27 | } 28 | 29 | internal class SearchResultAlbum 30 | { 31 | public long id; 32 | public string name; 33 | } 34 | 35 | internal class SearchResultArtist 36 | { 37 | public long id; 38 | public string name; 39 | } 40 | 41 | internal class LyricResult 42 | { 43 | public LyricInner lrc; 44 | public LyricInner tlyric; 45 | public int code; 46 | } 47 | 48 | internal class LyricInner 49 | { 50 | public string lyric; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 13 | 14 | 15 | 16 | 17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 18 | 19 | 20 | 21 | 22 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks. 23 | 24 | 25 | 26 | 27 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks. 28 | 29 | 30 | 31 | 32 | The order of preloaded assemblies, delimited with line breaks. 33 | 34 | 35 | 36 | 37 | 38 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 39 | 40 | 41 | 42 | 43 | Controls if .pdbs for reference assemblies are also embedded. 44 | 45 | 46 | 47 | 48 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 49 | 50 | 51 | 52 | 53 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 54 | 55 | 56 | 57 | 58 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 59 | 60 | 61 | 62 | 63 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 64 | 65 | 66 | 67 | 68 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 69 | 70 | 71 | 72 | 73 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 74 | 75 | 76 | 77 | 78 | A list of unmanaged 32 bit assembly names to include, delimited with |. 79 | 80 | 81 | 82 | 83 | A list of unmanaged 64 bit assembly names to include, delimited with |. 84 | 85 | 86 | 87 | 88 | The order of preloaded assemblies, delimited with |. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 97 | 98 | 99 | 100 | 101 | A comma-separated list of error codes that can be safely ignored in assembly verification. 102 | 103 | 104 | 105 | 106 | 'false' to turn off automatic generation of the XML Schema file. 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-Zony: -------------------------------------------------------------------------------- 1 | [Included due to adoption of code from ZonyLrcToolsX in the Netease API part.] 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 Zony 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /LyricProcessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Linq; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace MusicBeePlugin 8 | { 9 | [SuppressMessage("ReSharper", "InconsistentNaming")] 10 | internal static class LyricProcessor 11 | { 12 | private static readonly Regex LyricLineRegex = new Regex(@"((\[.+?])+)(.*)", RegexOptions.Compiled); 13 | public static string InjectTranslation(string originalLrc, string translationLrc) 14 | { 15 | var originalEntries = ExpandEntries(Parse(originalLrc)); 16 | var translationEntries = ExpandEntries(Parse(translationLrc)); 17 | foreach (var originalEntry in originalEntries) 18 | { 19 | var translationEntry = translationEntries.FirstOrDefault(entry => entry.timeLabel == originalEntry.timeLabel); 20 | if (translationEntry != null) 21 | originalEntry.content += "/" + translationEntry.content; 22 | } 23 | 24 | originalEntries.Sort(); 25 | return string.Join("\n", originalEntries); 26 | } 27 | 28 | private static List Parse(string lrc) 29 | { 30 | var result = lrc.Split('\n') 31 | .Where(line => !string.IsNullOrWhiteSpace(line)) 32 | .Select(line => LyricLineRegex.Matches(line)) 33 | .Where(matches => matches.Count >= 1) 34 | .Select(matches => matches[0]) 35 | .Where(match => match.Groups.Count >= 3) 36 | .SelectMany(match => match.Groups[1].Captures.Cast(), 37 | (match, capture) => new LyricEntry(capture.Value, match.Groups[3].Value)) 38 | .ToList(); 39 | 40 | return result; 41 | } 42 | 43 | private static List ExpandEntries(List entries) 44 | { 45 | return entries.SelectMany(entry => entry.ExpandTimeLabel()).ToList(); 46 | } 47 | } 48 | 49 | [SuppressMessage("ReSharper", "InconsistentNaming")] 50 | internal class LyricEntry : IComparable 51 | { 52 | private static readonly Regex LyricTimeRegex = new Regex(@"(\[[0-9.:]*])", RegexOptions.Compiled); 53 | 54 | public string timeLabel; 55 | public string content; 56 | 57 | public LyricEntry(string timeLabel, string content) 58 | { 59 | this.timeLabel = timeLabel; 60 | this.content = content; 61 | } 62 | 63 | public override string ToString() 64 | { 65 | return timeLabel + content; 66 | } 67 | 68 | public IEnumerable ExpandTimeLabel() 69 | { 70 | var matches = LyricTimeRegex.Matches(timeLabel); 71 | foreach (var match in matches.Cast()) 72 | yield return new LyricEntry(match.Value, content); 73 | } 74 | 75 | public int CompareTo(LyricEntry other) 76 | { 77 | if (ReferenceEquals(this, other)) return 0; 78 | if (ReferenceEquals(null, other)) return 1; 79 | return string.Compare(timeLabel, other.timeLabel, StringComparison.Ordinal); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /MusicBeeInterface.cs: -------------------------------------------------------------------------------- 1 | // WARNING: This file is NOT a part of my work and it's from downloaded MusicBee API source!!! 2 | 3 | using System; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Runtime.InteropServices; 6 | 7 | namespace MusicBeePlugin 8 | { 9 | [SuppressMessage("ReSharper", "InconsistentNaming")] 10 | public partial class Plugin 11 | { 12 | public const short PluginInfoVersion = 1; 13 | public const short MinInterfaceVersion = 36; 14 | public const short MinApiRevision = 48; 15 | 16 | [StructLayout(LayoutKind.Sequential)] 17 | public struct MusicBeeApiInterface 18 | { 19 | public void Initialise(IntPtr apiInterfacePtr) 20 | { 21 | CopyMemory(ref this, apiInterfacePtr, 4); 22 | if (MusicBeeVersion == MusicBeeVersion.v2_0) 23 | // MusicBee version 2.0 - Api methods > revision 25 are not available 24 | CopyMemory(ref this, apiInterfacePtr, 456); 25 | else if (MusicBeeVersion == MusicBeeVersion.v2_1) 26 | CopyMemory(ref this, apiInterfacePtr, 516); 27 | else if (MusicBeeVersion == MusicBeeVersion.v2_2) 28 | CopyMemory(ref this, apiInterfacePtr, 584); 29 | else if (MusicBeeVersion == MusicBeeVersion.v2_3) 30 | CopyMemory(ref this, apiInterfacePtr, 596); 31 | else if (MusicBeeVersion == MusicBeeVersion.v2_4) 32 | CopyMemory(ref this, apiInterfacePtr, 604); 33 | else if (MusicBeeVersion == MusicBeeVersion.v2_5) 34 | CopyMemory(ref this, apiInterfacePtr, 648); 35 | else 36 | CopyMemory(ref this, apiInterfacePtr, Marshal.SizeOf(this)); 37 | } 38 | public MusicBeeVersion MusicBeeVersion 39 | { 40 | get { 41 | if (ApiRevision <= 25) 42 | return MusicBeeVersion.v2_0; 43 | else if (ApiRevision <= 31) 44 | return MusicBeeVersion.v2_1; 45 | else if (ApiRevision <= 33) 46 | return MusicBeeVersion.v2_2; 47 | else if (ApiRevision <= 38) 48 | return MusicBeeVersion.v2_3; 49 | else if (ApiRevision <= 43) 50 | return MusicBeeVersion.v2_4; 51 | else if (ApiRevision <= 47) 52 | return MusicBeeVersion.v2_5; 53 | else 54 | return MusicBeeVersion.v3_0; 55 | } 56 | } 57 | public short InterfaceVersion; 58 | public short ApiRevision; 59 | public MB_ReleaseStringDelegate MB_ReleaseString; 60 | public MB_TraceDelegate MB_Trace; 61 | public Setting_GetPersistentStoragePathDelegate Setting_GetPersistentStoragePath; 62 | public Setting_GetSkinDelegate Setting_GetSkin; 63 | public Setting_GetSkinElementColourDelegate Setting_GetSkinElementColour; 64 | public Setting_IsWindowBordersSkinnedDelegate Setting_IsWindowBordersSkinned; 65 | public Library_GetFilePropertyDelegate Library_GetFileProperty; 66 | public Library_GetFileTagDelegate Library_GetFileTag; 67 | public Library_SetFileTagDelegate Library_SetFileTag; 68 | public Library_CommitTagsToFileDelegate Library_CommitTagsToFile; 69 | public Library_GetLyricsDelegate Library_GetLyrics; 70 | [Obsolete("Use Library_GetArtworkEx")] 71 | public Library_GetArtworkDelegate Library_GetArtwork; 72 | public Library_QueryFilesDelegate Library_QueryFiles; 73 | public Library_QueryGetNextFileDelegate Library_QueryGetNextFile; 74 | public Player_GetPositionDelegate Player_GetPosition; 75 | public Player_SetPositionDelegate Player_SetPosition; 76 | public Player_GetPlayStateDelegate Player_GetPlayState; 77 | public Player_ActionDelegate Player_PlayPause; 78 | public Player_ActionDelegate Player_Stop; 79 | public Player_ActionDelegate Player_StopAfterCurrent; 80 | public Player_ActionDelegate Player_PlayPreviousTrack; 81 | public Player_ActionDelegate Player_PlayNextTrack; 82 | public Player_ActionDelegate Player_StartAutoDj; 83 | public Player_ActionDelegate Player_EndAutoDj; 84 | public Player_GetVolumeDelegate Player_GetVolume; 85 | public Player_SetVolumeDelegate Player_SetVolume; 86 | public Player_GetMuteDelegate Player_GetMute; 87 | public Player_SetMuteDelegate Player_SetMute; 88 | public Player_GetShuffleDelegate Player_GetShuffle; 89 | public Player_SetShuffleDelegate Player_SetShuffle; 90 | public Player_GetRepeatDelegate Player_GetRepeat; 91 | public Player_SetRepeatDelegate Player_SetRepeat; 92 | public Player_GetEqualiserEnabledDelegate Player_GetEqualiserEnabled; 93 | public Player_SetEqualiserEnabledDelegate Player_SetEqualiserEnabled; 94 | public Player_GetDspEnabledDelegate Player_GetDspEnabled; 95 | public Player_SetDspEnabledDelegate Player_SetDspEnabled; 96 | public Player_GetScrobbleEnabledDelegate Player_GetScrobbleEnabled; 97 | public Player_SetScrobbleEnabledDelegate Player_SetScrobbleEnabled; 98 | public NowPlaying_GetFileUrlDelegate NowPlaying_GetFileUrl; 99 | public NowPlaying_GetDurationDelegate NowPlaying_GetDuration; 100 | public NowPlaying_GetFilePropertyDelegate NowPlaying_GetFileProperty; 101 | public NowPlaying_GetFileTagDelegate NowPlaying_GetFileTag; 102 | public NowPlaying_GetLyricsDelegate NowPlaying_GetLyrics; 103 | public NowPlaying_GetArtworkDelegate NowPlaying_GetArtwork; 104 | public NowPlayingList_ActionDelegate NowPlayingList_Clear; 105 | public Library_QueryFilesDelegate NowPlayingList_QueryFiles; 106 | public Library_QueryGetNextFileDelegate NowPlayingList_QueryGetNextFile; 107 | public NowPlayingList_FileActionDelegate NowPlayingList_PlayNow; 108 | public NowPlayingList_FileActionDelegate NowPlayingList_QueueNext; 109 | public NowPlayingList_FileActionDelegate NowPlayingList_QueueLast; 110 | public NowPlayingList_ActionDelegate NowPlayingList_PlayLibraryShuffled; 111 | public Playlist_QueryPlaylistsDelegate Playlist_QueryPlaylists; 112 | public Playlist_QueryGetNextPlaylistDelegate Playlist_QueryGetNextPlaylist; 113 | public Playlist_GetTypeDelegate Playlist_GetType; 114 | public Playlist_QueryFilesDelegate Playlist_QueryFiles; 115 | public Library_QueryGetNextFileDelegate Playlist_QueryGetNextFile; 116 | public MB_WindowHandleDelegate MB_GetWindowHandle; 117 | public MB_RefreshPanelsDelegate MB_RefreshPanels; 118 | public MB_SendNotificationDelegate MB_SendNotification; 119 | public MB_AddMenuItemDelegate MB_AddMenuItem; 120 | public Setting_GetFieldNameDelegate Setting_GetFieldName; 121 | [Obsolete("Use Library_QueryFilesEx", true)] 122 | public Library_QueryGetAllFilesDelegate Library_QueryGetAllFiles; 123 | [Obsolete("Use NowPlayingList_QueryFilesEx", true)] 124 | public Library_QueryGetAllFilesDelegate NowPlayingList_QueryGetAllFiles; 125 | [Obsolete("Use Playlist_QueryFilesEx", true)] 126 | public Library_QueryGetAllFilesDelegate Playlist_QueryGetAllFiles; 127 | public MB_CreateBackgroundTaskDelegate MB_CreateBackgroundTask; 128 | public MB_SetBackgroundTaskMessageDelegate MB_SetBackgroundTaskMessage; 129 | public MB_RegisterCommandDelegate MB_RegisterCommand; 130 | public Setting_GetDefaultFontDelegate Setting_GetDefaultFont; 131 | public Player_GetShowTimeRemainingDelegate Player_GetShowTimeRemaining; 132 | public NowPlayingList_GetCurrentIndexDelegate NowPlayingList_GetCurrentIndex; 133 | public NowPlayingList_GetFileUrlDelegate NowPlayingList_GetListFileUrl; 134 | public NowPlayingList_GetFilePropertyDelegate NowPlayingList_GetFileProperty; 135 | public NowPlayingList_GetFileTagDelegate NowPlayingList_GetFileTag; 136 | public NowPlaying_GetSpectrumDataDelegate NowPlaying_GetSpectrumData; 137 | public NowPlaying_GetSoundGraphDelegate NowPlaying_GetSoundGraph; 138 | public MB_GetPanelBoundsDelegate MB_GetPanelBounds; 139 | public MB_AddPanelDelegate MB_AddPanel; 140 | public MB_RemovePanelDelegate MB_RemovePanel; 141 | public MB_GetLocalisationDelegate MB_GetLocalisation; 142 | public NowPlayingList_IsAnyPriorTracksDelegate NowPlayingList_IsAnyPriorTracks; 143 | public NowPlayingList_IsAnyFollowingTracksDelegate NowPlayingList_IsAnyFollowingTracks; 144 | public Player_ShowEqualiserDelegate Player_ShowEqualiser; 145 | public Player_GetAutoDjEnabledDelegate Player_GetAutoDjEnabled; 146 | public Player_GetStopAfterCurrentEnabledDelegate Player_GetStopAfterCurrentEnabled; 147 | public Player_GetCrossfadeDelegate Player_GetCrossfade; 148 | public Player_SetCrossfadeDelegate Player_SetCrossfade; 149 | public Player_GetReplayGainModeDelegate Player_GetReplayGainMode; 150 | public Player_SetReplayGainModeDelegate Player_SetReplayGainMode; 151 | public Player_QueueRandomTracksDelegate Player_QueueRandomTracks; 152 | public Setting_GetDataTypeDelegate Setting_GetDataType; 153 | public NowPlayingList_GetNextIndexDelegate NowPlayingList_GetNextIndex; 154 | public NowPlaying_GetArtistPictureDelegate NowPlaying_GetArtistPicture; 155 | public NowPlaying_GetArtworkDelegate NowPlaying_GetDownloadedArtwork; 156 | // api version 16 157 | public MB_ShowNowPlayingAssistantDelegate MB_ShowNowPlayingAssistant; 158 | // api version 17 159 | public NowPlaying_GetLyricsDelegate NowPlaying_GetDownloadedLyrics; 160 | // api version 18 161 | public Player_GetShowRatingTrackDelegate Player_GetShowRatingTrack; 162 | public Player_GetShowRatingLoveDelegate Player_GetShowRatingLove; 163 | // api version 19 164 | public MB_CreateParameterisedBackgroundTaskDelegate MB_CreateParameterisedBackgroundTask; 165 | public Setting_GetLastFmUserIdDelegate Setting_GetLastFmUserId; 166 | public Playlist_GetNameDelegate Playlist_GetName; 167 | public Playlist_CreatePlaylistDelegate Playlist_CreatePlaylist; 168 | public Playlist_SetFilesDelegate Playlist_SetFiles; 169 | public Library_QuerySimilarArtistsDelegate Library_QuerySimilarArtists; 170 | public Library_QueryLookupTableDelegate Library_QueryLookupTable; 171 | public Library_QueryGetLookupTableValueDelegate Library_QueryGetLookupTableValue; 172 | public NowPlayingList_FilesActionDelegate NowPlayingList_QueueFilesNext; 173 | public NowPlayingList_FilesActionDelegate NowPlayingList_QueueFilesLast; 174 | // api version 20 175 | public Setting_GetWebProxyDelegate Setting_GetWebProxy; 176 | // api version 21 177 | public NowPlayingList_RemoveAtDelegate NowPlayingList_RemoveAt; 178 | // api version 22 179 | public Playlist_RemoveAtDelegate Playlist_RemoveAt; 180 | // api version 23 181 | public MB_SetPanelScrollableAreaDelegate MB_SetPanelScrollableArea; 182 | // api version 24 183 | public MB_InvokeCommandDelegate MB_InvokeCommand; 184 | public MB_OpenFilterInTabDelegate MB_OpenFilterInTab; 185 | // api version 25 186 | public MB_SetWindowSizeDelegate MB_SetWindowSize; 187 | public Library_GetArtistPictureDelegate Library_GetArtistPicture; 188 | public Pending_GetFileUrlDelegate Pending_GetFileUrl; 189 | public Pending_GetFilePropertyDelegate Pending_GetFileProperty; 190 | public Pending_GetFileTagDelegate Pending_GetFileTag; 191 | // api version 26 192 | public Player_GetButtonEnabledDelegate Player_GetButtonEnabled; 193 | // api version 27 194 | public NowPlayingList_MoveFilesDelegate NowPlayingList_MoveFiles; 195 | // api version 28 196 | public Library_GetArtworkDelegate Library_GetArtworkUrl; 197 | public Library_GetArtistPictureThumbDelegate Library_GetArtistPictureThumb; 198 | public NowPlaying_GetArtworkDelegate NowPlaying_GetArtworkUrl; 199 | public NowPlaying_GetArtworkDelegate NowPlaying_GetDownloadedArtworkUrl; 200 | public NowPlaying_GetArtistPictureThumbDelegate NowPlaying_GetArtistPictureThumb; 201 | // api version 29 202 | public Playlist_IsInListDelegate Playlist_IsInList; 203 | // api version 30 204 | public Library_GetArtistPictureUrlsDelegate Library_GetArtistPictureUrls; 205 | public NowPlaying_GetArtistPictureUrlsDelegate NowPlaying_GetArtistPictureUrls; 206 | // api version 31 207 | public Playlist_AddFilesDelegate Playlist_AppendFiles; 208 | // api version 32 209 | public Sync_FileStartDelegate Sync_FileStart; 210 | public Sync_FileEndDelegate Sync_FileEnd; 211 | // api version 33 212 | public Library_QueryFilesExDelegate Library_QueryFilesEx; 213 | public Library_QueryFilesExDelegate NowPlayingList_QueryFilesEx; 214 | public Playlist_QueryFilesExDelegate Playlist_QueryFilesEx; 215 | public Playlist_MoveFilesDelegate Playlist_MoveFiles; 216 | public Playlist_PlayNowDelegate Playlist_PlayNow; 217 | public NowPlaying_IsSoundtrackDelegate NowPlaying_IsSoundtrack; 218 | public NowPlaying_GetArtistPictureUrlsDelegate NowPlaying_GetSoundtrackPictureUrls; 219 | public Library_GetDevicePersistentIdDelegate Library_GetDevicePersistentId; 220 | public Library_SetDevicePersistentIdDelegate Library_SetDevicePersistentId; 221 | public Library_FindDevicePersistentIdDelegate Library_FindDevicePersistentId; 222 | public Setting_GetValueDelegate Setting_GetValue; 223 | public Library_AddFileToLibraryDelegate Library_AddFileToLibrary; 224 | public Playlist_DeletePlaylistDelegate Playlist_DeletePlaylist; 225 | public Library_GetSyncDeltaDelegate Library_GetSyncDelta; 226 | // api version 35 227 | public Library_GetFileTagsDelegate Library_GetFileTags; 228 | public NowPlaying_GetFileTagsDelegate NowPlaying_GetFileTags; 229 | public NowPlayingList_GetFileTagsDelegate NowPlayingList_GetFileTags; 230 | // api version 43 231 | public MB_AddTreeNodeDelegate MB_AddTreeNode; 232 | public MB_DownloadFileDelegate MB_DownloadFile; 233 | // api version 47 234 | public Setting_GetFileConvertCommandLineDelegate Setting_GetFileConvertCommandLine; 235 | public Player_OpenStreamHandleDelegate Player_OpenStreamHandle; 236 | public Player_UpdatePlayStatisticsDelegate Player_UpdatePlayStatistics; 237 | public Library_GetArtworkExDelegate Library_GetArtworkEx; 238 | public Library_SetArtworkExDelegate Library_SetArtworkEx; 239 | public MB_GetVisualiserInformationDelegate MB_GetVisualiserInformation; 240 | public MB_ShowVisualiserDelegate MB_ShowVisualiser; 241 | public MB_GetPluginViewInformationDelegate MB_GetPluginViewInformation; 242 | public MB_ShowPluginViewDelegate MB_ShowPluginView; 243 | public Player_GetOutputDevicesDelegate Player_GetOutputDevices; 244 | public Player_SetOutputDeviceDelegate Player_SetOutputDevice; 245 | // api version 48 246 | public MB_UninistallPluginDelegate MB_UninstallPlugin; 247 | } 248 | 249 | public enum MusicBeeVersion 250 | { 251 | v2_0 = 0, 252 | v2_1 = 1, 253 | v2_2 = 2, 254 | v2_3 = 3, 255 | v2_4 = 4, 256 | v2_5 = 5, 257 | v3_0 = 6 258 | } 259 | 260 | public enum PluginType 261 | { 262 | Unknown = 0, 263 | General = 1, 264 | LyricsRetrieval = 2, 265 | ArtworkRetrieval = 3, 266 | PanelView = 4, 267 | DataStream = 5, 268 | InstantMessenger = 6, 269 | Storage = 7, 270 | VideoPlayer = 8, 271 | DSP = 9, 272 | TagRetrieval = 10, 273 | TagOrArtworkRetrieval = 11, 274 | Upnp = 12 275 | } 276 | 277 | [StructLayout(LayoutKind.Sequential)] 278 | public class PluginInfo 279 | { 280 | public short PluginInfoVersion; 281 | public PluginType Type; 282 | public string Name; 283 | public string Description; 284 | public string Author; 285 | public string TargetApplication; 286 | public short VersionMajor; 287 | public short VersionMinor; 288 | public short Revision; 289 | public short MinInterfaceVersion; 290 | public short MinApiRevision; 291 | public ReceiveNotificationFlags ReceiveNotifications; 292 | public int ConfigurationPanelHeight; 293 | } 294 | 295 | [Flags()] 296 | public enum ReceiveNotificationFlags 297 | { 298 | StartupOnly = 0x0, 299 | PlayerEvents = 0x1, 300 | DataStreamEvents = 0x2, 301 | TagEvents = 0x04, 302 | DownloadEvents = 0x08 303 | } 304 | 305 | public enum NotificationType 306 | { 307 | PluginStartup = 0, // notification sent after successful initialisation for an enabled plugin 308 | TrackChanging = 16, 309 | TrackChanged = 1, 310 | PlayStateChanged = 2, 311 | AutoDjStarted = 3, 312 | AutoDjStopped = 4, 313 | VolumeMuteChanged = 5, 314 | VolumeLevelChanged = 6, 315 | NowPlayingListChanged = 7, 316 | NowPlayingListEnded = 18, 317 | NowPlayingArtworkReady = 8, 318 | NowPlayingLyricsReady = 9, 319 | TagsChanging = 10, 320 | TagsChanged = 11, 321 | RatingChanging = 15, 322 | RatingChanged = 12, 323 | PlayCountersChanged = 13, 324 | ScreenSaverActivating = 14, 325 | ShutdownStarted = 17, 326 | EmbedInPanel = 19, 327 | PlayerRepeatChanged = 20, 328 | PlayerShuffleChanged = 21, 329 | PlayerEqualiserOnOffChanged = 22, 330 | PlayerScrobbleChanged = 23, 331 | ReplayGainChanged = 24, 332 | FileDeleting = 25, 333 | FileDeleted = 26, 334 | ApplicationWindowChanged = 27, 335 | StopAfterCurrentChanged = 28, 336 | LibrarySwitched = 29, 337 | FileAddedToLibrary = 30, 338 | FileAddedToInbox = 31, 339 | SynchCompleted = 32, 340 | DownloadCompleted = 33, 341 | MusicBeeStarted = 34 342 | } 343 | 344 | public enum PluginCloseReason 345 | { 346 | MusicBeeClosing = 1, 347 | UserDisabled = 2, 348 | StopNoUnload = 3 349 | } 350 | 351 | public enum CallbackType 352 | { 353 | SettingsUpdated = 1, 354 | StorageReady = 2, 355 | StorageFailed = 3, 356 | FilesRetrievedChanged = 4, 357 | FilesRetrievedNoChange = 5, 358 | FilesRetrievedFail = 6, 359 | LyricsDownloaded = 7, 360 | StorageEject = 8, 361 | SuspendPlayCounters = 9, 362 | ResumePlayCounters = 10, 363 | EnablePlugin = 11, 364 | DisablePlugin = 12, 365 | RenderingDevicesChanged = 13, 366 | FullscreenOn = 14, 367 | FullscreenOff = 15 368 | } 369 | 370 | public enum FilePropertyType 371 | { 372 | Url = 2, 373 | Kind = 4, 374 | Format = 5, 375 | Size = 7, 376 | Channels = 8, 377 | SampleRate = 9, 378 | Bitrate = 10, 379 | DateModified = 11, 380 | DateAdded = 12, 381 | LastPlayed = 13, 382 | PlayCount = 14, 383 | SkipCount = 15, 384 | Duration = 16, 385 | Status = 21, 386 | NowPlayingListIndex = 78, // only has meaning when called from NowPlayingList_* commands 387 | ReplayGainTrack = 94, 388 | ReplayGainAlbum = 95 389 | } 390 | 391 | public enum MetaDataType 392 | { 393 | TrackTitle = 65, 394 | Album = 30, 395 | AlbumArtist = 31, // displayed album artist 396 | AlbumArtistRaw = 34, // stored album artist 397 | Artist = 32, // displayed artist 398 | MultiArtist = 33, // individual artists, separated by a null char 399 | PrimaryArtist = 19, // first artist from multi-artist tagged file, otherwise displayed artist 400 | Artists = 144, 401 | ArtistsWithArtistRole = 145, 402 | ArtistsWithPerformerRole = 146, 403 | ArtistsWithGuestRole = 147, 404 | ArtistsWithRemixerRole = 148, 405 | Artwork = 40, 406 | BeatsPerMin = 41, 407 | Composer = 43, // displayed composer 408 | MultiComposer = 89, // individual composers, separated by a null char 409 | Comment = 44, 410 | Conductor = 45, 411 | Custom1 = 46, 412 | Custom2 = 47, 413 | Custom3 = 48, 414 | Custom4 = 49, 415 | Custom5 = 50, 416 | Custom6 = 96, 417 | Custom7 = 97, 418 | Custom8 = 98, 419 | Custom9 = 99, 420 | Custom10 = 128, 421 | Custom11 = 129, 422 | Custom12 = 130, 423 | Custom13 = 131, 424 | Custom14 = 132, 425 | Custom15 = 133, 426 | Custom16 = 134, 427 | DiscNo = 52, 428 | DiscCount = 54, 429 | Encoder = 55, 430 | Genre = 59, 431 | Genres = 143, 432 | GenreCategory = 60, 433 | Grouping = 61, 434 | Keywords = 84, 435 | HasLyrics = 63, 436 | Lyricist = 62, 437 | Lyrics = 114, 438 | Mood = 64, 439 | Occasion = 66, 440 | Origin = 67, 441 | Publisher = 73, 442 | Quality = 74, 443 | Rating = 75, 444 | RatingLove = 76, 445 | RatingAlbum = 104, 446 | Tempo = 85, 447 | TrackNo = 86, 448 | TrackCount = 87, 449 | Virtual1 = 109, 450 | Virtual2 = 110, 451 | Virtual3 = 111, 452 | Virtual4 = 112, 453 | Virtual5 = 113, 454 | Virtual6 = 122, 455 | Virtual7 = 123, 456 | Virtual8 = 124, 457 | Virtual9 = 125, 458 | Virtual10 = 135, 459 | Virtual11 = 136, 460 | Virtual12 = 137, 461 | Virtual13 = 138, 462 | Virtual14 = 139, 463 | Virtual15 = 140, 464 | Virtual16 = 141, 465 | Year = 88 466 | } 467 | 468 | public enum FileCodec 469 | { 470 | Unknown = -1, 471 | Mp3 = 1, 472 | Aac = 2, 473 | Flac = 3, 474 | Ogg = 4, 475 | WavPack = 5, 476 | Wma = 6, 477 | Tak = 7, 478 | Mpc = 8, 479 | Wave = 9, 480 | Asx = 10, 481 | Alac = 11, 482 | Aiff = 12, 483 | Pcm = 13, 484 | Opus = 15, 485 | Spx = 16, 486 | Dsd = 17, 487 | AacNoContainer = 18 488 | } 489 | 490 | public enum EncodeQuality 491 | { 492 | SmallSize = 1, 493 | Portable = 2, 494 | HighQuality = 3, 495 | Archiving = 4 496 | } 497 | 498 | [Flags()] 499 | public enum LibraryCategory 500 | { 501 | Music = 0, 502 | Audiobook = 1, 503 | Video = 2, 504 | Inbox = 4 505 | } 506 | 507 | public enum DeviceIdType 508 | { 509 | GooglePlay = 1, 510 | AppleDevice = 2, 511 | GooglePlay2 = 3, 512 | AppleDevice2 = 4 513 | } 514 | 515 | public enum DataType 516 | { 517 | String = 0, 518 | Number = 1, 519 | DateTime = 2, 520 | Rating = 3 521 | } 522 | 523 | public enum SettingId 524 | { 525 | CompactPlayerFlickrEnabled = 1, 526 | FileTaggingPreserveModificationTime = 2, 527 | LastDownloadFolder = 3, 528 | ArtistGenresOnly = 4, 529 | IgnoreNamePrefixes = 5, 530 | IgnoreNameChars = 6, 531 | PlayCountTriggerPercent = 7, 532 | PlayCountTriggerSeconds = 8, 533 | SkipCountTriggerPercent = 9, 534 | SkipCountTriggerSeconds = 10, 535 | CustomWebLinkName1 = 11, 536 | CustomWebLinkName2 = 12, 537 | CustomWebLinkName3 = 13, 538 | CustomWebLinkName4 = 14, 539 | CustomWebLinkName5 = 15, 540 | CustomWebLinkName6 = 16, 541 | CustomWebLink1 = 17, 542 | CustomWebLink2 = 18, 543 | CustomWebLink3 = 19, 544 | CustomWebLink4 = 20, 545 | CustomWebLink5 = 21, 546 | CustomWebLink6 = 22, 547 | CustomWebLinkNowPlaying1 = 23, 548 | CustomWebLinkNowPlaying2 = 24, 549 | CustomWebLinkNowPlaying3 = 25, 550 | CustomWebLinkNowPlaying4 = 26, 551 | CustomWebLinkNowPlaying5 = 27, 552 | CustomWebLinkNowPlaying6 = 28 553 | } 554 | 555 | public enum ComparisonType 556 | { 557 | Is = 0, 558 | IsSimilar = 20 559 | } 560 | 561 | public enum LyricsType 562 | { 563 | NotSpecified = 0, 564 | Synchronised = 1, 565 | UnSynchronised = 2 566 | } 567 | 568 | public enum PlayState 569 | { 570 | Undefined = 0, 571 | Loading = 1, 572 | Playing = 3, 573 | Paused = 6, 574 | Stopped = 7 575 | } 576 | 577 | public enum RepeatMode 578 | { 579 | None = 0, 580 | All = 1, 581 | One = 2 582 | } 583 | 584 | public enum PlayButtonType 585 | { 586 | PreviousTrack = 0, 587 | PlayPause = 1, 588 | NextTrack = 2, 589 | Stop = 3 590 | } 591 | 592 | public enum PlaylistFormat 593 | { 594 | Unknown = 0, 595 | M3u = 1, 596 | Xspf = 2, 597 | Asx = 3, 598 | Wpl = 4, 599 | Pls = 5, 600 | Auto = 7, 601 | M3uAscii = 8, 602 | AsxFile = 9, 603 | Radio = 10, 604 | M3uExtended = 11, 605 | Mbp = 12 606 | } 607 | 608 | public enum SkinElement 609 | { 610 | SkinInputControl = 7, 611 | SkinInputPanel = 10, 612 | SkinInputPanelLabel = 14, 613 | SkinTrackAndArtistPanel = -1 614 | } 615 | 616 | public enum ElementState 617 | { 618 | ElementStateDefault = 0, 619 | ElementStateModified = 6 620 | } 621 | 622 | public enum ElementComponent 623 | { 624 | ComponentBorder = 0, 625 | ComponentBackground = 1, 626 | ComponentForeground = 3 627 | } 628 | 629 | public enum PluginPanelDock 630 | { 631 | ApplicationWindow = 0, 632 | TrackAndArtistPanel = 1, 633 | TextBox = 3, 634 | ComboBox = 4, 635 | MainPanel = 5 636 | } 637 | 638 | 639 | public enum ReplayGainMode 640 | { 641 | Off = 0, 642 | Track = 1, 643 | Album = 2, 644 | Smart = 3 645 | } 646 | 647 | public enum PlayStatisticType 648 | { 649 | NoChange = 0, 650 | IncreasePlayCount = 1, 651 | IncreaseSkipCount = 2 652 | } 653 | 654 | public enum Command 655 | { 656 | NavigateTo = 1 657 | } 658 | 659 | public enum DownloadTarget 660 | { 661 | Inbox = 0, 662 | MusicLibrary = 1, 663 | SpecificFolder = 3 664 | } 665 | 666 | [Flags()] 667 | public enum PictureLocations: byte 668 | { 669 | None = 0, 670 | EmbedInFile = 1, 671 | LinkToOrganisedCopy = 2, 672 | LinkToSource = 4, 673 | FolderThumb = 8 674 | } 675 | 676 | public enum WindowState 677 | { 678 | Off = -1, 679 | Normal = 0, 680 | Fullscreen = 1, 681 | Desktop = 2 682 | } 683 | 684 | public delegate void MB_ReleaseStringDelegate(string p1); 685 | public delegate void MB_TraceDelegate(string p1); 686 | public delegate IntPtr MB_WindowHandleDelegate(); 687 | public delegate void MB_RefreshPanelsDelegate(); 688 | public delegate void MB_SendNotificationDelegate(CallbackType type); 689 | public delegate System.Windows.Forms.ToolStripItem MB_AddMenuItemDelegate(string menuPath, string hotkeyDescription, EventHandler handler); 690 | public delegate bool MB_AddTreeNodeDelegate(string treePath, string name, System.Drawing.Bitmap icon, EventHandler openHandler, EventHandler closeHandler); 691 | public delegate void MB_RegisterCommandDelegate(string command, EventHandler handler); 692 | public delegate void MB_CreateBackgroundTaskDelegate(System.Threading.ThreadStart taskCallback, System.Windows.Forms.Form owner); 693 | public delegate void MB_CreateParameterisedBackgroundTaskDelegate(System.Threading.ParameterizedThreadStart taskCallback, object parameters, System.Windows.Forms.Form owner); 694 | public delegate void MB_SetBackgroundTaskMessageDelegate(string message); 695 | public delegate System.Drawing.Rectangle MB_GetPanelBoundsDelegate(PluginPanelDock dock); 696 | public delegate bool MB_SetPanelScrollableAreaDelegate(System.Windows.Forms.Control panel, System.Drawing.Size scrollArea, bool alwaysShowScrollBar); 697 | public delegate System.Windows.Forms.Control MB_AddPanelDelegate(System.Windows.Forms.Control panel, PluginPanelDock dock); 698 | public delegate void MB_RemovePanelDelegate(System.Windows.Forms.Control panel); 699 | public delegate string MB_GetLocalisationDelegate(string id, string defaultText); 700 | public delegate bool MB_ShowNowPlayingAssistantDelegate(); 701 | public delegate bool MB_InvokeCommandDelegate(Command command, object parameter); 702 | public delegate bool MB_OpenFilterInTabDelegate(MetaDataType field1, ComparisonType comparison1, string value1, MetaDataType field2, ComparisonType comparison2, string value2); 703 | public delegate bool MB_SetWindowSizeDelegate(int width, int height); 704 | public delegate bool MB_DownloadFileDelegate(string url, DownloadTarget target, string targetFolder, bool cancelDownload); 705 | public delegate bool MB_GetVisualiserInformationDelegate(out string[] visualiserNames, out string defaultVisualiserName, out WindowState defaultState, out WindowState currentState); 706 | public delegate bool MB_ShowVisualiserDelegate(string visualiserName, WindowState state); 707 | public delegate bool MB_GetPluginViewInformationDelegate(string pluginFilename, out string[] viewNames, out string defaultViewName, out WindowState defaultState, out WindowState currentState); 708 | public delegate bool MB_ShowPluginViewDelegate(string pluginFilename, string viewName, WindowState state); 709 | public delegate bool MB_UninistallPluginDelegate(string pluginFilename, string password); 710 | public delegate string Setting_GetFieldNameDelegate(MetaDataType field); 711 | public delegate string Setting_GetPersistentStoragePathDelegate(); 712 | public delegate string Setting_GetSkinDelegate(); 713 | public delegate int Setting_GetSkinElementColourDelegate(SkinElement element, ElementState state, ElementComponent component); 714 | public delegate bool Setting_IsWindowBordersSkinnedDelegate(); 715 | public delegate System.Drawing.Font Setting_GetDefaultFontDelegate(); 716 | public delegate DataType Setting_GetDataTypeDelegate(MetaDataType field); 717 | public delegate string Setting_GetLastFmUserIdDelegate(); 718 | public delegate string Setting_GetWebProxyDelegate(); 719 | public delegate bool Setting_GetValueDelegate(SettingId settingId, ref object value); 720 | public delegate string Setting_GetFileConvertCommandLineDelegate(FileCodec codec, EncodeQuality encodeQuality); 721 | public delegate string Library_GetFilePropertyDelegate(string sourceFileUrl, FilePropertyType type); 722 | public delegate string Library_GetFileTagDelegate(string sourceFileUrl, MetaDataType field); 723 | public delegate bool Library_GetFileTagsDelegate(string sourceFileUrl, MetaDataType[] fields, ref string[] results); 724 | public delegate bool Library_SetFileTagDelegate(string sourceFileUrl, MetaDataType field, string value); 725 | public delegate string Library_GetDevicePersistentIdDelegate(string sourceFileUrl, DeviceIdType idType); 726 | public delegate bool Library_SetDevicePersistentIdDelegate(string sourceFileUrl, DeviceIdType idType, string value); 727 | public delegate bool Library_FindDevicePersistentIdDelegate(DeviceIdType idType, string[] ids, ref string[] values); 728 | public delegate bool Library_CommitTagsToFileDelegate(string sourceFileUrl); 729 | public delegate string Library_AddFileToLibraryDelegate(string sourceFileUrl, LibraryCategory category); 730 | public delegate bool Library_GetSyncDeltaDelegate(string[] cachedFiles, DateTime updatedSince, LibraryCategory categories, ref string[] newFiles, ref string[] updatedFiles, ref string[] deletedFiles); 731 | public delegate string Library_GetLyricsDelegate(string sourceFileUrl, LyricsType type); 732 | public delegate string Library_GetArtworkDelegate(string sourceFileUrl, int index); 733 | public delegate bool Library_GetArtworkExDelegate(string sourceFileUrl, int index, bool retrievePictureData, ref PictureLocations pictureLocations, ref string pictureUrl, ref byte[] imageData); 734 | public delegate bool Library_SetArtworkExDelegate(string sourceFileUrl, int index, byte[] imageData); 735 | public delegate string Library_GetArtistPictureDelegate(string artistName, int fadingPercent, int fadingColor); 736 | public delegate bool Library_GetArtistPictureUrlsDelegate(string artistName, bool localOnly, ref string[] urls); 737 | public delegate string Library_GetArtistPictureThumbDelegate(string artistName); 738 | public delegate bool Library_QueryFilesDelegate(string query); 739 | public delegate string Library_QueryGetNextFileDelegate(); 740 | public delegate string Library_QueryGetAllFilesDelegate(); 741 | public delegate bool Library_QueryFilesExDelegate(string query, ref string[] files); 742 | public delegate string Library_QuerySimilarArtistsDelegate(string artistName, double minimumArtistSimilarityRating); 743 | public delegate bool Library_QueryLookupTableDelegate(string keyTags, string valueTags, string query); 744 | public delegate string Library_QueryGetLookupTableValueDelegate(string key); 745 | public delegate int Player_GetPositionDelegate(); 746 | public delegate bool Player_SetPositionDelegate(int position); 747 | public delegate PlayState Player_GetPlayStateDelegate(); 748 | public delegate bool Player_GetButtonEnabledDelegate(PlayButtonType button); 749 | public delegate bool Player_ActionDelegate(); 750 | public delegate int Player_QueueRandomTracksDelegate(int count); 751 | public delegate float Player_GetVolumeDelegate(); 752 | public delegate bool Player_SetVolumeDelegate(float volume); 753 | public delegate bool Player_GetMuteDelegate(); 754 | public delegate bool Player_SetMuteDelegate(bool mute); 755 | public delegate bool Player_GetShuffleDelegate(); 756 | public delegate bool Player_SetShuffleDelegate(bool shuffle); 757 | public delegate RepeatMode Player_GetRepeatDelegate(); 758 | public delegate bool Player_SetRepeatDelegate(RepeatMode repeat); 759 | public delegate bool Player_GetEqualiserEnabledDelegate(); 760 | public delegate bool Player_SetEqualiserEnabledDelegate(bool enabled); 761 | public delegate bool Player_GetDspEnabledDelegate(); 762 | public delegate bool Player_SetDspEnabledDelegate(bool enabled); 763 | public delegate bool Player_GetScrobbleEnabledDelegate(); 764 | public delegate bool Player_SetScrobbleEnabledDelegate(bool enabled); 765 | public delegate bool Player_GetShowTimeRemainingDelegate(); 766 | public delegate bool Player_GetShowRatingTrackDelegate(); 767 | public delegate bool Player_GetShowRatingLoveDelegate(); 768 | public delegate bool Player_ShowEqualiserDelegate(); 769 | public delegate bool Player_GetAutoDjEnabledDelegate(); 770 | public delegate bool Player_GetStopAfterCurrentEnabledDelegate(); 771 | public delegate bool Player_GetCrossfadeDelegate(); 772 | public delegate bool Player_SetCrossfadeDelegate(bool crossfade); 773 | public delegate ReplayGainMode Player_GetReplayGainModeDelegate(); 774 | public delegate bool Player_SetReplayGainModeDelegate(ReplayGainMode mode); 775 | public delegate int Player_OpenStreamHandleDelegate(string url, bool useMusicBeeSettings, bool enableDsp, ReplayGainMode gainType); 776 | public delegate bool Player_UpdatePlayStatisticsDelegate(string url, PlayStatisticType countType, bool disableScrobble); 777 | public delegate bool Player_GetOutputDevicesDelegate(out string[] deviceNames, out string activeDeviceName); 778 | public delegate bool Player_SetOutputDeviceDelegate(string deviceName); 779 | public delegate string NowPlaying_GetFileUrlDelegate(); 780 | public delegate int NowPlaying_GetDurationDelegate(); 781 | public delegate string NowPlaying_GetFilePropertyDelegate(FilePropertyType type); 782 | public delegate string NowPlaying_GetFileTagDelegate(MetaDataType field); 783 | public delegate bool NowPlaying_GetFileTagsDelegate(MetaDataType[] fields, ref string[] results); 784 | public delegate string NowPlaying_GetLyricsDelegate(); 785 | public delegate string NowPlaying_GetArtworkDelegate(); 786 | public delegate string NowPlaying_GetArtistPictureDelegate(int fadingPercent); 787 | public delegate bool NowPlaying_GetArtistPictureUrlsDelegate(bool localOnly, ref string[] urls); 788 | public delegate string NowPlaying_GetArtistPictureThumbDelegate(); 789 | public delegate bool NowPlaying_IsSoundtrackDelegate(); 790 | public delegate int NowPlaying_GetSpectrumDataDelegate(float[] fftData); 791 | public delegate bool NowPlaying_GetSoundGraphDelegate(float[] graphData); 792 | public delegate int NowPlayingList_GetCurrentIndexDelegate(); 793 | public delegate int NowPlayingList_GetNextIndexDelegate(int offset); 794 | public delegate bool NowPlayingList_IsAnyPriorTracksDelegate(); 795 | public delegate bool NowPlayingList_IsAnyFollowingTracksDelegate(); 796 | public delegate string NowPlayingList_GetFileUrlDelegate(int index); 797 | public delegate string NowPlayingList_GetFilePropertyDelegate(int index, FilePropertyType type); 798 | public delegate string NowPlayingList_GetFileTagDelegate(int index, MetaDataType field); 799 | public delegate bool NowPlayingList_GetFileTagsDelegate(int index, MetaDataType[] fields, ref string[] results); 800 | public delegate bool NowPlayingList_ActionDelegate(); 801 | public delegate bool NowPlayingList_FileActionDelegate(string sourceFileUrl); 802 | public delegate bool NowPlayingList_FilesActionDelegate(string[] sourceFileUrl); 803 | public delegate bool NowPlayingList_RemoveAtDelegate(int index); 804 | public delegate bool NowPlayingList_MoveFilesDelegate(int[] fromIndices, int toIndex); 805 | public delegate string Playlist_GetNameDelegate(string playlistUrl); 806 | public delegate PlaylistFormat Playlist_GetTypeDelegate(string playlistUrl); 807 | public delegate bool Playlist_QueryPlaylistsDelegate(); 808 | public delegate string Playlist_QueryGetNextPlaylistDelegate(); 809 | public delegate bool Playlist_IsInListDelegate(string playlistUrl, string filename); 810 | public delegate bool Playlist_QueryFilesDelegate(string playlistUrl); 811 | public delegate bool Playlist_QueryFilesExDelegate(string playlistUrl, ref string[] filenames); 812 | public delegate string Playlist_CreatePlaylistDelegate(string folderName, string playlistName, string[] filenames); 813 | public delegate bool Playlist_DeletePlaylistDelegate(string playlistUrl); 814 | public delegate bool Playlist_SetFilesDelegate(string playlistUrl, string[] filenames); 815 | public delegate bool Playlist_AddFilesDelegate(string playlistUrl, string[] filenames); 816 | public delegate bool Playlist_RemoveAtDelegate(string playlistUrl, int index); 817 | public delegate bool Playlist_MoveFilesDelegate(string playlistUrl, int[] fromIndices, int toIndex); 818 | public delegate bool Playlist_PlayNowDelegate(string playlistUrl); 819 | public delegate string Pending_GetFileUrlDelegate(); 820 | public delegate string Pending_GetFilePropertyDelegate(FilePropertyType field); 821 | public delegate string Pending_GetFileTagDelegate(MetaDataType field); 822 | public delegate string Sync_FileStartDelegate(string filename); 823 | public delegate void Sync_FileEndDelegate(string filename, bool success, string errorMessage); 824 | 825 | [System.Security.SuppressUnmanagedCodeSecurity()] 826 | [DllImport("kernel32.dll")] 827 | private static extern void CopyMemory(ref MusicBeeApiInterface mbApiInterface, IntPtr src, int length); 828 | } 829 | } -------------------------------------------------------------------------------- /NeteaseApi.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Http; 8 | using System.Text; 9 | 10 | namespace MusicBeePlugin 11 | { 12 | /* 13 | * Partially adopted from https://github.com/real-zony/ZonyLrcToolsX/blob/dev/src/ZonyLrcTools.Common/Lyrics/Providers/NetEase/NetEaseLyricsProvider.cs 14 | */ 15 | internal static class NeteaseApi 16 | { 17 | public static IEnumerable Search(string s) 18 | { 19 | var postData = new Dictionary 20 | { 21 | { "csrf_token", "" }, 22 | { "s", s }, 23 | { "offset", 0 }, 24 | { "type", 1 }, 25 | { "limit", 20 } 26 | }; 27 | var result = RequestNewApi( 28 | @"https://music.163.com/weapi/search/get", 29 | postData, it => it.code == 200); 30 | if (result == null) 31 | return SearchLegacy(s); 32 | return result.result.songCount > 0 ? result.result.songs : Enumerable.Empty(); 33 | } 34 | 35 | public static LyricResult RequestLyric(long id) 36 | { 37 | var postData = new Dictionary 38 | { 39 | { "OS", "pc" }, 40 | { "id", id }, 41 | { "lv", -1 }, 42 | { "kv", -1 }, 43 | { "tv", -1 }, 44 | { "rv", -1 } 45 | }; 46 | return RequestNewApi( 47 | @"https://music.163.com/weapi/song/lyric?csrf_token=", 48 | postData, it => it.code == 200) ?? RequestLyricLegacy(id); 49 | } 50 | 51 | private static T RequestNewApi(string url, Dictionary postData, Func checkFunc) 52 | where T : class 53 | { 54 | try 55 | { 56 | using (var client = new HttpClient()) 57 | { 58 | client.DefaultRequestHeaders.Referrer = new Uri(@"https://music.163.com"); 59 | client.DefaultRequestHeaders.UserAgent.ParseAdd( 60 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"); 61 | using (var result = client.PostAsync( 62 | url, 63 | new FormUrlEncodedContent(EncryptRequest(postData))).Result) 64 | { 65 | var resultString = result.Content.ReadAsStringAsync().Result; 66 | if (!result.IsSuccessStatusCode) 67 | throw new HttpRequestException($"non 200 response from {url}: {resultString}");; 68 | var resultObject = JsonConvert.DeserializeObject(resultString); 69 | if (!checkFunc(resultObject)) 70 | throw new HttpRequestException($"non 200 response from {url}: {resultString}"); 71 | return resultObject; 72 | } 73 | } 74 | } 75 | catch (Exception e) 76 | { 77 | Debug.WriteLine(e); 78 | return null; 79 | } 80 | } 81 | 82 | private static Dictionary EncryptRequest(object srcParams) 83 | { 84 | var secretKey = NeteaseMusicEncryptionHelper.CreateSecretKey(16); 85 | var encSecKey = NeteaseMusicEncryptionHelper.RsaEncode(secretKey); 86 | return new Dictionary 87 | { 88 | { 89 | "params", 90 | NeteaseMusicEncryptionHelper.AesEncode( 91 | NeteaseMusicEncryptionHelper.AesEncode( 92 | JsonConvert.SerializeObject(srcParams), 93 | NeteaseMusicEncryptionHelper.Nonce), 94 | secretKey) 95 | }, 96 | { "encSecKey", encSecKey } 97 | }; 98 | } 99 | 100 | private static IEnumerable SearchLegacy(string s) 101 | { 102 | try 103 | { 104 | using (var client = new WebClient()) 105 | { 106 | client.Headers[HttpRequestHeader.Referer] = "https://music.163.com/"; 107 | client.Headers[HttpRequestHeader.UserAgent] = 108 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"; 109 | 110 | var nameEncoded = Uri.EscapeDataString(s); 111 | var resultStr = Encoding.UTF8.GetString( 112 | client.DownloadData( 113 | $"http://music.163.com/api/search/get/?csrf_token=hlpretag=&hlposttag=&s={nameEncoded}&type=1&offset=0&total=true&limit=6") 114 | ); 115 | var searchResult = JsonConvert.DeserializeObject(resultStr); 116 | if (searchResult.code != 200) return null; 117 | return searchResult.result.songCount <= 0 118 | ? Enumerable.Empty() 119 | : searchResult.result.songs; 120 | } 121 | } 122 | catch (Exception ex) 123 | { 124 | Debug.WriteLine(ex); 125 | return Enumerable.Empty(); 126 | } 127 | } 128 | 129 | private static LyricResult RequestLyricLegacy(long id) 130 | { 131 | try 132 | { 133 | using (var client = new WebClient()) 134 | { 135 | client.Headers[HttpRequestHeader.Referer] = "http://music.163.com/"; 136 | client.Headers[HttpRequestHeader.Cookie] = "appver=1.5.0.75771;"; 137 | var lyricResult = JsonConvert.DeserializeObject( 138 | Encoding.UTF8.GetString(client.DownloadData("http://music.163.com/api/song/lyric?os=pc&id=" + 139 | id + "&lv=-1&kv=-1&tv=-1"))); 140 | return lyricResult.code != 200 ? null : lyricResult; 141 | } 142 | } 143 | catch (Exception ex) 144 | { 145 | Debug.WriteLine(ex); 146 | return null; 147 | } 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /NeteaseLyrics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | using System.Drawing; 4 | using System.Windows.Forms; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Text; 9 | using Newtonsoft.Json; 10 | using System.Text.RegularExpressions; 11 | using System.Runtime.CompilerServices; 12 | 13 | [assembly: InternalsVisibleTo("NeteaseLyricsTest")] 14 | 15 | namespace MusicBeePlugin 16 | { 17 | public class NeteaseConfig 18 | { 19 | public enum OutputFormat 20 | { 21 | Original = 0, 22 | Both = 1, 23 | Translation = 2 24 | } 25 | 26 | public OutputFormat Format { get; set; } = OutputFormat.Both; 27 | public bool Fuzzy { get; set; } 28 | public bool UseLegacyMatch { get; set; } 29 | } 30 | 31 | public partial class Plugin 32 | { 33 | private const string ProviderName = "Netease Cloud Music(网易云音乐)"; 34 | private const string ConfigFilename = "netease_config"; 35 | private const string NoTranslateFilename = "netease_notranslate"; 36 | private NeteaseConfig _config = new NeteaseConfig(); 37 | private ComboBox _formatComboBox; 38 | private CheckBox _fuzzyCheckBox; 39 | private CheckBox _useLegacyCheckBox; 40 | 41 | private MusicBeeApiInterface _mbApiInterface; 42 | private readonly PluginInfo _about = new PluginInfo(); 43 | 44 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 45 | public PluginInfo Initialise(IntPtr apiInterfacePtr) 46 | { 47 | var versions = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); 48 | 49 | _mbApiInterface = new MusicBeeApiInterface(); 50 | _mbApiInterface.Initialise(apiInterfacePtr); 51 | _about.PluginInfoVersion = PluginInfoVersion; 52 | _about.Name = "Netease Lyrics"; 53 | _about.Description = "A plugin to retrieve lyrics from Netease Cloud Music.(从网易云音乐获取歌词的插件。)"; 54 | _about.Author = "Charlie Jiang"; 55 | _about.TargetApplication = ""; // current only applies to artwork, lyrics or instant messenger name that appears in the provider drop down selector or target Instant Messenger 56 | _about.Type = PluginType.LyricsRetrieval; 57 | _about.VersionMajor = short.Parse(versions[0]); // your plugin version 58 | _about.VersionMinor = short.Parse(versions[1]); 59 | _about.Revision = short.Parse(versions[2]); 60 | _about.MinInterfaceVersion = MinInterfaceVersion; 61 | _about.MinApiRevision = MinApiRevision; 62 | _about.ReceiveNotifications = ReceiveNotificationFlags.DownloadEvents; 63 | _about.ConfigurationPanelHeight = 120; // height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function 64 | 65 | ReadConfig(); 66 | MigrateLegacySetting(); 67 | return _about; 68 | } 69 | 70 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 71 | public bool Configure(IntPtr panelHandle) 72 | { 73 | if (panelHandle == IntPtr.Zero) return false; 74 | var configPanel = (Panel)Control.FromHandle(panelHandle); 75 | // Components are automatically disposed when this is called. 76 | configPanel.Controls.Clear(); 77 | 78 | // MB_AddPanel doesn't skin the component correctly either 79 | //_formatComboBox = (ComboBox)_mbApiInterface.MB_AddPanel(null, PluginPanelDock.ComboBox); 80 | _formatComboBox = new ComboBox 81 | { 82 | DropDownStyle = ComboBoxStyle.DropDownList, 83 | AutoSize = true, 84 | Location = new Point(0, 0), 85 | Width = 300 86 | }; 87 | _formatComboBox.Items.Add("Only original text"); 88 | _formatComboBox.Items.Add("Original text and translation"); 89 | _formatComboBox.Items.Add("Only translation"); 90 | _formatComboBox.SelectedIndex = (int)_config.Format; 91 | configPanel.Controls.Add(_formatComboBox); 92 | 93 | _useLegacyCheckBox = new CheckBox 94 | { 95 | Text = "Use legacy matching strategy", 96 | Location = new Point(0, 50), 97 | Checked = _config.UseLegacyMatch, 98 | AutoSize = true 99 | }; 100 | 101 | _fuzzyCheckBox = new CheckBox 102 | { 103 | Text = "Fuzzy matching (Don't double check match and use first result directly)", 104 | Location = new Point(0, 80), 105 | Checked = _config.Fuzzy, 106 | AutoSize = true 107 | }; 108 | 109 | _useLegacyCheckBox.CheckedChanged += (sender, e) => 110 | { 111 | // "Fuzzy" not available when using new strategy 112 | _fuzzyCheckBox.Enabled = !_useLegacyCheckBox.Checked; 113 | }; 114 | 115 | configPanel.Controls.Add(_useLegacyCheckBox); 116 | configPanel.Controls.Add(_fuzzyCheckBox); 117 | 118 | return false; 119 | } 120 | 121 | // called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen. 122 | // It's up to you to figure out whether anything has changed and needs updating 123 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 124 | public void SaveSettings() 125 | { 126 | if (_formatComboBox.SelectedIndex < 0 || _formatComboBox.SelectedIndex > 2) 127 | _config.Format = NeteaseConfig.OutputFormat.Both; 128 | else 129 | _config.Format = (NeteaseConfig.OutputFormat)_formatComboBox.SelectedIndex; 130 | _config.Fuzzy = _fuzzyCheckBox.Checked; 131 | _config.UseLegacyMatch = _useLegacyCheckBox.Checked; 132 | SaveSettingsInternal(); 133 | } 134 | 135 | private void SaveSettingsInternal() 136 | { 137 | var configPath = Path.Combine(_mbApiInterface.Setting_GetPersistentStoragePath(), ConfigFilename); 138 | var json = JsonConvert.SerializeObject(_config); 139 | File.WriteAllText(configPath, json, Encoding.UTF8); 140 | } 141 | 142 | // MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down) 143 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 144 | [SuppressMessage("ReSharper", "UnusedParameter.Global")] 145 | public void Close(PluginCloseReason reason) 146 | { 147 | } 148 | 149 | // uninstall this plugin - clean up any persisted files 150 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 151 | public void Uninstall() 152 | { 153 | var dataPath = _mbApiInterface.Setting_GetPersistentStoragePath(); 154 | var p = Path.Combine(dataPath, NoTranslateFilename); 155 | if (File.Exists(p)) File.Delete(p); 156 | var configPath = Path.Combine(_mbApiInterface.Setting_GetPersistentStoragePath(), ConfigFilename); 157 | if (File.Exists(configPath)) File.Delete(configPath); 158 | } 159 | 160 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 161 | [SuppressMessage("ReSharper", "UnusedParameter.Global")] 162 | public string RetrieveLyrics(string sourceFileUrl, 163 | string artist, string trackTitle, string album, 164 | bool synchronisedPreferred, string provider) 165 | { 166 | if (provider != ProviderName) return null; 167 | 168 | var specifiedId = _mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.Custom10) 169 | ?? _mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Custom10); 170 | 171 | var id = TryParseNeteaseUrl(specifiedId); 172 | if (id == 0) 173 | { 174 | var realTitle = _mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.TrackTitle); 175 | var realArtist = _mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.Artist); 176 | var realAlbum = _mbApiInterface.Library_GetFileTag(sourceFileUrl, MetaDataType.Album); 177 | var durationStr = _mbApiInterface.Library_GetFileProperty(sourceFileUrl, FilePropertyType.Duration); 178 | id = !_config.UseLegacyMatch 179 | ? SearchMatch.SearchAndMatch(realTitle, realArtist, realAlbum, ParseDurationString(durationStr)) 180 | : SearchMatchLegacy.QueryWithFeatRemoved(realTitle, realArtist, _config.Fuzzy); 181 | } 182 | 183 | if (id == 0) 184 | return null; 185 | 186 | var lyricResult = NeteaseApi.RequestLyric(id); 187 | 188 | if (lyricResult.lrc?.lyric == null) return null; 189 | if (lyricResult.tlyric?.lyric == null || _config.Format == NeteaseConfig.OutputFormat.Original) 190 | return lyricResult.lrc.lyric; // No need to process translation 191 | 192 | if (_config.Format == NeteaseConfig.OutputFormat.Translation) 193 | return lyricResult.tlyric?.lyric ?? lyricResult.lrc.lyric; 194 | // translation 195 | return LyricProcessor.InjectTranslation(lyricResult.lrc.lyric, lyricResult.tlyric.lyric); 196 | } 197 | 198 | private void ReadConfig() 199 | { 200 | var configPath = Path.Combine(_mbApiInterface.Setting_GetPersistentStoragePath(), ConfigFilename); 201 | if (!File.Exists(configPath)) 202 | return; 203 | try 204 | { 205 | _config = JsonConvert.DeserializeObject(File.ReadAllText(configPath, Encoding.UTF8)); 206 | } 207 | catch (Exception ex) 208 | { 209 | _mbApiInterface.MB_Trace("[NeteaseMusic] Failed to load config" + ex); 210 | } 211 | } 212 | 213 | private void MigrateLegacySetting() 214 | { 215 | var noTranslatePath = Path.Combine(_mbApiInterface.Setting_GetPersistentStoragePath(), NoTranslateFilename); 216 | if (!File.Exists(noTranslatePath)) 217 | return; 218 | File.Delete(noTranslatePath); 219 | _config.Format = NeteaseConfig.OutputFormat.Original; 220 | SaveSettingsInternal(); 221 | } 222 | 223 | private static long TryParseNeteaseUrl(string input) 224 | { 225 | if (input == null) 226 | return 0; 227 | if (input.StartsWith("netease=")) 228 | { 229 | input = input.Substring("netease=".Length); 230 | long.TryParse(input, out var id); 231 | return id; 232 | } 233 | 234 | if (!input.Contains("music.163.com")) 235 | return 0; 236 | 237 | var matches = Regex.Matches(input, "id=(\\d+)"); 238 | if (matches.Count <= 0) 239 | return 0; 240 | 241 | var groups = matches[0].Groups; 242 | if (groups.Count <= 1) 243 | return 0; 244 | 245 | var idString = groups[1].Captures[0].Value; 246 | long.TryParse(idString, out var id2); 247 | return id2; 248 | } 249 | 250 | private static long ParseDurationString(string durationStr) 251 | { 252 | var multiplier = 1000L; 253 | var sum = 0L; 254 | foreach (var part in durationStr.Split(':').Reverse()) 255 | { 256 | if (part.Length > 0) 257 | sum += multiplier * long.Parse(part); 258 | multiplier *= 60; 259 | } 260 | return sum; 261 | } 262 | 263 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 264 | public string[] GetProviders() 265 | { 266 | return new []{ProviderName}; 267 | } 268 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 269 | public void ReceiveNotification(string sourceFileUrl, NotificationType type) 270 | { 271 | } 272 | } 273 | } -------------------------------------------------------------------------------- /NeteaseLyrics.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 9.0.30729 8 | 2.0 9 | {F5D46BA1-6F21-40EF-9695-46105CCACD08} 10 | Library 11 | Properties 12 | MusicBeePlugin 13 | mb_NeteaseLyrics 14 | v4.8 15 | 512 16 | 17 | 18 | 3.5 19 | 20 | publish\ 21 | true 22 | Disk 23 | false 24 | Foreground 25 | 7 26 | Days 27 | false 28 | false 29 | true 30 | 0 31 | 1.0.0.%2a 32 | false 33 | false 34 | true 35 | 36 | 37 | 38 | 39 | 40 | true 41 | full 42 | false 43 | bin\Debug\ 44 | DEBUG;TRACE 45 | prompt 46 | 4 47 | false 48 | 49 | 50 | pdbonly 51 | true 52 | bin\Release\ 53 | TRACE 54 | prompt 55 | 4 56 | false 57 | 58 | 59 | true 60 | bin\x86\Debug\ 61 | DEBUG;TRACE 62 | full 63 | x86 64 | prompt 65 | true 66 | true 67 | false 68 | 69 | 70 | bin\x86\Release\ 71 | TRACE 72 | true 73 | pdbonly 74 | x86 75 | prompt 76 | false 77 | false 78 | false 79 | 80 | 81 | 82 | packages\Costura.Fody.3.2.2\lib\net40\Costura.dll 83 | 84 | 85 | packages\Newtonsoft.Json.12.0.1\lib\net40\Newtonsoft.Json.dll 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | False 113 | Microsoft .NET Framework 4 %28x86 and x64%29 114 | true 115 | 116 | 117 | False 118 | .NET Framework 3.5 SP1 Client Profile 119 | false 120 | 121 | 122 | False 123 | .NET Framework 3.5 SP1 124 | false 125 | 126 | 127 | False 128 | Windows Installer 3.1 129 | true 130 | 131 | 132 | 133 | 134 | 135 | 136 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | $(TargetPath) 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /NeteaseLyrics.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34728.123 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeteaseLyrics", "NeteaseLyrics.csproj", "{F5D46BA1-6F21-40EF-9695-46105CCACD08}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeteaseLyricsTest", "..\NeteaseLyricsTest\NeteaseLyricsTest.csproj", "{0969FA2C-61EE-4EC4-B386-156C344ED099}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Debug|x86.ActiveCfg = Debug|x86 21 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Debug|x86.Build.0 = Debug|x86 22 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|x86.ActiveCfg = Release|x86 25 | {F5D46BA1-6F21-40EF-9695-46105CCACD08}.Release|x86.Build.0 = Release|x86 26 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Debug|x86.ActiveCfg = Debug|Any CPU 29 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Debug|x86.Build.0 = Debug|Any CPU 30 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Release|x86.ActiveCfg = Release|Any CPU 33 | {0969FA2C-61EE-4EC4-B386-156C344ED099}.Release|x86.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /NeteaseMusicEncryptionHandler.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Numerics; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System; 7 | 8 | namespace MusicBeePlugin 9 | { 10 | /* 11 | * Adopted from https://github.com/real-zony/ZonyLrcToolsX/blob/dev/src/ZonyLrcTools.Common/Infrastructure/Encryption/NetEaseMusicEncryptionHelper.cs 12 | * (MIT License) 13 | * and https://github.com/jitwxs/163MusicLyrics/blob/master/MusicLyricApp/Api/Music/NetEaseMusicNativeApi.cs 14 | * and https://github.com/mos9527/pyncm/blob/ad0a84b2ed5f1affa9890d5f54f6170c2cf99bbb/pyncm/utils/crypto.py#L53 15 | */ 16 | internal static class NeteaseMusicEncryptionHelper 17 | { 18 | private const string Modulus = 19 | "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"; 20 | 21 | internal const string Nonce = "0CoJUm6Qyw8W8jud"; 22 | private const string PubKey = "010001"; 23 | private const string Vi = "0102030405060708"; 24 | private static readonly byte[] ID_XOR_KEY_1 = Encoding.UTF8.GetBytes("3go8&$8*3*3h0k(2)2"); 25 | 26 | public static string RsaEncode(string text) 27 | { 28 | var srText = new string(text.Reverse().ToArray()); 29 | var a = BCHexDec(BitConverter.ToString(Encoding.Default.GetBytes(srText)).Replace("-", string.Empty)); 30 | var b = BCHexDec(PubKey); 31 | var c = BCHexDec(Modulus); 32 | var key = BigInteger.ModPow(a, b, c).ToString("x"); 33 | key = key.PadLeft(256, '0'); 34 | 35 | return key.Length > 256 ? key.Substring(key.Length - 256, 256) : key; 36 | } 37 | 38 | public static BigInteger BCHexDec(string hex) 39 | { 40 | var dec = new BigInteger(0); 41 | var len = hex.Length; 42 | 43 | for (var i = 0; i < len; i++) 44 | { 45 | dec += BigInteger.Multiply(new BigInteger(Convert.ToInt32(hex[i].ToString(), 16)), 46 | BigInteger.Pow(new BigInteger(16), len - i - 1)); 47 | } 48 | 49 | return dec; 50 | } 51 | 52 | public static string AesEncode(string secretData, string secret = "TA3YiYCfY2dDJQgg") 53 | { 54 | byte[] encrypted; 55 | var iv = Encoding.UTF8.GetBytes(Vi); 56 | 57 | using (var aes = Aes.Create()) 58 | { 59 | aes.Key = Encoding.UTF8.GetBytes(secret); 60 | aes.IV = iv; 61 | aes.Mode = CipherMode.CBC; 62 | using (var encryptor = aes.CreateEncryptor()) 63 | { 64 | using (var stream = new MemoryStream()) 65 | { 66 | using (var cryptoStream = new CryptoStream(stream, encryptor, CryptoStreamMode.Write)) 67 | { 68 | using (var sw = new StreamWriter(cryptoStream)) 69 | { 70 | sw.Write(secretData); 71 | } 72 | 73 | encrypted = stream.ToArray(); 74 | } 75 | } 76 | } 77 | } 78 | 79 | return Convert.ToBase64String(encrypted); 80 | } 81 | 82 | public static string CreateSecretKey(int length) 83 | { 84 | const string str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 85 | var sb = new StringBuilder(length); 86 | var rnd = new Random(); 87 | 88 | for (var i = 0; i < length; ++i) 89 | { 90 | sb.Append(str[rnd.Next(0, str.Length)]); 91 | } 92 | 93 | return sb.ToString(); 94 | } 95 | 96 | public static string CloudMusicDllEncode(string deviceId) 97 | { 98 | var xored = new byte[deviceId.Length]; 99 | for (var i = 0; i < deviceId.Length; i++) 100 | { 101 | xored[i] = (byte)(deviceId[i] ^ ID_XOR_KEY_1[i % ID_XOR_KEY_1.Length]); 102 | } 103 | 104 | using (var md5 = MD5.Create()) 105 | { 106 | var digest = md5.ComputeHash(xored); 107 | return Convert.ToBase64String(digest); 108 | } 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NeteaseLyrics")] 9 | [assembly: AssemblyDescription("A plugin to retrieve lyrics from Netease Cloud Music.")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NeteaseLyrics")] 13 | [assembly: AssemblyCopyright("Copyright © chariri 2024")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("34d2725e-ae30-4f65-ad54-9eade3bb5973")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.9.0.0")] 36 | [assembly: AssemblyFileVersion("1.9.0.0")] 37 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Netease Lyric 2 | 3 | This is another lyrics retrieval plugin for music player MusicBee. It can get **synchronized** lyrics from Netease Cloud Music(网易云音乐, a cloud music service in China). 4 | 5 | It can combine the translation to the lyrics if available, like: 6 | Blalalala(Original) 7 | Alalalala(Translation) 8 | is wrapped to: Blalalala/Alalalalala 9 | etc.. 10 | 11 | But if you don't want this function you can disable it in plugin settings. 12 | 13 | ## Usage 14 | To use this plugin, download it from links below: 15 | For users who is not in China: 16 | [OneDrive](https://1drv.ms/f/s!AicHZ6DLvCtX6Qp6KQfEppoQtjLG) 17 | For users who is in China: 18 | [BaiduYun](https://pan.baidu.com/s/1ZL9dyrAczhPSMvMtvvG5yA?pwd=vede) , passcode: `vede` 19 | Install(via "Add plugin" button) and enable it in the `Plugin` tab in the preferences. 20 | And adjust the retrieving provider priority of "Netease Cloud Music" in the Tags(2) Tab. 21 | If you want a specific song's lyric from NetEase Cloud Music to be matched, you may set the `custom10` tag to the song URL like `https://music.163.com/#/song?id=29126914` (You can directly copy URL like this from the Netease website or client) or `netease=123123` (where "123123" should be your song id) in the music and re-search lyrics. 22 | 23 | ## For non-Chinese users 24 | And this plugin is also useful for people who aren't from China as Netease CloudMusic also has bunch of songs in other languages. You can disable the translation in the plugin settings. 25 | 26 | # 网易云音乐歌词 27 | 28 | 这是MusicBee另一个获取歌词的插件。可以从网易云音乐获取**同步歌词**。 29 | 30 | 该插件可以合并歌词翻译(如果有的话)到歌词。例如: 31 | 巴拉巴拉巴拉巴(原句) 32 | 阿啦啦啦啦啦(翻译) 33 | 会被合并为:巴拉巴拉巴拉巴/阿啦啦啦啦啦 34 | 35 | 如果不想要这个功能可以在设置里面的插件设置中关闭。 36 | 如果想设置网易云音乐中特定的歌曲,可以在 `标签 (2)` 标签页给歌曲设定 `custom10` 标签,内容为曲目的 URL,比如 `https://music.163.com/#/song?id=29126914`(可以直接从网易云网站或客户端复制下来),或者 `netease=123123`,其中 123123 是曲目的 ID,并重新搜索歌词。 37 | 38 | ## 使用 39 | 从[度盘](https://pan.baidu.com/s/1ZL9dyrAczhPSMvMtvvG5yA?pwd=vede)下载(提取码 `vede`),并在首选项的 `插件` 中安装(“添加插件”按钮)、启用插件,在 `标签 (2)` 标签页调整歌词的提供者优先级。 40 | -------------------------------------------------------------------------------- /SearchMatch.cs: -------------------------------------------------------------------------------- 1 | using F23.StringSimilarity; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace MusicBeePlugin 8 | { 9 | internal static class SearchMatch 10 | { 11 | /// 12 | /// 有多个 artist 时,分割各 artist 的符号。 13 | /// 部分圈子的人喜欢用比较有个性的分割符,比如“ x ”,此事在《みんなみくみくにしてあげる♪》中亦有记载 14 | /// 15 | private static readonly string[] Delimiters = {"/", "&", ",", ",", " x ", " * ", "\u00d7", "\u00B7"}; 16 | private static readonly Regex FeatPatternWithoutParenthesis = new Regex(@"\s+feat(.+)"); 17 | private static readonly Regex FeatPatternWithParenthesis = new Regex(@"\s*\(feat(.+)\)"); 18 | 19 | public static long SearchAndMatch(string title, string artist, string album, long duration) 20 | { 21 | var (titleWithoutArtist, artists) = SplitTitleArtist(title, artist); 22 | var artistsStr = string.Join(" ", artists); 23 | var results = new HashSet(new IdOnlyEqualityComparer()); 24 | results.UnionWith(NeteaseApi.Search(titleWithoutArtist)); 25 | results.UnionWith(NeteaseApi.Search($"{titleWithoutArtist} {artistsStr}")); 26 | results.UnionWith(NeteaseApi.Search($"{titleWithoutArtist} {artistsStr} {album}")); 27 | 28 | if (results.Count <= 0) 29 | return 0; 30 | var ranked = results.Select(it => ( 31 | rank: CalculateMatchScore(it, titleWithoutArtist, artistsStr, album, duration), 32 | it.id, // prevent comparer from checking `song`, because SearchResultSong is not comparable. 33 | song: it) 34 | ).ToList(); 35 | ranked.Sort(); 36 | return ranked.Max().song.id; 37 | } 38 | 39 | private static double CalculateMatchScore( 40 | SearchResultSong song, string titleWithoutArtist, string artistsStr, 41 | string album, long duration) 42 | { 43 | var resultArtists = song.artists.Select(it => it.name).ToList(); 44 | resultArtists.Sort(); 45 | var resultArtistsStr = string.Join(" ", resultArtists); 46 | 47 | // “距离”公式: 48 | // 歌曲长度距离^2 + 标题距离 * 2 + 表演者距离 * 0.7 + 专辑距离 * 1 49 | // 因为长度是比较重要的 metrics,并且当长度差得超过一定距离的时候应该起到“一票否决”的效果,因此使用了平方 50 | var l = new Levenshtein(); 51 | var durationDiff = (duration / 1000.0 - song.duration / 1000.0); 52 | var score = -(durationDiff * durationDiff); 53 | score -= l.Distance(titleWithoutArtist, song.name) * 2; 54 | score -= l.Distance(artistsStr, resultArtistsStr) * 0.7; 55 | score -= l.Distance(album, song.album.name); 56 | return score; 57 | } 58 | 59 | /// 60 | /// 有些人会把 (feat. Somebody) 这样的信息写在曲目标题里面, 61 | /// 并且网易云不会做特殊处理(网易云本身支持多 artist),因此会搜出来一堆奇怪的结果。 62 | /// 因此需要先把这些 feat. 的子句提出来放到 artist 里面。 63 | /// 当然 Artist 里面的也需要处理 64 | /// 65 | /// 66 | public static (string, IEnumerable) SplitTitleArtist(string title, string artist) 67 | { 68 | var (artistsWithoutFeat, featArtists) = ExtractFeat(SanitizeString(artist)); 69 | 70 | var artists = artistsWithoutFeat.Split(Delimiters, StringSplitOptions.RemoveEmptyEntries) 71 | .Select(it => it.Trim()) 72 | .ToList(); 73 | artists.AddRange(featArtists); 74 | 75 | var (titleWithoutFeat, featArtists2) = ExtractFeat(SanitizeString(title)); 76 | artists.AddRange(featArtists2); 77 | 78 | artists.Sort(); 79 | return (titleWithoutFeat, artists); 80 | } 81 | 82 | private static string SanitizeString(string str) 83 | { 84 | return str.Replace('(', '(').Replace(')', ')').Replace('\u00A0', ' '); 85 | } 86 | 87 | private static (string, IEnumerable) ExtractFeat(string str) 88 | { 89 | var match = FeatPatternWithParenthesis.Match(str); 90 | if (!match.Success) 91 | match = FeatPatternWithoutParenthesis.Match(str); 92 | if (!match.Success) return (str, Enumerable.Empty()); 93 | 94 | str = str.Remove(match.Index, match.Length).Trim(); 95 | if (match.Groups.Count <= 0) return (str, Enumerable.Empty()); 96 | 97 | var featClause = match.Groups[1].Captures[0].Value; 98 | featClause = featClause.TrimStart('.', ' '); 99 | if (featClause.EndsWith(")")) 100 | featClause = featClause.Substring(0, featClause.Length - 1); 101 | 102 | return (str, featClause.Split(Delimiters, StringSplitOptions.RemoveEmptyEntries).Select(it => it.Trim())); 103 | } 104 | 105 | private class IdOnlyEqualityComparer : EqualityComparer 106 | { 107 | public override bool Equals(SearchResultSong x, SearchResultSong y) 108 | { 109 | if (ReferenceEquals(x, y)) return true; 110 | if (x is null) return false; 111 | if (y is null) return false; 112 | if (x.GetType() != y.GetType()) return false; 113 | return x.id == y.id; 114 | } 115 | 116 | public override int GetHashCode(SearchResultSong obj) 117 | { 118 | return obj.id.GetHashCode(); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /SearchMatchLegacy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace MusicBeePlugin 6 | { 7 | /// 8 | /// 旧的匹配设置 9 | /// 10 | internal static class SearchMatchLegacy 11 | { 12 | public static long QueryWithFeatRemoved(string trackTitle, string artist, bool fuzzy) 13 | { 14 | var ret = Query(trackTitle, artist, fuzzy); 15 | if (ret != null) return ret.id; 16 | 17 | ret = Query(RemoveLeadingNumber(RemoveFeat(trackTitle)), artist, fuzzy); 18 | return ret?.id ?? 0; 19 | } 20 | 21 | private static SearchResultSong Query(string trackTitle, string artist, bool fuzzy) 22 | { 23 | var ret = NeteaseApi.Search(trackTitle + " " + artist)?.Where(rst => 24 | fuzzy || string.Equals(GetFirstSeq(RemoveLeadingNumber(rst.name)), GetFirstSeq(trackTitle), 25 | StringComparison.OrdinalIgnoreCase)).ToList(); 26 | if (ret != null && ret.Count > 0) return ret[0]; 27 | 28 | ret = NeteaseApi.Search(trackTitle)?.Where(rst => 29 | fuzzy || string.Equals(GetFirstSeq(RemoveLeadingNumber(rst.name)), GetFirstSeq(trackTitle), 30 | StringComparison.OrdinalIgnoreCase)).ToList(); 31 | return ret != null && ret.Count > 0 ? ret[0] : null; 32 | } 33 | 34 | private static string GetFirstSeq(string s) 35 | { 36 | s = s.Replace("\u00A0", " "); 37 | var pos = s.IndexOf(' '); 38 | return s.Substring(0, pos == -1 ? s.Length : pos).Trim(); 39 | } 40 | 41 | private static string RemoveFeat(string name) 42 | { 43 | return Regex.Replace(name, @"\s*\(feat.+\)", "", RegexOptions.IgnoreCase); 44 | } 45 | 46 | private static string RemoveLeadingNumber(string name) 47 | { 48 | return Regex.Replace(name, @"^\d+\.?\s*", "", RegexOptions.IgnoreCase); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | --------------------------------------------------------------------------------