From d56299be9b21959071f5b0c87c925febcb5b2df3 Mon Sep 17 00:00:00 2001 From: yaronzz <392309221@qq.com> Date: Sat, 24 Aug 2019 20:04:49 +0800 Subject: [PATCH] --- TIDALDL-UI/TIDALDL-UI.sln | 2 +- TIDALDL-UI/TIDALDL-UI/App.config | 26 +- TIDALDL-UI/TIDALDL-UI/App.xaml | Bin 2786 -> 4402 bytes TIDALDL-UI/TIDALDL-UI/App.xaml.cs | 34 +- TIDALDL-UI/TIDALDL-UI/Else/Config.cs | 378 ++++----- TIDALDL-UI/TIDALDL-UI/Else/DownloadItem.cs | 516 ++++++------ TIDALDL-UI/TIDALDL-UI/Else/ProgressHelper.cs | 105 --- TIDALDL-UI/TIDALDL-UI/Else/ThreadTool.cs | 101 ++- TIDALDL-UI/TIDALDL-UI/FodyWeavers.xml | 20 +- TIDALDL-UI/TIDALDL-UI/FodyWeavers.xsd | 278 +++---- TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml | 92 +-- TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml.cs | 58 +- TIDALDL-UI/TIDALDL-UI/Pages/AboutViewModel.cs | 66 +- TIDALDL-UI/TIDALDL-UI/Pages/InfoView.xaml | 154 ++-- TIDALDL-UI/TIDALDL-UI/Pages/InfoView.xaml.cs | 61 +- TIDALDL-UI/TIDALDL-UI/Pages/InfoViewModel.cs | 259 +++--- TIDALDL-UI/TIDALDL-UI/Pages/LoginView.xaml | 161 ++-- TIDALDL-UI/TIDALDL-UI/Pages/LoginView.xaml.cs | 58 +- TIDALDL-UI/TIDALDL-UI/Pages/LoginViewModel.cs | 286 +++---- .../TIDALDL-UI/Pages/MainListItemView.xaml | 178 +++-- .../TIDALDL-UI/Pages/MainListItemView.xaml.cs | 56 +- .../TIDALDL-UI/Pages/MainListItemViewModel.cs | 283 +++---- TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml | 180 ++--- TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml.cs | 64 +- TIDALDL-UI/TIDALDL-UI/Pages/MainViewModel.cs | 508 +++++------- TIDALDL-UI/TIDALDL-UI/Pages/SearchView.xaml | 19 +- .../TIDALDL-UI/Pages/SearchView.xaml.cs | 61 +- .../TIDALDL-UI/Pages/SearchViewModel.cs | 228 +++--- TIDALDL-UI/TIDALDL-UI/Pages/SettingView.xaml | 150 ++-- .../TIDALDL-UI/Pages/SettingView.xaml.cs | 58 +- .../TIDALDL-UI/Pages/SettingViewModel.cs | 184 ++--- TIDALDL-UI/TIDALDL-UI/Pages/Wait.xaml | 48 +- TIDALDL-UI/TIDALDL-UI/Pages/Wait.xaml.cs | 122 +-- TIDALDL-UI/TIDALDL-UI/Pages/WaitView.xaml | 36 - TIDALDL-UI/TIDALDL-UI/Pages/WaitView.xaml.cs | 26 - TIDALDL-UI/TIDALDL-UI/Pages/WatiViewModel.cs | 43 - .../TIDALDL-UI/Properties/AssemblyInfo.cs | 110 +-- .../Properties/Resources.Designer.cs | 146 ++-- .../TIDALDL-UI/Properties/Resources.resx | 246 +++--- .../Properties/Settings.Designer.cs | 60 +- .../TIDALDL-UI/Properties/Settings.settings | 12 +- TIDALDL-UI/TIDALDL-UI/TIDALDL-UI.csproj | 533 ++++++------- TIDALDL-UI/TIDALDL-UI/Tidal/Account.cs | 59 -- TIDALDL-UI/TIDALDL-UI/Tidal/Album.cs | 126 --- TIDALDL-UI/TIDALDL-UI/Tidal/Artist.cs | 54 -- .../TIDALDL-UI/Tidal/ArtistAlbumList.cs | 38 - TIDALDL-UI/TIDALDL-UI/Tidal/Enum.cs | 70 +- TIDALDL-UI/TIDALDL-UI/Tidal/Model.cs | 139 ++++ TIDALDL-UI/TIDALDL-UI/Tidal/Playlist.cs | 102 --- TIDALDL-UI/TIDALDL-UI/Tidal/SearchResult.cs | 18 - TIDALDL-UI/TIDALDL-UI/Tidal/StreamUrl.cs | 61 -- TIDALDL-UI/TIDALDL-UI/Tidal/TidalTool.cs | 689 ++++++++++++++++ TIDALDL-UI/TIDALDL-UI/Tidal/Tool.cs | 739 ------------------ TIDALDL-UI/TIDALDL-UI/Tidal/Track.cs | 99 --- TIDALDL-UI/TIDALDL-UI/Tidal/Video.cs | 109 --- TIDALDL-UI/TIDALDL-UI/packages.config | 22 +- TIDALDL-UI/TIDALDL-UI/updateLog.md | 14 + TIDALDL-UI/TIDALDL-UI/updateLog.txt | 2 - TIDALDL-UI/packages/AIGS/AIGS.dll | Bin 97792 -> 101376 bytes 59 files changed, 3617 insertions(+), 4730 deletions(-) delete mode 100644 TIDALDL-UI/TIDALDL-UI/Else/ProgressHelper.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Pages/WaitView.xaml delete mode 100644 TIDALDL-UI/TIDALDL-UI/Pages/WaitView.xaml.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Pages/WatiViewModel.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Account.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Album.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Artist.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/ArtistAlbumList.cs create mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Model.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Playlist.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/SearchResult.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/StreamUrl.cs create mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/TidalTool.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Tool.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Track.cs delete mode 100644 TIDALDL-UI/TIDALDL-UI/Tidal/Video.cs create mode 100644 TIDALDL-UI/TIDALDL-UI/updateLog.md delete mode 100644 TIDALDL-UI/TIDALDL-UI/updateLog.txt diff --git a/TIDALDL-UI/TIDALDL-UI.sln b/TIDALDL-UI/TIDALDL-UI.sln index 79e250cf..29681e6a 100644 --- a/TIDALDL-UI/TIDALDL-UI.sln +++ b/TIDALDL-UI/TIDALDL-UI.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIDALDL-UI", "TIDALDL-UI\TIDALDL-UI.csproj", "{87F39F78-056F-4747-A835-12BA03FE575A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIGS", "..\..\AIGS\AIGS.csproj", "{E0F1B398-B4D4-4536-9135-BE2EB077BBB2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIGS", "..\..\..\AIGS.git\trunk\AIGS.csproj", "{E0F1B398-B4D4-4536-9135-BE2EB077BBB2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/TIDALDL-UI/TIDALDL-UI/App.config b/TIDALDL-UI/TIDALDL-UI/App.config index 02d18eed..fb5350eb 100644 --- a/TIDALDL-UI/TIDALDL-UI/App.config +++ b/TIDALDL-UI/TIDALDL-UI/App.config @@ -1,14 +1,14 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/TIDALDL-UI/TIDALDL-UI/App.xaml b/TIDALDL-UI/TIDALDL-UI/App.xaml index 0d63d05b51a4ed98b3c6057df99d40745fb126ea..834fc71e02943f0a5e01cf3fcccdbf11cd995ba1 100644 GIT binary patch delta 126 zcmaDPx=Cq+9v8O(g9U>TgDZn6gURI8Y^v-w42lf847!uov#M`)V$ow{cVS3mC}PN- zypV0@WC7NM&6C(X7}?!{La7Xun-{V%GERQSv4DYZOmQOyL!i+Rti+(e NpwD0jHrk$RF#u_s95Da@ delta 29 jcmdm_^hk7r9+#jYgENCAgE50EkXB+)V9=l3FR&N@XR-!! diff --git a/TIDALDL-UI/TIDALDL-UI/App.xaml.cs b/TIDALDL-UI/TIDALDL-UI/App.xaml.cs index 27a23521..595aff69 100644 --- a/TIDALDL-UI/TIDALDL-UI/App.xaml.cs +++ b/TIDALDL-UI/TIDALDL-UI/App.xaml.cs @@ -1,17 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; - -namespace TIDALDL_UI -{ - /// - /// App.xaml 的交互逻辑 - /// - public partial class App : Application - { - } -} +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace TIDALDL_UI +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Else/Config.cs b/TIDALDL-UI/TIDALDL-UI/Else/Config.cs index 2ea7a750..05800540 100644 --- a/TIDALDL-UI/TIDALDL-UI/Else/Config.cs +++ b/TIDALDL-UI/TIDALDL-UI/Else/Config.cs @@ -1,185 +1,193 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using AIGS.Common; -using AIGS.Helper; -using System.Collections.ObjectModel; - -namespace TIDALDL_UI.Else -{ - public class Config - { - private static string CONFIGPATH = "./tidal-dl.ini"; - private static string BASEGROUP = "base"; - private static string HISTORYGROUP = "history"; - - private static string SetOrGet(string Key, string SetValue = null, string GetDefault = "", string Group = null) - { - if (Group.IsBlank()) - Group = BASEGROUP; - if (SetValue.IsBlank()) - return ConfigHelper.GetValue(Key, GetDefault, Group, CONFIGPATH); - else - ConfigHelper.SetValue(Key, SetValue, Group, CONFIGPATH); - return null; - } - - - #region Base Config - public static string OutputDir(string Setvalue = null) - { - return SetOrGet("outputdir", Setvalue, "./"); - } - - public static string Quality(string Setvalue = null) - { - return SetOrGet("quality", Setvalue, "HIGH"); - } - - public static Dictionary QualityList() - { - return AIGS.Common.Convert.ConverEnumToDictionary(typeof(Tidal.eSoundQuality)); - } - - public static int QualityIndex() - { - string sValue = Config.Quality(); - Dictionary pList = QualityList(); - for (int i = 0; i < pList.Count; i++) - { - if (sValue.ToUpper() == pList.ElementAt(i).Value) - return i; - } - return 0; - } - - public static string ThreadNum(string Setvalue = null) - { - return SetOrGet("threadnum", Setvalue, "3"); - } - - public static string Username(string Setvalue = null) - { - return SetOrGet("username", Setvalue, ""); - } - - public static string Password(string Setvalue = null) - { - return SetOrGet("password", Setvalue, ""); - } - - public static string Sessionid(string Setvalue = null) - { - return SetOrGet("sessionid", Setvalue, ""); - } - - public static string Countrycode(string Setvalue = null) - { - return SetOrGet("countrycode", Setvalue, ""); - } - - public static string Userid(string Setvalue = null) - { - return SetOrGet("userid", Setvalue, ""); - } - - public static bool Remember(string Setvalue = null) - { - string sRet = SetOrGet("remember", Setvalue, "true"); - if (sRet.IsNotBlank() && sRet.ToLower() == "true") - return true; - return false; - } - - public static bool AutoLogin(string Setvalue = null) - { - string sRet = SetOrGet("autologin", Setvalue, "true"); - if (sRet.IsNotBlank() && sRet.ToLower() == "true") - return true; - return false; - } - - public static string Resolution(string Setvalue = null) - { - return SetOrGet("resolution", Setvalue, "e720P"); - } - #endregion - - #region History Account - /// - /// Get History Account List - /// - public static List HistoryAccounts() - { - List pRet = new List(); - string sValue = SetOrGet("historyusernum", null, "", HISTORYGROUP); - int iNum = AIGS.Common.Convert.ConverStringToInt(sValue, 0); - for (int i = 0; i < iNum; i++) - { - string sUser = SetOrGet("historyuser" + i, null, "", HISTORYGROUP); - string sPwd = SetOrGet("historypwd" + i, null, "", HISTORYGROUP); - if (sUser.IsNotBlank() && pRet.FindIndex((Property user) => user.Key.ToString() == sUser) < 0) - pRet.Add(new Property(sUser, sPwd)); - } - return pRet; - } - - /// - /// Add Account To Config File - /// - public static void AddHistoryAccount(string sUsername, string sPassword) - { - List pArray = HistoryAccounts(); - int iIndex = pArray.FindIndex((Property user) => user.Key.ToString() == sUsername); - if (iIndex >= 0) - pArray.RemoveAt(iIndex); - - pArray.Insert(0, new Property(sUsername, sPassword)); - for (int i = 0; i < pArray.Count; i++) - { - SetOrGet("historyuser" + i, pArray[i].Key.ToString(), "", HISTORYGROUP); - SetOrGet("historypwd" + i, pArray[i].Value.ToString(), "", HISTORYGROUP); - } - SetOrGet("historyusernum", pArray.Count.ToString(), "", HISTORYGROUP); - Username(sUsername); - Password(sPassword); - } - #endregion - - #region History Search - /// - /// Get History Search List - /// - public static ObservableCollection HistorySearchs() - { - ObservableCollection pRet = new ObservableCollection(); - string sValue = SetOrGet("historysearchnum", null, "", HISTORYGROUP); - int iNum = AIGS.Common.Convert.ConverStringToInt(sValue, 0); - for (int i = 0; i < iNum; i++) - { - string sStr = SetOrGet("historysearch" + i, null, "", HISTORYGROUP); - if (sStr.IsNotBlank() && pRet.IndexOf(sStr) < 0) - pRet.Add(sStr); - } - return pRet; - } - /// - /// Add Search To Config File - /// - public static void AddHistorySearch(string sNewStr) - { - ObservableCollection pArray = HistorySearchs(); - int iIndex = pArray.IndexOf(sNewStr); - if (iIndex >= 0) - pArray.RemoveAt(iIndex); - - pArray.Insert(0, sNewStr); - for (int i = 0; i < pArray.Count; i++) - SetOrGet("historysearch" + i, pArray[i], "", HISTORYGROUP); - SetOrGet("historysearchnum", pArray.Count.ToString(), "", HISTORYGROUP); - } - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AIGS.Common; +using AIGS.Helper; +using System.Collections.ObjectModel; + +namespace TIDALDL_UI.Else +{ + public class Config + { + private static string CONFIGPATH = "./tidal-dl.ini"; + private static string BASEGROUP = "base"; + private static string HISTORYGROUP = "history"; + + private static string SetOrGet(string Key, string SetValue = null, string GetDefault = "", string Group = null) + { + if (Group.IsBlank()) + Group = BASEGROUP; + if (SetValue.IsBlank()) + return ConfigHelper.GetValue(Key, GetDefault, Group, CONFIGPATH); + else + ConfigHelper.SetValue(Key, SetValue, Group, CONFIGPATH); + return null; + } + + + #region Base Config + public static string OutputDir(string Setvalue = null) + { + return SetOrGet("outputdir", Setvalue, "./"); + } + + public static bool OnlyM4a(string Setvalue = null) + { + string sValue = SetOrGet("onlym4a", Setvalue, "./"); + if (sValue == null || sValue.ToLower() != "true") + return false; + return true; + } + + public static string Quality(string Setvalue = null) + { + return SetOrGet("quality", Setvalue, "HIGH"); + } + + public static Dictionary QualityList() + { + return AIGS.Common.Convert.ConverEnumToDictionary(typeof(Tidal.eSoundQuality)); + } + + public static int QualityIndex() + { + string sValue = Config.Quality(); + Dictionary pList = QualityList(); + for (int i = 0; i < pList.Count; i++) + { + if (sValue.ToUpper() == pList.ElementAt(i).Value) + return i; + } + return 0; + } + + public static string ThreadNum(string Setvalue = null) + { + return SetOrGet("threadnum", Setvalue, "1"); + } + + public static string Username(string Setvalue = null) + { + return SetOrGet("username", Setvalue, ""); + } + + public static string Password(string Setvalue = null) + { + return SetOrGet("password", Setvalue, ""); + } + + public static string Sessionid(string Setvalue = null) + { + return SetOrGet("sessionid", Setvalue, ""); + } + + public static string Countrycode(string Setvalue = null) + { + return SetOrGet("countrycode", Setvalue, ""); + } + + public static string Userid(string Setvalue = null) + { + return SetOrGet("userid", Setvalue, ""); + } + + public static bool Remember(string Setvalue = null) + { + string sRet = SetOrGet("remember", Setvalue, "true"); + if (sRet.IsNotBlank() && sRet.ToLower() == "true") + return true; + return false; + } + + public static bool AutoLogin(string Setvalue = null) + { + string sRet = SetOrGet("autologin", Setvalue, "true"); + if (sRet.IsNotBlank() && sRet.ToLower() == "true") + return true; + return false; + } + + public static string Resolution(string Setvalue = null) + { + return SetOrGet("resolution", Setvalue, "e720P"); + } + #endregion + + #region History Account + /// + /// Get History Account List + /// + public static List HistoryAccounts() + { + List pRet = new List(); + string sValue = SetOrGet("historyusernum", null, "", HISTORYGROUP); + int iNum = AIGS.Common.Convert.ConverStringToInt(sValue, 0); + for (int i = 0; i < iNum; i++) + { + string sUser = SetOrGet("historyuser" + i, null, "", HISTORYGROUP); + string sPwd = SetOrGet("historypwd" + i, null, "", HISTORYGROUP); + if (sUser.IsNotBlank() && pRet.FindIndex((Property user) => user.Key.ToString() == sUser) < 0) + pRet.Add(new Property(sUser, sPwd)); + } + return pRet; + } + + /// + /// Add Account To Config File + /// + public static void AddHistoryAccount(string sUsername, string sPassword) + { + List pArray = HistoryAccounts(); + int iIndex = pArray.FindIndex((Property user) => user.Key.ToString() == sUsername); + if (iIndex >= 0) + pArray.RemoveAt(iIndex); + + pArray.Insert(0, new Property(sUsername, sPassword)); + for (int i = 0; i < pArray.Count; i++) + { + SetOrGet("historyuser" + i, pArray[i].Key.ToString(), "", HISTORYGROUP); + SetOrGet("historypwd" + i, pArray[i].Value.ToString(), "", HISTORYGROUP); + } + SetOrGet("historyusernum", pArray.Count.ToString(), "", HISTORYGROUP); + Username(sUsername); + Password(sPassword); + } + #endregion + + #region History Search + /// + /// Get History Search List + /// + public static ObservableCollection HistorySearchs() + { + ObservableCollection pRet = new ObservableCollection(); + string sValue = SetOrGet("historysearchnum", null, "", HISTORYGROUP); + int iNum = AIGS.Common.Convert.ConverStringToInt(sValue, 0); + for (int i = 0; i < iNum; i++) + { + string sStr = SetOrGet("historysearch" + i, null, "", HISTORYGROUP); + if (sStr.IsNotBlank() && pRet.IndexOf(sStr) < 0) + pRet.Add(sStr); + } + return pRet; + } + /// + /// Add Search To Config File + /// + public static void AddHistorySearch(string sNewStr) + { + ObservableCollection pArray = HistorySearchs(); + int iIndex = pArray.IndexOf(sNewStr); + if (iIndex >= 0) + pArray.RemoveAt(iIndex); + + pArray.Insert(0, sNewStr); + for (int i = 0; i < pArray.Count; i++) + SetOrGet("historysearch" + i, pArray[i], "", HISTORYGROUP); + SetOrGet("historysearchnum", pArray.Count.ToString(), "", HISTORYGROUP); + } + #endregion + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Else/DownloadItem.cs b/TIDALDL-UI/TIDALDL-UI/Else/DownloadItem.cs index 2fcc58f0..63fc06d7 100644 --- a/TIDALDL-UI/TIDALDL-UI/Else/DownloadItem.cs +++ b/TIDALDL-UI/TIDALDL-UI/Else/DownloadItem.cs @@ -1,290 +1,226 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tidal; -using AIGS.Common; -using AIGS.Helper; -using Stylet; -using TagLib; -using System.IO; - -namespace TIDALDL_UI.Else -{ - public class DownloadItem:Screen - { - /// - /// Item Object - Track | Videp - /// - public Album TidalAlbum { get; set; } - public Track TidalTrack { get; set; } - public Video TidalVideo { get; set; } - public StreamUrl TidalStream { get; set; } - public string[] TidalVideoUrls { get; set; } - - /// - /// Item Para - BasePath | FilePath | Track Quality | Title | Duration | Type - /// - public string BasePath { get; set; } - public string FilePath { get; set; } - public string Quality { get; set; } - public string Resolution { get; set; } - public int Index { get; set; } - public string Title { get; set; } - public string Duration { get; set; } - public string sType { get; set; } - public byte[] Cover { get; set; } - public string CoverPath { get; set; } - - /// - /// Errmsg - /// - public string Errlabel { get; set; } - - ///// - ///// Progress - ///// - public ProgressHelper Progress { get; set; } - - /// - /// SendMessage To Parent - /// - public delegate void UpdateNotify(DownloadItem item); - public UpdateNotify UpdataFunc { get; set; } - - public DownloadItem(int index, string basePath, UpdateNotify Func, Track track = null, string quality = "LOW", Video video = null, string resolution = "720", byte[] cover = null, string coverPath = null, Album album = null) - { - TidalAlbum = album; - TidalVideo = video; - TidalTrack = track; - Quality = quality; - Resolution = resolution; - BasePath = basePath; - Index = index; - Errlabel = ""; - Progress = new ProgressHelper(); - UpdataFunc = Func; - Cover = cover; - CoverPath = coverPath; - - if (TidalTrack != null) - { - Title = track.Title; - Duration = track.SDuration; - sType = "Track"; - } - else - { - Title = video.Title; - Duration = video.SDuration; - sType = "Video"; - } - } - - /// - /// Prepare Before Download - /// - private string Prepare() - { - string Errmsg; - if (sType == "Track") - { - TidalStream = Tool.GetStreamUrl(TidalTrack.ID, Quality, out Errmsg); - if (Errmsg.IsNotBlank()) - return Errmsg; - FilePath = BasePath + '\\' + Tool.GetTrackFileName(TidalTrack, TidalStream); - } - if(sType == "Video") - { - TidalVideoUrls = Tool.GetVideoDLUrls(TidalVideo.ID, Resolution, out Errmsg); - if (Errmsg.IsNotBlank()) - return Errmsg; - else if (TidalVideoUrls == null) - return "Get DownloadUrl Err!"; - FilePath = BasePath + '\\' + Tool.GetVideoFileName(TidalVideo); - } - return null; - } - - #region Method - public void Cancel() - { - Progress.IsCanceled = true; - } - - public void Start() - { - if (ThreadTool.GetThreadNum() <= 0) - ThreadTool.SetThreadNum(int.Parse(Config.ThreadNum())); - ThreadTool.AddWork(ThreadFuncDownload); - } - - public bool MergerTsFiles(string sPath, string sToFile) - { - try - { - string[] sFileNames = PathHelper.GetFileNames(sPath); - List sList = new List(); - foreach (string item in sFileNames) - { - if (item.IndexOf(".ts") < 0) - continue; - sList.Add(item); - } - - return FFmpegHelper.MergerByFiles(sList.ToArray(), sToFile); - } - catch - { - return false; - } - } - #endregion - - - #region Thread - public void ThreadFuncDownload(object data) - { - if (Progress.IsCanceled) - return; - - //Prepare - Errlabel = Prepare(); - if (Errlabel.IsNotBlank()) - { - Progress.Errlabel = Errlabel; - Progress.IsErr = true; - UpdataFunc(this); - return; - } - - if (sType == "Track") - DownloadTrack(); - if (sType == "Video") - DownloadVideo(); - - - } - - public void DownloadVideo() - { - string sTmpDir = BasePath + '\\' + PathHelper.ReplaceLimitChar(TidalVideo.Title, "-") + "TMP" + RandHelper.GetIntRandom(5, 9, 0); - try - { - if (Directory.Exists(sTmpDir)) - Directory.Delete(sTmpDir, true); - PathHelper.Mkdirs(sTmpDir); - - long lCount = TidalVideoUrls.Count(); - for (int i = 0; i < lCount; i++) - { - string sUrl = TidalVideoUrls[i]; - string sName = sTmpDir + '\\' + (100000 + i + 1).ToString() + ".ts"; - bool bFlag = (bool)DownloadFileHepler.Start(sUrl, sName, Timeout:9999*1000); - if (bFlag == false) - { - Progress.Errlabel = "Download failed!"; - goto ERR_POINT; - } - - Progress.Update(i + 1, lCount); - if (Progress.IsCanceled) - goto CANCEL_POINT; - } - if (!MergerTsFiles(sTmpDir + '\\', FilePath)) - { - Progress.Errlabel = "FFmpeg merger err!"; - goto ERR_POINT; - } - - Progress.Update(lCount, lCount); - Progress.IsComplete = true; - UpdataFunc(this); - - CANCEL_POINT: - if (Directory.Exists(sTmpDir)) - Directory.Delete(sTmpDir, true); - return; - } - catch(Exception e) - { - Progress.Errlabel = "Err!" + e.Message; - } - - ERR_POINT: - Progress.IsErr = true; - UpdataFunc(this); - if (Directory.Exists(sTmpDir)) - Directory.Delete(sTmpDir, true); - } - - public void DownloadTrack() - { - // Check if the track was existing - if (System.IO.File.Exists(FilePath)) - { - Errlabel = "Existing"; - goto UPDATE_RETURN; - } - - - //Download - bool bFlag = (bool)DownloadFileHepler.Start(TidalStream.Url, - FilePath, - RetryNum: 3, - Timeout: 99999 * 1000, - UpdateFunc: UpdateDownloadNotify, - CompleteFunc: CompleteDownloadNotify, - ErrFunc: ErrDownloadNotify); - //Err - if (!bFlag) - { - Errlabel = "Download failed!"; - Progress.IsErr = true; - goto UPDATE_RETURN; - } - - if(!Tool.DecryptTrackFile(TidalStream, FilePath)) - { - Errlabel = "Decrypt Failed!"; - Progress.IsErr = true; - goto UPDATE_RETURN; - } - - string sLabel = Tool.SetMetaData(FilePath, TidalAlbum, TidalTrack, CoverPath); - if(sLabel.IsNotBlank()) - { - Errlabel = "SetMetaData Failed! " + sLabel; - Progress.IsErr = true; - goto UPDATE_RETURN; - } - - UPDATE_RETURN: - if(!Progress.IsErr) - Progress.IsComplete = true; - - Progress.Errlabel = Errlabel; - UpdataFunc(this); - } - - public bool UpdateDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, long lIncreSize, object data) - { - Progress.Update(lAlreadyDownloadSize, lTotalSize); - if (Progress.IsCanceled) - return false; - return true; - } - - public void CompleteDownloadNotify(long lTotalSize, object data) - { - Progress.Update(lTotalSize, lTotalSize); - } - - public void ErrDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, string sErrMsg, object data) - { - Progress.IsErr = true; - } - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tidal; +using AIGS.Common; +using AIGS.Helper; +using Stylet; +using TagLib; +using System.IO; + +namespace TIDALDL_UI.Else +{ + public class DownloadItem : Screen + { + public Album TidalAlbum { get; set; } + public Track TidalTrack { get; set; } + public Video TidalVideo { get; set; } + + /// + /// Item Para - OutputDir | FilePath | Track Quality | Title | Type + /// + public string OutputDir { get; set; } + public string FilePath { get; set; } + public eSoundQuality Quality { get; set; } + public eResolution Resolution { get; set; } + public int Index { get; set; } + public string Title { get; set; } + public string sType { get; set; } + public int ErrlabelHeight { get; set; } + public bool OnlyM4a { get; set; } + public string Own { get; set; } + + ///// + ///// Progress + ///// + public ProgressHelper Progress { get; set; } + + public DownloadItem(int index, Track track = null, Video video = null, Album album = null) + { + TidalAlbum = album; + TidalVideo = video; + TidalTrack = track; + Quality = TidalTool.getQuality(Config.Quality()); + Resolution = TidalTool.getResolution(Config.Resolution()); + OutputDir = Config.OutputDir(); + Index = index; + Progress = new ProgressHelper(); + OnlyM4a = Config.OnlyM4a(); + Own = album == null?null : album.Title; + + if (TidalTrack != null) + { + Title = track.Title; + sType = "MusicCircle"; + } + else + { + Title = video.Title; + sType = "PlayCircle"; + } + } + + + #region Method + public void Start() + { + ThreadTool.AddWork((object[] data) => + { + if (Progress.GetStatus() != ProgressHelper.STATUS.WAIT) + return; + + ErrlabelHeight = 0; + Progress.SetStatus(ProgressHelper.STATUS.RUNNING); + if (TidalTrack != null) + DownloadTrack(); + else + DownloadVideo(); + }); + } + + public void Cancel() + { + if (Progress.GetStatus() != ProgressHelper.STATUS.COMPLETE) + Progress.SetStatus(ProgressHelper.STATUS.CANCLE); + } + + public void Restart() + { + ProgressHelper.STATUS status = Progress.GetStatus(); + if (status == ProgressHelper.STATUS.CANCLE || status == ProgressHelper.STATUS.ERROR) + { + Progress.Clear(); + Start(); + } + } + #endregion + + + #region DownloadVideo + public bool ProgressNotify(long lCurSize, long lAllSize) + { + Progress.Update(lCurSize, lAllSize); + if (Progress.GetStatus() != ProgressHelper.STATUS.RUNNING) + return false; + return true; + } + + public void DownloadVideo() + { + //GetStream + Progress.StatusMsg = "GetStream..."; + string Errlabel = ""; + string[] TidalVideoUrls = TidalTool.getVideoDLUrls(TidalVideo.ID.ToString(), Resolution, out Errlabel); + if (Errlabel.IsNotBlank()) + goto ERR_RETURN; + string TsFilePath = TidalTool.getVideoPath(OutputDir, TidalVideo, TidalAlbum, ".ts"); + + //Download + Progress.StatusMsg = "Start..."; + if(!(bool)M3u8Helper.Download(TidalVideoUrls, TsFilePath, ProgressNotify)) + { + Errlabel = "Download failed!"; + goto ERR_RETURN; + } + + //Convert + FilePath = TidalTool.getVideoPath(OutputDir, TidalVideo, TidalAlbum); + if(!FFmpegHelper.IsExist()) + { + Errlabel = "FFmpeg is not exist!"; + goto ERR_RETURN; + } + if (!FFmpegHelper.Convert(TsFilePath, FilePath)) + { + Errlabel = "Convert failed!"; + goto ERR_RETURN; + } + System.IO.File.Delete(TsFilePath); + Progress.SetStatus(ProgressHelper.STATUS.COMPLETE); + return; + + ERR_RETURN: + if (Progress.GetStatus() == ProgressHelper.STATUS.CANCLE) + return; + + ErrlabelHeight = 15; + Progress.SetStatus(ProgressHelper.STATUS.ERROR); + Progress.Errmsg = Errlabel; + } + #endregion + + #region DownloadTrack + public void DownloadTrack() + { + //GetStream + Progress.StatusMsg = "GetStream..."; + string Errlabel = ""; + StreamUrl TidalStream = TidalTool.getStreamUrl(TidalTrack.ID.ToString(), Quality, out Errlabel); + if (Errlabel.IsNotBlank()) + goto ERR_RETURN; + FilePath = TidalTool.getAlbumTrackPath(OutputDir, TidalAlbum, TidalTrack, TidalStream.Url); + + //Download + Progress.StatusMsg = "Start..."; + for (int i = 0; i < 100 && Progress.GetStatus() != ProgressHelper.STATUS.CANCLE; i++) + { + if ((bool)DownloadFileHepler.Start(TidalStream.Url, FilePath, Timeout: 5 * 1000, UpdateFunc: UpdateDownloadNotify, ErrFunc: ErrDownloadNotify)) + { + //Decrypt + if (!TidalTool.DecryptTrackFile(TidalStream, FilePath)) + { + Errlabel = "Decrypt failed!"; + goto ERR_RETURN; + } + + if(OnlyM4a) + { + string sNewName; + if (!TidalTool.ConvertMp4ToM4a(FilePath, out sNewName)) + { + Errlabel = "Convert mp4 to m4a failed!"; + ErrlabelHeight = 15; + } + else + FilePath = sNewName; + } + + //SetMetaData + string sLabel = TidalTool.SetMetaData(FilePath, TidalAlbum, TidalTrack, TidalTool.getAlbumCoverPath(OutputDir, TidalAlbum)); + if (sLabel.IsNotBlank()) + { + Errlabel = "Set metadata failed!"; + goto ERR_RETURN; + } + Progress.SetStatus(ProgressHelper.STATUS.COMPLETE); + return; + } + } + Errlabel = "Download failed!"; + + ERR_RETURN: + if (Progress.GetStatus() == ProgressHelper.STATUS.CANCLE) + return; + + ErrlabelHeight = 15; + Progress.SetStatus(ProgressHelper.STATUS.ERROR); + Progress.Errmsg = Errlabel; + } + + public void ErrDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, string sErrMsg, object data) + { + return; + } + + public bool UpdateDownloadNotify(long lTotalSize, long lAlreadyDownloadSize, long lIncreSize, object data) + { + Progress.Update(lAlreadyDownloadSize, lTotalSize); + if (Progress.GetStatus() != ProgressHelper.STATUS.RUNNING) + return false; + return true; + } + #endregion + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Else/ProgressHelper.cs b/TIDALDL-UI/TIDALDL-UI/Else/ProgressHelper.cs deleted file mode 100644 index bb19611a..00000000 --- a/TIDALDL-UI/TIDALDL-UI/Else/ProgressHelper.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Stylet; -using System.Windows.Media; -using AIGS.Common; - -namespace TIDALDL_UI.Else -{ - public class ProgressHelper:Screen - { - /// - /// Progress Bar - /// - public string ProgressPercent { get; private set; } - public int ProgressMaxValue { get; private set; } - public int ProgressCurValue { get; private set; } - - public long AllSize { get; set; } - public long CurSize { get; set; } - public long ErrSize { get; set; } - - /// - /// Flag - /// - public bool IsComplete { get; set; } - public bool IsCanceled { get; set; } - public bool IsErr { get; set; } - public bool IsSomeErr { get; set; } - public string Errlabel { get; set; } - public int HeightOfErrlable - { - get { if (Errlabel.IsBlank()) return 0;return 18; } - set { } - } - - /// - /// Status - /// - public System.Windows.Media.SolidColorBrush StatusColor { get; set; } = System.Windows.Media.Brushes.White; - public string Status - { - get { - if (IsComplete) - { - StatusColor = System.Windows.Media.Brushes.Green; - return "[COMPLETE]"; - } - if (IsErr) - { - StatusColor = System.Windows.Media.Brushes.DarkRed; - return "[ERR]"; - } - if(IsSomeErr) - { - StatusColor = System.Windows.Media.Brushes.DarkRed; - return "[SOME-ERR]"; - } - if (IsCanceled) - { - StatusColor = System.Windows.Media.Brushes.DarkRed; - return "[CANCEL]"; - } - StatusColor = System.Windows.Media.Brushes.Black; - return ProgressPercent; - } - } - - public ProgressHelper() - { - ProgressMaxValue = 100; - ProgressCurValue = 0; - ProgressPercent = "0%"; - - IsComplete = false; - IsCanceled = false; - IsErr = false; - } - - public void Update(long lCurSize, long lAllSize) - { - try - { - this.AllSize = lAllSize; - this.CurSize = lCurSize; - - this.ProgressCurValue = (int)(lCurSize * this.ProgressMaxValue / lAllSize); - this.ProgressPercent = this.ProgressCurValue.ToString() + "%"; - } - catch { } - } - - public void UpdateErr(long lErrSize, long lAllSize) - { - try - { - this.AllSize = lAllSize; - this.ErrSize = lErrSize; - } - catch { } - } - } -} diff --git a/TIDALDL-UI/TIDALDL-UI/Else/ThreadTool.cs b/TIDALDL-UI/TIDALDL-UI/Else/ThreadTool.cs index e9c57f7a..51649a74 100644 --- a/TIDALDL-UI/TIDALDL-UI/Else/ThreadTool.cs +++ b/TIDALDL-UI/TIDALDL-UI/Else/ThreadTool.cs @@ -1,52 +1,49 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using AIGS.Helper; -using AIGS.Common; -using System.Threading; - -namespace TIDALDL_UI.Else -{ - public class ThreadTool - { - private static ThreadPoolManager Pool = null; - - public static void SetThreadNum(int iNum) - { - if (Pool == null) - Pool = new ThreadPoolManager(iNum); - else - Pool.SetPoolSize(iNum); - } - - public static int GetThreadNum() - { - if (Pool == null) - return 0; - return Pool.GetPoolSize(); - } - - /// - /// Add Download - /// - public static bool AddWork(ThreadPoolManager.EventFunc Func, object[] data=null) - { - if (Pool == null) - return false; - Pool.AddWork(Func, data); - return true; - } - - /// - /// End - /// - public static void Close() - { - if (Pool == null) - return; - Pool.CloseAll(true); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AIGS.Helper; +using AIGS.Common; +using System.Threading; + +namespace TIDALDL_UI.Else +{ + public class ThreadTool + { + private static ThreadPoolManager Pool = new ThreadPoolManager(1); + + public static void SetThreadNum(int iNum) + { + Pool.SetPoolSize(iNum); + } + + public static int GetThreadNum() + { + if (Pool == null) + return 0; + return Pool.GetPoolSize(); + } + + /// + /// Add Download + /// + public static bool AddWork(ThreadPoolManager.EventFunc Func, object[] data=null) + { + if (Pool == null) + return false; + Pool.AddWork(Func, data); + return true; + } + + /// + /// End + /// + public static void Close() + { + if (Pool == null) + return; + Pool.CloseAll(true); + } + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xml b/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xml index 7a4a9ab8..d6e79d28 100644 --- a/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xml +++ b/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xml @@ -1,10 +1,10 @@ - - - - - - Foo - Bar - - - + + + + + + Foo + Bar + + + diff --git a/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xsd b/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xsd index 112d3631..2ba96e6c 100644 --- a/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xsd +++ b/TIDALDL-UI/TIDALDL-UI/FodyWeavers.xsd @@ -1,140 +1,140 @@ - - - - - - - - - - - Used to control if the On_PropertyName_Changed feature is enabled. - - - - - Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. - - - - - Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. - - - - - Used to control if equality checks should use the Equals method resolved from the base class. - - - - - Used to control if equality checks should use the static Equals method resolved from the base class. - - - - - - - - - - A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks - - - - - A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. - - - - - A list of unmanaged 32 bit assembly names to include, delimited with line breaks. - - - - - A list of unmanaged 64 bit assembly names to include, delimited with line breaks. - - - - - The order of preloaded assemblies, delimited with line breaks. - - - - - - This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. - - - - - Controls if .pdbs for reference assemblies are also embedded. - - - - - Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. - - - - - As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. - - - - - Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. - - - - - Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. - - - - - A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | - - - - - A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. - - - - - A list of unmanaged 32 bit assembly names to include, delimited with |. - - - - - A list of unmanaged 64 bit assembly names to include, delimited with |. - - - - - The order of preloaded assemblies, delimited with |. - - - - - - - - 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. - - - - - A comma-separated list of error codes that can be safely ignored in assembly verification. - - - - - 'false' to turn off automatic generation of the XML Schema file. - - - - + + + + + + + + + + + Used to control if the On_PropertyName_Changed feature is enabled. + + + + + Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. + + + + + Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project. + + + + + Used to control if equality checks should use the Equals method resolved from the base class. + + + + + Used to control if equality checks should use the static Equals method resolved from the base class. + + + + + + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with line breaks. + + + + + The order of preloaded assemblies, delimited with line breaks. + + + + + + This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. + + + + + Controls if .pdbs for reference assemblies are also embedded. + + + + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. + + + + + As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. + + + + + Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. + + + + + Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with |. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with |. + + + + + The order of preloaded assemblies, delimited with |. + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + \ No newline at end of file diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml b/TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml index 29d08c85..ca60e2b6 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml +++ b/TIDALDL-UI/TIDALDL-UI/Pages/AboutView.xaml @@ -1,46 +1,46 @@ - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemView.xaml.cs b/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemView.xaml.cs index 31d25b33..7a242d00 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemView.xaml.cs +++ b/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemView.xaml.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace TIDALDL_UI.Pages -{ - /// - /// MainListItemView.xaml 的交互逻辑 - /// - public partial class MainListItemView : UserControl - { - public MainListItemView() - { - InitializeComponent(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace TIDALDL_UI.Pages +{ + /// + /// MainListItemView.xaml 的交互逻辑 + /// + public partial class MainListItemView : UserControl + { + public MainListItemView() + { + InitializeComponent(); + } + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemViewModel.cs b/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemViewModel.cs index 32054e01..b5bec727 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemViewModel.cs +++ b/TIDALDL-UI/TIDALDL-UI/Pages/MainListItemViewModel.cs @@ -1,164 +1,119 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using AIGS.Helper; -using AIGS.Common; -using Stylet; -using System.Windows.Media.Imaging; -using Tidal; -using System.Diagnostics; -using TIDALDL_UI.Else; -using System.Collections.ObjectModel; -using System.Windows; -using System.IO; - -namespace TIDALDL_UI.Pages -{ - public class MainListItemViewModel : Screen - { - /// - /// Item Name | Type(Album\Track\Video\Playlist) | Cover | SvaePath | Quality - /// - public string Title { get; private set; } - public string Type { get; private set; } - public string Author { get; set; } - public BitmapImage Cover { get; private set; } - public string BasePath { get; private set; } - public string Quality { get; private set; } - public string CoverPath { get; private set; } - public Byte[] CoverData { get; private set; } - - /// - /// Item Objec - Album|Playlist|Track|Video - /// - public ArtistAlbumList TidalArtistAlbumList { get; private set; } - public Album TidalAlbum { get; private set; } - public Playlist TidalPlaylist { get; private set; } - public Track TidalTrack { get; private set; } - public Video TidalVideo { get; private set; } - - /// - /// Item DowmloadList - /// - public ObservableCollection DLItemList { get; set; } - - /// - /// Progress - /// - public ProgressHelper Progress { get; set; } - - - public MainListItemViewModel(object data, string path, string quality = "HIGH", string resolution = "720") - { - Progress = new ProgressHelper(); - DLItemList = new ObservableCollection(); - - if(data.GetType() == typeof(ArtistAlbumList)) - { - ArtistAlbumList artistAlbumList = (ArtistAlbumList)data; - TidalArtistAlbumList = artistAlbumList; - Title = String.Format("{0} Total Albums:{1}", artistAlbumList.Artist.Name, artistAlbumList.TotalAlbums); - Type = "Album List"; - Quality = quality; - BasePath = path + "\\Album\\"; - Author = ""; - foreach(Album album in artistAlbumList.Albums) - { - if (album.Tracks != null) - { - String fullBasePath = BasePath + Tool.GetAlbumFolderName(album); - foreach (Track item in album.Tracks) - DLItemList.Add(new DownloadItem(DLItemList.Count, fullBasePath, Update, item, quality, album: album)); - } - } - } - else if (data.GetType() == typeof(Album)) - { - Album album = (Album)data; - TidalAlbum = album; - Title = album.Title; - Type = "Album"; - Quality = quality; - BasePath = path + "\\Album\\" + Tool.GetAlbumFolderName(album); - Author = album.Artist.Name; - CoverPath = BasePath + '\\' + Tool.GetAlbumCoverName(album); - CoverData = album.CoverData; - - //init DownloadList - if(album.Tracks != null) - foreach (Track item in album.Tracks) - DLItemList.Add(new DownloadItem(DLItemList.Count, BasePath, Update, item, quality, cover:CoverData, coverPath: CoverPath, album:album)); - if(album.Videos != null) - foreach (Video item in album.Videos) - DLItemList.Add(new DownloadItem(DLItemList.Count, BasePath, Update, null, null, item, resolution, album: album)); - } - else if(data.GetType() == typeof(Video)) - { - Video video = (Video)data; - TidalVideo = video; - Title = video.Title; - Type = "Video"; - BasePath = path + "\\Video\\"; - Author = video.Artist.Name; - CoverPath = BasePath + '\\' + Tool.GetVideoCoverName(video); - CoverData = video.CoverData; - DLItemList.Add(new DownloadItem(DLItemList.Count, BasePath, Update, null, null, video, resolution)); - } - - //Save Cover - Cover = AIGS.Common.Convert.ConverByteArrayToBitmapImage(CoverData); - FileHelper.Write(CoverData, true, CoverPath); - } - - /// - /// Update Progress - /// - /// - public void Update(DownloadItem item) - { - if (item.Progress.IsErr) - this.Progress.UpdateErr(this.Progress.ErrSize + 1, DLItemList.Count); - else if (item.Progress.IsComplete) - this.Progress.Update(this.Progress.CurSize + 1, DLItemList.Count); - - if (this.Progress.ErrSize >= DLItemList.Count) - this.Progress.IsErr = true; - else if (this.Progress.CurSize >= DLItemList.Count) - this.Progress.IsComplete = true; - else if (this.Progress.CurSize + this.Progress.ErrSize >= DLItemList.Count) - this.Progress.IsSomeErr = true; - } - - /// - /// Start All Download List Items - /// - public void StartWork() - { - foreach (DownloadItem item in DLItemList) - item.Start(); - } - - #region Button - /// - /// Cancel Work - /// - public void Cancel() - { - foreach (DownloadItem item in DLItemList) - item.Cancel(); - this.Progress.IsCanceled = true; - } - - /// - /// Open BasePath - /// - public void OpenBasePath() - { - Process.Start(BasePath); - } - #endregion - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AIGS.Helper; +using AIGS.Common; +using Stylet; +using System.Windows.Media.Imaging; +using Tidal; +using System.Diagnostics; +using TIDALDL_UI.Else; +using System.Collections.ObjectModel; +using System.Windows; +using System.IO; + +namespace TIDALDL_UI.Pages +{ + public class MainListItemViewModel : Screen + { + public string Title { get; private set; } + public string Desc { get; set; } + public BitmapImage Cover { get; private set; } + public string BasePath { get; private set; } + public ObservableCollection DLItemList { get; set; } + private BindableCollection Parents { get; set; } + + public string ButtonKind { get; set; } = "CloseCircle"; + public string ButtonTip { get; set; } = "Cancel"; + + public MainListItemViewModel(object data, BindableCollection parents) + { + Parents = parents; + DLItemList = new ObservableCollection(); + if (data.GetType() == typeof(Album)) + { + Album album = (Album)data; + Title = album.Title; + BasePath = TidalTool.getAlbumFolder(Config.OutputDir(), album); + Desc = string.Format("by {0}-{1} Tracks-{2} Videos-{3}", album.Artist.Name, TimeHelper.ConverIntToString(album.Duration), album.NumberOfTracks, album.NumberOfVideos); + Cover = AIGS.Common.Convert.ConverByteArrayToBitmapImage(album.CoverData); + + AddAlbum(album); + } + else if (data.GetType() == typeof(Video)) + { + Video video = (Video)data; + Title = video.Title; + BasePath = TidalTool.getVideoFolder(Config.OutputDir()); + Desc = string.Format("by {0}-{1}", video.Artist.Name, TimeHelper.ConverIntToString(video.Duration)); + Cover = AIGS.Common.Convert.ConverByteArrayToBitmapImage(video.CoverData); + DLItemList.Add(new DownloadItem(DLItemList.Count + 1, null, video, null)); + } + else if(data.GetType() == typeof(Artist)) + { + Artist artist = (Artist)data; + Title = artist.Name; + BasePath = TidalTool.getArtistFolder(Config.OutputDir(), artist); + Desc = string.Format("by {0} Albums-{1}", artist.Name, artist.Albums.Count); + Cover = AIGS.Common.Convert.ConverByteArrayToBitmapImage(artist.CoverData); + + foreach (var item in artist.Albums) + AddAlbum(item); + } + + PathHelper.Mkdirs(BasePath); + } + + private void AddAlbum(Album album) + { + string CoverPath = TidalTool.getAlbumCoverPath(Config.OutputDir(), album); + FileHelper.Write(album.CoverData, true, CoverPath); + + foreach (Track item in album.Tracks) + DLItemList.Add(new DownloadItem(DLItemList.Count +1, item, null, album: album)); + foreach (Video item in album.Videos) + DLItemList.Add(new DownloadItem(DLItemList.Count + 1, null, item, album: album)); + } + + public void StartWork() + { + foreach (DownloadItem item in DLItemList) + item.Start(); + } + + #region Button + public void CancelAndRestart() + { + if (ButtonKind == "CloseCircle") + { + foreach (DownloadItem item in DLItemList) + item.Cancel(); + ButtonKind = "Restart"; + ButtonTip = "Restart"; + } + else + { + foreach (DownloadItem item in DLItemList) + item.Restart(); + ButtonKind = "CloseCircle"; + ButtonTip = "Cancel"; + } + } + + public void Delete() + { + foreach (DownloadItem item in DLItemList) + item.Cancel(); + Parents.Remove(this); + } + + public void OpenBasePath() + { + Process.Start(BasePath); + } + #endregion + + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml b/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml index aff70446..e767b0e1 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml +++ b/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml @@ -1,89 +1,91 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml.cs b/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml.cs index 1c2b0d25..c568ea31 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml.cs +++ b/TIDALDL-UI/TIDALDL-UI/Pages/MainView.xaml.cs @@ -1,32 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace TIDALDL_UI.Pages -{ - /// - /// MainView.xaml 的交互逻辑 - /// - public partial class MainView - { - public MainView() - { - InitializeComponent(); - } - - private void ColorZone_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - DragMove(); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace TIDALDL_UI.Pages +{ + /// + /// MainView.xaml 的交互逻辑 + /// + public partial class MainView + { + public MainView() + { + InitializeComponent(); + } + + private void ColorZone_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + DragMove(); + } + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/MainViewModel.cs b/TIDALDL-UI/TIDALDL-UI/Pages/MainViewModel.cs index c6ee1068..a4240547 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/MainViewModel.cs +++ b/TIDALDL-UI/TIDALDL-UI/Pages/MainViewModel.cs @@ -1,303 +1,205 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Stylet; -using AIGS.Common; -using AIGS.Helper; -using Tidal; -using TIDALDL_UI.Else; -using MaterialDesignThemes.Wpf; -using System.Threading; -using System.Windows; -using System.Collections.ObjectModel; -using System.IO; -using ICSharpCode.SharpZipLib.Zip; - -namespace TIDALDL_UI.Pages -{ - public class MainViewModel : Screen - { - /// - /// Errmsg - /// - public string Errlabel { get; set; } = ""; - public bool ShowErrlabel { get; set; } = false; - /// - /// Search Text/List/Thread - /// - public string SearchStr { get; set; } - public int SelectIndex { get; set; } - public ObservableCollection SearchList { get; set; } - private Thread SearchTread; - - /// - /// Download Items - /// - public BindableCollection ItemList { get; } = new BindableCollection(); - - /// - /// Open Window Tool - /// - private IWindowManager Manager; - - /// - /// Update Thread - /// - private Thread UpdateThread; - - /// - /// All Windows - /// - private LoginViewModel VMLogin; - private SettingViewModel VMSetting; - private AboutViewModel VMAbout; - private WaitViewModel VMWait; - private InfoViewModel VMInfo; - private SearchViewModel VMSearch; - - public MainViewModel(IWindowManager manager, - SettingViewModel setting, - AboutViewModel about, - WaitViewModel wait, - InfoViewModel albuminfo, - SearchViewModel search) - { - Manager = manager; - VMSetting = setting; - VMAbout = about; - VMWait = wait; - VMInfo = albuminfo; - VMSearch = search; - SearchList = Config.HistorySearchs(); - SearchStr = SearchList.Count > 0 ? SearchList[0] : null; - - UpdateThread = new Thread(ThreadUpdateFunc); - UpdateThread.IsBackground = true; - UpdateThread.Start(); - return; - } - - public void SetLogViewModel(LoginViewModel model) - { - VMLogin = model; - } - - public void WindowClose() - { - ThreadTool.Close(); - RequestClose(); - } - - public void SelectChange() - { - if (SelectIndex < 0 || SelectIndex >= SearchList.Count) - return; - SearchStr = SearchList[SelectIndex]; - } - - #region Button - /// - /// Search Func - /// - public void Search() - { - Errlabel = ""; - if (SearchStr.IsBlank()) - Errlabel = "Search String is Err!"; - if(SearchTread != null) - Errlabel = "Somethig is in Searching!"; - if (Errlabel.IsNotBlank()) - { - ShowErrlabel = true; - return; - } - - SearchTread = ThreadHelper.Start(ThreadFuncSearch); - ShowWaitView(ThreadSearchClose); - } - - public void Logout() - { - Manager.ShowWindow(VMLogin); - WindowClose(); - } - - /// - /// Show Setting Window - /// - public void Setting() - { - Manager.ShowDialog(VMSetting); - - string sValue = Config.ThreadNum(); - ThreadTool.SetThreadNum(int.Parse(sValue)); - } - - /// - /// Show About Window - /// - public void About() - { - Manager.ShowDialog(VMAbout); - } - - /// - /// FeedBack In Project Page - /// - public void FeedBack() - { - NetHelper.OpenWeb("https://github.com/yaronzz/Tidal-Media-Downloader/issues"); - } - - /// - /// Close Errlabel Box - /// - public void CloseErrlabel() - { - ShowErrlabel = false; - } - #endregion - - #region WaitForm - /// - /// Show Wait Window - /// - public void ShowWaitView(WaitViewModel.CloseFunc Func) - { - VMWait.Init(Func); - Manager.ShowDialog(VMWait); - } - - /// - /// Close Wait Window - /// - public void CloseWaitView() - { - VMWait.Close(); - } - - #endregion - - - - #region Search Thread - /// - /// Login Thread - /// - public void ThreadFuncSearch(object[] data) - { - string sID = SearchStr; - string sType = null; - object oRecord = null; - - oRecord = Tool.TryGet(sID, out sType); - if (Application.Current != null) - { - Application.Current.Dispatcher.BeginInvoke((Action)delegate () - { - if (sType.IsNotBlank()) - { - Config.AddHistorySearch(SearchStr); - SearchList = Config.HistorySearchs(); - if (sType == "Search") - { - VMSearch.Load((SearchResult)oRecord); - Manager.ShowDialog(VMSearch); - sType = VMSearch.ResultType; - oRecord = VMSearch.ResultObject; - } - - if (sType.IsNotBlank() && sType != "Search") - { - oRecord = VMInfo.Load(oRecord); - Manager.ShowDialog(VMInfo); - if (VMInfo.Result) - { - MainListItemViewModel newNode = new MainListItemViewModel(oRecord, VMInfo.OutputDir, VMInfo.QualityList[VMInfo.SelectQualityIndex], Config.Resolution()); - ItemList.Add(newNode); - newNode.StartWork(); - } - } - } - else - { - Errlabel = "Search Err!"; - ShowErrlabel = true; - } - CloseWaitView(); - }); - } - } - - /// - /// Close Login Thread - /// - public void ThreadSearchClose() - { - SearchTread.Abort(); - SearchTread = null; - } - #endregion - - #region Version Update Thread - public void ThreadUpdateFunc() - { - string PATH = Path.GetFullPath("./tidal_new/"); - string VERF = PATH + "version"; - string BATF = PATH + "update.bat"; - string sSelfVer = VersionHelper.GetSelfVersion(); - - //Get Already Download Ver - string sDlVer = FileHelper.Read(VERF); - if(sDlVer.IsNotBlank() && VersionHelper.Compare(sSelfVer, sDlVer) < 0 && File.Exists(PATH + "tidal-gui.exe") && File.Exists(BATF)) - { - MessageBoxResult ret = MessageBox.Show("Update New Version?", "Info", MessageBoxButton.YesNo); - if (ret == MessageBoxResult.No) - return; - - if (Application.Current != null) - { - Application.Current.Dispatcher.BeginInvoke((Action)delegate () - { - CmdHelper.StartExe(BATF, null, IsShowWindow: false); - RequestClose(); - }); - } - return; - } - - //Get Github Last Ver - string sLastVer = githubHelper.getLastReleaseVersion("yaronzz", "Tidal-Media-Downloader"); - if (VersionHelper.Compare(sSelfVer, sLastVer) >= 0) - return; - - if (Directory.Exists(PATH)) - Directory.Delete(PATH, true); - PathHelper.Mkdirs(PATH); - if (githubHelper.getLastReleaseFile("yaronzz", "Tidal-Media-Downloader", "tidal-gui.zip", PATH + "tidal-gui.zip")) - { - FastZip fz = new FastZip(); - try - { - fz.ExtractZip(PATH + "tidal-gui.zip", PATH, null); - if (File.Exists(PATH + "tidal-gui.exe")) - { - string sBat = "ping -n 5 127.0.0.1\n"; - sBat += string.Format("move {0}tidal-gui.exe {0}..\\tidal-gui.exe\n", PATH); - sBat += string.Format("start {0}..\\tidal-gui.exe\n", PATH); - FileHelper.Write(sBat, true, BATF); - FileHelper.Write(sLastVer, true, VERF); - } - } - catch (Exception e) - { - return; - } - } - } - #endregion - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Stylet; +using AIGS.Common; +using AIGS.Helper; +using Tidal; +using TIDALDL_UI.Else; +using MaterialDesignThemes.Wpf; +using System.Threading; +using System.Windows; +using System.Collections.ObjectModel; +using System.IO; +using ICSharpCode.SharpZipLib.Zip; + +namespace TIDALDL_UI.Pages +{ + public class MainViewModel : Screen + { + public string Errlabel { get; set; } + public string SearchStr { get; set; } + public bool InSearch { get; set; } + + /// + /// Download Items + /// + public BindableCollection ItemList { get; } = new BindableCollection(); + + + private IWindowManager Manager; + private LoginViewModel VMLogin; + private SettingViewModel VMSetting; + private AboutViewModel VMAbout; + private InfoViewModel VMInfo; + private SearchViewModel VMSearch; + + public MainViewModel(IWindowManager manager, + SettingViewModel setting, + AboutViewModel about, + InfoViewModel albuminfo, + SearchViewModel search) + { + Manager = manager; + VMSetting = setting; + VMAbout = about; + VMInfo = albuminfo; + VMSearch = search; + ThreadTool.SetThreadNum(int.Parse(Config.ThreadNum())); + + Thread UpdateThread = new Thread(ThreadUpdateFunc); + UpdateThread.IsBackground = true; + UpdateThread.Start(); + return; + } + + public void SetLogViewModel(LoginViewModel model) + { + VMLogin = model; + } + + public void WindowClose() + { + ThreadTool.Close(); + RequestClose(); + } + + + #region Button + public async void Search() + { + if (InSearch) + return; + if (SearchStr.IsBlank()) + { + Errlabel = "Search String is Empty!"; + return; + } + + //Search + InSearch = true; + eObjectType SearchType = eObjectType.None; + object SearchObj = await Task.Run(() => { return TidalTool.tryGet(SearchStr, out SearchType); }); + InSearch = false; + + if (SearchType == eObjectType.None) + { + Errlabel = "Search Err!"; + return; + } + if (SearchType == Tidal.eObjectType.SEARCH) + { + VMSearch.Load((Tidal.SearchResult)SearchObj); + Manager.ShowDialog(VMSearch); + SearchType = VMSearch.ResultType; + SearchObj = VMSearch.ResultObject; + if (SearchType == eObjectType.None) + return; + } + + SearchObj = VMInfo.Load(SearchObj); + Manager.ShowDialog(VMInfo); + if (VMInfo.Result) + { + MainListItemViewModel newNode = new MainListItemViewModel(SearchObj, ItemList); + ItemList.Add(newNode); + newNode.StartWork(); + } + } + + public void Logout() + { + TidalTool.logout(); + Manager.ShowWindow(VMLogin); + WindowClose(); + } + + public void Setting() + { + Manager.ShowDialog(VMSetting); + + string sValue = Config.ThreadNum(); + ThreadTool.SetThreadNum(int.Parse(sValue)); + } + + public void About() + { + Manager.ShowDialog(VMAbout); + } + + public void FeedBack() + { + NetHelper.OpenWeb("https://github.com/yaronzz/Tidal-Media-Downloader/issues"); + } + + public void CloseErrlabel() + { + Errlabel = null; + } + #endregion + + + + + #region Version Update Thread + public void ThreadUpdateFunc() + { + string PATH = Path.GetFullPath("./tidal_new/"); + string VERF = PATH + "version"; + string BATF = PATH + "update.bat"; + string sSelfVer = VersionHelper.GetSelfVersion(); + + //Get Already Download Ver + string sDlVer = FileHelper.Read(VERF); + if (sDlVer.IsNotBlank() && VersionHelper.Compare(sSelfVer, sDlVer) < 0 && File.Exists(PATH + "tidal-gui.exe") && File.Exists(BATF)) + { + MessageBoxResult ret = MessageBox.Show("Update new version?", "Info", MessageBoxButton.YesNo); + if (ret == MessageBoxResult.No) + return; + + if (Application.Current != null) + { + Application.Current.Dispatcher.BeginInvoke((Action)delegate () + { + CmdHelper.StartExe(BATF, null, IsShowWindow: false); + WindowClose(); + }); + } + return; + } + + //Get Github Last Ver + string sLastVer = GithubHelper.getLastReleaseVersion("yaronzz", "Tidal-Media-Downloader"); + if (VersionHelper.Compare(sSelfVer, sLastVer) >= 0) + return; + + if (Directory.Exists(PATH)) + Directory.Delete(PATH, true); + PathHelper.Mkdirs(PATH); + if (GithubHelper.getLastReleaseFile("yaronzz", "Tidal-Media-Downloader", "tidal-gui.zip", PATH + "tidal-gui.zip")) + { + FastZip fz = new FastZip(); + try + { + fz.ExtractZip(PATH + "tidal-gui.zip", PATH, null); + if (File.Exists(PATH + "tidal-gui.exe")) + { + string sBat = "ping -n 5 127.0.0.1\n"; + sBat += string.Format("move {0}tidal-gui.exe {0}..\\tidal-gui.exe\n", PATH); + sBat += string.Format("start {0}..\\tidal-gui.exe\n", PATH); + FileHelper.Write(sBat, true, BATF); + FileHelper.Write(sLastVer, true, VERF); + } + } + catch + { + return; + } + } + } + #endregion + + } +} diff --git a/TIDALDL-UI/TIDALDL-UI/Pages/SearchView.xaml b/TIDALDL-UI/TIDALDL-UI/Pages/SearchView.xaml index 2d5fe4a5..df5df0e9 100644 --- a/TIDALDL-UI/TIDALDL-UI/Pages/SearchView.xaml +++ b/TIDALDL-UI/TIDALDL-UI/Pages/SearchView.xaml @@ -15,19 +15,19 @@ TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Auto" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" - Width="568" + Width="850" WindowStartupLocation="CenterOwner" WindowStyle="None" Background="{x:Null}" AllowsTransparency="True" - Height="540" + Height="575" ShowInTaskbar="False" d:DataContext="{d:DesignInstance pages:SearchViewModel}"> - + @@ -38,10 +38,10 @@