Skip to content

Commit

Permalink
1.0.0.3
Browse files Browse the repository at this point in the history
Added search and debug logging (mostly)
  • Loading branch information
ImAiiR committed Oct 21, 2024
1 parent 366d1f5 commit 6d460ab
Show file tree
Hide file tree
Showing 18 changed files with 1,018 additions and 111 deletions.
53 changes: 41 additions & 12 deletions QobuzDownloaderX/Download/DownloadAlbum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DownloadAlbum
public Album QoAlbum = new Album();
public Item QoItem = new Item();
public QopenAPI.Stream QoStream = new QopenAPI.Stream();

public int paddedTrackLength { get; set; }
public int paddedDiscLength { get; set; }

Expand All @@ -45,39 +45,50 @@ class DownloadAlbum

public Item getTrackInfoLabels(string app_id, string track_id, string user_auth_token)
{
qbdlxForm._qbdlxForm.logger.Debug("Grabbing track info...");
try
{
// Grab album info with auth
getInfo.outputText = null;
getInfo.updateDownloadOutput("Getting Track Info...");
QoItem = QoService.TrackGetWithAuth(app_id, track_id, user_auth_token);
qbdlxForm._qbdlxForm.logger.Debug("Grabbed QoItem");
string album_id = QoItem.Album.Id;
qbdlxForm._qbdlxForm.logger.Info("Album ID: " + album_id);
QoAlbum = QoService.AlbumGetWithAuth(app_id, album_id, user_auth_token);
qbdlxForm._qbdlxForm.logger.Debug("Grabbed QoAlbum");
return QoItem;
}
catch (Exception getAlbumInfoLabelsEx)
catch (Exception getTrackInfoLabelsEx)
{
getInfo.updateDownloadOutput("\r\n" + getAlbumInfoLabelsEx.ToString());
Console.WriteLine(getAlbumInfoLabelsEx);
qbdlxForm._qbdlxForm.logger.Error("Error occured during getTrackInfoLabels, error below:\r\n" + getTrackInfoLabelsEx);
getInfo.updateDownloadOutput("\r\n" + getTrackInfoLabelsEx.ToString());
Console.WriteLine(getTrackInfoLabelsEx);
return null;
}
}

