From 79b24a38d0dc8bbec5e77237154c225ac4c33299 Mon Sep 17 00:00:00 2001 From: Viliam Date: Sat, 4 Nov 2023 21:24:32 +0200 Subject: [PATCH] Added the 'save album art' feature. Double-clicking on a path now opens the path folder. --- Form1.Designer.cs | 108 ++++++++++++++++------------ Form1.cs | 143 +++++++++++++++++++++++++++++++------ Properties/AssemblyInfo.cs | 4 +- 3 files changed, 189 insertions(+), 66 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 50c1e23..d6f0097 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -46,6 +46,7 @@ private void InitializeComponent() this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); + this.chk_download_art = new System.Windows.Forms.CheckBox(); this.chk_suppress_downloading_logs = new System.Windows.Forms.CheckBox(); this.btn_opensearch = new System.Windows.Forms.Button(); this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel(); @@ -66,7 +67,7 @@ private void InitializeComponent() this.txt_urllist.Multiline = true; this.txt_urllist.Name = "txt_urllist"; this.txt_urllist.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txt_urllist.Size = new System.Drawing.Size(650, 142); + this.txt_urllist.Size = new System.Drawing.Size(774, 123); this.txt_urllist.TabIndex = 0; // // txt_log @@ -78,15 +79,15 @@ private void InitializeComponent() this.txt_log.Name = "txt_log"; this.txt_log.ReadOnly = true; this.txt_log.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txt_log.Size = new System.Drawing.Size(487, 136); + this.txt_log.Size = new System.Drawing.Size(611, 117); this.txt_log.TabIndex = 1; // // btn_download // this.btn_download.Dock = System.Windows.Forms.DockStyle.Fill; - this.btn_download.Location = new System.Drawing.Point(3, 99); + this.btn_download.Location = new System.Drawing.Point(3, 85); this.btn_download.Name = "btn_download"; - this.btn_download.Size = new System.Drawing.Size(145, 34); + this.btn_download.Size = new System.Drawing.Size(145, 29); this.btn_download.TabIndex = 2; this.btn_download.Text = "Download"; this.btn_download.UseVisualStyleBackColor = true; @@ -99,7 +100,7 @@ private void InitializeComponent() this.box_quality.Dock = System.Windows.Forms.DockStyle.Fill; this.box_quality.Location = new System.Drawing.Point(3, 3); this.box_quality.Name = "box_quality"; - this.box_quality.Size = new System.Drawing.Size(145, 90); + this.box_quality.Size = new System.Drawing.Size(145, 76); this.box_quality.TabIndex = 3; this.box_quality.TabStop = false; this.box_quality.Text = "Audio Quality"; @@ -135,13 +136,14 @@ private void InitializeComponent() this.lbl_path.Size = new System.Drawing.Size(35, 13); this.lbl_path.TabIndex = 4; this.lbl_path.Text = "label1"; + this.lbl_path.Click += new System.EventHandler(this.lbl_path_Click); // // btn_selectpath // this.btn_selectpath.Anchor = System.Windows.Forms.AnchorStyles.Right; - this.btn_selectpath.Location = new System.Drawing.Point(420, 3); + this.btn_selectpath.Location = new System.Drawing.Point(520, 3); this.btn_selectpath.Name = "btn_selectpath"; - this.btn_selectpath.Size = new System.Drawing.Size(88, 22); + this.btn_selectpath.Size = new System.Drawing.Size(92, 22); this.btn_selectpath.TabIndex = 5; this.btn_selectpath.Text = "Select Path..."; this.btn_selectpath.UseVisualStyleBackColor = true; @@ -152,17 +154,17 @@ private void InitializeComponent() this.label1.Anchor = System.Windows.Forms.AnchorStyles.Right; this.label1.AutoSize = true; this.label1.ForeColor = System.Drawing.Color.DarkGray; - this.label1.Location = new System.Drawing.Point(565, 2); + this.label1.Location = new System.Drawing.Point(689, 2); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(82, 13); this.label1.TabIndex = 6; - this.label1.Text = "Weespin - 2022"; + this.label1.Text = "Weespin - 2023"; this.label1.DoubleClick += new System.EventHandler(this.label1_DoubleClick); // // num_threads // this.num_threads.Anchor = System.Windows.Forms.AnchorStyles.None; - this.num_threads.Location = new System.Drawing.Point(355, 4); + this.num_threads.Location = new System.Drawing.Point(476, 4); this.num_threads.Maximum = new decimal(new int[] { 1000, 0, @@ -174,7 +176,7 @@ private void InitializeComponent() 0, 0}); this.num_threads.Name = "num_threads"; - this.num_threads.Size = new System.Drawing.Size(59, 20); + this.num_threads.Size = new System.Drawing.Size(36, 20); this.num_threads.TabIndex = 8; this.num_threads.Value = new decimal(new int[] { 1, @@ -187,7 +189,7 @@ private void InitializeComponent() // this.label2.Anchor = System.Windows.Forms.AnchorStyles.None; this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(248, 7); + this.label2.Location = new System.Drawing.Point(367, 7); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(99, 13); this.label2.TabIndex = 9; @@ -197,7 +199,7 @@ private void InitializeComponent() // this.label3.Anchor = System.Windows.Forms.AnchorStyles.None; this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(97, 7); + this.label3.Location = new System.Drawing.Point(226, 7); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(81, 13); this.label3.TabIndex = 11; @@ -206,7 +208,7 @@ private void InitializeComponent() // num_album_threads // this.num_album_threads.Anchor = System.Windows.Forms.AnchorStyles.None; - this.num_album_threads.Location = new System.Drawing.Point(187, 4); + this.num_album_threads.Location = new System.Drawing.Point(318, 4); this.num_album_threads.Maximum = new decimal(new int[] { 1000, 0, @@ -218,7 +220,7 @@ private void InitializeComponent() 0, 0}); this.num_album_threads.Name = "num_album_threads"; - this.num_album_threads.Size = new System.Drawing.Size(52, 20); + this.num_album_threads.Size = new System.Drawing.Size(39, 20); this.num_album_threads.TabIndex = 10; this.num_album_threads.Value = new decimal(new int[] { 1, @@ -243,22 +245,22 @@ private void InitializeComponent() this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 34F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 22F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(656, 353); + this.tableLayoutPanel1.Size = new System.Drawing.Size(780, 315); this.tableLayoutPanel1.TabIndex = 13; // // tableLayoutPanel2 // this.tableLayoutPanel2.ColumnCount = 2; this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20.79566F)); - this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 156F)); + this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 157F)); this.tableLayoutPanel2.Controls.Add(this.txt_log, 0, 0); this.tableLayoutPanel2.Controls.Add(this.tableLayoutPanel3, 1, 0); this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 151); + this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 132); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.RowCount = 1; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(650, 142); + this.tableLayoutPanel2.Size = new System.Drawing.Size(774, 123); this.tableLayoutPanel2.TabIndex = 1; // // tableLayoutPanel3 @@ -268,45 +270,61 @@ private void InitializeComponent() this.tableLayoutPanel3.Controls.Add(this.box_quality, 0, 0); this.tableLayoutPanel3.Controls.Add(this.btn_download, 0, 1); this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel3.Location = new System.Drawing.Point(496, 3); + this.tableLayoutPanel3.Location = new System.Drawing.Point(620, 3); this.tableLayoutPanel3.Name = "tableLayoutPanel3"; this.tableLayoutPanel3.RowCount = 2; this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 70.7317F)); this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 29.26829F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(151, 136); + this.tableLayoutPanel3.Size = new System.Drawing.Size(151, 117); this.tableLayoutPanel3.TabIndex = 2; // // tableLayoutPanel4 // - this.tableLayoutPanel4.ColumnCount = 7; + this.tableLayoutPanel4.ColumnCount = 8; this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 90F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 109F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 65F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 94F)); - this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 139F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 110F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 95F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 47F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 112F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 42F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 159F)); + this.tableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel4.Controls.Add(this.chk_download_art, 0, 0); this.tableLayoutPanel4.Controls.Add(this.chk_suppress_downloading_logs, 0, 0); - this.tableLayoutPanel4.Controls.Add(this.btn_opensearch, 6, 0); - this.tableLayoutPanel4.Controls.Add(this.num_threads, 4, 0); - this.tableLayoutPanel4.Controls.Add(this.label2, 3, 0); - this.tableLayoutPanel4.Controls.Add(this.btn_selectpath, 5, 0); - this.tableLayoutPanel4.Controls.Add(this.num_album_threads, 2, 0); - this.tableLayoutPanel4.Controls.Add(this.label3, 1, 0); + this.tableLayoutPanel4.Controls.Add(this.btn_opensearch, 7, 0); + this.tableLayoutPanel4.Controls.Add(this.num_threads, 5, 0); + this.tableLayoutPanel4.Controls.Add(this.label2, 4, 0); + this.tableLayoutPanel4.Controls.Add(this.btn_selectpath, 6, 0); + this.tableLayoutPanel4.Controls.Add(this.num_album_threads, 3, 0); + this.tableLayoutPanel4.Controls.Add(this.label3, 2, 0); this.tableLayoutPanel4.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 299); + this.tableLayoutPanel4.Location = new System.Drawing.Point(3, 261); this.tableLayoutPanel4.Name = "tableLayoutPanel4"; this.tableLayoutPanel4.RowCount = 1; this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel4.Size = new System.Drawing.Size(650, 28); + this.tableLayoutPanel4.Size = new System.Drawing.Size(774, 28); this.tableLayoutPanel4.TabIndex = 2; // + // chk_download_art + // + this.chk_download_art.AutoSize = true; + this.chk_download_art.Dock = System.Windows.Forms.DockStyle.Fill; + this.chk_download_art.Location = new System.Drawing.Point(112, 3); + this.chk_download_art.Name = "chk_download_art"; + this.chk_download_art.Size = new System.Drawing.Size(104, 22); + this.chk_download_art.TabIndex = 14; + this.chk_download_art.Text = "Download Art"; + this.chk_download_art.UseVisualStyleBackColor = true; + this.chk_download_art.CheckedChanged += new System.EventHandler(this.chk_download_art_CheckedChanged); + // // chk_suppress_downloading_logs // this.chk_suppress_downloading_logs.AutoSize = true; + this.chk_suppress_downloading_logs.Dock = System.Windows.Forms.DockStyle.Fill; this.chk_suppress_downloading_logs.Location = new System.Drawing.Point(3, 3); this.chk_suppress_downloading_logs.Name = "chk_suppress_downloading_logs"; - this.chk_suppress_downloading_logs.Size = new System.Drawing.Size(87, 17); + this.chk_suppress_downloading_logs.Size = new System.Drawing.Size(103, 22); this.chk_suppress_downloading_logs.TabIndex = 12; this.chk_suppress_downloading_logs.Text = "Suppress Logs"; this.chk_suppress_downloading_logs.UseVisualStyleBackColor = true; @@ -314,9 +332,10 @@ private void InitializeComponent() // // btn_opensearch // - this.btn_opensearch.Location = new System.Drawing.Point(514, 3); + this.btn_opensearch.Dock = System.Windows.Forms.DockStyle.Fill; + this.btn_opensearch.Location = new System.Drawing.Point(618, 3); this.btn_opensearch.Name = "btn_opensearch"; - this.btn_opensearch.Size = new System.Drawing.Size(130, 22); + this.btn_opensearch.Size = new System.Drawing.Size(153, 22); this.btn_opensearch.TabIndex = 7; this.btn_opensearch.Text = "Search"; this.btn_opensearch.UseVisualStyleBackColor = true; @@ -325,23 +344,23 @@ private void InitializeComponent() // tableLayoutPanel5 // this.tableLayoutPanel5.ColumnCount = 2; - this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 83.59173F)); + this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.40827F)); this.tableLayoutPanel5.Controls.Add(this.lbl_path, 0, 0); this.tableLayoutPanel5.Controls.Add(this.label1, 1, 0); this.tableLayoutPanel5.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel5.Location = new System.Drawing.Point(3, 333); + this.tableLayoutPanel5.Location = new System.Drawing.Point(3, 295); this.tableLayoutPanel5.Name = "tableLayoutPanel5"; this.tableLayoutPanel5.RowCount = 1; this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel5.Size = new System.Drawing.Size(650, 17); + this.tableLayoutPanel5.Size = new System.Drawing.Size(774, 17); this.tableLayoutPanel5.TabIndex = 3; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(757, 304); + this.ClientSize = new System.Drawing.Size(780, 315); this.Controls.Add(this.tableLayoutPanel1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; @@ -385,6 +404,7 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chk_suppress_downloading_logs; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel5; private System.Windows.Forms.Button btn_opensearch; + private System.Windows.Forms.CheckBox chk_download_art; } } diff --git a/Form1.cs b/Form1.cs index a907126..f05b1d0 100644 --- a/Form1.cs +++ b/Form1.cs @@ -5,12 +5,24 @@ using System.Linq; using System.Net; using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using AngleSharp.Dom; using AngleSharp.Html.Dom; using AngleSharp.Html.Parser; using Newtonsoft.Json; +//using TagLib; +//using TagLib.Mpeg; +//using TagLib.Id3v2; +using File = System.IO.File; +using Version = System.Version; +using AngleSharp.Io; +using System.Web; +using System.Xml.Linq; +using static System.Windows.Forms.LinkLabel; + // ReSharper disable ConvertToUsingDeclaration namespace KhinsiderDownloader @@ -69,8 +81,8 @@ public Form1() Downloader.g_albumsParralelOptions.MaxDegreeOfParallelism = 1; num_threads.Value = 2; Task.Run(() => { checkUpdates(); }); + txt_log.Text = $"KhinsiderDownloader - {new Version(Application.ProductVersion)}\r\nIf you encounter any problems, crashes, or have suggestions, please share your feedback on GitHub: https://github.com/weespin/KhinsiderDownloader/issues"; } - public void Log(string textIn) { if (txt_log.InvokeRequired) @@ -90,7 +102,6 @@ public void LoadConfig() { var configLines = File.ReadAllLines("khinsiderdl.config"); lbl_path.Text = Downloader.m_szDownloadPath = configLines[0]; - Downloader.eQuality = bool.Parse(configLines[1]) ? Downloader.EDownloadQuality.QUALITY_MP3_ONLY : Downloader.EDownloadQuality.QUALITY_BEST_ONLY; @@ -106,7 +117,8 @@ public void LoadConfig() Downloader.g_songsParralelOptions.MaxDegreeOfParallelism = Int32.Parse(configLines[2]); Downloader.g_albumsParralelOptions.MaxDegreeOfParallelism = Int32.Parse(configLines[3]); Downloader.m_bSuppessLogs = bool.Parse(configLines[4]); - + Downloader.m_bDownloadArt = bool.Parse(configLines[5]); + //Downloader.m_bArtFix = bool.Parse(configLines[6]); } catch (Exception) @@ -117,14 +129,14 @@ public void LoadConfig() void SaveConfig() { - string[] configLines = new string[5]; + string[] configLines = new string[6]; configLines[0] = Downloader.m_szDownloadPath; configLines[1] = (Downloader.eQuality == Downloader.EDownloadQuality.QUALITY_MP3_ONLY).ToString(); configLines[2] = Downloader.g_songsParralelOptions.MaxDegreeOfParallelism.ToString(); configLines[3] = Downloader.g_albumsParralelOptions.MaxDegreeOfParallelism.ToString(); configLines[4] = Downloader.m_bSuppessLogs.ToString(); - - + configLines[5] = Downloader.m_bDownloadArt.ToString(); + //configLines[6] = Downloader.m_bArtFix.ToString(); File.WriteAllLines("khinsiderdl.config", configLines); } @@ -217,9 +229,20 @@ private void chk_suppress_downloading_logs_CheckedChanged(object sender, EventAr Downloader.m_bSuppessLogs = chk_suppress_downloading_logs.Checked; } + private void chk_set_art_as_icon_CheckedChanged(object sender, EventArgs e) + { + //Downloader.m_bArtFix = chk_fix_picture.Checked; + } + private void chk_download_art_CheckedChanged(object sender, EventArgs e) + { + Downloader.m_bDownloadArt = chk_download_art.Checked; + } + private void lbl_path_Click(object sender, EventArgs e) + { + Process.Start(Downloader.m_szDownloadPath); + } } - static class Downloader { public static CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); @@ -260,7 +283,9 @@ public enum EDownloadQuality : byte public static EDownloadQuality eQuality = EDownloadQuality.QUALITY_MP3_ONLY; public static string m_szDownloadPath = Directory.GetCurrentDirectory() + "\\Downloads\\"; public static bool m_bSuppessLogs; - + public static bool m_bDownloadArt; + //public static bool m_bArtFix; + public static string m_szHostName = "https://downloads.khinsider.com"; public static void DownloadAlbums(List url) { g_albumsParralelOptions.CancellationToken = Downloader.cancelTokenSource.Token; @@ -304,7 +329,6 @@ public struct HTMLResult public string ResponseURI; public string HTML; } - public static HTMLResult GetHTMLFromURL(string sUrl) { HTMLResult result = new HTMLResult(); @@ -333,9 +357,10 @@ public static HTMLResult GetHTMLFromURL(string sUrl) return result; } - public static void DownloadAlbum(string sUrl) { + SynchronizedCollection currentTasks = new SynchronizedCollection(); + string albumHTML = String.Empty; try { @@ -366,13 +391,18 @@ public static void DownloadAlbum(string sUrl) var albumNameNode = albumHtmlDocument.All .FirstOrDefault(element => element.Id == "pageContent") ?.Children[1]; //DocumentNode.SelectSingleNode("//*[@id=\"EchoTopic\"]/h2[1]"); + var albumImageNodes = albumHtmlDocument.All.Where(element => + element.LocalName == "div" && + element.ClassName == + "albumImage"); //.SelectNodes("//td[contains(@class, 'playlistDownloadSong')]"); + string szAlbumName; if (albumNameNode != null && songNodes.Any() && qualityNode != null) { //Trim spaces and dots! szAlbumName = string .Join("_", WebUtility.HtmlDecode(albumNameNode.InnerHtml).Split(Path.GetInvalidFileNameChars())) - .Trim(new char[] { ' ', '.' }); + .Trim(new[] { ' ', '.' }); } else { @@ -380,6 +410,54 @@ public static void DownloadAlbum(string sUrl) return; } + List albumImageLinks = albumImageNodes + .Where(albumImageNode => albumImageNode.ChildElementCount > 0) + .Select(albumImageNode => albumImageNode.Children[0].GetAttribute("href")) + .ToList(); + + //byte[] ArtFix = null; + //string ArtFixPath = ""; + //if (m_bArtFix) + //{ + // //find and download best image + // string bestLink = albumImageLinks + // .FirstOrDefault(link => + // { + // string fileName = link.Split('/').Last(); + // string fileExtension = fileName.Split('.').Last(); + // return fileExtension.ToLower().Contains("cover"); + // }) ?? albumImageLinks.FirstOrDefault(); + // if (bestLink != null) + // { + // WebClient downloadClient = new WebClient() { Proxy = null }; + // ArtFix = downloadClient.DownloadData(bestLink); + // ArtFixPath = bestLink; + // } + //} + if (m_bDownloadArt) + { + + if (albumImageLinks.Count != 0) + { + Directory.CreateDirectory(m_szDownloadPath + "\\" + szAlbumName + "\\art\\"); + foreach (var albumImageLink in albumImageLinks) + { + WebClient downloadClient = new WebClient() { Proxy = null }; + + string filename = albumImageLink.Split('/').Last(); + var shh = string + .Join("_", Uri.UnescapeDataString(filename).Split(Path.GetInvalidFileNameChars())) + .Trim(new[] { ' ', '.' }); + Task currentTask = downloadClient.DownloadFileTaskAsync(new Uri(albumImageLink), m_szDownloadPath + "\\" + szAlbumName + "\\art\\" + shh); + currentTask.ContinueWith( + task => { downloadClient.Dispose(); }); + currentTasks.Add(currentTask); + + } + } + } + + Directory.CreateDirectory(Downloader.m_szDownloadPath + "\\" + szAlbumName); var selectedFormat = ".mp3"; if (eQuality != EDownloadQuality.QUALITY_MP3_ONLY) @@ -420,7 +498,6 @@ public static void DownloadAlbum(string sUrl) } } - SynchronizedCollection currentTasks = new SynchronizedCollection(); int nTotalSongs = songNodes.Count(); int nCurrentSong = 0; try @@ -428,7 +505,7 @@ public static void DownloadAlbum(string sUrl) Parallel.ForEach(songNodes, g_songsParralelOptions, song => { var songPageURL = - "https://downloads.khinsider.com" + song.Children[0].GetAttribute("href"); //["href"].Value; + m_szHostName + song.Children[0].GetAttribute("href"); //["href"].Value; IHtmlDocument songPageDocument; @@ -480,30 +557,56 @@ public static void DownloadAlbum(string sUrl) string.Join("_", name.Split(Path.GetInvalidFileNameChars())); try { - WebClient downloadClient = new WebClient() {Proxy = null}; Task currentTask = downloadClient.DownloadFileTaskAsync(new Uri(songFileURL), filename); currentTask.ContinueWith( task => { downloadClient.Dispose(); + if (!IsDownloading) { File.Delete(filename); return; } - ++nCurrentSong; - if (nTotalAlbums == 1) - { - UpdateTitle(nCurrentSong, nTotalSongs); - } + //if (m_bArtFix) + //{ + // var file = AudioFile.Create(filename); + // if (file.Tag.Pictures.Length > 0) + // { + // if (file.Tag.Pictures.All(n => n.Type != PictureType.FrontCover)) + // { + // file.Tag.Pictures[0].Type = PictureType.FrontCover; + // } + // } + // else + // { + // file.Tag.Pictures = new IPicture[] + // { + // new Picture(new ByteVector(ArtFix)) + // { + // Type = PictureType.FrontCover, + // Description = "Cover", + // MimeType = MimeMapping.GetMimeMapping(ArtFixPath) + // } + // }; + // } + // file.Save(); + //} if (!m_bSuppessLogs) { Program.MainForm.Log($"{name} has been downloaded!"); } - }); + + ++nCurrentSong; + if (nTotalAlbums == 1) + { + UpdateTitle(nCurrentSong, nTotalSongs); + } + + }, TaskContinuationOptions.ExecuteSynchronously); currentTasks.Add(currentTask); } catch (Exception e) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 228301a..c20277f 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.2.0")] -[assembly: AssemblyFileVersion("2.7.2.0")] +[assembly: AssemblyVersion("2.7.4.0")] +[assembly: AssemblyFileVersion("2.7.4.0")]