Skip to content

Commit

Permalink
Settings: Album folder format、Track file format
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronzz committed Oct 11, 2020
1 parent 45048c5 commit 321a398
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 16 deletions.
6 changes: 6 additions & 0 deletions TIDALDL-UI-PRO/Else/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public class Settings : Stylet.Screen
[JsonProperty("AddYear")]
public ePositionYear AddYear { get; set; } = ePositionYear.None;

[JsonProperty("AlbumFolderFormat")]
public string AlbumFolderFormat { get; set; } = "{Flag} {AlbumTitle} [{AlbumID}] [{AlbumYear}]";

[JsonProperty("TrackFileFormat")]
public string TrackFileFormat { get; set; } = "{TrackNumber} - {ArtistName} - {TrackTitle}{ExplicitFlag}";


public static void Change(Settings newItem, Settings oldItem = null)
{
Expand Down
72 changes: 71 additions & 1 deletion TIDALDL-UI-PRO/Else/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,35 @@ public static string GetArtistPath(Artist artist, Settings settings)
return basepath;
}

//[{Flag}] [{AlbumID}] [{AlbumYear}] {AlbumTitle}
public static string GetAlbumPath(Album album, Settings settings)
{
// outputdir/Album/artist/
string basepath = $"{settings.OutputDir}/Album/{FormatPath(album.Artists[0].Name, settings)}";

// album folder pre: [ME][ID]
string flag = Client.GetFlag(album, eType.ALBUM, true, "");
if (settings.AudioQuality != eAudioQuality.Master)
flag = flag.Replace("M", "");
if (flag.IsNotBlank())
flag = $"[{flag}]";

string name = settings.AlbumFolderFormat;
if (name.IsBlank())
name = "[{Flag}] [{AlbumID}] [{AlbumYear}] {AlbumTitle}";
name = name.Replace("{AlbumID}", album.ID);
name = name.Replace("{AlbumYear}", album.ReleaseDate.Substring(0, 4));
name = name.Replace("{AlbumTitle}", FormatPath(album.Title, settings));
name = name.Replace("{Flag}", flag);
name = name.Trim();
return $"{basepath}/{name}/";

}
public static string GetAlbumPath2(Album album, Settings settings)
{
// outputdir/Album/artist/
string basepath = $"{settings.OutputDir}/Album/{FormatPath(album.Artists[0].Name, settings)}";

// album folder pre: [ME][ID]
string flag = Client.GetFlag(album, eType.ALBUM, true, "");
if (settings.AudioQuality != eAudioQuality.Master)
Expand Down Expand Up @@ -92,8 +116,54 @@ public static string GetPlaylistPath(Playlist plist, Settings settings)
return path;
}

// number - artist - title(version)(Explicit).flac
// "{TrackNumber} - {ArtistName} - {TrackTitle}{ExplicitFlag}";
public static string GetTrackPath(Settings settings, Track track, StreamUrl stream, Album album, Playlist playlist = null)
{
string number = track.TrackNumber.ToString().PadLeft(2, '0');
if (playlist != null)
number = (playlist.Tracks.IndexOf(track) + 1).ToString().PadLeft(2, '0');

string artist = FormatPath(track.Artists[0].Name, settings, false);

//get explicit
string sexplicit = "";
if (settings.AddExplicitTag && track.Explicit)
sexplicit = "(Explicit)";

//get version
string version = "";
if (track.Version.IsNotBlank())
version = "(" + track.Version + ")";

//get title
string title = FormatPath(track.Title, settings, false);

//get extension
string extension = getExtension(stream.Url);

//base path
string basepath = null;
if (playlist == null)
{
basepath = GetAlbumPath(album, settings);
if (album.NumberOfVolumes > 1)
basepath += $"CD{track.VolumeNumber}/";
}
else
basepath = GetPlaylistPath(playlist, settings);

string name = settings.TrackFileFormat;
if (name.IsBlank())
name = "{TrackNumber} - {ArtistName} - {TrackTitle}{ExplicitFlag}";
name = name.Replace("{TrackNumber}", number);
name = name.Replace("{ArtistName}", artist);
name = name.Replace("{TrackTitle}", title + version);
name = name.Replace("{ExplicitFlag}", sexplicit);
return $"{basepath}{name}{extension}";
}

