Skip to content

Commit e83cc43

Browse files
committed
实现下载设置功能
1 parent 6abb898 commit e83cc43

File tree

11 files changed

+466
-37
lines changed

11 files changed

+466
-37
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.IO;
3+
using GalaSoft.MvvmLight;
4+
5+
namespace FishMusic.Download
6+
{
7+
public class DownloadSettings : ViewModelBase
8+
{
9+
private int _bitRate;
10+
private int _lossType;
11+
private string _downPath;
12+
private string _userFolder;
13+
private string _userName;
14+
private int _nameSelect;
15+
private int _folderSelect;
16+
private bool _downPic;
17+
private bool _downLrc;
18+
private bool _enableUserSetting;
19+
20+
public int BitRate
21+
{
22+
get => _bitRate;
23+
set
24+
{
25+
_bitRate = value;
26+
RaisePropertyChanged("BitRate");
27+
}
28+
}
29+
30+
public int LossType
31+
{
32+
get => _lossType;
33+
set
34+
{
35+
_lossType = value;
36+
RaisePropertyChanged("LossType");
37+
}
38+
}
39+
40+
public string DownPath
41+
{
42+
get => _downPath;
43+
set
44+
{
45+
_downPath = value;
46+
RaisePropertyChanged("DownPath");
47+
}
48+
}
49+
50+
public string UserFolder
51+
{
52+
get => _userFolder;
53+
set
54+
{
55+
_userFolder = value;
56+
RaisePropertyChanged("UserFolder");
57+
}
58+
}
59+
60+
public string UserName
61+
{
62+
get => _userName;
63+
set
64+
{
65+
_userName = value;
66+
RaisePropertyChanged("UserName");
67+
}
68+
}
69+
70+
public int NameSelect
71+
{
72+
get => _nameSelect;
73+
set
74+
{
75+
_nameSelect = value;
76+
RaisePropertyChanged("NameSelect");
77+
}
78+
}
79+
80+
public int FolderSelect
81+
{
82+
get => _folderSelect;
83+
set
84+
{
85+
_folderSelect = value;
86+
RaisePropertyChanged("FolderSelect");
87+
}
88+
}
89+
90+
public bool DownPic
91+
{
92+
get => _downPic;
93+
set
94+
{
95+
_downPic = value;
96+
RaisePropertyChanged("DownPic");
97+
}
98+
}
99+
100+
public bool DownLrc
101+
{
102+
get => _downLrc;
103+
set
104+
{
105+
_downLrc = value;
106+
RaisePropertyChanged("DownLrc");
107+
}
108+
}
109+
110+
public bool EnableUserSetting
111+
{
112+
get => _enableUserSetting;
113+
set
114+
{
115+
_enableUserSetting = value;
116+
RaisePropertyChanged("EnableUserSetting");
117+
}
118+
}
119+
120+
public DownloadSettings()
121+
{
122+
BitRate = 1;
123+
LossType = 0;
124+
DownPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Music");
125+
DownLrc = false;
126+
DownPic = false;
127+
EnableUserSetting = false;
128+
NameSelect = 1;
129+
FolderSelect = 0;
130+
UserName = "%ARTIST% - %SONG%";
131+
UserFolder = "";
132+
}
133+
}
134+
}

FishMusic/FishMusic/FishMusic.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@
101101
<Compile Include="Converter\TrackTimeConverter.cs" />
102102
<Compile Include="Converter\UrlConverter.cs" />
103103
<Compile Include="Download\DownloadInfo.cs" />
104+
<Compile Include="Download\DownloadSettings.cs" />
104105
<Compile Include="Download\XL.cs" />
105106
<Compile Include="Download\XunleiClient.cs" />
106107
<Compile Include="Helper\CommonHelper.cs" />
107108
<Compile Include="Helper\DbHelper.cs" />
108109
<Compile Include="Model\SearchEngine.cs" />
110+
<Compile Include="Model\SoftSetting.cs" />
109111
<Compile Include="TagLib\Aac\AudioHeader.cs" />
110112
<Compile Include="TagLib\Aac\BitStream.cs" />
111113
<Compile Include="TagLib\Aac\File.cs" />
@@ -359,6 +361,7 @@
359361
<Compile Include="ViewModel\MainViewModel.cs" />
360362
<Compile Include="ViewModel\PlayViewModel.cs" />
361363
<Compile Include="ViewModel\SearchViewModel.cs" />
364+
<Compile Include="ViewModel\SettingViewModel.cs" />
362365
<Compile Include="ViewModel\ViewModelLocator.cs" />
363366
<Compile Include="View\Controls\MainPlayControl.xaml.cs">
364367
<DependentUpon>MainPlayControl.xaml</DependentUpon>
@@ -369,6 +372,9 @@
369372
<Compile Include="View\Download\Downloading.xaml.cs">
370373
<DependentUpon>Downloading.xaml</DependentUpon>
371374
</Compile>
375+
<Compile Include="View\Download\DownSetting.xaml.cs">
376+
<DependentUpon>DownSetting.xaml</DependentUpon>
377+
</Compile>
372378
<Compile Include="View\MainControl.xaml.cs">
373379
<DependentUpon>MainControl.xaml</DependentUpon>
374380
</Compile>
@@ -436,6 +442,10 @@
436442
<SubType>Designer</SubType>
437443
<Generator>MSBuild:Compile</Generator>
438444
</Page>
445+
<Page Include="View\Download\DownSetting.xaml">
446+
<SubType>Designer</SubType>
447+
<Generator>MSBuild:Compile</Generator>
448+
</Page>
439449
<Page Include="View\MainControl.xaml">
440450
<Generator>MSBuild:Compile</Generator>
441451
<SubType>Designer</SubType>

