Skip to content

Commit

Permalink
radio@driglu4it: Add more debug information (#6802)
Browse files Browse the repository at this point in the history
* Enhancements to error handling and logging:
    * radio@driglu4it/files/radio@driglu4it/6.4/radio-applet.js: Modify the downloadWithYouTubeDl, downloadWithYtDlp, and downloadSongFromYouTube functions to pass the downloadCommand to the onSuccess callback. This allows better tracking of the command used during the download process.
    * radio@driglu4it/files/radio@driglu4it/6.4/radio-applet.js: Enhance the notifyYouTubeDownloadFailed function to include an additional button for viewing logs, providing users with more information for troubleshooting.
    * radio@driglu4it/files/radio@driglu4it/6.4/radio-applet.js: Update the moveFileFromTmpDir function to handle errors more gracefully by passing detailed error messages to the onError callback.
  • Loading branch information
jonath92 authored Jan 25, 2025
1 parent 4e72de1 commit bd6cd26
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 96 deletions.
92 changes: 51 additions & 41 deletions radio@driglu4it/files/radio@driglu4it/6.4/radio-applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4185,7 +4185,7 @@ function downloadWithYouTubeDl(props) {
return;
}
if (stdout) {
onSuccess();
onSuccess(downloadCommand);
return;
}
if (stderr) {
Expand Down Expand Up @@ -4215,7 +4215,7 @@ function downloadWithYtDlp(props) {
return;
}
if (stdout) {
onSuccess();
onSuccess(downloadCommand);
return;
}
if (stderr) {
Expand All @@ -4242,12 +4242,17 @@ const { File: YoutubeDownloadManager_File, FileCopyFlags, FileQueryInfoFlags } =
const notifyYouTubeDownloadFailed = (props) => {
const { youtubeCli, errorMessage } = props;
notifyError(`Couldn't download Song from YouTube due to an Error. Make Sure you have the newest version of ${youtubeCli} installed.
\n<b>Important:</b> Don't use apt for the installation but follow the installation instruction given on the Radio Applet Site in the Cinnamon Store instead`, errorMessage, {
\n<b>Important:</b> Don't use apt for the installation but follow the installation instruction given on the Radio Applet Site in the Cinnamon Store instead.
\nReview the logs for more information`, errorMessage, {
additionalBtns: [
{
text: "View Installation Instruction",
onClick: () => YoutubeDownloadManager_spawnCommandLine(`xdg-open ${APPLET_SITE} `),
},
{
text: "View Logs",
onClick: () => YoutubeDownloadManager_spawnCommandLine(`xdg-open ~/.xsession-errors`),
}
],
});
};
Expand Down Expand Up @@ -4305,28 +4310,25 @@ function downloadSongFromYouTube(title) {
downloadProcesses = downloadProcesses.filter((downloadingSong) => downloadingSong.songTitle !== title);
downloadingSongsChangedListener.forEach((listener) => listener(downloadProcesses));
},
onSuccess: () => {
try {
moveFileFromTmpDir({
targetDirPath: music_dir_absolut,
tmpDirPath,
onFileMoved: (props) => {
const { fileAlreadyExist, targetFilePath } = props;
updateFileModifiedTime(targetFilePath);
notifyYouTubeDownloadFinished({
downloadPath: targetFilePath,
fileAlreadyExist,
});
},
});
}
catch (error) {
const errorMessage = error instanceof imports.gi.GLib.Error ? error.message : error;
notifyYouTubeDownloadFailed({
youtubeCli,
errorMessage: `Failed to copy download from tmp dir. The following error occurred: ${errorMessage}`,
});
}
onSuccess: (downloadCommand) => {
moveFileFromTmpDir({
targetDirPath: music_dir_absolut,
tmpDirPath,
onFileMoved: (props) => {
const { fileAlreadyExist, targetFilePath } = props;
updateFileModifiedTime(targetFilePath);
notifyYouTubeDownloadFinished({
downloadPath: targetFilePath,
fileAlreadyExist,
});
},
onError: (errorMessage) => {
notifyYouTubeDownloadFailed({
youtubeCli,
errorMessage: `Failed to copy download from tmp dir. The following error occurred: ${errorMessage}. The tmp dir Path is: ${tmpDirPath}. The download command is: ${downloadCommand}`,
});
},
});
},
};
const { cancel } = youtubeCli === "youtube-dl"
Expand All @@ -4337,24 +4339,32 @@ function downloadSongFromYouTube(title) {
downloadingSongsChangedListener.forEach((listener) => listener(downloadProcesses));
}
const moveFileFromTmpDir = (props) => {
var _a;
const { tmpDirPath, targetDirPath, onFileMoved } = props;
const fileName = (_a = YoutubeDownloadManager_File.new_for_path(tmpDirPath)
.enumerate_children("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null)
.next_file(null)) === null || _a === void 0 ? void 0 : _a.get_name();
if (!fileName) {
throw new Error(`filename couldn't be determined`);
var _a, _b;
const { tmpDirPath, targetDirPath, onFileMoved, onError } = props;
try {
const fileName = (_a = YoutubeDownloadManager_File.new_for_path(tmpDirPath)
.enumerate_children("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null)
.next_file(null)) === null || _a === void 0 ? void 0 : _a.get_name();
if (!fileName) {
throw new Error(`filename couldn't be determined.This seems to be a problem with the used Youtube Download Cli tool.`);
}
const tmpFile = YoutubeDownloadManager_File.new_for_path(`${tmpDirPath}/${fileName}`);
if ((_b = tmpFile.get_path()) === null || _b === void 0 ? void 0 : _b.endsWith(".webp")) {
throw new Error("Only the cover image has been downloaded. This seems to be a problem with the used Youtube Download Cli tool.");
}
const targetFilePath = `${targetDirPath}/${fileName}`;
const targetFile = YoutubeDownloadManager_File.parse_name(targetFilePath);
if (targetFile.query_exists(null)) {
onFileMoved({ targetFilePath, fileAlreadyExist: true });
return;
}
tmpFile.move(YoutubeDownloadManager_File.parse_name(targetFilePath), FileCopyFlags.BACKUP, null, null);
onFileMoved({ targetFilePath, fileAlreadyExist: false });
}
const tmpFilePath = `${tmpDirPath}/${fileName}`;
const tmpFile = YoutubeDownloadManager_File.new_for_path(tmpFilePath);
const targetFilePath = `${targetDirPath}/${fileName}`;
const targetFile = YoutubeDownloadManager_File.parse_name(targetFilePath);
if (targetFile.query_exists(null)) {
onFileMoved({ targetFilePath, fileAlreadyExist: true });
return;
catch (error) {
const errorMessage = error instanceof imports.gi.GLib.Error ? error.message : error;
onError(errorMessage);
}
tmpFile.move(YoutubeDownloadManager_File.parse_name(targetFilePath), FileCopyFlags.BACKUP, null, null);
onFileMoved({ targetFilePath, fileAlreadyExist: false });
};
const getCurrentDownloadingSongs = () => {
return downloadProcesses.map((downloadingSong) => downloadingSong.songTitle);
Expand Down
2 changes: 1 addition & 1 deletion radio@driglu4it/src/services/youtubeDownload/YoutubeDl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function downloadWithYouTubeDl(
}

if (stdout) {
onSuccess();
onSuccess(downloadCommand);
return;
}

Expand Down
120 changes: 67 additions & 53 deletions radio@driglu4it/src/services/youtubeDownload/YoutubeDownloadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface YouTubeDownloadServiceProps {
downloadDir: string;
title: string;
onFinished: () => void;
onSuccess: () => void;
onSuccess: (downloadCommand: string) => void;
onError: (errorMessage: string, downloadCommand: string) => void;
}

Expand All @@ -34,14 +34,19 @@ const notifyYouTubeDownloadFailed = (props: {

notifyError(
`Couldn't download Song from YouTube due to an Error. Make Sure you have the newest version of ${youtubeCli} installed.
\n<b>Important:</b> Don't use apt for the installation but follow the installation instruction given on the Radio Applet Site in the Cinnamon Store instead`,
\n<b>Important:</b> Don't use apt for the installation but follow the installation instruction given on the Radio Applet Site in the Cinnamon Store instead.
\nReview the logs for more information`,
errorMessage,
{
additionalBtns: [
{
text: "View Installation Instruction",
onClick: () => spawnCommandLine(`xdg-open ${APPLET_SITE} `),
},
{
text: "View Logs",
onClick: () => spawnCommandLine(`xdg-open ~/.xsession-errors`),
}
],
}
);
Expand Down Expand Up @@ -123,30 +128,27 @@ export function downloadSongFromYouTube(title: string) {
listener(downloadProcesses)
);
},
onSuccess: () => {
try {
moveFileFromTmpDir({
targetDirPath: music_dir_absolut,
tmpDirPath,
onFileMoved: (props) => {
const { fileAlreadyExist, targetFilePath } = props;

updateFileModifiedTime(targetFilePath);

notifyYouTubeDownloadFinished({
downloadPath: targetFilePath,
fileAlreadyExist,
});
},
});
} catch (error) {
const errorMessage =
error instanceof imports.gi.GLib.Error ? error.message : error;
notifyYouTubeDownloadFailed({
youtubeCli,
errorMessage: `Failed to copy download from tmp dir. The following error occurred: ${errorMessage}`,
});
}
onSuccess: (downloadCommand) => {
moveFileFromTmpDir({
targetDirPath: music_dir_absolut,
tmpDirPath,
onFileMoved: (props) => {
const { fileAlreadyExist, targetFilePath } = props;

updateFileModifiedTime(targetFilePath);

notifyYouTubeDownloadFinished({
downloadPath: targetFilePath,
fileAlreadyExist,
});
},
onError: (errorMessage) => {
notifyYouTubeDownloadFailed({
youtubeCli,
errorMessage: `Failed to copy download from tmp dir. The following error occurred: ${errorMessage}. The tmp dir Path is: ${tmpDirPath}. The download command is: ${downloadCommand}`,
});
},
});
},
};

Expand All @@ -170,39 +172,51 @@ const moveFileFromTmpDir = (props: {
targetFilePath: string;
fileAlreadyExist: boolean;
}) => void;
onError: (error: string) => void;
}) => {
const { tmpDirPath, targetDirPath, onFileMoved } = props;
const { tmpDirPath, targetDirPath, onFileMoved, onError } = props;

try {
const fileName = File.new_for_path(tmpDirPath)
.enumerate_children(
"standard::*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null
)
.next_file(null)
?.get_name();

if (!fileName) {
throw new Error(`filename couldn't be determined.This seems to be a problem with the used Youtube Download Cli tool.`);
}

const fileName = File.new_for_path(tmpDirPath)
.enumerate_children(
"standard::*",
FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
null
)
.next_file(null)
?.get_name();
const tmpFile = File.new_for_path(`${tmpDirPath}/${fileName}`);
if (tmpFile.get_path()?.endsWith(".webp")){
throw new Error("Only the cover image has been downloaded. This seems to be a problem with the used Youtube Download Cli tool.")
}

if (!fileName) {
throw new Error(`filename couldn't be determined`);
}
const targetFilePath = `${targetDirPath}/${fileName}`;
const targetFile = File.parse_name(targetFilePath);

const tmpFilePath = `${tmpDirPath}/${fileName}`;
const tmpFile = File.new_for_path(tmpFilePath);
const targetFilePath = `${targetDirPath}/${fileName}`;
const targetFile = File.parse_name(targetFilePath);

if (targetFile.query_exists(null)) {
onFileMoved({ targetFilePath, fileAlreadyExist: true });
return;
}
if (targetFile.query_exists(null)) {
onFileMoved({ targetFilePath, fileAlreadyExist: true });
return;
}

tmpFile.move(
File.parse_name(targetFilePath),
FileCopyFlags.BACKUP,
null,
null
);
onFileMoved({ targetFilePath, fileAlreadyExist: false });
tmpFile.move(
File.parse_name(targetFilePath),
FileCopyFlags.BACKUP,
null,
null
);
onFileMoved({ targetFilePath, fileAlreadyExist: false });
} catch (error) {
const errorMessage =
error instanceof imports.gi.GLib.Error ? error.message : error;

onError(errorMessage as string);
}
};

export const getCurrentDownloadingSongs = () => {
Expand Down
2 changes: 1 addition & 1 deletion radio@driglu4it/src/services/youtubeDownload/YtDlp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function downloadWithYtDlp(
}

if (stdout) {
onSuccess();
onSuccess(downloadCommand);
return;
}

Expand Down

0 comments on commit bd6cd26

Please sign in to comment.