Skip to content

Commit

Permalink
实现下载设置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
AnyListen committed Jan 3, 2019
1 parent 6abb898 commit e83cc43
Show file tree
Hide file tree
Showing 11 changed files with 466 additions and 37 deletions.
134 changes: 134 additions & 0 deletions FishMusic/FishMusic/Download/DownloadSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.IO;
using GalaSoft.MvvmLight;

namespace FishMusic.Download
{
public class DownloadSettings : ViewModelBase
{
private int _bitRate;
private int _lossType;
private string _downPath;
private string _userFolder;
private string _userName;
private int _nameSelect;
private int _folderSelect;
private bool _downPic;
private bool _downLrc;
private bool _enableUserSetting;

public int BitRate
{
get => _bitRate;
set
{
_bitRate = value;
RaisePropertyChanged("BitRate");
}
}

public int LossType
{
get => _lossType;
set
{
_lossType = value;
RaisePropertyChanged("LossType");
}
}

public string DownPath
{
get => _downPath;
set
{
_downPath = value;
RaisePropertyChanged("DownPath");
}
}

public string UserFolder
{
get => _userFolder;
set
{
_userFolder = value;
RaisePropertyChanged("UserFolder");
}
}

public string UserName
{
get => _userName;
set
{
_userName = value;
RaisePropertyChanged("UserName");
}
}

public int NameSelect
{
get => _nameSelect;
set
{
_nameSelect = value;
RaisePropertyChanged("NameSelect");
}
}

public int FolderSelect
{
get => _folderSelect;
set
{
_folderSelect = value;
RaisePropertyChanged("FolderSelect");
}
}

public bool DownPic
{
get => _downPic;
set
{
_downPic = value;
RaisePropertyChanged("DownPic");
}
}

public bool DownLrc
{
get => _downLrc;
set
{
_downLrc = value;
RaisePropertyChanged("DownLrc");
}
}

public bool EnableUserSetting
{
get => _enableUserSetting;
set
{
_enableUserSetting = value;
RaisePropertyChanged("EnableUserSetting");
}
}

public DownloadSettings()
{
BitRate = 1;
LossType = 0;
DownPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Music");
DownLrc = false;
DownPic = false;
EnableUserSetting = false;
NameSelect = 1;
FolderSelect = 0;
UserName = "%ARTIST% - %SONG%";
UserFolder = "";
}
}
}
10 changes: 10 additions & 0 deletions FishMusic/FishMusic/FishMusic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@
<Compile Include="Converter\TrackTimeConverter.cs" />
<Compile Include="Converter\UrlConverter.cs" />
<Compile Include="Download\DownloadInfo.cs" />
<Compile Include="Download\DownloadSettings.cs" />
<Compile Include="Download\XL.cs" />
<Compile Include="Download\XunleiClient.cs" />
<Compile Include="Helper\CommonHelper.cs" />
<Compile Include="Helper\DbHelper.cs" />
<Compile Include="Model\SearchEngine.cs" />
<Compile Include="Model\SoftSetting.cs" />
<Compile Include="TagLib\Aac\AudioHeader.cs" />
<Compile Include="TagLib\Aac\BitStream.cs" />
<Compile Include="TagLib\Aac\File.cs" />
Expand Down Expand Up @@ -359,6 +361,7 @@
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\PlayViewModel.cs" />
<Compile Include="ViewModel\SearchViewModel.cs" />
<Compile Include="ViewModel\SettingViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="View\Controls\MainPlayControl.xaml.cs">
<DependentUpon>MainPlayControl.xaml</DependentUpon>
Expand All @@ -369,6 +372,9 @@
<Compile Include="View\Download\Downloading.xaml.cs">
<DependentUpon>Downloading.xaml</DependentUpon>
</Compile>
<Compile Include="View\Download\DownSetting.xaml.cs">
<DependentUpon>DownSetting.xaml</DependentUpon>
</Compile>
<Compile Include="View\MainControl.xaml.cs">
<DependentUpon>MainControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -436,6 +442,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\Download\DownSetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="View\MainControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
64 changes: 64 additions & 0 deletions FishMusic/FishMusic/Helper/CommonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Text.RegularExpressions;
using AnyListen.Models;
using FishMusic.Download;
using Newtonsoft.Json.Linq;

namespace FishMusic.Helper
Expand Down Expand Up @@ -193,6 +194,10 @@ public static string GetFormat(string url)
{
link = "wma";
}
else if (url.ToLower().Contains(".dsf"))
{
link = "dsf";
}
else
{
link = "mp3";
Expand Down Expand Up @@ -279,5 +284,64 @@ public static string SecondsToTime(int total)
return hour.ToString().PadLeft(2, '0') + ":" + min.ToString().PadLeft(2, '0') + ":" +
sec.ToString().PadLeft(2, '0');
}

public static string GetSongName(DownloadSettings downSetting, SongResult songResult)
{
if (downSetting.EnableUserSetting)
{
return downSetting.UserName.Replace("%ARTIST%", songResult.ArtistName)
.Replace("%INDEX%", songResult.TrackNum.ToString()).Replace("%SONG%", songResult.SongName)
.Replace("%DISC%", songResult.Disc.ToString());
}
switch (downSetting.NameSelect)
{
case 0:
return songResult.SongName;
case 1:
if (string.IsNullOrEmpty(songResult.ArtistName))
{
return songResult.SongName;
}
return songResult.ArtistName + " - " + songResult.SongName;
case 2:
if (string.IsNullOrEmpty(songResult.ArtistName))
{
return songResult.SongName;
}
return songResult.SongName + " - " + songResult.ArtistName;
default:
if (songResult.TrackNum < 0)
{
return songResult.SongName;
}
return songResult.TrackNum.ToString().PadLeft(2, '0') + " - " + songResult.SongName;
}
}

