├── FiddlerCore4.dll ├── Unblock163MusicClient ├── packages.config ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── Unblock163MusicClient.csproj └── Program.cs ├── Unblock163MusicClient.sln ├── .gitattributes ├── README.md ├── .gitignore └── LICENSE /FiddlerCore4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EraserKing/Unblock163MusicClient/HEAD/FiddlerCore4.dll -------------------------------------------------------------------------------- /Unblock163MusicClient/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Unblock163MusicClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Unblock163MusicClient.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unblock163MusicClient", "Unblock163MusicClient\Unblock163MusicClient.csproj", "{11986D6C-2B2C-4197-A3B7-03AA21430705}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {11986D6C-2B2C-4197-A3B7-03AA21430705}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {11986D6C-2B2C-4197-A3B7-03AA21430705}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {11986D6C-2B2C-4197-A3B7-03AA21430705}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {11986D6C-2B2C-4197-A3B7-03AA21430705}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Unblock163MusicClient/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("Unblock163MusicClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Unblock163MusicClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 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("11986d6c-2b2c-4197-a3b7-03aa21430705")] 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("0.5.0.0")] 36 | [assembly: AssemblyFileVersion("0.5.0.0")] 37 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IMPORTANT NOTICE 2 | This project is discontinued. Please visit [https://github.com/EraserKing/CloudMusicGear] and switch to the new tool. 3 | 4 | # Unblock163MusicClient 5 | 6 | Unblock 163 Cloud Music Windows client. 7 | 8 | Acts as a proxy. 9 | 10 | Didn't do much about this, but just to prove it works! 11 | 12 | When you access song / album / artist / playlist page, or search result, you should find the disabled songs return to enabled. 13 | 14 | ## Usage 15 | 16 | 1. Run and it listens at port 3412 (default). 17 | 2. Open Windows client, set proxy to IP 127.0.0.1, port 3412. 18 | 3. Save and restart the client. 19 | 4. Enjoy! 20 | 21 | ## Command line arugments 22 | 23 | `/port` : specify the port it listens at. **Example**: `/port 3456` 24 | 25 | `/verbose`: turn on verbose log. 26 | 27 | `/overseas`: turn on overseas mode (not tested yet). *Not recommended for Mainland China users.* 28 | 29 | `/overseasproxy`: assign a reverse proxy for overseas users. *This should be used when the default overseas mode is not working.* **`/overseas` must be turned on first.** **Example**: `/overseasproxy 14.215.9.16` 30 | 31 | Available proxys are `14.215.9.16, 14.215.9.43, 219.138.27.16, 219.138.27.67, 163.177.171.13, 163.177.171.14, 163.177.171.16, 163.177.171.17, 163.177.171.18, 163.177.171.19, 163.177.171.20, 163.177.171.21, 163.177.171.22, 163.177.171.28, 163.177.171.29, 163.177.171.31, 163.177.171.32, 163.177.171.33, 163.177.171.34, 163.177.171.35, 163.177.171.37, 163.177.171.175, 163.177.171.206`. 32 | 33 | `/playbackbitrate`: override the playback bitrate specified in the client. **Accepted values**: `96000`, `128000`, `192000`, `320000`. **Example**: `/playbackbitrate 320000` 34 | 35 | `/downloadbitrate`: override the download bitrate specified in the client. **Accepted values**: `96000`, `128000`, `192000`, `320000`. **Example**: `/downloadbitrate 320000` 36 | 37 | ## Download 38 | 39 | See [https://github.com/EraserKing/Unblock163MusicClient/releases] 40 | 41 | ## Known issues 42 | 43 | 1. Download is working, but if you just specify download quality to 320k, you may find during downloading the quality returns to 128k. This cannot be solved, but it's **strongly recommended to override the download bitrate to 320k** via command line arguments `/downloadbitrate 320000`. 44 | 2. The settings playback music quality won't take effect immediately after you change them; instead it will only be switched properly after it meets a normal song (not disabled). **You could use command line arguments to override this!** 45 | 46 | ## Open issues 47 | 48 | Please report the following information: 49 | 50 | * Operating system 51 | * Song / Album / Playlist name (how I can locate to that song) 52 | * Whether the issue happens on specific songs, or all songs 53 | * Whether it can be reproduced on web client for the same song 54 | 55 | ## Building 56 | 57 | Need the following packages: 58 | 59 | FiddlerCore [http://www.telerik.com/fiddler/fiddlercore] 60 | 61 | Newtonsoft.Json 6.0.8 [https://github.com/JamesNK/Newtonsoft.Json] 62 | 63 | Under Visual Studio 2015. 64 | 65 | ## Thanks 66 | 67 | Thanks yanunon for his API analysis! [https://github.com/yanunon/NeteaseCloudMusic] 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | -------------------------------------------------------------------------------- /Unblock163MusicClient/Unblock163MusicClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {11986D6C-2B2C-4197-A3B7-03AA21430705} 8 | Exe 9 | Properties 10 | Unblock163MusicClient 11 | Unblock163MusicClient 12 | v4.5.2 13 | 512 14 | true 15 | false 16 | publish\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | 0 27 | 0.5.0.%2a 28 | false 29 | true 30 | 31 | 32 | AnyCPU 33 | true 34 | full 35 | false 36 | bin\Debug\ 37 | DEBUG;TRACE 38 | prompt 39 | 4 40 | 41 | 42 | AnyCPU 43 | pdbonly 44 | true 45 | bin\Release\ 46 | TRACE 47 | prompt 48 | 4 49 | false 50 | 51 | 52 | 53 | False 54 | ..\FiddlerCore4.dll 55 | 56 | 57 | ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll 58 | True 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | False 80 | Microsoft .NET Framework 4.5.2 %28x86 和 x64%29 81 | true 82 | 83 | 84 | False 85 | .NET Framework 3.5 SP1 86 | false 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /Unblock163MusicClient/Program.cs: -------------------------------------------------------------------------------- 1 | using Fiddler; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Net; 8 | using System.Security.Cryptography; 9 | using System.Text; 10 | using System.Text.RegularExpressions; 11 | using System.Windows.Forms; 12 | 13 | namespace Unblock163MusicClient 14 | { 15 | internal static class Configuration 16 | { 17 | public static int Port = 3412; 18 | 19 | public static string ForcePlaybackBitrate { get; private set; } = string.Empty; 20 | public static string PlaybackBitrate { get; set; } = "320000"; 21 | public static string PlaybackQuality { get; set; } = "hMusic"; 22 | 23 | public static string ForceDownloadBitrate { get; private set; } = string.Empty; 24 | public static string DownloadBitrate { get; set; } = "320000"; 25 | public static string DownloadQuality { get; set; } = "hMusic"; 26 | 27 | public static bool Overseas { get; private set; } = false; 28 | public static bool Verbose { get; private set; } = false; 29 | public static string OverseasProxy { get; private set; } = ""; 30 | 31 | public static List AvailableProxy { get; private set; } = new List(); 32 | 33 | static Configuration() 34 | { 35 | foreach (string ip in new string[] { "16", "43" }) 36 | AvailableProxy.Add("14.215.9." + ip); 37 | 38 | foreach (string ip in new string[] { "16", "67" }) 39 | AvailableProxy.Add("219.138.27." + ip); 40 | 41 | foreach (string ip in new string[] { "13", "14", "16", "17", "18", "19", "20", "21", "22", "28", "29", "31", "32", "33", "34", "35", "37", "175", "206" }) 42 | AvailableProxy.Add("163.177.171." + ip); 43 | } 44 | 45 | /// 46 | /// Set configuration according to the arguments passed in. 47 | /// 48 | /// Command line arguments. 49 | public static void SetStartupParameters(string[] args) 50 | { 51 | for (int i = 0; i < args.Length;) 52 | { 53 | string argKey = args[i]; 54 | if (argKey == "/port") 55 | { 56 | if (i != args.Length - 1 && !args[i + 1].StartsWith("/")) 57 | { 58 | try 59 | { 60 | Port = int.Parse(args[i + 1]); 61 | i += 2; 62 | if (Port < 1 || Port > 65535) 63 | { 64 | throw new ArgumentException("Invalid port number."); 65 | } 66 | } 67 | catch (FormatException) 68 | { 69 | throw new ArgumentException("Invalid port number."); 70 | } 71 | } 72 | else 73 | { 74 | throw new ArgumentException("No port number specified."); 75 | } 76 | } 77 | else if (argKey == "/overseas") 78 | { 79 | Console.WriteLine("Overseas mode is turned on."); 80 | Overseas = true; 81 | i++; 82 | } 83 | else if (argKey == "/overseasproxy") 84 | { 85 | if (i != args.Length - 1 && !args[i + 1].StartsWith("/")) 86 | { 87 | OverseasProxy = args[i + 1]; 88 | Console.WriteLine($"Overseas proxy is fixed to {OverseasProxy}"); 89 | i += 2; 90 | } 91 | else 92 | { 93 | Random random = new Random(); 94 | OverseasProxy = AvailableProxy[random.Next(0, AvailableProxy.Count - 1)]; 95 | Console.WriteLine($"Overseas proxy is randomly set to {OverseasProxy}"); 96 | i++; 97 | } 98 | if (AvailableProxy.IndexOf(OverseasProxy) == -1) 99 | { 100 | throw new ArgumentException("Invalid overseas proxy specified.\nAvailable proxys are:\n" + string.Join("\n", AvailableProxy)); 101 | } 102 | } 103 | else if (argKey == "/verbose") 104 | { 105 | Console.WriteLine("Verbose output is turned on."); 106 | Verbose = true; 107 | i++; 108 | } 109 | else if (argKey == "/playbackbitrate") 110 | { 111 | if (i != args.Length - 1 && !args[i + 1].StartsWith("/")) 112 | { 113 | ForcePlaybackBitrate = args[i + 1]; 114 | Console.WriteLine($"Playback bitrate is forced to {ForcePlaybackBitrate}"); 115 | i += 2; 116 | } 117 | else 118 | { 119 | throw new ArgumentException("No playback bitrate specified."); 120 | } 121 | if (ForcePlaybackBitrate != "" && ForcePlaybackBitrate != "96000" && ForcePlaybackBitrate != "128000" && 122 | ForcePlaybackBitrate != "192000" && ForcePlaybackBitrate != "320000") 123 | { 124 | throw new ArgumentException("Unrecognized playback bitrate."); 125 | } 126 | } 127 | else if (argKey == "/downloadbitrate") 128 | { 129 | if (i != args.Length - 1 && !args[i + 1].StartsWith("/")) 130 | { 131 | ForceDownloadBitrate = args[i + 1]; 132 | Console.WriteLine($"Download bitrate is forced to {ForceDownloadBitrate}"); 133 | i += 2; 134 | } 135 | else 136 | { 137 | throw new ArgumentException("No download bitrate specified."); 138 | } 139 | if (ForceDownloadBitrate != "" && ForceDownloadBitrate != "96000" && ForceDownloadBitrate != "128000" && 140 | ForceDownloadBitrate != "192000" && ForceDownloadBitrate != "320000") 141 | { 142 | throw new ArgumentException("Unrecognized download bitrate."); 143 | } 144 | } 145 | else 146 | { 147 | throw new ArgumentException("Unrecognized startup parameter."); 148 | } 149 | } 150 | } 151 | } 152 | 153 | internal static class Program 154 | { 155 | private static readonly Regex RexPl = new Regex("\"pl\":\\d+", RegexOptions.Compiled); 156 | private static readonly Regex RexDl = new Regex("\"dl\":\\d+", RegexOptions.Compiled); 157 | private static readonly Regex RexSt = new Regex("\"st\":-?\\d+", RegexOptions.Compiled); 158 | private static readonly Regex RexSubp = new Regex("\"subp\":\\d+", RegexOptions.Compiled); 159 | 160 | private static void Main(string[] args) 161 | { 162 | try 163 | { 164 | Configuration.SetStartupParameters(args); 165 | } 166 | catch (ArgumentException ex) 167 | { 168 | MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 169 | Environment.Exit(1); 170 | } 171 | 172 | FiddlerCoreStartupFlags fcsf = FiddlerCoreStartupFlags.None; 173 | FiddlerApplication.Startup(Configuration.Port, fcsf); 174 | // We just need to hack APIs and so let other HTTP requests pass directly. API responses must be fully buffered (and then modified). 175 | FiddlerApplication.BeforeRequest += s => { s.bBufferResponse = s.fullUrl.Contains("http://music.163.com/eapi/"); }; 176 | FiddlerApplication.BeforeResponse += OnResponse; 177 | 178 | Console.WriteLine($"Proxy started, listening at port {Configuration.Port}"); 179 | Console.Read(); 180 | FiddlerApplication.Shutdown(); 181 | } 182 | 183 | private static void OnResponse(Session s) 184 | { 185 | s.bBufferResponse = true; 186 | int responseStatusCode = s.responseCode; 187 | string responseContentType = s.ResponseHeaders["Content-Type"].Trim().ToLower(); 188 | string url = s.fullUrl; 189 | 190 | if (responseStatusCode == 200) 191 | { 192 | // Most APIs are returned in text/plain but serach songs page is returned in JSON. Don't forget this! 193 | if (responseContentType.Contains("text/plain") || responseContentType.Contains("application/json")) 194 | { 195 | if (Configuration.Verbose) 196 | { 197 | Console.WriteLine($"Accessing URL {url}"); 198 | } 199 | // It should include album / playlist / artist / search pages. 200 | if (url.Contains("/eapi/v3/song/detail/") || url.Contains("/eapi/v1/album/") || url.Contains("/eapi/v3/playlist/detail") || 201 | url.Contains("/eapi/batch") || url.Contains("/eapi/cloudsearch/pc") || url.Contains("/eapi/v1/artist") || 202 | url.Contains("/eapi/v1/search/get")) 203 | { 204 | string modified = ModifyDetailApi(s.GetResponseBodyAsString()); 205 | s.utilSetResponseBody(modified); 206 | } 207 | // This is called when player tries to get the URL for a song. 208 | else if (url.Contains("/eapi/song/enhance/player/url")) 209 | { 210 | string bitrate = GetPlaybackBitrate(s.GetResponseBodyAsString()); 211 | // Whatever current playback bitrate is, it's overriden. 212 | if (!string.IsNullOrEmpty(Configuration.ForcePlaybackBitrate)) 213 | { 214 | bitrate = Configuration.ForcePlaybackBitrate; 215 | Console.WriteLine($"Plackback bitrate is forced set to {bitrate}"); 216 | } 217 | // We receive a wrong bitrate... 218 | else if (bitrate == "0") 219 | { 220 | bitrate = string.IsNullOrEmpty(Configuration.ForcePlaybackBitrate) ? "320000" : Configuration.ForcePlaybackBitrate; 221 | Console.WriteLine($"Plackback bitrate is forced set to {bitrate} as the given bitrate is not valid."); 222 | } 223 | else if (bitrate != Configuration.PlaybackBitrate) 224 | { 225 | Console.WriteLine($"Plackback bitrate is switched to {bitrate} from {Configuration.PlaybackBitrate}"); 226 | } 227 | Configuration.PlaybackBitrate = bitrate; 228 | Configuration.PlaybackQuality = ParseBitrate(Configuration.ForcePlaybackBitrate); 229 | 230 | string modified = ModifyPlayerApi(s.GetResponseBodyAsString()); 231 | s.utilSetResponseBody(modified); 232 | } 233 | // When we try to download a song, the API tells whether it exceeds the limit. Of course no! 234 | else if (url.Contains("/eapi/song/download/limit")) 235 | { 236 | string modified = ModifyDownloadLimitApi(); 237 | s.utilSetResponseBody(modified); 238 | } 239 | // Similar to the player URL API, but used for download. 240 | else if (url.Contains("/eapi/song/enhance/download/url")) 241 | { 242 | string bitrate = GetDownloadBitrate(s.GetResponseBodyAsString()); 243 | 244 | // Whatever current download bitrate is, it's overriden. 245 | if (!string.IsNullOrEmpty(Configuration.ForceDownloadBitrate)) 246 | { 247 | bitrate = Configuration.ForceDownloadBitrate; 248 | Console.WriteLine($"Download bitrate is forced set to {bitrate}"); 249 | } 250 | // We receive a wrong bitrate... 251 | else if (bitrate == "0") 252 | { 253 | bitrate = string.IsNullOrEmpty(Configuration.ForceDownloadBitrate) ? "320000" : Configuration.ForceDownloadBitrate; 254 | Console.WriteLine($"Download bitrate is forced set to {bitrate} as the given bitrate is not valid."); 255 | } 256 | else if (bitrate != Configuration.DownloadBitrate) 257 | { 258 | Console.WriteLine($"Download bitrate is switched to {bitrate} from {Configuration.DownloadBitrate}"); 259 | } 260 | Configuration.DownloadBitrate = bitrate; 261 | Configuration.DownloadQuality = ParseBitrate(bitrate); 262 | 263 | string modified = ModifyDownloadApi(s.GetResponseBodyAsString()); 264 | s.utilSetResponseBody(modified); 265 | } 266 | } 267 | } 268 | } 269 | 270 | /// 271 | /// Get current playback bitrate from API result. 272 | /// 273 | /// API result containing playback bitrate. 274 | /// Current playback bitrate. 275 | private static string GetPlaybackBitrate(string apiResult) 276 | { 277 | JObject root = JObject.Parse(apiResult); 278 | string bitrate = root["data"][0]["br"].Value(); 279 | return bitrate; 280 | } 281 | 282 | /// 283 | /// Get current download bitrate from API result. 284 | /// 285 | /// API result containing download bitrate. 286 | /// Current download bitrate. 287 | private static string GetDownloadBitrate(string apiResult) 288 | { 289 | JObject root = JObject.Parse(apiResult); 290 | string bitrate = root["data"]["br"].Value(); 291 | return bitrate; 292 | } 293 | 294 | /// 295 | /// Get quality string from bitrate. Default to HQ. 296 | /// 297 | /// Bitrate. 298 | /// Quality. 299 | private static string ParseBitrate(string bitrate) 300 | { 301 | switch (bitrate) 302 | { 303 | case "320000": 304 | return "hMusic"; 305 | 306 | case "192000": 307 | return "mMusic"; 308 | 309 | case "128000": 310 | return "lMusic"; 311 | 312 | case "96000": 313 | return "bMusic"; 314 | } 315 | return "hMusic"; 316 | } 317 | 318 | /// 319 | /// Hack the result of download limit API. 320 | /// 321 | /// Just return a normal status. 322 | private static string ModifyDownloadLimitApi() 323 | { 324 | return "{\"overflow\":false,\"code\":200}"; 325 | } 326 | 327 | /// 328 | /// Hack the result of download API and redirects it to the new URL. 329 | /// 330 | /// The original API result. 331 | /// The modified API result. 332 | private static string ModifyDownloadApi(string originalContent) 333 | { 334 | Console.WriteLine("Hack download API"); 335 | 336 | JObject root = JObject.Parse(originalContent); 337 | string songId = root["data"]["id"].Value(); 338 | string newUrl = NeteaseIdProcess.GetUrl(songId, Configuration.DownloadQuality); 339 | root["data"]["url"] = newUrl; 340 | root["data"]["br"] = Configuration.DownloadBitrate; 341 | root["data"]["code"] = "200"; 342 | 343 | return root.ToString(Formatting.None); 344 | } 345 | 346 | /// 347 | /// Hack the result of song / album / playlist API and treat the client to let it work as the song is not disabled. 348 | /// 349 | /// The original API result. 350 | /// The modified API result. 351 | private static string ModifyDetailApi(string originalContent) 352 | { 353 | Console.WriteLine("Hack detail API"); 354 | 355 | string modified = originalContent; 356 | //Playback bitrate 357 | modified = RexPl.Replace(modified, $"\"pl\":{Configuration.PlaybackBitrate}"); 358 | 359 | //Download bitrate 360 | modified = RexDl.Replace(modified, $"\"dl\":{Configuration.DownloadBitrate}"); 361 | 362 | //Disabled 363 | modified = RexSt.Replace(modified, "\"st\":0"); 364 | 365 | //Can favorite 366 | modified = RexSubp.Replace(modified, "\"subp\":1"); 367 | return modified; 368 | } 369 | 370 | /// 371 | /// Hack the result of player getting song URL and redirects it to the new URL. 372 | /// 373 | /// The original API result. 374 | /// The modified API result. 375 | private static string ModifyPlayerApi(string originalContent) 376 | { 377 | Console.WriteLine("Hack player API"); 378 | 379 | JObject root = JObject.Parse(originalContent); 380 | string songId = root["data"][0]["id"].Value(); 381 | string newUrl = NeteaseIdProcess.GetUrl(songId, Configuration.PlaybackQuality); 382 | root["data"][0]["url"] = newUrl; 383 | root["data"][0]["br"] = Configuration.PlaybackBitrate; 384 | root["data"][0]["code"] = "200"; 385 | 386 | return root.ToString(Formatting.None); 387 | } 388 | } 389 | 390 | public static class Utility 391 | { 392 | /// 393 | /// Require the content of a URL via GET method. 394 | /// 395 | /// URL to get. 396 | /// Content. 397 | public static string GetPage(string url) 398 | { 399 | try 400 | { 401 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 402 | request.Method = "GET"; 403 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 404 | return new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd(); 405 | } 406 | catch (Exception ex) 407 | { 408 | Console.WriteLine(url); 409 | Console.WriteLine(ex.Message); 410 | return ""; 411 | } 412 | } 413 | } 414 | 415 | /// 416 | /// Get song url from song id. 417 | /// It works as this flow: extract song id from original page -> get dfs ID -> call another API to get URL -> replace the original result with the new URL. 418 | /// 419 | public static class NeteaseIdProcess 420 | { 421 | /// 422 | /// Get song url from original song ID. 423 | /// 424 | /// Song ID. 425 | /// Quality. Accepts: bMusic, lMusic, mMusic, hMusic. 426 | /// Song URL. 427 | public static string GetUrl(string songId, string quality) 428 | { 429 | string dfsId = GetDfsId(Utility.GetPage($"http://music.163.com/api/song/detail?id={songId}&ids=[{songId}]"), quality); 430 | if (Configuration.Verbose) 431 | { 432 | Console.WriteLine($"Song ID = {songId}, DFS ID = {dfsId}"); 433 | } 434 | return GenerateUrl(dfsId); 435 | } 436 | 437 | /// 438 | /// Calculate enc ID from dfs ID. 439 | /// 440 | /// dfs ID. 441 | /// enc ID. 442 | private static string GetEncId(string dfsId) 443 | { 444 | byte[] magicBytes = new ASCIIEncoding().GetBytes("3go8&$8*3*3h0k(2)2"); 445 | byte[] songId = new ASCIIEncoding().GetBytes(dfsId); 446 | for (int i = 0; i < songId.Length; i++) 447 | { 448 | songId[i] = (byte)(songId[i] ^ magicBytes[i % magicBytes.Length]); 449 | } 450 | byte[] hash = MD5.Create().ComputeHash(songId); 451 | return Convert.ToBase64String(hash).Replace('/', '_').Replace('+', '-'); 452 | } 453 | 454 | /// 455 | /// Generate final URL with dfsId. 456 | /// 457 | /// 458 | /// 459 | private static string GenerateUrl(string dfsId) 460 | { 461 | string url = $"http://m{DateTime.Now.Second % 2 + 1}.music.126.net/{GetEncId(dfsId)}/{dfsId}.mp3"; 462 | if (Configuration.Overseas) 463 | { 464 | if (string.IsNullOrEmpty(Configuration.OverseasProxy)) 465 | { 466 | url = url.Replace("http://m", "http://p"); 467 | } 468 | else 469 | { 470 | url = url.Replace("http://m", $"http://{Configuration.OverseasProxy}/m"); 471 | } 472 | } 473 | if (Configuration.Verbose) 474 | { 475 | Console.WriteLine($"Song URL = {url}"); 476 | } 477 | return url; 478 | } 479 | 480 | /// 481 | /// Extract dfs ID from the original API return value. 482 | /// 483 | /// The original API return value. 484 | /// Quality. Accepts: bMusic, lMusic, mMusic, hMusic. 485 | /// dfs ID. 486 | private static string GetDfsId(string pageContent, string quality) 487 | { 488 | JObject root = JObject.Parse(pageContent); 489 | 490 | // Downgrade if we don't have higher quality... 491 | 492 | if (quality == "hMusic" && !root["songs"][0]["hMusic"].HasValues) 493 | { 494 | Console.WriteLine("Downgrade to medium quality."); 495 | quality = "mMusic"; 496 | } 497 | if (quality == "mMusic" && !root["songs"][0]["mMusic"].HasValues) 498 | { 499 | Console.WriteLine("Downgrade to low quality."); 500 | quality = "lMusic"; 501 | } 502 | if (quality == "lMusic" && !root["songs"][0]["lMusic"].HasValues) 503 | { 504 | Console.WriteLine("Downgrade to can't be lower quality."); 505 | quality = "bMusic"; 506 | } 507 | 508 | if (quality == "bMusic" && !root["songs"][0]["bMusic"].HasValues) 509 | { 510 | // Don't ask me what to do if there's even no lowest quality... 511 | Console.WriteLine("No resource available."); 512 | } 513 | 514 | return root["songs"][0][quality]["dfsId"].Value(); 515 | } 516 | } 517 | } --------------------------------------------------------------------------------