Skip to content

Commit

Permalink
v1.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
heliomarpm committed Aug 18, 2024
1 parent 3ab1c06 commit e86fe29
Show file tree
Hide file tree
Showing 30 changed files with 208 additions and 150 deletions.
34 changes: 31 additions & 3 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Change Log

## Version [1.13.1](https://github.com/heliomarpm/udemy-downloader-gui/compare/v1.13.0...v1.13.1)
##### Aug, 08 2024
![](https://img.shields.io/github/downloads/heliomarpm/udemy-downloader-gui/v1.13.1/total)


### Issues Fixed
* Download preparer
- [#198](https://github.com/heliomarpm/udemy-downloader-gui/issues/198)
- [#201](https://github.com/heliomarpm/udemy-downloader-gui/issues/201)
- [#206](https://github.com/heliomarpm/udemy-downloader-gui/issues/206)
- [#207](https://github.com/heliomarpm/udemy-downloader-gui/issues/207)

* Server Unavailable - improved error messages
- [#200](https://github.com/heliomarpm/udemy-downloader-gui/issues/200)
- [#204](https://github.com/heliomarpm/udemy-downloader-gui/issues/204)


----
## Version [1.13.0](https://github.com/heliomarpm/udemy-downloader-gui/compare/v1.12.9...v1.13.0)
##### Jul, 11 2024
![](https://img.shields.io/github/downloads/heliomarpm/udemy-downloader-gui/v1.13.0/total)

### Fixed
* download speed information


----
## Version [1.12.8](https://github.com/heliomarpm/udemy-downloader-gui/compare/v1.12.7...v1.12.8)
##### Aug, 22 2023
![](https://img.shields.io/github/downloads/heliomarpm/udemy-downloader-gui/v1.12.8/total)
## Version [1.12.9](https://github.com/heliomarpm/udemy-downloader-gui/compare/v1.12.7...v1.12.9)
##### Apr, 04 2024
![](https://img.shields.io/github/downloads/heliomarpm/udemy-downloader-gui/v1.12.9/total)

### Fixed
* download speed information
* downloadError (#185)

### Updates
* GitHub Issues Templates
Expand Down
126 changes: 69 additions & 57 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ async function checkUpdate(account, silent = false) {
}
}

async function checkLogin() {
async function checkLogin(alertExpired = true) {
if (Settings.accessToken) {
try {
ui.busyLogin(true);
Expand All @@ -291,6 +291,9 @@ async function checkLogin() {
const userContext = await udemyService.fetchProfile(Settings.accessToken, 30000);

if (!userContext.header.isLoggedIn) {
if (alertExpired) {
showAlert(translate("Token expired"));
}
ui.resetToLogin();
return;
}
Expand Down Expand Up @@ -516,8 +519,8 @@ function resetCourse($course, $elMessage, autoRetry, courseData, subtitle) {
} else {
$course.attr("course-completed", "");

if ($elMessage.hasClass("download-error")) {
if (autoRetry && courseData.errorCount++ < 5) {
if ($elMessage.hasClass("download-error") && autoRetry && courseData) {
if (courseData.errorCount++ < 5) {
$course.length = 1;
startDownload($course, courseData, subtitle);
return;
Expand Down Expand Up @@ -648,7 +651,7 @@ async function fetchCourseContent(courseId, courseName, courseUrl) {
showAlert(`Id: ${courseId}`, translate("Course not found"));
return null;
}
// console.log("fetchCourseContent", response);
console.log(`fetchCourseContent (${courseId})`, response);

const downloadType = Number(Settings.download.type);
const downloadAttachments = downloadType === Settings.DownloadType.Both || downloadType === Settings.DownloadType.OnlyAttachments;
Expand All @@ -672,7 +675,7 @@ async function fetchCourseContent(courseId, courseName, courseUrl) {
}
chapterData = { id: item.id, name: item.title.trim(), lectures: [] };
}
else if (type == "quiz") {
else if (type == "quiz" || type == "practice") {
const srcUrl = `${courseUrl}t/${item._class}/${item.id}`;

chapterData.lectures.push({
Expand Down Expand Up @@ -765,22 +768,7 @@ async function fetchCourseContent(courseId, courseName, courseUrl) {
// ui.busyBuildingCourseData(false);
return courseData;
} catch (error) {
let msgError;
const statusCode = error.response ? error.response.status : 0;
switch (statusCode) {
case 403:
msgError = translate("You do not have permission to access this course");
prompt.alert(msgError);
break;
case 504:
msgError = "Gateway timeout";
break;
default:
msgError = error.message;
break;
}
appendLog(`EBUILDING_COURSE_DATA: ${error.code}(${statusCode})`, msgError);
throw utils.newError("EBUILDING_COURSE_DATA", msgError);
handleApiError(error, "EBUILDING_COURSE_DATA", courseName, true);
}
}

Expand All @@ -795,10 +783,7 @@ async function fetchCourses(isSubscriber) {
}
})
.catch(e => {
const statusCode = (e.response?.status || 0).toString() + (e.code ? ` :${e.code}` : "");
appendLog(`EFETCHING_COURSES: ${e.code}(${statusCode})`, e.message);
//showAlert(error.message, "Fetching Courses");
throw utils.newError("EFETCHING_COURSES", e.message);
handleApiError(e, "EFETCHING_COURSES");
})
.finally(() => {
ui.busyLoadCourses(false);
Expand All @@ -821,7 +806,7 @@ function loadMore(loadMoreButton) {
}
}).catch(e => {
const statusCode = (e.response?.status || 0).toString() + (e.code ? ` :${e.code}` : "");
appendLog(`loadMore_Error: (${statusCode})`, e);
appendLog(`ELOADING_MORE: (${statusCode})`, e);
}).finally(() => {
ui.busyLoadCourses(false);
});
Expand All @@ -834,8 +819,7 @@ async function search(keyword) {
const courses = await udemyService.fetchSearchCourses(keyword, PAGE_SIZE, Settings.subscriber);
renderCourses(courses, !!keyword);
} catch (error) {
const statusCode = (error.response?.status || 0).toString() + (error.code ? ` :${error.code}` : "");
appendLog(`search_Error: (${statusCode})`, error);
handleApiError(error, "ESEARCHING_COURSES", null, false);
} finally {
ui.busyLoadCourses(false);
}
Expand Down Expand Up @@ -984,8 +968,9 @@ async function prepareDownloading($course, subtitle) {

console.clear();

let courseData = null;
try {
const courseData = await fetchCourseContent(courseId, courseName, courseUrl);
courseData = await fetchCourseContent(courseId, courseName, courseUrl);
if (!courseData) {
ui.showProgress($course, false);
return;
Expand All @@ -1006,22 +991,11 @@ async function prepareDownloading($course, subtitle) {
}

} catch (error) {
let msgError;
const statusCode = error.response?.status || 0;
switch (statusCode) {
case 403:
msgError = translate("You do not have permission to access this course") + `\nId: ${courseId}`;
showAlert(msgError, "Download Error");
break;
case 504:
msgError = "Gateway timeout";
break;
default:
msgError = error;
}
const errorCode = error.code ? ` :${error.code}` : "";
appendLog(`EPREPARE_DOWNLOADING: (${statusCode}${errorCode})`, msgError);
const errorName = error.name === "EASK_FOR_SUBTITLE" ? error.name : "EPREPARE_DOWNLOADING";
handleApiError(error, errorName, null, false);
ui.busyOff();

resetCourse($course, $course.find(".download-error"), Settings.download.autoRetry, courseData, subtitle);
}
}

Expand Down Expand Up @@ -1173,9 +1147,7 @@ function startDownload($course, courseData, subTitle = "") {
fs.mkdirSync(seqName.fullPath, { recursive: true });
downloadLecture(chapterIndex, lectureIndex, countLectures, seqName.name);
} catch (error) {
appendLog("downloadChapter_Error:", error);
dialog.showErrorBox("downloadChapter_Error", error.message);

handleApiError(error, "EDOWNLOADING_CHAPTER", null, false);
resetCourse($course, $course.find(".download-error"), false, courseData);
}
}
Expand Down Expand Up @@ -1266,9 +1238,7 @@ function startDownload($course, courseData, subTitle = "") {
}).then(() => {
resetCourse($course, $course.find(".download-error"), Settings.download.autoRetry, courseData, subtitle);
}).catch((error) => {
const statusCode = error.response?.status || 0;
const errorCode = error.code ? ` :${error.code}` : "";
appendLog(`downloadLecture_Error: (${statusCode}${errorCode})`, error);
handleApiError(error, "EDL_DOWNLOADING_LECTURE", courseData.name, false);

try {
if (statusCode == 401 || statusCode == 403) {
Expand Down Expand Up @@ -1296,7 +1266,7 @@ function startDownload($course, courseData, subTitle = "") {
if (hasDRMProtection(dl)) {
dl.emit("end");
} else {
appendLog("errorDownload", dl.error.message);
appendLog("DL_ONERROR", dl.error.message);
}
});

Expand Down Expand Up @@ -1779,11 +1749,13 @@ function clearBagdeLoggers() {
* @param {string} title - The title of the log entry.
* @param {string|Error|object} error - The error message or Error object.
*/
function appendLog(title, error) {
const description = error instanceof Error
? error.message
function appendLog(title, error, additionalDescription = "") {
let description = error instanceof Error
? error.message //`${error.message}\n ${error.stack}`
: (typeof error == "object" ? JSON.stringify(error) : error);

description += additionalDescription !== "" ? "\n\n" + additionalDescription : "";

// item added to list to display
$(".ui.logger.section .ui.list").prepend(
`<div class="item">
Expand All @@ -1810,6 +1782,7 @@ function appendLog(title, error) {

if (error instanceof Error) {
console.error(`[${title}] ${error.message}\n ${error.stack}`);
captureException(error);
} else {
console.warn(`[${title}] ${description}`);
}
Expand Down Expand Up @@ -1846,6 +1819,45 @@ function saveLogFile() {
});
}

function handleApiError(error, errorName, courseName = null, triggerThrow = true) {
error.name = errorName;
error.code = error.code || "";

const statusCode = error.response?.status || 0;
switch (statusCode) {
case 403:
error.message = translate("You do not have permission to access this course");
// prompt.alert(msgError);
showAlertError(error.message, errorName);
break;
case 503:
error.message = translate("Service is temporarily unavailable. Please wait a few minutes and try again.");
showAlertError(error.message, errorName);
break;
case 504:
error.message = "Gateway timeout";
showAlertError(error.message, errorName);
break;
default:
break;
}

if (courseName)
error.message += `\n\n course: ${courseName}`;

appendLog(`${errorName}: ${error.code}(${statusCode})`, error);

if (triggerThrow) {
// throw utils.newError(errorName, error.message);
throw error;
}
}

function showAlertError(message, title = "") {
title = title ? `.:: ${title} ::.` : ".:: Error ::.";
dialog.showErrorBox(title, message);
}

function showAlert(message, title = "") {
if (title) title = `.:: ${title} ::.\n\r`;
dialogs.alert(`${title}${message}`);
Expand All @@ -1856,14 +1868,14 @@ function captureException(exception) {
}

process.on("uncaughtException", (error) => {
appendLog("uncaughtException", error);
appendLog("EPROCESS_UNCAUGHT_EXCEPTION", error);
captureException(error);
});

process.on("unhandledRejection", (error) => {
appendLog("unhandledRejection", error);
appendLog("EPROCESS_UNHANDLED_REJECTION", error);
captureException(error);
});

// console.table(getAllDownloadsHistory());
checkLogin();
checkLogin(false);
Loading

0 comments on commit e86fe29

Please sign in to comment.