From 58a6be7283445ba16650e776fd731005c16a08ee Mon Sep 17 00:00:00 2001 From: AiiR <22158489+ImAiiR@users.noreply.github.com> Date: Tue, 16 Jun 2020 03:35:27 -0400 Subject: [PATCH] 0.9.9.16 0.9.9.16 --- QobuzDownloaderX/App.config | 3 + QobuzDownloaderX/Form1.Designer.cs | 18 + QobuzDownloaderX/Form1.cs | 701 +++++++++++++----- QobuzDownloaderX/LoginForm-v2.cs | 14 +- QobuzDownloaderX/Properties/AssemblyInfo.cs | 4 +- .../Properties/Settings.Designer.cs | 12 + QobuzDownloaderX/Properties/Settings.settings | 3 + 7 files changed, 561 insertions(+), 194 deletions(-) diff --git a/QobuzDownloaderX/App.config b/QobuzDownloaderX/App.config index e50e13c..3d8dde4 100644 --- a/QobuzDownloaderX/App.config +++ b/QobuzDownloaderX/App.config @@ -112,6 +112,9 @@ 1 + + True + diff --git a/QobuzDownloaderX/Form1.Designer.cs b/QobuzDownloaderX/Form1.Designer.cs index ab0662b..ce78c6b 100644 --- a/QobuzDownloaderX/Form1.Designer.cs +++ b/QobuzDownloaderX/Form1.Designer.cs @@ -105,6 +105,7 @@ private void InitializeComponent() this.downloadFaveArtistsBG = new System.ComponentModel.BackgroundWorker(); this.artSizeSelect = new System.Windows.Forms.ComboBox(); this.artSizeLabel = new System.Windows.Forms.Label(); + this.typeCheckbox = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.albumArtPicBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.logoBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.profilePictureBox)).BeginInit(); @@ -966,12 +967,28 @@ private void InitializeComponent() this.artSizeLabel.TabIndex = 97; this.artSizeLabel.Text = "Embedded Art Size: px"; // + // typeCheckbox + // + this.typeCheckbox.AutoSize = true; + this.typeCheckbox.Checked = true; + this.typeCheckbox.CheckState = System.Windows.Forms.CheckState.Checked; + this.typeCheckbox.FlatAppearance.BorderSize = 0; + this.typeCheckbox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(88)))), ((int)(((byte)(92)))), ((int)(((byte)(102))))); + this.typeCheckbox.Location = new System.Drawing.Point(533, 563); + this.typeCheckbox.Name = "typeCheckbox"; + this.typeCheckbox.Size = new System.Drawing.Size(92, 17); + this.typeCheckbox.TabIndex = 98; + this.typeCheckbox.Text = "Release Type"; + this.typeCheckbox.UseVisualStyleBackColor = true; + this.typeCheckbox.CheckedChanged += new System.EventHandler(this.typeCheckbox_CheckedChanged); + // // QobuzDownloaderX // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20))))); this.ClientSize = new System.Drawing.Size(938, 733); + this.Controls.Add(this.typeCheckbox); this.Controls.Add(this.artSizeSelect); this.Controls.Add(this.artSizeLabel); this.Controls.Add(this.hiddenTextPanel); @@ -1133,6 +1150,7 @@ private void InitializeComponent() private System.ComponentModel.BackgroundWorker downloadFaveArtistsBG; private System.Windows.Forms.ComboBox artSizeSelect; private System.Windows.Forms.Label artSizeLabel; + private System.Windows.Forms.CheckBox typeCheckbox; } } diff --git a/QobuzDownloaderX/Form1.cs b/QobuzDownloaderX/Form1.cs index 77e5d6f..ed14935 100644 --- a/QobuzDownloaderX/Form1.cs +++ b/QobuzDownloaderX/Form1.cs @@ -56,6 +56,8 @@ public QobuzDownloaderX() public string audioFileType { get; set; } public string trackRequest { get; set; } public string artSize { get; set; } + public string finalTrackNamePath { get; set; } + public string finalTrackNameVersionPath { get; set; } public int MaxLength { get; set; } public int devClickEggThingValue { get; set; } @@ -63,6 +65,8 @@ public QobuzDownloaderX() private void Form1_Load(object sender, EventArgs e) { + MaxLength = 36; + // Set main form size on launch and bring to center. this.Height = 533; this.CenterToScreen(); @@ -112,6 +116,7 @@ private void Form1_Load(object sender, EventArgs e) discTotalCheckbox.Checked = Settings.Default.totalDiscsTag; genreCheckbox.Checked = Settings.Default.genreTag; isrcCheckbox.Checked = Settings.Default.isrcTag; + typeCheckbox.Checked = Settings.Default.typeTag; explicitCheckbox.Checked = Settings.Default.explicitTag; trackTitleCheckbox.Checked = Settings.Default.trackTitleTag; trackNumberCheckbox.Checked = Settings.Default.trackTag; @@ -615,9 +620,6 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) foreach (Match mtrack in Regex.Matches(trackinput, trackIdspattern, trackoptions)) { - // Set default value for max length. - const int MaxLength = 36; - //output.Invoke(new Action(() => output.AppendText(string.Format("{0}\r\n", m.Groups["trackId"].Value)))); trackIdString = string.Format("{0}", mtrack.Groups["trackId"].Value); @@ -675,12 +677,6 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) // Display album artist in text box under cover art. albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); - // If name goes over 200 characters, limit it to 200 - if (albumArtistPath.Length > MaxLength) - { - albumArtistPath = albumArtistPath.Substring(0, MaxLength); - } - // Track Artist tag var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?.*?),\"name\":\"(?.*?)\"},\\\"").Groups; var performerName = performerNameLog[2].Value; @@ -693,12 +689,6 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) performerName = performerName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var performerNamePath = performerName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (performerNamePath.Length > MaxLength) - { - performerNamePath = performerNamePath.Substring(0, MaxLength); - } - // Track Composer tag var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?.*?),\"name\":\"(?.*?)\",").Groups; var composerName = composerNameLog[2].Value; @@ -729,12 +719,6 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) // Display album name in text box under cover art. albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); - // If name goes over 200 characters, limit it to 200 - if (albumNamePath.Length > MaxLength) - { - albumNamePath = albumNamePath.Substring(0, MaxLength); - } - // Track Name tag var trackNameLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\"title\":\"(?.*?)\",\"").Groups; var trackName = trackNameLog[2].Value; @@ -748,12 +732,6 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) trackName = trackName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var trackNamePath = trackName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (trackNamePath.Length > MaxLength) - { - trackNamePath = trackNamePath.Substring(0, MaxLength); - } - // Version Name tag var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?.*?)\",\\\"").Groups; var versionName = versionNameLog[1].Value; @@ -804,6 +782,10 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) var isrcLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\\\"").Groups; var isrc = isrcLog[1].Value; + // Release Type tag + var typeLog = Regex.Match(trackRequest, "\"release_type\":\"(?.*?)\",\"").Groups; + var type = typeLog[1].Value.ToUpper(); + // Total Tracks tag var trackTotalLog = Regex.Match(trackRequest, "\"tracks_count\":(?[0-9]+)").Groups; var trackTotal = trackTotalLog[1].Value; @@ -816,6 +798,24 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) var discTotal = discTotalLog[1].Value; #endregion + #region Create Shortened Strings + // If name goes over 36 characters, limit it to 36 + if (albumArtistPath.Length > MaxLength) + { + albumArtistPath = albumArtistPath.Substring(0, MaxLength).TrimEnd(); + } + + if (performerNamePath.Length > MaxLength) + { + performerNamePath = performerNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + #endregion + #region Filename Number Padding // Set default track number padding length var paddingLength = 2; @@ -866,6 +866,33 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) string discogPath = loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + discFolderCreate; #endregion + #region Create Shortened Strings (Again) + // Create final shortened track file names to avoid errors with file names being too long. + if (versionName == null | versionName == "") + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Length > MaxLength) + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).TrimEnd(); + } + + } + else + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Length > MaxLength) + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").TrimEnd(); + } + } + #endregion + #region Availability Check (Streamable?) // Check if available for streaming. var streamCheckLog = Regex.Match(trackRequest, "\"track_number\":(?.*?)\"streamable\":(?.*?),\"").Groups; @@ -890,7 +917,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) // Check if there is a version name. if (versionName == null | versionName == "") { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNamePath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -899,7 +926,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNameVersionPath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -941,7 +968,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) if (versionNamePath == null | versionNamePath == "") { // If there is NOT a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType)) { await stream.CopyToAsync(output); } @@ -949,7 +976,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType)) { await stream.CopyToAsync(output); } @@ -994,7 +1021,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -1105,6 +1132,16 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -1117,7 +1154,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -1228,6 +1265,16 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -1247,7 +1294,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -1356,6 +1403,15 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -1368,7 +1424,7 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -1477,6 +1533,15 @@ private async void downloadDiscogBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -1610,6 +1675,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) var labelName = labelNameLog[1].Value; labelName = labelName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); + var labelNamePath = labelName; // Grab all Track IDs listed on the API. string artistAlbumIdspattern = ",\"maximum_channel_count\":(?.*?),\"id\":\"(?.*?)\","; @@ -1746,9 +1812,6 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) foreach (Match mtrack in Regex.Matches(trackinput, trackIdspattern, trackoptions)) { - // Set default value for max length. - const int MaxLength = 36; - //output.Invoke(new Action(() => output.AppendText(string.Format("{0}\r\n", m.Groups["trackId"].Value)))); trackIdString = string.Format("{0}", mtrack.Groups["trackId"].Value); @@ -1806,12 +1869,6 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) // Display album artist in text box under cover art. albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); - // If name goes over 200 characters, limit it to 200 - if (albumArtistPath.Length > MaxLength) - { - albumArtistPath = albumArtistPath.Substring(0, MaxLength); - } - // Track Artist tag var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?.*?),\"name\":\"(?.*?)\"},\\\"").Groups; var performerName = performerNameLog[2].Value; @@ -1824,12 +1881,6 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) performerName = performerName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var performerNamePath = performerName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (performerNamePath.Length > MaxLength) - { - performerNamePath = performerNamePath.Substring(0, MaxLength); - } - // Track Composer tag var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?.*?),\"name\":\"(?.*?)\",").Groups; var composerName = composerNameLog[2].Value; @@ -1860,12 +1911,6 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) // Display album name in text box under cover art. albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); - // If name goes over 200 characters, limit it to 200 - if (albumNamePath.Length > MaxLength) - { - albumNamePath = albumNamePath.Substring(0, MaxLength); - } - // Track Name tag var trackNameLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\"title\":\"(?.*?)\",\"").Groups; var trackName = trackNameLog[2].Value; @@ -1879,12 +1924,6 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) trackName = trackName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var trackNamePath = trackName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (trackNamePath.Length > MaxLength) - { - trackNamePath = trackNamePath.Substring(0, MaxLength); - } - // Version Name tag var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?.*?)\",\\\"").Groups; var versionName = versionNameLog[1].Value; @@ -1935,6 +1974,10 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) var isrcLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\\\"").Groups; var isrc = isrcLog[1].Value; + // Release Type tag + var typeLog = Regex.Match(trackRequest, "\"release_type\":\"(?.*?)\",\"").Groups; + var type = typeLog[1].Value.ToUpper(); + // Total Tracks tag var trackTotalLog = Regex.Match(trackRequest, "\"tracks_count\":(?[0-9]+)").Groups; var trackTotal = trackTotalLog[1].Value; @@ -1947,6 +1990,34 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) var discTotal = discTotalLog[1].Value; #endregion + #region Create Shortened Strings + // If name goes over 36 characters, limit it to 36 + if (albumArtistPath.Length > MaxLength) + { + albumArtistPath = albumArtistPath.Substring(0, MaxLength).TrimEnd(); + } + + if (performerNamePath.Length > MaxLength) + { + performerNamePath = performerNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (labelNamePath.Length > MaxLength) + { + labelNamePath = labelNamePath.Substring(0, MaxLength).TrimEnd(); + } + #endregion + #region Filename Number Padding // Set default track number padding length var paddingLength = 2; @@ -1989,14 +2060,41 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) discFolderCreate = "\\CD " + discNumber.PadLeft(paddingDiscLength, '0') + "\\"; } - System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath); - System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]"); - System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath); - System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + discFolderCreate); + System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath); + System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]"); + System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath); + System.IO.Directory.CreateDirectory(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + discFolderCreate); string discogPath = loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + discFolderCreate; #endregion + #region Create Shortened Strings (Again) + // Create final shortened track file names to avoid errors with file names being too long. + if (versionName == null | versionName == "") + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Length > MaxLength) + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).TrimEnd(); + } + + } + else + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Length > MaxLength) + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").TrimEnd(); + } + } + #endregion + #region Availability Check (Streamable?) // Check if available for streaming. var streamCheckLog = Regex.Match(trackRequest, "\"track_number\":(?.*?)\"streamable\":(?.*?),\"").Groups; @@ -2021,7 +2119,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) // Check if there is a version name. if (versionName == null | versionName == "") { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNamePath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -2030,7 +2128,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNameVersionPath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -2072,7 +2170,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) if (versionNamePath == null | versionNamePath == "") { // If there is NOT a version name. - using (var output = System.IO.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType)) { await stream.CopyToAsync(output); } @@ -2080,7 +2178,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - using (var output = System.IO.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType)) { await stream.CopyToAsync(output); } @@ -2088,14 +2186,14 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) #endregion #region Cover Art Saving - if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Cover.jpg")) + if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Cover.jpg")) { // Skip, don't re-download. // Download selected cover art size for tagging files (Currently happens every time a track is downloaded). using (WebClient imgClient = new WebClient()) { - imgClient.DownloadFile(new Uri(frontCoverImg.Replace("_max", "_" + artSize)), loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + imgClient.DownloadFile(new Uri(frontCoverImg.Replace("_max", "_" + artSize)), loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); } } else @@ -2106,10 +2204,10 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) using (WebClient imgClient = new WebClient()) { // Download max quality Cover Art to "Cover.jpg" file in chosen path. - imgClient.DownloadFile(new Uri(frontCoverImg), loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Cover.jpg"); + imgClient.DownloadFile(new Uri(frontCoverImg), loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Cover.jpg"); // Download selected cover art size for tagging files (Currently happens every time a track is downloaded). - imgClient.DownloadFile(new Uri(frontCoverImg.Replace("_max", "_" + artSize)), loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + imgClient.DownloadFile(new Uri(frontCoverImg.Replace("_max", "_" + artSize)), loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); } } } @@ -2125,7 +2223,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -2138,7 +2236,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; - pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); // Save cover art to MP3 file. tfile.Tag.Pictures = new TagLib.IPicture[1] { pic }; @@ -2236,6 +2334,16 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -2248,7 +2356,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -2261,7 +2369,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; - pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); // Save cover art to FLAC file. tfile.Tag.Pictures = new TagLib.IPicture[1] { pic }; @@ -2359,6 +2467,16 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -2378,7 +2496,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -2391,7 +2509,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; - pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); // Save cover art to FLAC file. tfile.Tag.Pictures = new TagLib.IPicture[1] { pic }; @@ -2487,6 +2605,15 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -2499,7 +2626,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -2512,7 +2639,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) pic.TextEncoding = TagLib.StringType.Latin1; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; pic.Type = TagLib.PictureType.FrontCover; - pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + pic.Data = TagLib.ByteVector.FromPath(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); // Save cover art to FLAC file. tfile.Tag.Pictures = new TagLib.IPicture[1] { pic }; @@ -2608,6 +2735,15 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -2629,7 +2765,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Digital Booklet.pdf")) + if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Digital Booklet.pdf")) { // Skip, don't re-download. } @@ -2640,7 +2776,7 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) using (WebClient bookClient = new WebClient()) { // Download max quality Cover Art to "Cover.jpg" file in chosen path. - bookClient.DownloadFile(new Uri(goodiesPDF), loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Digital Booklet.pdf"); + bookClient.DownloadFile(new Uri(goodiesPDF), loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + "Digital Booklet.pdf"); } } } @@ -2663,9 +2799,9 @@ private async void downloadLabelBG_DoWork(object sender, DoWorkEventArgs e) } // Delete image file used for tagging - if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg")) + if (System.IO.File.Exists(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg")) { - System.IO.File.Delete(loc + "\\" + "- Labels" + "\\" + labelName + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); + System.IO.File.Delete(loc + "\\" + "- Labels" + "\\" + labelNamePath + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + artSize + ".jpg"); } // Say when a track is done downloading, then wait for the next track / end. @@ -2935,12 +3071,6 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) // Display album artist in text box under cover art. albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); - // If name goes over 200 characters, limit it to 200 - if (albumArtistPath.Length > MaxLength) - { - albumArtistPath = albumArtistPath.Substring(0, MaxLength); - } - // Track Artist tag var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?.*?),\"name\":\"(?.*?)\"},\\\"").Groups; var performerName = performerNameLog[2].Value; @@ -2953,12 +3083,6 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) performerName = performerName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var performerNamePath = performerName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (performerNamePath.Length > MaxLength) - { - performerNamePath = performerNamePath.Substring(0, MaxLength); - } - // Track Composer tag var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?.*?),\"name\":\"(?.*?)\",").Groups; var composerName = composerNameLog[2].Value; @@ -2989,12 +3113,6 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) // Display album name in text box under cover art. albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); - // If name goes over 200 characters, limit it to 200 - if (albumNamePath.Length > MaxLength) - { - albumNamePath = albumNamePath.Substring(0, MaxLength); - } - // Track Name tag var trackNameLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\"title\":\"(?.*?)\",\"").Groups; var trackName = trackNameLog[2].Value; @@ -3008,12 +3126,6 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) trackName = trackName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var trackNamePath = trackName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (trackNamePath.Length > MaxLength) - { - trackNamePath = trackNamePath.Substring(0, MaxLength); - } - // Version Name tag var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?.*?)\",\\\"").Groups; var versionName = versionNameLog[1].Value; @@ -3064,6 +3176,10 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) var isrcLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\\\"").Groups; var isrc = isrcLog[1].Value; + // Release Type tag + var typeLog = Regex.Match(trackRequest, "\"release_type\":\"(?.*?)\",\"").Groups; + var type = typeLog[1].Value.ToUpper(); + // Total Tracks tag var trackTotalLog = Regex.Match(trackRequest, "\"tracks_count\":(?[0-9]+)").Groups; var trackTotal = trackTotalLog[1].Value; @@ -3076,6 +3192,24 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) var discTotal = discTotalLog[1].Value; #endregion + #region Create Shortened Strings + // If name goes over 36 characters, limit it to 36 + if (albumArtistPath.Length > MaxLength) + { + albumArtistPath = albumArtistPath.Substring(0, MaxLength).TrimEnd(); + } + + if (performerNamePath.Length > MaxLength) + { + performerNamePath = performerNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + #endregion + #region Filename Number Padding // Set default track number padding length var paddingLength = 2; @@ -3126,6 +3260,33 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) string discogPath = loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + discFolderCreate; #endregion + #region Create Shortened Strings (Again) + // Create final shortened track file names to avoid errors with file names being too long. + if (versionName == null | versionName == "") + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Length > MaxLength) + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).TrimEnd(); + } + + } + else + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Length > MaxLength) + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").TrimEnd(); + } + } + #endregion + #region Availability Check (Streamable?) // Check if available for streaming. var streamCheckLog = Regex.Match(trackRequest, "\"track_number\":(?.*?)\"streamable\":(?.*?),\"").Groups; @@ -3150,7 +3311,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) // Check if there is a version name. if (versionName == null | versionName == "") { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNamePath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -3159,7 +3320,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + if (System.IO.File.Exists(discogPath + "\\" + finalTrackNameVersionPath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -3201,7 +3362,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) if (versionNamePath == null | versionNamePath == "") { // If there is NOT a version name. - using (var output = System.IO.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType)) { await stream.CopyToAsync(output); } @@ -3209,7 +3370,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - using (var output = System.IO.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType)) { await stream.CopyToAsync(output); } @@ -3254,7 +3415,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -3365,6 +3526,16 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -3377,7 +3548,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -3488,6 +3659,16 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -3507,7 +3688,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -3616,6 +3797,15 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -3628,7 +3818,7 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + "- Favorites" + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -3737,6 +3927,15 @@ private async void downloadFaveAlbumsBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -3959,9 +4158,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) foreach (Match m in Regex.Matches(input, trackIdspattern, options)) { - // Set default value for max length. - const int MaxLength = 36; - // Grab matches for Track IDs trackIdString = string.Format("{0}", m.Groups["trackId"].Value); @@ -4024,12 +4220,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) // Display album artist in text box under cover art. albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); - // If name goes over 200 characters, limit it to 200 - if (albumArtistPath.Length > MaxLength) - { - albumArtistPath = albumArtistPath.Substring(0, MaxLength); - } - // Track Artist tag var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?.*?),\"name\":\"(?.*?)\"},\\\"").Groups; var performerName = performerNameLog[2].Value; @@ -4043,12 +4233,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) performerName = performerName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var performerNamePath = performerName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (performerNamePath.Length > MaxLength) - { - performerNamePath = performerNamePath.Substring(0, MaxLength); - } - // Track Composer tag var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?.*?),\"name\":\"(?.*?)\",").Groups; var composerName = composerNameLog[2].Value; @@ -4081,12 +4265,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) // Display album name in text box under cover art. albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); - // If name goes over 200 characters, limit it to 200 - if (albumNamePath.Length > MaxLength) - { - albumNamePath = albumNamePath.Substring(0, MaxLength); - } - // Track Name tag var trackNameLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\"title\":\"(?.*?)\",\"").Groups; var trackName = trackNameLog[2].Value; @@ -4101,12 +4279,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) trackName = trackName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var trackNamePath = trackName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (trackNamePath.Length > MaxLength) - { - trackNamePath = trackNamePath.Substring(0, MaxLength); - } - // Version Name tag var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?.*?)\",\\\"").Groups; var versionName = versionNameLog[1].Value; @@ -4119,12 +4291,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) // Replace double slashes & path unfriendly characters versionName = versionName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var versionNamePath = versionName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - - //// If name goes over 200 characters, limit it to 200 - //if (trackNamePath.Length + versionNamePath.Length > MaxLength) - //{ - // versionNamePath = null; - //} // Genre tag var genreLog = Regex.Match(trackRequest, "\"genre\":{\"id\":(?.*?),\"color\":\"(?.*?)\",\"name\":\"(?.*?)\",\\\"").Groups; @@ -4164,6 +4330,10 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) var isrcLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\\\"").Groups; var isrc = isrcLog[1].Value; + // Release Type tag + var typeLog = Regex.Match(trackRequest, "\"release_type\":\"(?.*?)\",\"").Groups; + var type = typeLog[1].Value.ToUpper(); + // Total Tracks tag var trackTotalLog = Regex.Match(trackRequest, "\"tracks_count\":(?[0-9]+)").Groups; var trackTotal = trackTotalLog[1].Value; @@ -4176,6 +4346,24 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) var discTotal = discTotalLog[1].Value; #endregion + #region Create Shortened Strings + // If name goes over 36 characters, limit it to 36 + if (albumArtistPath.Length > MaxLength) + { + albumArtistPath = albumArtistPath.Substring(0, MaxLength).TrimEnd(); + } + + if (performerNamePath.Length > MaxLength) + { + performerNamePath = performerNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + #endregion + #region Filename Number Padding // Set default track number padding length var paddingLength = 2; @@ -4228,6 +4416,33 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) string albumPath = loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + discFolderCreate; #endregion + #region Create Shortened Strings (Again) + // Create final shortened track file names to avoid errors with file names being too long. + if (versionName == null | versionName == "") + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Length > MaxLength) + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).TrimEnd(); + } + + } + else + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Length > MaxLength) + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").TrimEnd(); + } + } + #endregion + #region Availability Check (Streamable?) // Check if available for streaming. var streamCheckLog = Regex.Match(trackRequest, "\"track_number\":(?.*?)\"streamable\":(?.*?),\"").Groups; @@ -4252,7 +4467,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) // Check if there is a version name. if (versionName == null | versionName == "") { - if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + if (System.IO.File.Exists(albumPath + "\\" + finalTrackNamePath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -4261,7 +4476,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + if (System.IO.File.Exists(albumPath + "\\" + finalTrackNameVersionPath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -4304,7 +4519,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) if (versionNamePath == null | versionNamePath == "") { // If there is NOT a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType)) { await stream.CopyToAsync(output); } @@ -4312,7 +4527,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType)) { await stream.CopyToAsync(output); } @@ -4355,7 +4570,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -4466,6 +4681,16 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -4478,7 +4703,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -4589,6 +4814,16 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -4608,7 +4843,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -4717,6 +4952,15 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -4729,7 +4973,7 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -4838,6 +5082,15 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -4938,9 +5191,6 @@ private async void downloadAlbumBG_DoWork(object sender, DoWorkEventArgs e) private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) { #region If URL has "track" - // Set default value for max length. - const int MaxLength = 36; - // Set "loc" as the selected path. String loc = folderBrowserDialog.SelectedPath; @@ -5061,12 +5311,6 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) // Display album artist in text box under cover art. albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); - // If name goes over 200 characters, limit it to 200 - if (albumArtistPath.Length > MaxLength) - { - albumArtistPath = albumArtistPath.Substring(0, MaxLength); - } - // Track Artist tag var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?.*?),\"name\":\"(?.*?)\"},\\\"").Groups; var performerName = performerNameLog[2].Value; @@ -5115,12 +5359,6 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) // Display album name in text box under cover art. albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); - // If name goes over 200 characters, limit it to 200 - if (albumNamePath.Length > MaxLength) - { - albumNamePath = albumNamePath.Substring(0, MaxLength); - } - // Track Name tag var trackNameLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\"title\":\"(?.*?)\",\"").Groups; var trackName = trackNameLog[2].Value; @@ -5134,12 +5372,6 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) trackName = trackName.Replace("\\\"", "\"").Replace(@"\\/", @"/").Replace(@"\\", @"\").Replace(@"\/", @"/"); var trackNamePath = trackName.Replace("\\\"", "-").Replace("\"", "-").Replace(@"\", "-").Replace(@"/", "-").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); - // If name goes over 200 characters, limit it to 200 - if (trackNamePath.Length > MaxLength) - { - trackNamePath = trackNamePath.Substring(0, MaxLength).ToString(); - } - // Version Name tag var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?.*?)\",\\\"").Groups; var versionName = versionNameLog[1].Value; @@ -5195,6 +5427,10 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) var isrcLog = Regex.Match(trackRequest, "\"isrc\":\"(?.*?)\",\\\"").Groups; var isrc = isrcLog[1].Value; + // Release Type tag + var typeLog = Regex.Match(trackRequest, "\"release_type\":\"(?.*?)\",\"").Groups; + var type = typeLog[1].Value.ToUpper(); + // Total Tracks tag var trackTotalLog = Regex.Match(trackRequest, "\"tracks_count\":(?[0-9]+),").Groups; var trackTotal = trackTotalLog[1].Value; @@ -5235,6 +5471,24 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) } #endregion + #region Create Shortened Strings + // If name goes over 36 characters, limit it to 36 + if (albumArtistPath.Length > MaxLength) + { + albumArtistPath = albumArtistPath.Substring(0, MaxLength).TrimEnd(); + } + + if (performerNamePath.Length > MaxLength) + { + performerNamePath = performerNamePath.Substring(0, MaxLength).TrimEnd(); + } + + if (albumNamePath.Length > MaxLength) + { + albumNamePath = albumNamePath.Substring(0, MaxLength).TrimEnd(); + } + #endregion + #region Create Directories // Create strings for disc folders string discFolder = null; @@ -5257,6 +5511,33 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) string trackPath = loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + discFolderCreate; #endregion + #region Create Shortened Strings (Again) + // Create final shortened track file names to avoid errors with file names being too long. + if (versionName == null | versionName == "") + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Length > MaxLength) + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNamePath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath).TrimEnd(); + } + + } + else + { + if ((trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Length > MaxLength) + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").Substring(0, MaxLength).TrimEnd(); + } + else + { + finalTrackNameVersionPath = (trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")").TrimEnd(); + } + } + #endregion + #region Availability Check (Streamable?) // Check if available for streaming. var streamCheckLog = Regex.Match(trackRequest, "\"track_number\":(?.*?)\"streamable\":(?.*?),\"").Groups; @@ -5286,7 +5567,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) // Check if there is a version name. if (versionName == null | versionName == "") { - if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + if (System.IO.File.Exists(trackPath + "\\" + finalTrackNamePath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -5300,7 +5581,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) } else { - if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + if (System.IO.File.Exists(trackPath + "\\" + finalTrackNameVersionPath + audioFileType)) { output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); System.Threading.Thread.Sleep(400); @@ -5348,7 +5629,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) if (versionNamePath == null | versionNamePath == "") { // If there is NOT a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType)) { await stream.CopyToAsync(output); } @@ -5356,7 +5637,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType)) + using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType)) { await stream.CopyToAsync(output); } @@ -5398,7 +5679,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -5509,6 +5790,16 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -5521,7 +5812,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); @@ -5632,6 +5923,16 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) tag.SetTextFrame("TSRC", isrc); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)tfile.GetTag(TagTypes.Id3v2, true); + tag.SetTextFrame("TMED", type); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -5651,7 +5952,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) if (versionName == null | versionName == "") { // If there is NOT a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNamePath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -5760,6 +6061,15 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -5772,7 +6082,7 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) else { // If there is a version name. - var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType); + var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + finalTrackNameVersionPath + audioFileType); // For custom / troublesome tags. var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); @@ -5881,6 +6191,15 @@ private async void downloadTrackBG_DoWork(object sender, DoWorkEventArgs e) custom.SetField("ISRC", new string[] { isrc }); } + // Release Type tag + if (type != null) + { + if (typeCheckbox.Checked == true) + { + custom.SetField("MEDIATYPE", new string[] { type }); + } + } + // Explicit tag if (explicitCheckbox.Checked == true) { @@ -6023,6 +6342,12 @@ private void isrcCheckbox_CheckedChanged(object sender, EventArgs e) Settings.Default.Save(); } + private void typeCheckbox_CheckedChanged(object sender, EventArgs e) + { + Settings.Default.typeTag = typeCheckbox.Checked; + Settings.Default.Save(); + } + private void upcCheckbox_CheckedChanged(object sender, EventArgs e) { Settings.Default.upcTag = upcCheckbox.Checked; diff --git a/QobuzDownloaderX/LoginForm-v2.cs b/QobuzDownloaderX/LoginForm-v2.cs index 76c425f..ed25e3d 100644 --- a/QobuzDownloaderX/LoginForm-v2.cs +++ b/QobuzDownloaderX/LoginForm-v2.cs @@ -99,12 +99,18 @@ private void LoginFrm_Load(object sender, EventArgs e) WebClient versionURLClient = new WebClient(); // Run through TLS to allow secure connection. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; - string versionHTML = versionURLClient.DownloadString("https://github.com/ImAiiR/QobuzDownloaderX/releases"); + // Set user-agent to Firefox. + versionURLClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0"); + string versionHTML = versionURLClient.DownloadString("https://api.github.com/repos/ImAiiR/QobuzDownloaderX/releases/latest"); - // Grab link to bundle.js - var versionLog = Regex.Match(versionHTML, "(?.*?)<\\/span>").Groups; + // Grab latest version number + var versionLog = Regex.Match(versionHTML, "\"tag_name\": \"(?.*?)\",").Groups; var version = versionLog[1].Value; + // Grab changelog + var changesLog = Regex.Match(versionHTML, "\"body\": \"(?.*?)\"").Groups; + var changes = changesLog[1].Value; + string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); string newVersion = version; @@ -114,7 +120,7 @@ private void LoginFrm_Load(object sender, EventArgs e) } else { - DialogResult dialogResult = MessageBox.Show("New version of QBDLX is available!\r\n\r\nInstalled version - " + currentVersion + "\r\nLatest version - "+ newVersion + "\r\n\r\nWould you like to update?", "QBDLX | Update Available", MessageBoxButtons.YesNo); + DialogResult dialogResult = MessageBox.Show("New version of QBDLX is available!\r\n\r\nInstalled version - " + currentVersion + "\r\nLatest version - "+ newVersion + "\r\n\r\nChangelog Below\r\n==============\r\n" + changes.Replace("\\r\\n", "\r\n") + "\r\n==============\r\n\r\nWould you like to update?", "QBDLX | Update Available", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { // If "Yes" is clicked, open GitHub page and close QBDLX. diff --git a/QobuzDownloaderX/Properties/AssemblyInfo.cs b/QobuzDownloaderX/Properties/AssemblyInfo.cs index 3436a78..62a6804 100644 --- a/QobuzDownloaderX/Properties/AssemblyInfo.cs +++ b/QobuzDownloaderX/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("0.9.9.15")] -[assembly: AssemblyFileVersion("0.9.9.15")] +[assembly: AssemblyVersion("0.9.9.16")] +[assembly: AssemblyFileVersion("0.9.9.16")] diff --git a/QobuzDownloaderX/Properties/Settings.Designer.cs b/QobuzDownloaderX/Properties/Settings.Designer.cs index 23dd201..38370ff 100644 --- a/QobuzDownloaderX/Properties/Settings.Designer.cs +++ b/QobuzDownloaderX/Properties/Settings.Designer.cs @@ -430,5 +430,17 @@ public int savedArtSize { this["savedArtSize"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool typeTag { + get { + return ((bool)(this["typeTag"])); + } + set { + this["typeTag"] = value; + } + } } } diff --git a/QobuzDownloaderX/Properties/Settings.settings b/QobuzDownloaderX/Properties/Settings.settings index 67fb6c7..3316b37 100644 --- a/QobuzDownloaderX/Properties/Settings.settings +++ b/QobuzDownloaderX/Properties/Settings.settings @@ -104,5 +104,8 @@ 1 + + True + \ No newline at end of file