FishMusic/FishMusic/Helper/CommonHelper.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Text.RegularExpressions;
77
using AnyListen.Models;
8+
using FishMusic.Download;
89
using Newtonsoft.Json.Linq;
910

1011
namespace FishMusic.Helper
@@ -193,6 +194,10 @@ public static string GetFormat(string url)
193194
{
194195
link = "wma";
195196
}
197+
else if (url.ToLower().Contains(".dsf"))
198+
{
199+
link = "dsf";
200+
}
196201
else
197202
{
198203
link = "mp3";
@@ -279,5 +284,64 @@ public static string SecondsToTime(int total)
279284
return hour.ToString().PadLeft(2, '0') + ":" + min.ToString().PadLeft(2, '0') + ":" +
280285
sec.ToString().PadLeft(2, '0');
281286
}
287+
288+
public static string GetSongName(DownloadSettings downSetting, SongResult songResult)
289+
{
290+
if (downSetting.EnableUserSetting)
291+
{
292+
return downSetting.UserName.Replace("%ARTIST%", songResult.ArtistName)
293+
.Replace("%INDEX%", songResult.TrackNum.ToString()).Replace("%SONG%", songResult.SongName)
294+
.Replace("%DISC%", songResult.Disc.ToString());
295+
}
296+
switch (downSetting.NameSelect)
297+
{
298+
case 0:
299+
return songResult.SongName;
300+
case 1:
301+
if (string.IsNullOrEmpty(songResult.ArtistName))
302+
{
303+
return songResult.SongName;
304+
}
305+
return songResult.ArtistName + " - " + songResult.SongName;
306+
case 2:
307+
if (string.IsNullOrEmpty(songResult.ArtistName))
308+
{
309+
return songResult.SongName;
310+
}
311+
return songResult.SongName + " - " + songResult.ArtistName;
312+
default:
313+
if (songResult.TrackNum < 0)
314+
{
315+
return songResult.SongName;
316+
}
317+
return songResult.TrackNum.ToString().PadLeft(2, '0') + " - " + songResult.SongName;
318+
}
319+
}
320+
321+
public static string GetSongPath(DownloadSettings downSetting, SongResult songResult)
322+
{
323+
if (downSetting.EnableUserSetting)
324+
{
325+
var path = downSetting.UserFolder.Replace("%ARTIST%", songResult.ArtistName)
326+
.Replace("%INDEX%", songResult.TrackNum.ToString()).Replace("%SONG%", songResult.SongName)
327+
.Replace("%DISC%", songResult.Disc.ToString());
328+
if (!string.IsNullOrEmpty(songResult.Year) && songResult.Year.Length >= 4)
329+
{
330+
path = path.Replace("%YEAR%", songResult.Year.Substring(0, 4));
331+
}
332+
return path;
333+
}
334+
switch (downSetting.FolderSelect)
335+
{
336+
case 0:
337+
return "";
338+
case 1:
339+
return songResult.ArtistName;
340+
case 2:
341+
return songResult.AlbumName;
342+
default:
343+
return songResult.ArtistName + "/" + songResult.AlbumName;
344+
}
345+
}
282346
}
283347
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using FishMusic.Download;
3+
using GalaSoft.MvvmLight;
4+
5+
namespace FishMusic.Model
6+
{
7+
public class SoftSetting : ViewModelBase
8+
{
9+
private DownloadSettings _downSetting;
10+
11+
public DownloadSettings DownSetting
12+
{
13+
get => _downSetting;
14+
set
15+
{
16+
_downSetting = value;
17+
RaisePropertyChanged("DownSetting");
18+
}
19+
}
20+
21+
public string Id { get; set; }
22+
public DateTime UpdateTime { get; set; }
23+
24+
public SoftSetting()
25+
{
26+
Id = "luooqi";
27+
UpdateTime = DateTime.Now;
28+
DownSetting = new DownloadSettings();
29+
}
30+
}
31+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<UserControl x:Class="FishMusic.View.Download.DownSetting"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d"
7+
d:DesignHeight="900" d:DesignWidth="600">
8+
<UserControl.Resources>
9+
<Style x:Key="TextBlockHeader" TargetType="TextBlock">
10+
<Setter Property="FontWeight" Value="Bold" />
11+
<Setter Property="FontSize" Value="14" />
12+
<Setter Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
13+
</Style>
14+
<Style TargetType="TextBlock">
15+
<Setter Property="Foreground" Value="{DynamicResource BlackBrush}" />
16+
</Style>
17+
</UserControl.Resources>
18+
<UserControl.DataContext>
19+
<Binding Path="Setting" Source="{StaticResource Locator}" />
20+
</UserControl.DataContext>
21+
<Grid>
22+
<ScrollViewer>
23+
<StackPanel Margin="10" Orientation="Vertical">
24+
<TextBlock Style="{StaticResource TextBlockHeader}" Text="常规设置"/>
25+
<TextBlock Margin="0,15,0,0" Text="下载根目录" />
26+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
27+
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.DownPath}" IsEnabled="False" />
28+
</StackPanel>
29+
<TextBlock Margin="0,15,0,0" Text="音质选择" />
30+
<ComboBox Width="270"
31+
Margin="0,10,0,0"
32+
HorizontalAlignment="Left"
33+
SelectedIndex="{Binding SoftSetting.DownSetting.BitRate}">
34+
<ComboBoxItem Content="无损" />
35+
<ComboBoxItem Content="320K" />
36+
<ComboBoxItem Content="192K" />
37+
<ComboBoxItem Content="128K" />
38+
</ComboBox>
39+
<TextBlock Margin="0,15,0,0" Text="无损偏好" />
40+
<ComboBox Width="270"
41+
Margin="0,10,0,0"
42+
HorizontalAlignment="Left"
43+
SelectedIndex="{Binding SoftSetting.DownSetting.LossType}">
44+
<ComboBoxItem Content="FLAC" />
45+
<ComboBoxItem Content="APE" />
46+
<ComboBoxItem Content="WAV" />
47+
</ComboBox>
48+
<TextBlock Margin="0,15,0,0" Text="音乐命名格式" />
49+
<ComboBox Width="270"
50+
Margin="0,10,0,0"
51+
HorizontalAlignment="Left"
52+
SelectedIndex="{Binding SoftSetting.DownSetting.NameSelect}">
53+
<ComboBoxItem Content="歌曲名" />
54+
<ComboBoxItem Content="歌手 - 歌曲名" />
55+
<ComboBoxItem Content="歌曲名 - 歌手" />
56+
<ComboBoxItem Content="歌曲序号 - 歌曲名" />
57+
</ComboBox>
58+
<TextBlock Margin="0,15,0,0" Text="文件智能分类" />
59+
<ComboBox Width="270"
60+
Margin="0,10,0,0"
61+
HorizontalAlignment="Left"
62+
SelectedIndex="{Binding SoftSetting.DownSetting.FolderSelect}">
63+
<ComboBoxItem Content="不分文件夹" />
64+
<ComboBoxItem Content="按歌手分文件夹" />
65+
<ComboBoxItem Content="按专辑分文件夹" />
66+
<ComboBoxItem Content="按歌手\专辑分文件夹" />
67+
</ComboBox>
68+
69+
<TextBlock Style="{StaticResource TextBlockHeader}" Text="其他设置"
70+
Margin="0,15,0,0"/>
71+
<CheckBox Margin="0,10,0,0" Content="下载LRC歌词" IsChecked="{Binding SoftSetting.DownSetting.DownLrc}" />
72+
<CheckBox Margin="0,10,0,0" Content="下载歌曲封面" IsChecked="{Binding SoftSetting.DownSetting.DownPic}" />
73+
<CheckBox Margin="0,10,0,0" Content="启用高级设置" IsChecked="{Binding SoftSetting.DownSetting.EnableUserSetting}" />
74+
75+
<TextBlock Style="{StaticResource TextBlockHeader}" Text="高级设置"
76+
Margin="0,15,0,0"/>
77+
<TextBlock Margin="0,15,0,0" Text="自定义文件名" />
78+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
79+
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.UserName}" />
80+
</StackPanel>
81+
<TextBlock Margin="0,15,0,0" Text="自定义目录结构" />
82+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
83+
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.UserFolder}" />
84+
</StackPanel>
85+
</StackPanel>
86+
</ScrollViewer>
87+
</Grid>
88+
</UserControl>

0 commit comments

Comments
 (0)