Skip to content

Commit

Permalink
upload new version
Browse files Browse the repository at this point in the history
  • Loading branch information
yaronzz committed Dec 2, 2020
1 parent c7a42bf commit 277d39c
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 103 deletions.
Binary file modified TIDALDL-UI-PRO/.vs/TIDALDL-UI/v16/.suo
Binary file not shown.
1 change: 1 addition & 0 deletions TIDALDL-UI-PRO/Else/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private static string FormatPath(string fileName, Settings settings, bool bIsDir
if (!bIsDir && sRet.Length > settings.MaxFileName)
sRet = sRet.Substring(0, settings.MaxFileName);
}
sRet = sRet.Trim();
return sRet;
}

Expand Down
125 changes: 78 additions & 47 deletions TIDALDL-UI-PRO/Else/TrackTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class TrackTask : Screen
public string Own { get; set; }
public ProgressHelper Progress { get; set; }

System.DateTime StartTime { get; set; }
public string CurSizeString { get; set; }
public string TotalSizeString { get; set; }
public long CountIncreSize { get; set; } = 0;
public string DownloadSpeedString { get; set; }

Track TidalTrack { get; set; }
Album TidalAlbum { get; set; }
Playlist TidalPlaylist { get; set; }
Expand Down Expand Up @@ -78,67 +84,77 @@ public void Restart()
#endregion




