├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── XmlyDownloader.sln ├── XmlyDownloader ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── SourceHanSansSC-Normal.otf │ └── avalonia-logo.ico ├── Commands │ ├── DelegateCommand.cs │ └── IAsyncCommand.cs ├── Models │ └── DownloadItem.cs ├── Program.cs ├── Services │ ├── DownloadService.cs │ └── IDownloadService.cs ├── ViewLocator.cs ├── ViewModels │ ├── DownloadItemViewModel.cs │ ├── MainWindowViewModel.cs │ └── ViewModelBase.cs ├── Views │ ├── MainWindow.xaml │ └── MainWindow.xaml.cs ├── XmlyDownloader.csproj └── nuget.config ├── mdfiles ├── Ubuntu16.04.png ├── start.png ├── 下载结果.png ├── 专辑示例.png └── 搜索结果.png └── publish.cmd /.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 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zxyao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XmlyDownloader 2 | 喜马拉雅专辑下载器,基于NET Core 3.1 和 Avalonia UI,支持Windows、MacOS、Linux~~(由于Avalonia的问题,在MacOS、Linux下中文会显示乱码[https://github.com/AvaloniaUI/Avalonia/issues/3522](https://github.com/AvaloniaUI/Avalonia/issues/3522))~~ (已修复)。 3 | 4 | **注意**:仅能够下载免费音频。 5 | 6 | # 平台支持 7 | 8 | 1. win-x64:Wndows 64位操作系统 9 | 2. win-x86:Wndows 32位操作系统 10 | 3. osx-x64:最低 OS 版本为 macOS 10.12 Sierra 11 | 4. linux-x64:大多数桌面发行版,如 CentOS、Debian、Fedora、Ubuntu 及派生版本 12 | 13 | 平台代码详见:https://docs.microsoft.com/zh-cn/dotnet/core/rid-catalog 14 | 15 | # 下载与使用 16 | 17 | ## 下载 18 | 19 | 请前往 [Releases](https://github.com/zxyao145/XmlyDownloader/releases) 选择对应平台进行下载。 20 | 21 | ## 使用 22 | 23 | ### 启动程序 24 | 25 | **Windows** 26 | 27 | 运行压缩包中的**XmlyDownloader.exe** 28 | 29 | **MacOS、Linux** 30 | 31 | 双击运行压缩包中**XmlyDownloader** 32 | 33 | ### 使用 34 | 35 | 程序启动后界面如下图1所示,在专辑地址中输入专辑的url(例如图2,专辑郭德纲单口《丑娘娘》,https://www.ximalaya.com/xiangsheng/8287357/ ),点击搜索按钮,搜索结果如图3所示,专辑中的音频将会以表格的形式呈现出来。 36 | 37 | ![image-20200620164934047](https://github.com/zxyao145/XmlyDownloader/blob/master/mdfiles/start.png) 38 | 39 |
图1 启动界面
40 | 41 |   42 | 43 | ![image-20200620165340869](https://github.com/zxyao145/XmlyDownloader/blob/master/mdfiles/专辑示例.png) 44 | 45 |
图2 专辑示例
46 | 47 |   48 | 49 | ![image-20200620165513485](https://github.com/zxyao145/XmlyDownloader/blob/master/mdfiles/搜索结果.png) 50 | 51 |
图3 专辑搜索结果
52 | 53 |   54 | 55 | 在搜索结果左侧,勾选想要下载的音频,然后点击下载。下载文件将保存在程序运行目录下 **1downloadResult/专辑名** 的文件夹中,此处下载结果保存在 **1downloadResult/【高清】郭德纲单口《丑娘娘》** 文件夹中,如图4所示: 56 | 57 | ![image-20200620170346355](https://github.com/zxyao145/XmlyDownloader/blob/master/mdfiles/下载结果.png) 58 | 59 |
图4 下载结果
60 | 61 |   62 | 63 | **注** 如果在Linux上运行,首先需要赋予程序执行权限,最简单的方式:`sudo chmod 777 ./XmlyDownloader`。Ubuntu16.04上运行效果如图5所示。 64 | 65 | ![Ubuntu16.04运行效果](https://github.com/zxyao145/XmlyDownloader/blob/master/mdfiles/Ubuntu16.04.png) 66 | 67 |
图5 Ubuntu16.04运行效果
68 | 69 |   70 | 71 | # 协议 72 | 73 | MIT。本工具仅限个人学习,不用于商业等用途,所涉及的所有音视频资源版权归喜马拉雅所有。 74 | -------------------------------------------------------------------------------- /XmlyDownloader.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30204.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XmlyDownloader", "XmlyDownloader\XmlyDownloader.csproj", "{5F73D7DB-C7F6-431F-A09A-9590E5DFBDE5}" 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 | {5F73D7DB-C7F6-431F-A09A-9590E5DFBDE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5F73D7DB-C7F6-431F-A09A-9590E5DFBDE5}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5F73D7DB-C7F6-431F-A09A-9590E5DFBDE5}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {5F73D7DB-C7F6-431F-A09A-9590E5DFBDE5}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {FD48A0B7-9EC7-4322-A111-B515874F989E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /XmlyDownloader/App.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /XmlyDownloader/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Markup.Xaml; 4 | using XmlyDownloader.Models; 5 | using XmlyDownloader.Views; 6 | 7 | namespace XmlyDownloader 8 | { 9 | public class App : Application 10 | { 11 | public override void Initialize() 12 | { 13 | AvaloniaXamlLoader.Load(this); 14 | } 15 | 16 | public override void OnFrameworkInitializationCompleted() 17 | { 18 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 19 | { 20 | desktop.MainWindow = new MainWindow(); 21 | } 22 | 23 | base.OnFrameworkInitializationCompleted(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /XmlyDownloader/Assets/SourceHanSansSC-Normal.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/XmlyDownloader/Assets/SourceHanSansSC-Normal.otf -------------------------------------------------------------------------------- /XmlyDownloader/Assets/avalonia-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/XmlyDownloader/Assets/avalonia-logo.ico -------------------------------------------------------------------------------- /XmlyDownloader/Commands/DelegateCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using System.Windows.Input; 6 | 7 | namespace XmlyDownloader.Commands 8 | { 9 | public class DelegateCommand : IAsyncCommand 10 | { 11 | 12 | public event EventHandler CanExecuteChanged; 13 | public void RaiseCanExecuteChanged() 14 | { 15 | CanExecuteChanged?.Invoke(this, EventArgs.Empty); 16 | } 17 | 18 | public bool CanExecute(object parameter) 19 | { 20 | return !_isExecuting && (CanExecuteFunc?.Invoke(parameter) ?? true); 21 | } 22 | 23 | public Func CanExecuteFunc { get; set; } 24 | 25 | 26 | public async void Execute(object parameter) 27 | { 28 | if (CanExecute(parameter)) 29 | { 30 | ExecuteAction?.Invoke(parameter); 31 | await ExecuteAsync(parameter); 32 | } 33 | } 34 | public Action ExecuteAction { get; set; } 35 | 36 | 37 | private bool _isExecuting; 38 | 39 | public async Task ExecuteAsync(object parameter) 40 | { 41 | if (CanExecute(parameter)) 42 | { 43 | if(ExecuteActionAsync != null) 44 | { 45 | try 46 | { 47 | _isExecuting = true; 48 | await ExecuteActionAsync(parameter); 49 | } 50 | finally 51 | { 52 | _isExecuting = false; 53 | } 54 | } 55 | 56 | } 57 | 58 | RaiseCanExecuteChanged(); 59 | } 60 | public Func ExecuteActionAsync { get; set; } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /XmlyDownloader/Commands/IAsyncCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using System.Windows.Input; 6 | 7 | namespace XmlyDownloader.Commands 8 | { 9 | public interface IAsyncCommand:ICommand 10 | { 11 | Task ExecuteAsync(object parameter); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /XmlyDownloader/Models/DownloadItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace XmlyDownloader.Models 6 | { 7 | public class DownloadItem 8 | { 9 | /// 10 | /// 用来区分是专辑中的第几个 11 | /// 12 | public int Index { get; set; } 13 | 14 | /// 15 | /// 专辑名,用来作为文件夹名 16 | /// 17 | public string DirName { get; set; } 18 | 19 | /// 20 | /// 歌曲名 21 | /// 22 | public string Title { get; set; } 23 | 24 | /// 25 | /// 下载地址 26 | /// 27 | public string Href { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /XmlyDownloader/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avalonia; 3 | using Avalonia.Controls.ApplicationLifetimes; 4 | using Avalonia.Logging.Serilog; 5 | using Avalonia.ReactiveUI; 6 | 7 | namespace XmlyDownloader 8 | { 9 | class Program 10 | { 11 | // Initialization code. Don't use any Avalonia, third-party APIs or any 12 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 13 | // yet and stuff might break. 14 | public static void Main(string[] args) => BuildAvaloniaApp() 15 | .With(new AvaloniaNativePlatformOptions { UseGpu = false }) 16 | .With(new MacOSPlatformOptions { ShowInDock = false }) 17 | .With(new Win32PlatformOptions { UseDeferredRendering = false }) 18 | .StartWithClassicDesktopLifetime(args); 19 | 20 | // Avalonia configuration, don't remove; also used by visual designer. 21 | public static AppBuilder BuildAvaloniaApp() 22 | => AppBuilder.Configure() 23 | .UsePlatformDetect() 24 | .LogToDebug() 25 | .UseReactiveUI(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /XmlyDownloader/Services/DownloadService.cs: -------------------------------------------------------------------------------- 1 | using HtmlAgilityPack; 2 | using Jil; 3 | using System; 4 | using System.Collections.Concurrent; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Net.Http; 9 | using System.Net.Http.Headers; 10 | using System.Text; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | using XmlyDownloader.Models; 14 | 15 | namespace XmlyDownloader.Services 16 | { 17 | 18 | 19 | public class DownloadService : IDownloadService 20 | { 21 | public event Action OnDownloaded; 22 | 23 | 24 | private ConcurrentQueue _downloadQueue = new ConcurrentQueue(); 25 | private List _searchResult = new List(); 26 | 27 | private string _saveDir = AppContext.BaseDirectory; 28 | 29 | private string _saveSubDir1 = "1downloadResult"; 30 | 31 | /// 32 | /// page parser client 33 | /// 34 | private HttpClient xmlyClicnt; 35 | 36 | 37 | /// 38 | /// static resource client 39 | /// 40 | private HttpClient _downloadClient; 41 | private bool _stop; 42 | 43 | public DownloadService() 44 | { 45 | Init(); 46 | } 47 | 48 | private void Init() 49 | { 50 | var sockets = new SocketsHttpHandler() 51 | { 52 | PooledConnectionLifetime = TimeSpan.FromMinutes(10), 53 | PooledConnectionIdleTimeout = TimeSpan.FromMinutes(5), 54 | MaxConnectionsPerServer = 10, 55 | UseCookies = true 56 | }; 57 | //var url = "https://www.ximalaya.com/xiqu/6113767/"; 58 | 59 | var http = new HttpClient(sockets); 60 | //http.DefaultRequestHeaders.Host = "www.ximalaya.com/"; 61 | http.DefaultRequestHeaders.Referrer = new Uri("https://www.ximalaya.com/"); 62 | http.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Chrome", "78.0.3904.87")); 63 | http.BaseAddress = new Uri("https://www.ximalaya.com"); 64 | xmlyClicnt = http; 65 | 66 | 67 | _downloadClient = new HttpClient(sockets); 68 | //_downloadClient.DefaultRequestHeaders.Host = "www.ximalaya.com/"; 69 | _downloadClient.DefaultRequestHeaders.Referrer = new Uri("https://www.ximalaya.com/"); 70 | _downloadClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Chrome", "78.0.3904.87")); 71 | 72 | } 73 | 74 | /// 75 | /// 获取专辑中所有音乐 76 | /// 77 | /// 78 | /// 79 | public async Task> ParsePagingInfo(string url) 80 | { 81 | _searchResult.Clear(); 82 | 83 | await ParsePagingInfoHandle(url, xmlyClicnt); 84 | 85 | return _searchResult; 86 | } 87 | 88 | /// 89 | /// 解析专辑中的所有音乐 90 | /// 91 | /// 专辑url 92 | /// 93 | /// 94 | /// 95 | private async Task ParsePagingInfoHandle(string url, HttpClient httpClient, 96 | HtmlNode pageNode = null, int index = 0) 97 | { 98 | var text = await httpClient.GetStringAsync(url); 99 | 100 | var html = new HtmlDocument(); 101 | html.LoadHtml(text); 102 | 103 | var xqName = html.DocumentNode.SelectSingleNode("//h1[@class=\"title lO_\"]").InnerText; 104 | 105 | var node = html.DocumentNode 106 | .SelectSingleNode("//div[@class=\"sound-list _Qp\"]"); 107 | if (node != null) 108 | { 109 | var aArr = node.SelectNodes("./ul/li//a"); 110 | 111 | foreach (var a in aArr) 112 | { 113 | var title = a.Attributes["title"].Value; 114 | var href = a.Attributes["href"].Value;// /xiqu/6113767/26628886 115 | 116 | _searchResult.Add(new DownloadItem() 117 | { 118 | DirName = xqName, 119 | Title = title, 120 | Index = index++, 121 | Href = "/revision/play/v1/audio?ptype=1&id=" 122 | + href.Split("/").Reverse().ToList()[0] 123 | }); 124 | } 125 | if (pageNode == null) 126 | { 127 | var pages = node.SelectNodes("./div//a"); 128 | if (pages != null) 129 | { 130 | foreach (var page in pages) 131 | { 132 | if (page != null) 133 | { 134 | var href = page.Attributes["href"].Value; 135 | if(href != url.Replace("https://www.ximalaya.com","")) 136 | { 137 | index = await ParsePagingInfoHandle(href, httpClient, page, index); 138 | } 139 | } 140 | } 141 | } 142 | } 143 | } 144 | 145 | return index; 146 | } 147 | 148 | private bool _hasStopd = false; 149 | 150 | 151 | 152 | public Task StartListenDownload() 153 | { 154 | _hasStopd = false; 155 | _stop = false; 156 | 157 | return Task.Factory.StartNew(async () => 158 | { 159 | var rand = new Random(); 160 | while (!_stop) 161 | { 162 | if (_downloadQueue.Count == 0) 163 | { 164 | Thread.Sleep(500); 165 | } 166 | else 167 | { 168 | if (_downloadQueue.TryDequeue(out var item)) 169 | { 170 | var jsonStr = await xmlyClicnt.GetStringAsync(item.Href); 171 | 172 | var downloadUrl = GetM4a(jsonStr); 173 | 174 | var bytes = await _downloadClient.GetByteArrayAsync(downloadUrl); 175 | if (bytes == null) 176 | { 177 | _downloadQueue.Enqueue(item); 178 | Console.WriteLine($"{item.Title} 下载失败"); 179 | continue; 180 | } 181 | var file = Path.Combine 182 | (_saveDir, _saveSubDir1, 183 | item.DirName, 184 | item.Index + "-" + item.Title + ".m4a"); 185 | 186 | var dir = Path.GetDirectoryName(file); 187 | if (!Directory.Exists(dir)) 188 | { 189 | Directory.CreateDirectory(dir); 190 | } 191 | else if (File.Exists(file)) 192 | { 193 | continue; 194 | //File.Delete(file); 195 | } 196 | await using var fs = new System.IO.FileStream(file, System.IO.FileMode.CreateNew); 197 | fs.Write(bytes, 0, bytes.Length); 198 | //暂停 200 ~ 3200毫秒 199 | int sleepTime = 200; // = (int)(rand.NextDouble() * 3 * 1000 + 200); 200 | OnDownloaded?.Invoke(item); 201 | Thread.Sleep(sleepTime); 202 | } 203 | } 204 | } 205 | _hasStopd = true; 206 | }, TaskCreationOptions.LongRunning); 207 | } 208 | 209 | public void StopDownload() 210 | { 211 | _stop = true; 212 | while (!_hasStopd) 213 | { 214 | Thread.Sleep(200); 215 | } 216 | } 217 | 218 | 219 | //{"ret":200, 220 | //"data": 221 | //{"trackId":26628886,"canPlay":true,"isPaid":false,"hasBuy":true, 222 | //"src":"https://fdfs.xmcdn.com/group24/M02/A7/0B/wKgJNVhKyNfRf_szAXz2YvP1I0g650.m4a", 223 | //"albumIsSample":false,"sampleDuration":0, 224 | //"isBaiduMusic":false,"firstPlayStatus":true}} 225 | private string GetM4a(string jsonStr) 226 | { 227 | var json = JSON.DeserializeDynamic(jsonStr); 228 | string url = json.data.src; 229 | return url; 230 | } 231 | 232 | 233 | public void Add(DownloadItem downloadItem) 234 | { 235 | this._downloadQueue.Enqueue(downloadItem); 236 | } 237 | 238 | public void AddRange(List downloadItems) 239 | { 240 | foreach (var item in downloadItems) 241 | { 242 | Add(item); 243 | } 244 | } 245 | 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /XmlyDownloader/Services/IDownloadService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using XmlyDownloader.Models; 6 | 7 | namespace XmlyDownloader.Services 8 | { 9 | public interface IDownloadService 10 | { 11 | Task> ParsePagingInfo(string url); 12 | event Action OnDownloaded; 13 | 14 | Task StartListenDownload(); 15 | 16 | void StopDownload(); 17 | 18 | 19 | void Add(DownloadItem downloadItem); 20 | void AddRange(List downloadItems); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /XmlyDownloader/ViewLocator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avalonia.Controls; 3 | using Avalonia.Controls.Templates; 4 | using XmlyDownloader.Models; 5 | 6 | namespace XmlyDownloader 7 | { 8 | public class ViewLocator : IDataTemplate 9 | { 10 | public bool SupportsRecycling => false; 11 | 12 | public IControl Build(object data) 13 | { 14 | var name = data.GetType().FullName.Replace("ViewModel", "View"); 15 | var type = Type.GetType(name); 16 | 17 | if (type != null) 18 | { 19 | return (Control)Activator.CreateInstance(type); 20 | } 21 | else 22 | { 23 | return new TextBlock { Text = "Not Found: " + name }; 24 | } 25 | } 26 | 27 | public bool Match(object data) 28 | { 29 | return data is ViewModelBase; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /XmlyDownloader/ViewModels/DownloadItemViewModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace XmlyDownloader.Models 7 | { 8 | public class DownloadItemViewModel:ViewModelBase 9 | { 10 | 11 | private DownloadItem downloadItem; 12 | 13 | public DownloadItem Item 14 | { 15 | get { return downloadItem; } 16 | set 17 | { 18 | downloadItem = value; 19 | this.RaisePropertyChanged("Item"); 20 | } 21 | } 22 | 23 | 24 | private bool selected; 25 | 26 | public bool Selected 27 | { 28 | get { return selected; } 29 | set 30 | { 31 | selected = value; 32 | this.RaisePropertyChanged("Selected"); 33 | } 34 | } 35 | 36 | private bool _isEnable = true; 37 | 38 | public bool IsEnable 39 | { 40 | get { return _isEnable; } 41 | set 42 | { 43 | _isEnable = value; 44 | this.RaisePropertyChanged("IsEnable"); 45 | } 46 | } 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /XmlyDownloader/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using XmlyDownloader.Commands; 8 | using XmlyDownloader.Services; 9 | 10 | namespace XmlyDownloader.Models 11 | { 12 | public class MainWindowViewModel : ViewModelBase,IDisposable 13 | { 14 | IDownloadService _downloadService; 15 | 16 | private string url; // = "https://www.ximalaya.com/xiangsheng/25335291/"; 17 | 18 | public string Url 19 | { 20 | get { return url; } 21 | set 22 | { 23 | url = value; 24 | this.RaisePropertyChanged("url"); 25 | } 26 | } 27 | 28 | 29 | private List downloadItems; 30 | public List DownloadItems 31 | { 32 | get { return downloadItems; } 33 | set 34 | { 35 | downloadItems = value; 36 | this.RaisePropertyChanged("DownloadItems"); 37 | } 38 | } 39 | 40 | 41 | private string _downloadStatus = "未进行下载过"; 42 | 43 | public string DownloadStatus 44 | { 45 | get { return _downloadStatus; } 46 | set 47 | { 48 | _downloadStatus = value; 49 | this.RaisePropertyChanged("DownloadStatus"); 50 | } 51 | } 52 | 53 | 54 | 55 | public DelegateCommand DownloadCommand { get; set; } 56 | private void Download(object parameter) 57 | { 58 | var selectItems = DownloadItems 59 | .Where(e => e.IsEnable && e.Selected) 60 | .Select(e=>e.Item) 61 | .ToList(); 62 | _downloadService.AddRange(selectItems); 63 | } 64 | 65 | 66 | public DelegateCommand SearchCommand { get; set; } 67 | private async Task Search(object parameter) 68 | { 69 | if (!string.IsNullOrWhiteSpace(Url)) 70 | { 71 | var result = await _downloadService.ParsePagingInfo(url); 72 | var downloadItemViewModels = new List(); 73 | foreach (var item in result) 74 | { 75 | downloadItemViewModels.Add(new DownloadItemViewModel() 76 | { 77 | Item = item, 78 | Selected = true 79 | }); 80 | } 81 | DownloadItems = downloadItemViewModels; 82 | } 83 | } 84 | 85 | public void Dispose() 86 | { 87 | _downloadService.StopDownload(); 88 | } 89 | 90 | public MainWindowViewModel() 91 | { 92 | this.DownloadCommand = new DelegateCommand(); 93 | DownloadCommand.ExecuteAction = new Action(Download); 94 | SearchCommand = new DelegateCommand(); 95 | SearchCommand.ExecuteActionAsync += new Func(Search); 96 | _downloadService = new DownloadService(); 97 | _downloadService.OnDownloaded += _downloadService_OnDownloaded; 98 | _downloadService.StartListenDownload(); 99 | } 100 | 101 | private void _downloadService_OnDownloaded(DownloadItem obj) 102 | { 103 | var vm = DownloadItems.SingleOrDefault(e => e.Item == obj); 104 | if(vm != null) 105 | { 106 | vm.IsEnable = false; 107 | } 108 | 109 | this.DownloadStatus = $"{obj.DirName}/{obj.Index}-{obj.Title} 下载完毕!"; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /XmlyDownloader/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Reflection; 5 | using System.Text; 6 | using ReactiveUI; 7 | 8 | namespace XmlyDownloader.Models 9 | { 10 | public class ViewModelBase : ReactiveObject 11 | { 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /XmlyDownloader/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  13 | 14 | 15 | 16 | 17 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 地址 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /XmlyDownloader/Views/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls; 3 | using Avalonia.Interactivity; 4 | using Avalonia.Markup.Xaml; 5 | using HtmlAgilityPack; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Collections.ObjectModel; 9 | using System.ComponentModel; 10 | using System.Linq; 11 | using System.Net.Http; 12 | using System.Net.Http.Headers; 13 | using System.Threading.Tasks; 14 | using XmlyDownloader.Models; 15 | 16 | namespace XmlyDownloader.Views 17 | { 18 | public class MainWindow : Window 19 | { 20 | private MainWindowViewModel vm; 21 | public MainWindow() 22 | { 23 | WindowStartupLocation = WindowStartupLocation.CenterScreen; 24 | InitializeComponent(); 25 | 26 | this.DataContext = vm = new MainWindowViewModel(); 27 | #if DEBUG 28 | this.AttachDevTools(); 29 | #endif 30 | } 31 | 32 | private void InitializeComponent() 33 | { 34 | AvaloniaXamlLoader.Load(this); 35 | } 36 | 37 | 38 | protected override void OnClosing(CancelEventArgs e) 39 | { 40 | vm?.Dispose(); 41 | base.OnClosing(e); 42 | } 43 | 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /XmlyDownloader/XmlyDownloader.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | WinExe 4 | netcoreapp3.1 5 | 0.3.0 6 | true 7 | True 8 | embedded 9 | 10 | 11 | 12 | %(Filename) 13 | 14 | 15 | Designer 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /XmlyDownloader/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /mdfiles/Ubuntu16.04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/mdfiles/Ubuntu16.04.png -------------------------------------------------------------------------------- /mdfiles/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/mdfiles/start.png -------------------------------------------------------------------------------- /mdfiles/下载结果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/mdfiles/下载结果.png -------------------------------------------------------------------------------- /mdfiles/专辑示例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/mdfiles/专辑示例.png -------------------------------------------------------------------------------- /mdfiles/搜索结果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zxyao145/XmlyDownloader/3c4264fd94d1b6c8c89a0c785fbbff3559a3579f/mdfiles/搜索结果.png -------------------------------------------------------------------------------- /publish.cmd: -------------------------------------------------------------------------------- 1 | 2 | dotnet publish -c Release -f netcoreapp3.1 -r win-x64 3 | dotnet publish -c Release -f netcoreapp3.1 -r win-x86 4 | dotnet publish -c Release -f netcoreapp3.1 -r osx-x64 5 | dotnet publish -c Release -f netcoreapp3.1 -r linux-x64 --------------------------------------------------------------------------------