public void downloadAlbum(string app_id, string album_id, string format_id, string audio_format, string user_auth_token, string app_secret, string downloadLocation, string artistTemplate, string albumTemplate, string trackTemplate, Album QoAlbum)
{
qbdlxForm._qbdlxForm.logger.Debug("Starting album download (downloadAlbum)");
// Clear output text from DownloadTrack to avoid text from previous downloads sticking around.
qbdlxForm._qbdlxForm.logger.Debug("Clearing output text");
downloadTrack.clearOutputText();
getInfo.outputText = null;

if (QoAlbum.Streamable == false)
{
if (Settings.Default.streamableCheck == true)
{
qbdlxForm._qbdlxForm.logger.Debug("Steamable tag is set to false on Qobuz, and streamable check is enabled, skipping download");
getInfo.updateDownloadOutput("Release is not available for streaming.");
getInfo.updateDownloadOutput("\r\n" + "DOWNLOAD COMPLETE");
return;
}
else { }
else
{
qbdlxForm._qbdlxForm.logger.Debug("Steamable tag is set to false on Qobuz, but streamable check is disabled, attempting download");
}
}

try
Expand All @@ -86,12 +97,16 @@ public void downloadAlbum(string app_id, string album_id, string format_id, stri
paddedDiscLength = padNumber.padTracks(QoAlbum);

downloadPath = downloadFile.createPath(downloadLocation, artistTemplate, albumTemplate, trackTemplate, null, null, paddedTrackLength, paddedDiscLength, QoAlbum, null, null);
qbdlxForm._qbdlxForm.logger.Debug("Download path: " + downloadPath);

try
{
qbdlxForm._qbdlxForm.logger.Debug("Downloading artwork...");
downloadFile.downloadArtwork(downloadPath, QoAlbum);
qbdlxForm._qbdlxForm.logger.Debug("Artwork download complete");
}
catch {
catch (Exception artworkEx) {
qbdlxForm._qbdlxForm.logger.Error("Artwork download failed, error below:\r\n" + artworkEx);
Console.WriteLine("Unable to download artwork");
}

Expand All @@ -100,47 +115,55 @@ public void downloadAlbum(string app_id, string album_id, string format_id, stri
{
try
{
qbdlxForm._qbdlxForm.logger.Debug("Downloading track...");
downloadTrack.downloadTrack(app_id, album_id, format_id, audio_format, user_auth_token, app_secret, downloadLocation, artistTemplate, albumTemplate, trackTemplate, QoAlbum, QoService.TrackGetWithAuth(app_id, item.Id.ToString(), user_auth_token));
qbdlxForm._qbdlxForm.logger.Debug("Track download complete");
}
catch (Exception downloadAlbumEx)
catch (Exception downloadTrackEx)
{
getInfo.updateDownloadOutput("\r\n" + downloadAlbumEx);
Console.WriteLine(downloadAlbumEx);
qbdlxForm._qbdlxForm.logger.Error("Track download failed, error below:\r\n" + downloadTrackEx);
getInfo.updateDownloadOutput("\r\n" + downloadTrackEx);
Console.WriteLine(downloadTrackEx);
return;
}
}

// Delete image used for embedded artwork
// Delete image used for embedding artwork
try
{
qbdlxForm._qbdlxForm.logger.Debug("Deleting artwork used for embedding");
System.IO.File.Delete(downloadPath + qbdlxForm._qbdlxForm.embeddedArtSize + @".jpg");
}
catch
{
Console.WriteLine("Unable to delete artwork");
qbdlxForm._qbdlxForm.logger.Warning("Unable to delete artwork used for embedding");
}

try
{
foreach (var goody in QoAlbum.Goodies)
{
qbdlxForm._qbdlxForm.logger.Debug("Goodies found, attempting to download...");
getInfo.updateDownloadOutput("Goodies found, attempting to download...");
if (goody.Url == null)
{
qbdlxForm._qbdlxForm.logger.Warning("No URL found for the goody, skipping");
Console.WriteLine("No goody URL, skipping");
getInfo.updateDownloadOutput(" No download URL found, skipping" + "\r\n");
}
else
{
qbdlxForm._qbdlxForm.logger.Debug("Downloading goody...");
Console.WriteLine("Downloading goody");
downloadFile.downloadGoody(downloadPath, QoAlbum, goody);
qbdlxForm._qbdlxForm.logger.Debug("Goody download complete");
getInfo.updateDownloadOutput(" DONE" + "\r\n");
}
}
}
catch
{

qbdlxForm._qbdlxForm.logger.Warning("No goodies found, or goodies failed to download");
}

//if (Settings.Default.fixMD5s == true)
Expand All @@ -154,9 +177,11 @@ public void downloadAlbum(string app_id, string album_id, string format_id, stri

// Say the downloading is finished when it's completed.
getInfo.outputText = qbdlxForm._qbdlxForm.downloadOutput.Text;
qbdlxForm._qbdlxForm.logger.Debug("All downloads completed!");
getInfo.updateDownloadOutput("\r\n" + "DOWNLOAD COMPLETE");

// JAM.S Post Template Export, not really useful for normal users.
qbdlxForm._qbdlxForm.logger.Debug("Writing a post template to post_template.txt");
var templateDate = DateTime.Parse(QoAlbum.ReleaseDateOriginal).ToString("MMMM d, yyyy");
File.WriteAllText("post_template.txt", String.Empty);
using (StreamWriter sw = File.AppendText("post_template.txt"))
Expand Down Expand Up @@ -188,16 +213,19 @@ public void downloadAlbum(string app_id, string album_id, string format_id, stri
sw.WriteLine("[spoiler=" + QoAlbum.Label.Name + " / " + QoAlbum.UPC + " / WEB]");
sw.WriteLine("[format=FLAC / Lossless (24bit/??kHz) / WEB]");
sw.WriteLine("Uploaded by [USER=2]@AiiR[/USER]");
sw.WriteLine("");
sw.WriteLine("DOWNLOAD");
sw.WriteLine("REPLACE THIS WITH URL");
sw.WriteLine("[/format]");
sw.WriteLine("[format=FLAC / Lossless / WEB]");
sw.WriteLine("Uploaded by [USER=2]@AiiR[/USER]");
sw.WriteLine("");
sw.WriteLine("DOWNLOAD");
sw.WriteLine("REPLACE THIS WITH URL");
sw.WriteLine("[/format]");
sw.WriteLine("[format=MP3 / 320 / WEB]");
sw.WriteLine("Uploaded by [USER=2]@AiiR[/USER]");
sw.WriteLine("");
sw.WriteLine("DOWNLOAD");
sw.WriteLine("REPLACE THIS WITH URL");
sw.WriteLine("[/format]");
Expand All @@ -211,6 +239,7 @@ public void downloadAlbum(string app_id, string album_id, string format_id, stri
}
catch (Exception downloadAlbumEx)
{
qbdlxForm._qbdlxForm.logger.Error("Error occured during downloadAlbum, error below:\r\n" + downloadAlbumEx);
Console.WriteLine(downloadAlbumEx);
return;
}
Expand Down
20 changes: 14 additions & 6 deletions QobuzDownloaderX/Download/DownloadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public string createPath(string downloadLocation, string artistTemplate, string
{
if (QoPlaylist == null)
{
qbdlxForm._qbdlxForm.logger.Debug("Using non-playlist path");
artistTemplateConverted = renameTemplates.renameTemplates(artistTemplate, paddedTrackLength, paddedDiscLength, qbdlxForm._qbdlxForm.audio_format, QoAlbum, null, null);
albumTemplateConverted = renameTemplates.renameTemplates(albumTemplate, paddedTrackLength, paddedDiscLength, qbdlxForm._qbdlxForm.audio_format, QoAlbum, null, null);
downloadPath = Path.Combine(downloadLocation, artistTemplateConverted, albumTemplateConverted.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);

return downloadPath;
}
else
{
qbdlxForm._qbdlxForm.logger.Debug("Using playlist path");
playlistTemplateConverted = renameTemplates.renameTemplates(playlistTemplate, paddedTrackLength, paddedDiscLength, qbdlxForm._qbdlxForm.audio_format, null, null, QoPlaylist);
downloadPath = Path.Combine(downloadLocation, playlistTemplateConverted.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar);

Expand All @@ -49,23 +51,26 @@ public string createPath(string downloadLocation, string artistTemplate, string

public void downloadStream(string streamUrl, string downloadPath, string filePath, string audio_format, Album QoAlbum, Item QoItem)
{
qbdlxForm._qbdlxForm.logger.Debug("Writing temp file to qbdlx-temp/qbdlx_downloading-" + QoItem.Id.ToString() + audio_format);
// Create a temp directory inside the exe location, to download files to.
string tempFile = Path.Combine(@"qbdlx-temp", "qbdlx_downloading" + audio_format);
string tempFile = Path.Combine(@"qbdlx-temp", "qbdlx_downloading-" + QoItem.Id.ToString() + audio_format);
Directory.CreateDirectory(@"qbdlx-temp");

using (var client = new WebClient())
{
// Set path for downloaded artwork.
artworkPath = downloadPath + qbdlxForm._qbdlxForm.embeddedArtSize + @".jpg";
qbdlxForm._qbdlxForm.logger.Debug("Artwork path: " + artworkPath);

// Use secure connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

// Download to the temp directory that was made, and tag the file
Console.WriteLine("Downloading");
qbdlxForm._qbdlxForm.logger.Debug("Downloading to temp file...");
Console.WriteLine(filePath);
if (QoAlbum.MediaCount > 1)
{
qbdlxForm._qbdlxForm.logger.Debug("More than 1 volume, using subfolders for each volume");
Directory.CreateDirectory(Path.GetDirectoryName(downloadPath + "CD " + QoItem.MediaNumber.ToString().PadLeft(paddingNumbers.padDiscs(QoAlbum), '0') + Path.DirectorySeparatorChar));
}
else
Expand All @@ -83,9 +88,11 @@ public void downloadStream(string streamUrl, string downloadPath, string filePat
}
}

qbdlxForm._qbdlxForm.logger.Debug("Starting file metadata tagging");
TagFile.WriteToFile(tempFile, artworkPath, QoAlbum, QoItem);

// Move the file with the full name (Zeta Long Paths to avoid MAX_PATH error)
qbdlxForm._qbdlxForm.logger.Debug("Moving temp file to - " + filePath);
ZetaLongPaths.ZlpIOHelper.MoveFile(tempFile, filePath);
}
}
Expand All @@ -98,15 +105,17 @@ public void downloadArtwork(string downloadPath, Album QoAlbum)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

// Download cover art (600x600) to the download path
Console.WriteLine("Downloading Cover Art");
qbdlxForm._qbdlxForm.logger.Debug("Downloading Cover Art");
Directory.CreateDirectory(Path.GetDirectoryName(downloadPath));

if (File.Exists(downloadPath + @"Cover.jpg") == false)
{
qbdlxForm._qbdlxForm.logger.Debug("Saved artwork Cover.jpg not found, downloading");
try { client.DownloadFile(QoAlbum.Image.Large.Replace("_600", "_" + qbdlxForm._qbdlxForm.savedArtSize), downloadPath + @"Cover.jpg"); } catch { Console.WriteLine("Failed to Download Cover Art"); }
}
if (File.Exists(downloadPath + qbdlxForm._qbdlxForm.embeddedArtSize + @".jpg") == false)
{
qbdlxForm._qbdlxForm.logger.Debug("Saved artwork for embedding not found, downloading");
try { client.DownloadFile(QoAlbum.Image.Large.Replace("_600", "_" + qbdlxForm._qbdlxForm.embeddedArtSize), downloadPath + qbdlxForm._qbdlxForm.embeddedArtSize + @".jpg"); } catch { Console.WriteLine("Failed to Download Cover Art"); }
}
}
Expand All @@ -119,8 +128,7 @@ public void downloadGoody(string downloadPath, Album QoAlbum, Goody QoGoody)
// Use secure connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

// Download cover art (600x600) to the download path
Console.WriteLine("Downloading Goody");
// Download goody to the download path
Directory.CreateDirectory(Path.GetDirectoryName(downloadPath));
client.DownloadFile(QoGoody.Url, downloadPath + QoAlbum.Title + " (" + QoGoody.Id + @").pdf");
}
Expand Down
2 changes: 1 addition & 1 deletion QobuzDownloaderX/Download/DownloadTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void downloadTrack(string app_id, string album_id, string format_id, stri
{
downloadPath = downloadFile.createPath(downloadLocation, artistTemplate, albumTemplate, trackTemplate, null, null, paddedTrackLength, paddedDiscLength, QoAlbum, QoItem, null);

try { downloadFile.downloadArtwork(downloadPath, QoAlbum); } catch { Console.WriteLine("Failed to Download Cover Art"); }
try { downloadFile.downloadArtwork(downloadPath, QoAlbum); } catch { qbdlxForm._qbdlxForm.logger.Error("Failed to Download Cover Art"); }

string trackTemplateConverted = renameTemplates.renameTemplates(trackTemplate, paddedTrackLength, paddedDiscLength, audio_format, QoAlbum, QoItem, null);

Expand Down
12 changes: 5 additions & 7 deletions QobuzDownloaderX/Download/FixMD5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ class FixMD5

public void fixMD5(string filePath, string flacEXEPath)
{
Console.WriteLine("Attempting to fix unset MD5...");
qbdlxForm._qbdlxForm.logger.Debug("Attempting to fix unset MD5...");
driveLetter = filePath.Substring(0, 2);
Console.WriteLine("Drive letter - " + driveLetter);
Console.WriteLine("File Path - " + filePath);
Console.WriteLine("FLAC exe Path - " + flacEXEPath);
cmdText = "/C echo Fixing unset MD5s... & \"" + flacEXEPath + "\" -f8 \"" + filePath + "\"";
Console.WriteLine("Commands - " + cmdText);
qbdlxForm._qbdlxForm.logger.Debug("Commands - " + cmdText);

try
{
qbdlxForm._qbdlxForm.logger.Debug("Running cmd to run ffmpeg command to fix MD5");
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.Arguments = cmdText;
cmd.Start();
cmd.WaitForExit();
outputResult = "COMPLETE";
qbdlxForm._qbdlxForm.logger.Debug("MD5 has been fixed for file!");
}
catch (Exception fixMD5ex)
{
outputResult = "Failed";
Console.WriteLine("Failed to fix MD5s");
Console.WriteLine(fixMD5ex);
qbdlxForm._qbdlxForm.logger.Error("Failed to fix MD5s, error below:\r\n" + fixMD5ex);
}
}
}
Expand Down
Loading

0 comments on commit 6d460ab

Please sign in to comment.