This commit is contained in:
AiiR 2020-01-09 05:34:23 -05:00
parent 272babb837
commit 4e14909b22
3 changed files with 121 additions and 105 deletions

View File

@ -506,7 +506,7 @@ namespace QobuzDownloaderX
foreach (Match mtrack in Regex.Matches(trackinput, trackIdspattern, trackoptions)) foreach (Match mtrack in Regex.Matches(trackinput, trackIdspattern, trackoptions))
{ {
// Set default value for max length. // Set default value for max length.
const int MaxLength = 100; const int MaxLength = 36;
//output.Invoke(new Action(() => output.AppendText(string.Format("{0}\r\n", m.Groups["trackId"].Value)))); //output.Invoke(new Action(() => output.AppendText(string.Format("{0}\r\n", m.Groups["trackId"].Value))));
trackIdString = string.Format("{0}", mtrack.Groups["trackId"].Value); trackIdString = string.Format("{0}", mtrack.Groups["trackId"].Value);
@ -769,7 +769,7 @@ namespace QobuzDownloaderX
// Check if there is a version name. // Check if there is a version name.
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType)) if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -778,7 +778,7 @@ namespace QobuzDownloaderX
} }
else else
{ {
if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) if (System.IO.File.Exists(discogPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -817,10 +817,10 @@ namespace QobuzDownloaderX
using (var stream = await client.GetStreamAsync(testURLBox.Text)) using (var stream = await client.GetStreamAsync(testURLBox.Text))
// Save single track in selected path. // Save single track in selected path.
if (versionName == null | versionName == "") if (versionNamePath == null | versionNamePath == "")
{ {
// If there is NOT a version name. // 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 + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -828,7 +828,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -864,7 +864,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -987,7 +987,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -1117,7 +1117,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -1238,7 +1238,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + " [" + albumIdDiscog + "]" + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -1389,7 +1389,7 @@ namespace QobuzDownloaderX
{ {
// If there is an issue trying to, or during the download, show error info. // If there is an issue trying to, or during the download, show error info.
string error = downloadError.ToString(); string error = downloadError.ToString();
output.Invoke(new Action(() => output.Text = String.Empty)); output.Invoke(new Action(() => output.AppendText("\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n"))); output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText(error))); output.Invoke(new Action(() => output.AppendText(error)));
output.Invoke(new Action(() => output.AppendText("\r\n\r\nIf some tracks aren't available for streaming on the album you're trying to download, try to manually download the available tracks individually."))); output.Invoke(new Action(() => output.AppendText("\r\n\r\nIf some tracks aren't available for streaming on the album you're trying to download, try to manually download the available tracks individually.")));
@ -1536,7 +1536,7 @@ namespace QobuzDownloaderX
foreach (Match m in Regex.Matches(input, trackIdspattern, options)) foreach (Match m in Regex.Matches(input, trackIdspattern, options))
{ {
// Set default value for max length. // Set default value for max length.
const int MaxLength = 100; const int MaxLength = 36;
// Grab matches for Track IDs // Grab matches for Track IDs
trackIdString = string.Format("{0}", m.Groups["trackId"].Value); trackIdString = string.Format("{0}", m.Groups["trackId"].Value);
@ -1584,40 +1584,42 @@ namespace QobuzDownloaderX
var albumArtistLog = Regex.Match(trackRequest, "\"artist\":{\"picture\":(?<notUsed1>.*?),\"id\"(?<notUsed2>.*?),\"albums_count\":(?<notUsed3>.*?),\"name\":\"(?<albumArtist>.*?)\",\\\"").Groups; var albumArtistLog = Regex.Match(trackRequest, "\"artist\":{\"picture\":(?<notUsed1>.*?),\"id\"(?<notUsed2>.*?),\"albums_count\":(?<notUsed3>.*?),\"name\":\"(?<albumArtist>.*?)\",\\\"").Groups;
var albumArtist = albumArtistLog[4].Value; var albumArtist = albumArtistLog[4].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeAlbumArtist = albumArtist; string unicodeAlbumArtist = albumArtist;
string decodedAlbumArtist = DecodeEncodedNonAsciiCharacters(unicodeAlbumArtist); string decodedAlbumArtist = DecodeEncodedNonAsciiCharacters(unicodeAlbumArtist);
albumArtist = decodedAlbumArtist; albumArtist = decodedAlbumArtist;
albumArtist = albumArtist.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes & path unfriendly characters
var albumArtistPath = albumArtist.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); albumArtist = albumArtist.Replace(@"\\", @"\").Replace(@"\/", @"/");
var albumArtistPath = albumArtist.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-");
// Display album artist in text box under cover art. // Display album artist in text box under cover art.
albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist)); albumArtistTextBox.Invoke(new Action(() => albumArtistTextBox.Text = albumArtist));
// If name goes over 200 characters, limit it to 200 // If name goes over 200 characters, limit it to 200
if (albumArtistPath.Length > MaxLength) if (albumArtistPath.Length > MaxLength)
{ {
albumArtistPath = albumArtistPath.Substring(0, MaxLength); albumArtistPath = albumArtistPath.Substring(0, MaxLength);
} }
// Track Artist tag // Track Artist tag
var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?<notUsed>.*?),\"name\":\"(?<trackArtist>.*?)\"},\\\"").Groups; var performerNameLog = Regex.Match(trackRequest, "\"performer\":{\"id\":(?<notUsed>.*?),\"name\":\"(?<trackArtist>.*?)\"},\\\"").Groups;
var performerName = performerNameLog[2].Value; var performerName = performerNameLog[2].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodePerformerName = performerName; string unicodePerformerName = performerName;
string decodedPerformerName = DecodeEncodedNonAsciiCharacters(unicodePerformerName); string decodedPerformerName = DecodeEncodedNonAsciiCharacters(unicodePerformerName);
performerName = decodedPerformerName; performerName = decodedPerformerName;
performerName = performerName.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes & path unfriendly characters
var performerNamePath = performerName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); performerName = performerName.Replace(@"\\", @"\").Replace(@"\/", @"/");
var performerNamePath = performerName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-");
// If name goes over 200 characters, limit it to 200 // If name goes over 200 characters, limit it to 200
if (performerNamePath.Length > MaxLength) if (performerNamePath.Length > MaxLength)
{ {
performerNamePath = performerNamePath.Substring(0, MaxLength); performerNamePath = performerNamePath.Substring(0, MaxLength);
} }
// Track Composer tag // Track Composer tag
var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?<notUsed>.*?),\"name\":\"(?<composer>.*?)\"},\\\"").Groups; var composerNameLog = Regex.Match(trackRequest, "\"composer\":{\"id\":(?<notUsed>.*?),\"name\":\"(?<composer>.*?)\"},\\\"").Groups;
@ -1627,91 +1629,101 @@ namespace QobuzDownloaderX
var advisoryLog = Regex.Match(trackRequest, "\"performers\":(?:.*?)\"parental_warning\":(?<composer>.*?),").Groups; var advisoryLog = Regex.Match(trackRequest, "\"performers\":(?:.*?)\"parental_warning\":(?<composer>.*?),").Groups;
var advisory = advisoryLog[1].Value; var advisory = advisoryLog[1].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeComposerName = composerName; string unicodeComposerName = composerName;
string decodedComposerName = DecodeEncodedNonAsciiCharacters(unicodeComposerName); string decodedComposerName = DecodeEncodedNonAsciiCharacters(unicodeComposerName);
composerName = decodedComposerName; composerName = decodedComposerName;
composerName = composerName.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes
composerName = composerName.Replace(@"\\", @"\").Replace(@"\/", @"/");
// Album Name tag // Album Name tag
var albumNameLog = Regex.Match(trackRequest, "\"title\":\"(?<albumTitle>.*?)\",\\\"").Groups; var albumNameLog = Regex.Match(trackRequest, "\"title\":\"(?<albumTitle>.*?)\",\\\"").Groups;
var albumName = albumNameLog[1].Value; var albumName = albumNameLog[1].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeAlbumName = albumName; string unicodeAlbumName = albumName;
string decodedAlbumName = DecodeEncodedNonAsciiCharacters(unicodeAlbumName); string decodedAlbumName = DecodeEncodedNonAsciiCharacters(unicodeAlbumName);
albumName = decodedAlbumName; albumName = decodedAlbumName;
albumName = albumName.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes & path unfriendly characters
var albumNamePath = albumName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); albumName = albumName.Replace(@"\\", @"\").Replace(@"\/", @"/");
var albumNamePath = albumName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-");
// Display album name in text box under cover art. // Display album name in text box under cover art.
albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName)); albumTextBox.Invoke(new Action(() => albumTextBox.Text = albumName));
// If name goes over 200 characters, limit it to 200 // If name goes over 200 characters, limit it to 200
if (albumNamePath.Length > MaxLength) if (albumNamePath.Length > MaxLength)
{ {
albumNamePath = albumNamePath.Substring(0, MaxLength); albumNamePath = albumNamePath.Substring(0, MaxLength);
} }
// Track Name tag // Track Name tag
var trackNameLog = Regex.Match(trackRequest, "\"version\":(?<notUsed1>.*?),\"id\":(?<notUsed2>.*?),\"maximum_bit_depth\":(?<notUsed3>.*?),\"title\":\"(?<trackName>.*?)\",\\\"").Groups; var trackNameLog = Regex.Match(trackRequest, "\"version\":(?<notUsed1>.*?),\"id\":(?<notUsed2>.*?),\"maximum_bit_depth\":(?<notUsed3>.*?),\"title\":\"(?<trackName>.*?)\",\\\"").Groups;
var trackName = trackNameLog[4].Value; var trackName = trackNameLog[4].Value;
trackName = trackName.Trim(); // Remove spaces from end of track name trackName = trackName.Trim(); // Remove spaces from end of track name
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeTrackName = trackName; string unicodeTrackName = trackName;
string decodedTrackName = DecodeEncodedNonAsciiCharacters(unicodeTrackName); string decodedTrackName = DecodeEncodedNonAsciiCharacters(unicodeTrackName);
trackName = decodedTrackName; trackName = decodedTrackName;
trackName = trackName.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes & path unfriendly characters
var trackNamePath = trackName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); trackName = trackName.Replace(@"\\", @"\").Replace(@"\/", @"/");
var trackNamePath = trackName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-");
// If name goes over 200 characters, limit it to 200 // If name goes over 200 characters, limit it to 200
if (trackNamePath.Length > MaxLength) if (trackNamePath.Length > MaxLength)
{ {
trackNamePath = trackNamePath.Substring(0, MaxLength); trackNamePath = trackNamePath.Substring(0, MaxLength);
} }
// Version Name tag // Version Name tag
var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?<version>.*?)\",\\\"").Groups; var versionNameLog = Regex.Match(trackRequest, "\"version\":\"(?<version>.*?)\",\\\"").Groups;
var versionName = versionNameLog[1].Value; var versionName = versionNameLog[1].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeVersionName = versionName; string unicodeVersionName = versionName;
string decodedVersionName = DecodeEncodedNonAsciiCharacters(unicodeVersionName); string decodedVersionName = DecodeEncodedNonAsciiCharacters(unicodeVersionName);
versionName = decodedVersionName; versionName = decodedVersionName;
versionName = versionName.Replace(@"\\", @"\").Replace(@"\/", @"/"); // Replace double slashes & path unfriendly characters
var versionNamePath = versionName.Replace(@"\", "-").Replace(@"/", "-").Replace("\"", "''").Replace(":", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace("?", "-").Replace("*", "-"); versionName = versionName.Replace(@"\\", @"\").Replace(@"\/", @"/");
var versionNamePath = versionName.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 // Genre tag
var genreLog = Regex.Match(trackRequest, "\"genre\":{\"id\":(?<notUsed>.*?),\"color\":\"(?<notUsed2>.*?)\",\"name\":\"(?<genreName>.*?)\",\\\"").Groups; var genreLog = Regex.Match(trackRequest, "\"genre\":{\"id\":(?<notUsed>.*?),\"color\":\"(?<notUsed2>.*?)\",\"name\":\"(?<genreName>.*?)\",\\\"").Groups;
var genre = genreLog[3].Value; var genre = genreLog[3].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeGenre = genre; string unicodeGenre = genre;
string decodedGenre = DecodeEncodedNonAsciiCharacters(unicodeGenre); string decodedGenre = DecodeEncodedNonAsciiCharacters(unicodeGenre);
genre = decodedGenre; genre = decodedGenre;
// Release Date tag, grabs the available "stream" date // Release Date tag, grabs the available "stream" date
var releaseDateLog = Regex.Match(trackRequest, "\"release_date_stream\":\"(?<releaseDate>.*?)\",\\\"").Groups; var releaseDateLog = Regex.Match(trackRequest, "\"release_date_stream\":\"(?<releaseDate>.*?)\",\\\"").Groups;
var releaseDate = releaseDateLog[1].Value; var releaseDate = releaseDateLog[1].Value;
// Display release date in text box under cover art. // Display release date in text box under cover art.
releaseDateTextBox.Invoke(new Action(() => releaseDateTextBox.Text = releaseDate)); releaseDateTextBox.Invoke(new Action(() => releaseDateTextBox.Text = releaseDate));
// Copyright tag // Copyright tag
var copyrightLog = Regex.Match(trackRequest, "\"copyright\":\"(?<notUsed>.*?)\"copyright\":\"(?<copyrigh>.*?)\\\"").Groups; var copyrightLog = Regex.Match(trackRequest, "\"copyright\":\"(?<notUsed>.*?)\"copyright\":\"(?<copyrigh>.*?)\\\"").Groups;
var copyright = copyrightLog[2].Value; var copyright = copyrightLog[2].Value;
// For converting unicode characters to ASCII // For converting unicode characters to ASCII
string unicodeCopyright = copyright; string unicodeCopyright = copyright;
string decodedCopyright = DecodeEncodedNonAsciiCharacters(unicodeCopyright); string decodedCopyright = DecodeEncodedNonAsciiCharacters(unicodeCopyright);
copyright = decodedCopyright; copyright = decodedCopyright;
copyright = copyright.Replace(@"\\", @"\").Replace(@"\/", @"/").Replace(@"\u2117", @"℗"); copyright = copyright.Replace(@"\\", @"\").Replace(@"\/", @"/").Replace(@"\u2117", @"℗");
// UPC tag // UPC tag
var upcLog = Regex.Match(trackRequest, "\"upc\":\"(?<upc>.*?)\",\\\"").Groups; var upcLog = Regex.Match(trackRequest, "\"upc\":\"(?<upc>.*?)\",\\\"").Groups;
@ -1805,7 +1817,7 @@ namespace QobuzDownloaderX
// Check if there is a version name. // Check if there is a version name.
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType)) if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -1814,7 +1826,7 @@ namespace QobuzDownloaderX
} }
else else
{ {
if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) if (System.IO.File.Exists(albumPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -1854,10 +1866,10 @@ namespace QobuzDownloaderX
using (var stream = await client.GetStreamAsync(testURLBox.Text)) using (var stream = await client.GetStreamAsync(testURLBox.Text))
// Save single track in selected path. // Save single track in selected path.
if (versionName == null | versionName == "") if (versionNamePath == null | versionNamePath == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -1865,7 +1877,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -1898,7 +1910,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -2021,7 +2033,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -2151,7 +2163,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -2272,7 +2284,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -2430,7 +2442,7 @@ namespace QobuzDownloaderX
{ {
// If there is an issue trying to, or during the download, show error info. // If there is an issue trying to, or during the download, show error info.
string error = downloadError.ToString(); string error = downloadError.ToString();
output.Invoke(new Action(() => output.Text = String.Empty)); output.Invoke(new Action(() => output.AppendText("\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n"))); output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText(error))); output.Invoke(new Action(() => output.AppendText(error)));
downloadButton.Invoke(new Action(() => downloadButton.Enabled = true)); downloadButton.Invoke(new Action(() => downloadButton.Enabled = true));
@ -2464,7 +2476,7 @@ namespace QobuzDownloaderX
{ {
#region If URL has "track" #region If URL has "track"
// Set default value for max length. // Set default value for max length.
const int MaxLength = 100; const int MaxLength = 36;
// Set "loc" as the selected path. // Set "loc" as the selected path.
String loc = folderBrowserDialog.SelectedPath; String loc = folderBrowserDialog.SelectedPath;
@ -2785,7 +2797,7 @@ namespace QobuzDownloaderX
// Check if there is a version name. // Check if there is a version name.
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType)) if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -2795,7 +2807,7 @@ namespace QobuzDownloaderX
} }
else else
{ {
if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) if (System.IO.File.Exists(trackPath + "\\" + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n"))); output.Invoke(new Action(() => output.AppendText("File for \"" + trackNumber.PadLeft(paddingLength, '0') + " " + trackName + " (" + versionName + ")" + "\" already exists. Skipping.\r\n")));
System.Threading.Thread.Sleep(800); System.Threading.Thread.Sleep(800);
@ -2836,10 +2848,10 @@ namespace QobuzDownloaderX
using (var stream = await client.GetStreamAsync(testURLBox.Text)) using (var stream = await client.GetStreamAsync(testURLBox.Text))
// Save single track in selected path. // Save single track in selected path.
if (versionName == null | versionName == "") if (versionNamePath == null | versionNamePath == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -2847,7 +2859,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)) using (var output = System.IO.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType))
{ {
await stream.CopyToAsync(output); await stream.CopyToAsync(output);
} }
@ -2880,7 +2892,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -3003,7 +3015,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2); TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)tfile.GetTag(TagLib.TagTypes.Id3v2);
@ -3133,7 +3145,7 @@ namespace QobuzDownloaderX
if (versionName == null | versionName == "") if (versionName == null | versionName == "")
{ {
// If there is NOT a version name. // If there is NOT a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -3254,7 +3266,7 @@ namespace QobuzDownloaderX
else else
{ {
// If there is a version name. // If there is a version name.
var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType); var tfile = TagLib.File.Create(loc + "\\" + albumArtistPath + "\\" + albumNamePath + "\\" + qualityPath + "\\" + discFolder + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath.Trim() + " (" + versionNamePath + ")" + audioFileType);
// For custom / troublesome tags. // For custom / troublesome tags.
var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph); var custom = (TagLib.Ogg.XiphComment)tfile.GetTag(TagLib.TagTypes.Xiph);
@ -3380,9 +3392,9 @@ namespace QobuzDownloaderX
{ {
// If there is an issue trying to, or during the download, show error info. // If there is an issue trying to, or during the download, show error info.
string error = downloadError.ToString(); string error = downloadError.ToString();
output.Invoke(new Action(() => output.AppendText("\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n"))); output.Invoke(new Action(() => output.AppendText("Track Download ERROR. Information below.\r\n\r\n")));
output.Invoke(new Action(() => output.AppendText(error))); output.Invoke(new Action(() => output.AppendText(error)));
output.Invoke(new Action(() => output.AppendText("\r\nTrack name path = " + trackNumber.PadLeft(paddingLength, '0') + " " + trackNamePath + " (" + versionNamePath + ")" + audioFileType)));
downloadButton.Invoke(new Action(() => downloadButton.Enabled = true)); downloadButton.Invoke(new Action(() => downloadButton.Enabled = true));
return; return;
} }

View File

@ -232,6 +232,7 @@ namespace QobuzDownloaderX
Settings.Default.Save(); Settings.Default.Save();
loginText.Text = "Logging in + obtaining app_secret..."; loginText.Text = "Logging in + obtaining app_secret...";
loginButton.Enabled = false;
loginBG.RunWorkerAsync(); loginBG.RunWorkerAsync();
} }
@ -441,6 +442,7 @@ namespace QobuzDownloaderX
loginText.Invoke(new Action(() => loginText.Text = "Login Failed. Error Log saved")); loginText.Invoke(new Action(() => loginText.Text = "Login Failed. Error Log saved"));
System.IO.File.WriteAllText(errorLog, error); System.IO.File.WriteAllText(errorLog, error);
wr.Abort(); wr.Abort();
loginButton.Invoke(new Action(() => loginButton.Enabled = true));
return; return;
} }
@ -505,6 +507,7 @@ namespace QobuzDownloaderX
loginText.Invoke(new Action(() => loginText.Text = "Couldn't obtain app_secret. Error Log saved")); loginText.Invoke(new Action(() => loginText.Text = "Couldn't obtain app_secret. Error Log saved"));
System.IO.File.WriteAllText(errorLog, bundleError); System.IO.File.WriteAllText(errorLog, bundleError);
bundleWR.Abort(); bundleWR.Abort();
loginButton.Invoke(new Action(() => loginButton.Enabled = true));
return; return;
} }
@ -515,6 +518,7 @@ namespace QobuzDownloaderX
private void finishLogin(object sender, EventArgs e) private void finishLogin(object sender, EventArgs e)
{ {
loginButton.Invoke(new Action(() => loginButton.Enabled = true));
// If info is legit, go to the main form. // If info is legit, go to the main form.
qbdlx.appid = appidTextbox.Text; qbdlx.appid = appidTextbox.Text;
qbdlx.eMail = emailTextbox.Text; qbdlx.eMail = emailTextbox.Text;

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.9.6")] [assembly: AssemblyVersion("0.9.9.7")]
[assembly: AssemblyFileVersion("0.9.9.6")] [assembly: AssemblyFileVersion("0.9.9.7")]