fix(downloader): Implement retry logic for download failures with fal… #3480

Open
User-425 wants to merge 1 commit from User-425/master into master
User-425 commented 2025-06-12 14:31:39 +00:00 (Migrated from github.com)

This pull request introduces a retry mechanism in the downloadSongUnsafe function to handle download failures more robustly. It includes retry logic with exponential backoff and a fallback to direct URL downloading if all retries fail.

Enhancements to download handling:

  • src/plugins/downloader/main/index.ts: Added a retry mechanism with a maximum of 3 attempts for downloading, including a delay between retries and a refresh of the session cookie. If all retries fail, the code attempts to download using the direct URL as a fallback. This ensures more reliable handling of intermittent failures during the download process.
This pull request introduces a retry mechanism in the `downloadSongUnsafe` function to handle download failures more robustly. It includes retry logic with exponential backoff and a fallback to direct URL downloading if all retries fail. ### Enhancements to download handling: * [`src/plugins/downloader/main/index.ts`](diffhunk://#diff-6d7898ec714b81a0a11f4c47a9df86f932d659b9af44355a9de4bfcc41692cdcL421-R469): Added a retry mechanism with a maximum of 3 attempts for downloading, including a delay between retries and a refresh of the session cookie. If all retries fail, the code attempts to download using the direct URL as a fallback. This ensures more reliable handling of intermittent failures during the download process.
User-425 commented 2025-06-12 14:36:46 +00:00 (Migrated from github.com)

I tried to implement a retry mechanism, it works. To fix download error #3328. Although I fix this using the V.3.9.0. Because I can't figure it out how to open menu in the master. Also in my case, in a long run (using auto downloader). Some song still got error, but this PR drastically reduce the chance.

I tried to implement a retry mechanism, it works. To fix download error #3328. Although I fix this using the V.3.9.0. Because I can't figure it out how to open menu in the master. Also in my case, in a long run (using auto downloader). Some song still got error, but this PR drastically reduce the chance.
Owner

The reason you can't test on master is due to a recent commit that replaces vite (the bundler) with rolldown-vite.
You can revert this change in your local clone to test directly on master

diff --git a/package.json b/package.json
index a4e9cc93..fa226d5d 100644
--- a/package.json
+++ b/package.json
@@ -222,7 +222,7 @@
   },
   "pnpm": {
     "overrides": {
-      "vite": "npm:rolldown-vite@6.3.18",
+      "vite": "6.3.5",
       "node-gyp": "11.2.0",
       "xml2js": "0.6.2",
       "node-fetch": "3.3.2",
@@ -341,7 +341,7 @@
     "typescript": "5.8.3",
     "typescript-eslint": "8.33.1",
     "utf-8-validate": "6.0.5",
-    "vite": "npm:rolldown-vite@6.3.18",
+    "vite": "6.3.5",
     "vite-plugin-inspect": "11.1.0",
     "vite-plugin-resolve": "2.5.2",
     "vite-plugin-solid": "2.11.6",

(do not forget to run pnpm i)

--

I tested it myself and the retry did indeed work!

The reason you can't test on master is due to a recent commit that replaces `vite` (the bundler) with `rolldown-vite`. You can revert this change in your local clone to test directly on master ```diff diff --git a/package.json b/package.json index a4e9cc93..fa226d5d 100644 --- a/package.json +++ b/package.json @@ -222,7 +222,7 @@ }, "pnpm": { "overrides": { - "vite": "npm:rolldown-vite@6.3.18", + "vite": "6.3.5", "node-gyp": "11.2.0", "xml2js": "0.6.2", "node-fetch": "3.3.2", @@ -341,7 +341,7 @@ "typescript": "5.8.3", "typescript-eslint": "8.33.1", "utf-8-validate": "6.0.5", - "vite": "npm:rolldown-vite@6.3.18", + "vite": "6.3.5", "vite-plugin-inspect": "11.1.0", "vite-plugin-resolve": "2.5.2", "vite-plugin-solid": "2.11.6", ``` (do not forget to run `pnpm i`) -- I tested it myself and the retry did indeed work!
Owner

This is my first time using the downloader, but I think I discovered a bug ☹️ (unrelated to ur PR btw, don't worry)

For some reason, the context menu downloads the current playing song, no matter what song I select to download from the "up next" list.

That only happens on the first time I click download, and it is unrelated to the player state (switching songs before pressing download doesn't fix it).

This is my first time using the downloader, but I think I discovered a bug :frowning_face: (unrelated to ur PR btw, don't worry) For some reason, the context menu downloads the current playing song, no matter what song I select to download from the "up next" list. That only happens on the first time I click download, and it is unrelated to the player state (switching songs before pressing download doesn't fix it).
arjix approved these changes 2025-06-14 22:08:41 +00:00
arjix left a comment
Owner

Honestly, I'd nag you about the code quality, but I won't do that since the downloader plugin needs major refactoring to be up to my standards.

So LGTM!

Honestly, I'd nag you about the code quality, but I won't do that since the downloader plugin needs major refactoring to be up to my standards. So LGTM!
halleck1 commented 2025-06-20 11:50:27 +00:00 (Migrated from github.com)

Hi, just a quick question - I was trying to build this branch locally and got the code to build successfully. However, when installing the local build (or running it from portable version) I cannot toggle the application menu (neither Alt is working nor backtick) and the plugins do not seem to be loaded. I've checked the config.json and hideMenu is false as well.

Are there any additional steps that need to be done on local builds to have this working and plugins loaded? I've followed the builds steps from readme.md (basically pnpm dist)

image

image

image

Hi, just a quick question - I was trying to build this branch locally and got the code to build successfully. However, when installing the local build (or running it from portable version) I cannot toggle the application menu (neither Alt is working nor backtick) and the plugins do not seem to be loaded. I've checked the config.json and hideMenu is false as well. Are there any additional steps that need to be done on local builds to have this working and plugins loaded? I've followed the builds steps from readme.md (basically pnpm dist) ![image](https://github.com/user-attachments/assets/ea523eb4-2de2-451f-9cd8-279b1abeff80) ![image](https://github.com/user-attachments/assets/0d4b6425-fdec-474b-97cf-947685c20c97) ![image](https://github.com/user-attachments/assets/332ea6ac-aae0-4702-b91b-4693849458d6)
Owner

@halleck1 this PR is 24 commits behind master, so your local clone does not have the required fix to run properly

also, I already discussed this before master even had the fix,
image

either do git merge master or git rebase master or manually do what my comment says

@halleck1 this PR is 24 commits behind master, so your local clone does not have the required fix to run properly also, I already discussed this before master even had the fix, ![image](https://github.com/user-attachments/assets/8e09a8e3-77e9-422d-b132-030af0cb38ff) either do `git merge master` or `git rebase master` or manually do what [my comment](https://github.com/th-ch/youtube-music/pull/3480#issuecomment-2973272803) says
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin User-425/master:User-425/master
git switch User-425/master

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff User-425/master
git switch User-425/master
git rebase master
git switch master
git merge --ff-only User-425/master
git switch User-425/master
git rebase master
git switch master
git merge --no-ff User-425/master
git switch master
git merge --squash User-425/master
git switch master
git merge --ff-only User-425/master
git switch master
git merge User-425/master
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: YTMD/youtube-music#3480
No description provided.