public void Download()
{
LoginKey key = Tools.GetKey();

//GetStream
Progress.StatusMsg = "GetStream...";
(Progress.Errmsg, Stream) = Client.GetTrackStreamUrl(key, TidalTrack.ID, Settings.AudioQuality).Result;
if (Progress.Errmsg.IsNotBlank() || Stream == null)
goto ERR_RETURN;
try
{
LoginKey key = Tools.GetKey();

Codec = Stream.Codec;
Progress.StatusMsg = "GetStream success...";
//GetStream
Progress.StatusMsg = "GetStream...";
(Progress.Errmsg, Stream) = Client.GetTrackStreamUrl(key, TidalTrack.ID, Settings.AudioQuality).Result;
if (Progress.Errmsg.IsNotBlank() || Stream == null)
goto ERR_RETURN;

//Get path
string path = Tools.GetTrackPath(Settings, TidalTrack, Stream, TidalAlbum, TidalPlaylist);
Codec = Stream.Codec;
Progress.StatusMsg = "GetStream success...";

//Check if song downloaded already
string checkpath = Settings.OnlyM4a ? path.Replace(".mp4", ".m4a") : path;
if (Settings.CheckExist && System.IO.File.Exists(checkpath))
{
Progress.UpdateInt(100, 100);
Progress.SetStatus(ProgressHelper.STATUS.COMPLETE);
goto CALL_RETURN;
}
//Get path
string path = Tools.GetTrackPath(Settings, TidalTrack, Stream, TidalAlbum, TidalPlaylist);

//Download
Progress.StatusMsg = "Start...";
for (int i = 0; i < 50 && Progress.GetStatus() != ProgressHelper.STATUS.CANCLE; i++)
{
if ((bool)DownloadFileHepler.Start(Stream.Url, path, Timeout: 5 * 1000, UpdateFunc: UpdateDownloadNotify, ErrFunc: ErrDownloadNotify, Proxy: key.Proxy))
//Check if song downloaded already
string checkpath = Settings.OnlyM4a ? path.Replace(".mp4", ".m4a") : path;
if (Settings.CheckExist && System.IO.File.Exists(checkpath))
{
//Decrypt
if (!Tools.DecryptTrackFile(Stream, path))
{
Progress.Errmsg = "Decrypt failed!";
goto ERR_RETURN;
}
Progress.UpdateInt(100, 100);
Progress.SetStatus(ProgressHelper.STATUS.COMPLETE);
goto CALL_RETURN;
}

if (Settings.OnlyM4a)
//Download
Progress.StatusMsg = "Start...";
for (int i = 0; i < 50 && Progress.GetStatus() != ProgressHelper.STATUS.CANCLE; i++)
{
StartTime = TimeHelper.GetCurrentTime();
if ((bool)DownloadFileHepler.Start(Stream.Url, path, Timeout: 5 * 1000, UpdateFunc: UpdateDownloadNotify, ErrFunc: ErrDownloadNotify, Proxy: key.Proxy))
{
(Progress.Errmsg, path) = Tools.ConvertMp4ToM4a(path, Stream);
if(Progress.Errmsg.IsNotBlank())
//Decrypt
if (!Tools.DecryptTrackFile(Stream, path))
{
Progress.Errmsg = "Decrypt failed!";
goto ERR_RETURN;
}
}

if (Settings.OnlyM4a)
{
(Progress.Errmsg, path) = Tools.ConvertMp4ToM4a(path, Stream);
if (Progress.Errmsg.IsNotBlank())
goto ERR_RETURN;
}

//SetMetaData
if (TidalAlbum == null)
(Progress.Errmsg, TidalAlbum) = Client.GetAlbum(key, TidalTrack.Album.ID, false).Result;
Progress.Errmsg = Tools.SetMetaData(path, TidalAlbum, TidalTrack);
if (Progress.Errmsg.IsNotBlank())
{
Progress.Errmsg = "Set metadata failed!" + Progress.Errmsg;
goto ERR_RETURN;
}

//SetMetaData
if (TidalAlbum == null)
(Progress.Errmsg, TidalAlbum) = Client.GetAlbum(key, TidalTrack.Album.ID, false).Result;
Progress.Errmsg = Tools.SetMetaData(path, TidalAlbum, TidalTrack);
if (Progress.Errmsg.IsNotBlank())
{
Progress.Errmsg = "Set metadata failed!" + Progress.Errmsg;
goto ERR_RETURN;
Progress.SetStatus(ProgressHelper.STATUS.COMPLETE);
goto CALL_RETURN;
}

Progress.SetStatus(ProgressHelper.STATUS.COMPLETE);
goto CALL_RETURN;
}
Progress.Errmsg = "Download failed!";
System.IO.File.Delete(path);
}
catch(Exception e)
{
Progress.Errmsg = "Download failed!" + e.Message;
}
Progress.Errmsg = "Download failed!";
System.IO.File.Delete(path);

ERR_RETURN:
if (Progress.GetStatus() == ProgressHelper.STATUS.CANCLE)
Expand All @@ -151,6 +167,7 @@ public void Download()

public void ErrDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, string sErrMsg, object data)
{
Progress.Errmsg = sErrMsg;
return;
}

Expand All @@ -159,6 +176,20 @@ public bool UpdateDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, lon
Progress.UpdateInt(lAlreadyDownloadSize, lTotalSize);
if (Progress.GetStatus() != ProgressHelper.STATUS.RUNNING)
return false;

CountIncreSize += lIncreSize;
long consumeTime = TimeHelper.CalcConsumeTime(StartTime);

if (consumeTime >= 1000)
{
DownloadSpeedString = AIGS.Common.Convert.ConverStorageUintToString(CountIncreSize, AIGS.Common.Convert.UnitType.BYTE) + "/S";
CountIncreSize = 0;
StartTime = TimeHelper.GetCurrentTime();
}

CurSizeString = AIGS.Common.Convert.ConverStorageUintToString(lAlreadyDownloadSize, AIGS.Common.Convert.UnitType.BYTE);
if (TotalSizeString.IsBlank())
TotalSizeString = AIGS.Common.Convert.ConverStorageUintToString(lTotalSize, AIGS.Common.Convert.UnitType.BYTE);
return true;
}
}
Expand Down
29 changes: 25 additions & 4 deletions TIDALDL-UI-PRO/Else/VideoTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class VideoTask : Screen
public string Title { get; set; }
public string Own { get; set; }
public ProgressHelper Progress { get; set; }
System.DateTime StartTime { get; set; }
public string CurSizeString { get; set; }
public string TotalSizeString { get; set; }
public long CountIncreSize { get; set; } = 0;
public string DownloadSpeedString { get; set; }