// number - artist - title(version)(Explicit).flac
public static string GetTrackPath2(Settings settings, Track track, StreamUrl stream, Album album, Playlist playlist = null)
{
//hyphen
string hyphen = " ";
Expand Down
35 changes: 20 additions & 15 deletions TIDALDL-UI-PRO/Pages/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<RowDefinition Height="15"/>

<RowDefinition Height="45"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="45"/>
<RowDefinition Height="15"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="15"/>
Expand All @@ -49,10 +49,10 @@
<RowDefinition Height="15"/>

<RowDefinition Height="35"/>
<RowDefinition Height="0"/>
<RowDefinition Height="0"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
<RowDefinition Height="0"/>
<RowDefinition Height="15"/>
<RowDefinition Height="45"/>
<RowDefinition Height="100"/>
Expand All @@ -74,12 +74,17 @@
<TextBlock Grid.Row="2" Grid.Column="1" Text="limit 10~50" FontSize="12" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Left" Margin="200,0,0,0" />
<hc:NumericUpDown Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Maximum="50" Minimum="10" Value="{Binding Settings.SearchNum}" Width="200" HorizontalAlignment="Left" VerticalAlignment="Center"/>

<TextBlock Grid.Row="4" Text="AddYear:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<ComboBox Grid.Row="4" Grid.Column="1" ItemsSource="{Binding ComboxAddYear}" SelectedValue="{Binding Settings.AddYear}" Grid.ColumnSpan="2" Width="200" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Row="4" Text="AlbumFolderFormat:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Settings.AlbumFolderFormat}" hc:InfoElement.Placeholder="eg: {Flag} {AlbumTitle} [{AlbumID}] [{AlbumYear}] -->> [ME] Happy End [103578093] [2016]" Margin="0,6,10,6"/>
<!--<TextBlock Grid.Row="4" Text="AddYear:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />-->
<!--<ComboBox Grid.Row="4" Grid.Column="1" ItemsSource="{Binding ComboxAddYear}" SelectedValue="{Binding Settings.AddYear}" Grid.ColumnSpan="2" Width="200" HorizontalAlignment="Left" VerticalAlignment="Center"/>-->

<TextBlock Grid.Row="5" Text="TrackFileFormat:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Settings.TrackFileFormat}" hc:InfoElement.Placeholder="eg: {TrackNumber} - {ArtistName} - {TrackTitle}{ExplicitFlag} -->> 01 - Back Number - Happy End(Explicit)" Margin="0,6,10,6"/>

<TextBlock Grid.Row="5" Text="Choose:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<CheckBox Grid.Row="5" Grid.Column="1" IsChecked="{Binding Settings.ArtistBeforeTitle}" Content="Add artist-name before title, like 'adele - hello.flac'" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="6" Grid.Column="1" IsChecked="{Binding Settings.AddAlbumIDBeforeFolder}" Content="Add album-id befor album-folder, like '[123] Only one'" HorizontalAlignment="Left"/>
<TextBlock Grid.Row="7" Text="Choose:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<!--<CheckBox Grid.Row="5" Grid.Column="1" IsChecked="{Binding Settings.ArtistBeforeTitle}" Content="Add artist-name before title, like 'adele - hello.flac'" HorizontalAlignment="Left"/>-->
<!--<CheckBox Grid.Row="6" Grid.Column="1" IsChecked="{Binding Settings.AddAlbumIDBeforeFolder}" Content="Add album-id befor album-folder, like '[123] Only one'" HorizontalAlignment="Left"/>-->
<CheckBox Grid.Row="7" Grid.Column="1" IsChecked="{Binding Settings.IncludeEP}" Content="Search artist-album include single/ep" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="8" Grid.Column="1" IsChecked="{Binding Settings.SaveCovers}" Content="Download cover" HorizontalAlignment="Left"/>