public static string GetSongPath(DownloadSettings downSetting, SongResult songResult)
{
if (downSetting.EnableUserSetting)
{
var path = downSetting.UserFolder.Replace("%ARTIST%", songResult.ArtistName)
.Replace("%INDEX%", songResult.TrackNum.ToString()).Replace("%SONG%", songResult.SongName)
.Replace("%DISC%", songResult.Disc.ToString());
if (!string.IsNullOrEmpty(songResult.Year) && songResult.Year.Length >= 4)
{
path = path.Replace("%YEAR%", songResult.Year.Substring(0, 4));
}
return path;
}
switch (downSetting.FolderSelect)
{
case 0:
return "";
case 1:
return songResult.ArtistName;
case 2:
return songResult.AlbumName;
default:
return songResult.ArtistName + "/" + songResult.AlbumName;
}
}
}
}
31 changes: 31 additions & 0 deletions FishMusic/FishMusic/Model/SoftSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using FishMusic.Download;
using GalaSoft.MvvmLight;

namespace FishMusic.Model
{
public class SoftSetting : ViewModelBase
{
private DownloadSettings _downSetting;

public DownloadSettings DownSetting
{
get => _downSetting;
set
{
_downSetting = value;
RaisePropertyChanged("DownSetting");
}
}

public string Id { get; set; }
public DateTime UpdateTime { get; set; }

public SoftSetting()
{
Id = "luooqi";
UpdateTime = DateTime.Now;
DownSetting = new DownloadSettings();
}
}
}
88 changes: 88 additions & 0 deletions FishMusic/FishMusic/View/Download/DownSetting.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<UserControl x:Class="FishMusic.View.Download.DownSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="900" d:DesignWidth="600">
<UserControl.Resources>
<Style x:Key="TextBlockHeader" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource BlackBrush}" />
</Style>
</UserControl.Resources>
<UserControl.DataContext>
<Binding Path="Setting" Source="{StaticResource Locator}" />
</UserControl.DataContext>
<Grid>
<ScrollViewer>
<StackPanel Margin="10" Orientation="Vertical">
<TextBlock Style="{StaticResource TextBlockHeader}" Text="常规设置"/>
<TextBlock Margin="0,15,0,0" Text="下载根目录" />
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.DownPath}" IsEnabled="False" />
</StackPanel>
<TextBlock Margin="0,15,0,0" Text="音质选择" />
<ComboBox Width="270"
Margin="0,10,0,0"
HorizontalAlignment="Left"
SelectedIndex="{Binding SoftSetting.DownSetting.BitRate}">
<ComboBoxItem Content="无损" />
<ComboBoxItem Content="320K" />
<ComboBoxItem Content="192K" />
<ComboBoxItem Content="128K" />
</ComboBox>
<TextBlock Margin="0,15,0,0" Text="无损偏好" />
<ComboBox Width="270"
Margin="0,10,0,0"
HorizontalAlignment="Left"
SelectedIndex="{Binding SoftSetting.DownSetting.LossType}">
<ComboBoxItem Content="FLAC" />
<ComboBoxItem Content="APE" />
<ComboBoxItem Content="WAV" />
</ComboBox>
<TextBlock Margin="0,15,0,0" Text="音乐命名格式" />
<ComboBox Width="270"
Margin="0,10,0,0"
HorizontalAlignment="Left"
SelectedIndex="{Binding SoftSetting.DownSetting.NameSelect}">
<ComboBoxItem Content="歌曲名" />
<ComboBoxItem Content="歌手 - 歌曲名" />
<ComboBoxItem Content="歌曲名 - 歌手" />
<ComboBoxItem Content="歌曲序号 - 歌曲名" />
</ComboBox>
<TextBlock Margin="0,15,0,0" Text="文件智能分类" />
<ComboBox Width="270"
Margin="0,10,0,0"
HorizontalAlignment="Left"
SelectedIndex="{Binding SoftSetting.DownSetting.FolderSelect}">
<ComboBoxItem Content="不分文件夹" />
<ComboBoxItem Content="按歌手分文件夹" />
<ComboBoxItem Content="按专辑分文件夹" />
<ComboBoxItem Content="按歌手\专辑分文件夹" />
</ComboBox>

<TextBlock Style="{StaticResource TextBlockHeader}" Text="其他设置"
Margin="0,15,0,0"/>
<CheckBox Margin="0,10,0,0" Content="下载LRC歌词" IsChecked="{Binding SoftSetting.DownSetting.DownLrc}" />
<CheckBox Margin="0,10,0,0" Content="下载歌曲封面" IsChecked="{Binding SoftSetting.DownSetting.DownPic}" />
<CheckBox Margin="0,10,0,0" Content="启用高级设置" IsChecked="{Binding SoftSetting.DownSetting.EnableUserSetting}" />

<TextBlock Style="{StaticResource TextBlockHeader}" Text="高级设置"
Margin="0,15,0,0"/>
<TextBlock Margin="0,15,0,0" Text="自定义文件名" />
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.UserName}" />
</StackPanel>
<TextBlock Margin="0,15,0,0" Text="自定义目录结构" />
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBox Width="270" Text="{Binding SoftSetting.DownSetting.UserFolder}" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
Loading

0 comments on commit e83cc43

Please sign in to comment.