Video TidalVideo { get; set; }
Album TidalAlbum { get; set; }
Expand Down Expand Up @@ -93,11 +98,12 @@ public void Download()
string path = Tools.GetVideoPath(Settings, TidalVideo, TidalAlbum, TidalPlaylist, ".mp4");

//Download
string errmsg = "";
Progress.StatusMsg = "Start...";
string[] tsurls = M3u8Helper.GetTsUrls(Stream.M3u8Url);
if (!(bool)M3u8Helper.Download(tsurls, path, ProgressNotify, Proxy: key.Proxy))
if (!(bool)M3u8Helper.Download(tsurls, path, UpdateDownloadNotify, ref errmsg, Proxy: key.Proxy))
{
Progress.Errmsg = "Download failed!";
Progress.Errmsg = "Download failed!" + errmsg;
goto ERR_RETURN;
}

Expand All @@ -119,12 +125,27 @@ public void Download()
TellParentOver();
}

public bool ProgressNotify(long lCurSize, long lAllSize)
public bool UpdateDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, long lIncreSize, object data)
{
Progress.UpdateInt(lCurSize, lAllSize);
Progress.UpdateInt(lAlreadyDownloadSize, lTotalSize);
if (Progress.GetStatus() != ProgressHelper.STATUS.RUNNING)
return false;

CountIncreSize += lIncreSize;
long consumeTime = TimeHelper.CalcConsumeTime(StartTime);

if (consumeTime >= 1000)
{
DownloadSpeedString = AIGS.Common.Convert.ConverStorageUintToString(CountIncreSize, AIGS.Common.Convert.UnitType.BYTE) + "/S";
CountIncreSize = 0;
StartTime = TimeHelper.GetCurrentTime();
}

CurSizeString = AIGS.Common.Convert.ConverStorageUintToString(lAlreadyDownloadSize, AIGS.Common.Convert.UnitType.BYTE);
if (TotalSizeString.IsBlank())
TotalSizeString = AIGS.Common.Convert.ConverStorageUintToString(lTotalSize, AIGS.Common.Convert.UnitType.BYTE);
return true;
}

}
}
5 changes: 5 additions & 0 deletions TIDALDL-UI-PRO/Pages/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<TextBlock Text="{Binding Version}" Foreground="BlueViolet" FontSize="14" FontFamily="Global Monospace" VerticalAlignment="Center" TextWrapping="Wrap" />
<TextBlock Text="{Binding Type}" Foreground="BlueViolet" FontSize="14" FontFamily="Global Monospace" VerticalAlignment="Center" TextWrapping="Wrap" />
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
<TextBlock Text="{DynamicResource strLASTVERSION}" Foreground="Gray" FontSize="14" FontFamily="Global Monospace" VerticalAlignment="Center" TextWrapping="Wrap" Margin="0,0,5,0" />
<TextBlock Text="{Binding LastVersion}" Foreground="BlueViolet" FontSize="14" FontFamily="Global Monospace" VerticalAlignment="Center" TextWrapping="Wrap" />
<TextBlock Text="{Binding Type}" Foreground="BlueViolet" FontSize="14" FontFamily="Global Monospace" VerticalAlignment="Center" TextWrapping="Wrap" />
</StackPanel>
<DockPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="0,20,0,20">
<Button Content="{DynamicResource strFeedback}" Command="{s:Action Feedback}" hc:IconElement.Geometry="{StaticResource GithubGeometry}" DockPanel.Dock="Left" Margin="0,0,10,0" Padding="15,6" HorizontalAlignment="Left" ></Button>
<Button Content="{DynamicResource strGroup}" Command="{s:Action Telegram}" hc:IconElement.Geometry="{StaticResource TelegramGeometry}" DockPanel.Dock="Left" Margin="0,0,10,0" Padding="15,6" HorizontalAlignment="Left" ></Button>
Expand Down
1 change: 1 addition & 0 deletions TIDALDL-UI-PRO/Pages/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class AboutViewModel : ModelBase
public string Type { get; set; } = "(BETA)";
public Visibility ShowDonate { get; set; } = Visibility.Collapsed;
public string Version { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public string LastVersion { get; set; }

public void Feedback() => NetHelper.OpenWeb(Global.URL_TIDAL_ISSUES);
public void Telegram() => NetHelper.OpenWeb(Global.URL_TIDAL_GROUP);
Expand Down
23 changes: 17 additions & 6 deletions TIDALDL-UI-PRO/Pages/LoginView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,29 @@
<!--Err label-->
<TextBlock Grid.Column="1" Text="{Binding Errlabel,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Foreground="Red" VerticalAlignment="Bottom" Margin="10,0,0,4" Grid.ColumnSpan="2"></TextBlock>

<Grid Margin="30,62,29.6,65" Grid.Column="1" VerticalAlignment="Center" Height="225">
<!--<Grid Margin="30,62,29.6,65" Grid.Column="1" VerticalAlignment="Center" Height="225">
<StackPanel VerticalAlignment="Center">
<DockPanel>
<TextBlock Text="DeviceCode:" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Padding="10"/>
<hc:TextBox Text="{Binding DeviceCode.UserCode}" Height="30" FontWeight="Normal"/>
</DockPanel>
<Button Content="Login" IsDefault="True" Command="{s:Action Login}" IsEnabled="{Binding BtnLoginEnable}" Style="{StaticResource ButtonPrimary}" HorizontalAlignment="Stretch" Margin="0,20,0,0"/>
</StackPanel>
</Grid>
</Grid>-->

<!--<TabControl Margin="30,62,29.6,65" Grid.Column="1" VerticalAlignment="Center" Height="225">
<TabControl Margin="30,62,29.6,65" Grid.Column="1" VerticalAlignment="Center" Height="250">
<TabItem Header="LOGIN" FontWeight="ExtraBold">
<Grid Margin="0 16 0 0" >
<StackPanel VerticalAlignment="Center">
<DockPanel>
<TextBlock Text="DeviceCode:" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Padding="10"/>
<hc:TextBox Text="{Binding DeviceCode.UserCode}" Height="30" FontWeight="Normal"/>
</DockPanel>
<Button Content="Login" IsDefault="True" Command="{s:Action Login}" IsEnabled="{Binding BtnLoginEnable}" Style="{StaticResource ButtonPrimary}" HorizontalAlignment="Stretch" Margin="5,20,5,0"/>
</StackPanel>
</Grid>
</TabItem>
<!--<TabItem Header="LOGIN" FontWeight="ExtraBold">
<Grid Margin="0 16 0 0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -88,7 +99,7 @@
<Button Grid.Row="3" IsDefault="True" Command="{s:Action Login}" IsEnabled="{Binding BtnLoginEnable}" CommandParameter="{Binding ElementName=PasswordBox}" Style="{StaticResource ButtonPrimary}"
Content="Login" Grid.RowSpan="2" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Margin="0,15,0,0"/>
</Grid>
</TabItem>
</TabItem>-->
<TabItem Header="PROXY" FontWeight="Bold">
<Grid Margin="0 16 0 0" >
<Grid.RowDefinitions>
Expand Down Expand Up @@ -116,11 +127,11 @@
<hc:TextBox Grid.Row="2" Grid.Column="2" Text="{Binding Settings.ProxyUser}" Height="30" FontWeight="Normal"/>
<hc:TextBox Grid.Row="3" Grid.Column="2" Text="{Binding Settings.ProxyPwd}" Height="30" FontWeight="Normal"/>

<Button Grid.Row="4" Grid.ColumnSpan="3" Command="{s:Action SaveProxy}" Content="Save" Style="{StaticResource ButtonPrimary}" Margin="22,3,20,2" Width="242"/>
<Button Grid.Row="4" Grid.ColumnSpan="3" Command="{s:Action SaveProxy}" Content="Save" Style="{StaticResource ButtonPrimary}" Margin="5,5,5,2" HorizontalAlignment="Stretch" />

</Grid>
</TabItem>
</TabControl>-->
</TabControl>

<!--Message page-->
<ScrollViewer Grid.ColumnSpan="3" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Right" VerticalAlignment="Bottom" VerticalContentAlignment="Bottom">
Expand Down
Loading

0 comments on commit 277d39c

Please sign in to comment.