Expand All @@ -91,18 +96,18 @@

<TextBlock Grid.Row="13" Text="Track:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<CheckBox Grid.Row="13" Grid.Column="1" IsChecked="{Binding Settings.OnlyM4a}" Content="Convert mp4 to m4a" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="14" Grid.Column="1" IsChecked="{Binding Settings.UseTrackNumber}" Content="Add track number" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="15" Grid.Column="1" IsChecked="{Binding Settings.AddHyphen}" Content="Addhyphen between track-number and title" HorizontalAlignment="Left"/>
<!--<CheckBox Grid.Row="14" Grid.Column="1" IsChecked="{Binding Settings.UseTrackNumber}" Content="Add track number" HorizontalAlignment="Left"/>-->
<!--<CheckBox Grid.Row="15" Grid.Column="1" IsChecked="{Binding Settings.AddHyphen}" Content="Addhyphen between track-number and title" HorizontalAlignment="Left"/>-->
<CheckBox Grid.Row="16" Grid.Column="1" IsChecked="{Binding Settings.CheckExist}" Content="Skipping exist file when downloading" HorizontalAlignment="Left"/>
<CheckBox Grid.Row="17" Grid.Column="1" IsChecked="{Binding Settings.AddExplicitTag}" Content="Add [explicit] after track-title " HorizontalAlignment="Left"/>
<!--<CheckBox Grid.Row="17" Grid.Column="1" IsChecked="{Binding Settings.AddExplicitTag}" Content="Add [explicit] after track-title " HorizontalAlignment="Left"/>-->

<TextBlock Grid.Row="19" Text="Theme:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />
<ComboBox Grid.Row="19" Grid.Column="1" ItemsSource="{Binding ComboxTheme}" SelectedValue="{Binding Settings.ThemeType}" Grid.ColumnSpan="2" Width="200" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Row="20" Text="AccessToken:" VerticalAlignment="Center" Padding="20,0" HorizontalAlignment="Right" />

<DockPanel Grid.Row="20" Grid.ColumnSpan="2" >
<DockPanel Grid.Row="20" Grid.Column="1" >
<Button Content="Try Get" Command="{s:Action GetAccessToken}" Width="100" Style="{StaticResource ButtonPrimary}" HorizontalAlignment="Center" DockPanel.Dock="Right" Margin="0,10,10,10" Height="80" ></Button>
<hc:TextBox Text="{Binding AccessToken}" FontFamily="Microsoft Yahei Regular" FontWeight="Normal" VerticalAlignment="Center" TextWrapping="Wrap" Height="80" Width="auto" Margin="123,10,10,10" />
<hc:TextBox Text="{Binding AccessToken}" FontFamily="Microsoft Yahei Regular" FontWeight="Normal" VerticalAlignment="Center" TextWrapping="Wrap" Height="80" Width="auto" Margin="0,10,10,10" />
</DockPanel>
</Grid>

Expand Down
5 changes: 5 additions & 0 deletions TIDALDL-UI-PRO/UPDATE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
- [ ] Auto update
- [ ] Multi-language

- [x] Fix: download video(get stream) [#30](https://github.com/yaronzz/Tidal-Media-Downloader-PRO/issues/30)
- [x] Fix: album path end with "..." [#27](https://github.com/yaronzz/Tidal-Media-Downloader-PRO/issues/27)
- [x] Settings: Album folder format¡¢Track file format [#33](https://github.com/yaronzz/Tidal-Media-Downloader-PRO/issues/33)
- [x] Version in filename [#32](https://github.com/yaronzz/Tidal-Media-Downloader-PRO/issues/32)

#### v1.2.0.4
- [x] Auto get the accessToken from tidal-desktop
- [x] Allow to cancel and retry download-task
Expand Down

0 comments on commit 321a398

Please sign in to comment.