Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radio@driglu4it: add more debug information when youtube download fails #6802

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading