#1
|
||||
|
||||
![]()
Convert .webp images to .jpg/.jpeg images
Code: Code:
// Converts webm files to jpg. // Trigger: "A Download Stopped" // Requires ffmpeg/ffprobe. Uses ffmpeg/ffprobe settings if available. // Does NOT overwrite the destination file if it already exists. function run() { var deleteSourceFile = true; var writeErrorToLogfile = true; var changeFilenameInJDownloaderOnSuccess = true; try { if (!link.isFinished()) { // This may sometimes happen (race condition) -> Early return without exception // throw new Error("Download is not finished yet"); return; } var fileName = link.name.replace(/(.+)(\..+$)/, "$1"); var sourceFile = link.getDownloadPath(); // Ensure the file is a .webp image if (!/\.webp$/i.test(sourceFile)) { return; } var downloadFolder = package.getDownloadFolder(); var destFile = downloadFolder + "/" + fileName + ".jpg"; // Prevent overwriting an existing file if (getPath(destFile).exists()) { throw new Error("The destination file already exists"); } var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath"); callSync(ffmpeg, "-y", "-i", sourceFile, "-q:v", "1", destFile); // Ensure the destination file was created successfully if (!getPath(destFile).exists()) { throw new Error("File conversion failed, destination file not found"); } // Delete the source file if conversion was successful if (deleteSourceFile) { deleteFile(sourceFile, false); } // Change filename in JDownloader if enabled if (changeFilenameInJDownloaderOnSuccess) { link.setName(fileName + ".jpg"); } } catch (e) { if (writeErrorToLogfile) { var logFilePath = package.getDownloadFolder() + "/" + fileName + ".txt"; writeFile(logFilePath, e.name + ": " + e.message, true); } throw e; } } // Execute the function run(); https://board.jdownloader.org/showth...497#post544497
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download Last edited by pspzockerscene; 19.02.2025 at 12:03. |
#2
|
||||
|
||||
![]()
Updated script:
- outsourced "if file exist after conversion" check - added boolean (default true) that allows for changing file name in JDownloader GUI too on successful conversion
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#3
|
|||
|
|||
![]()
Hi there!
This script works great, but.....I have one (similar) request. Can you make for me a script that converts .avif images too? Tnx in advance! ![]() |
#4
|
||||
|
||||
![]()
@Bear
A little initiative would be more than appropriate here. Have you already looked at the script I posted, adapted it to your target format, and tested it? Have you studied the topic of EventScripter in more detail? EventScripter subforum: https://board.jdownloader.org/forumdisplay.php?f=52 EventScripter help article: https://support.jdownloader.org/know...event-scripter Just a tip: ChatGPT can also be helpful in this regard.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#5
|
|||
|
|||
![]()
Hi!
Sorry, my bad that I didn't mentioned what I tried. ![]() I've looked your script before posting request and adapted to my needs. That is line 21, where is testing file extension. I've changed to .avif but it's not working. Getting error message: "Error: File conversion failed, destination file not found (#55)" Trigger -> A Download Stopped Din't used ChatGPT before, but now I had opportunity to test it (thanks for the tip) ![]() It says the same thing. Changing webp to avif. ffmpeg is correctly installed, can handle avif files (tried manually convert file from cmd and it works) Because of error which says that destination file is not found and it's downloaded, I'm stuck here, and I was thinking that there is more in code what needs to be changed and not only webp to avif. I hope you understand me. ![]() Any ideas? You have some detailed infos about error if it helps: (This error is caused by:)
Spoiler:
net.sourceforge.htmlunit.corejs.javascript.JavaScriptException: Error: File conversion failed, destination file not found (#55)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1006) at script.run(:55) at script(:60) at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411) at org.jdownloader.scripting.JSHtmlUnitPermissionRestricter$SandboxContextFactory.doTopCall(JSHtmlUnitP ermissionRestricter.java:134) at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3286) at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115) at net.sourceforge.htmlunit.corejs.javascript.Context.evaluateString(Context.java:1361) at org.jdownloader.extensions.eventscripter.ScriptThread.evalUNtrusted(ScriptThread.java:346) at org.jdownloader.extensions.eventscripter.ScriptThread.executeScipt(ScriptThread.java:194) at org.jdownloader.extensions.eventscripter.ScriptThread.run(ScriptThread.java:174) Thanks! |
#6
|
||||
|
||||
![]()
I need the full script/code you've triied otherwise I won't be able to help.
Also please provide example links to .avif image files.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#7
|
||||
|
||||
![]()
So here is my test results:
Indeed that didn't work out of the box but it wasn't "ChatGPTs fault": The FFmpeg version that came with JDownloader didn't support avif. That can be tested via this command: Code:
ffmpeg -formats | findstr avif Solution: 1. Grab another FFmpeg build here: ffmpeg.org/download.html 2. Make sure that that supports avif. 3. Either install it on your system or replace it in your JD install folder, see: https://support.jdownloader.org/know...roubleshooting 4. Use the .avif to .jpg script modified via ChatGPT: Script: Code:
// Converts avif files to jpg. // Trigger: "A Download Stopped" // Requires ffmpeg/ffprobe. Uses ffmpeg/ffprobe settings if available. // Does NOT overwrite the destination file if it already exists. function run() { var deleteSourceFile = true; var writeErrorToLogfile = true; var changeFilenameInJDownloaderOnSuccess = true; try { if (!link.isFinished()) { // This may sometimes happen (race condition) -> Early return without exception // throw new Error("Download is not finished yet"); return; } var fileName = link.name.replace(/(.+)(\..+$)/, "$1"); var sourceFile = link.getDownloadPath().replace(/\//g, "\\"); // Ensure the file is a .avif image if (!/\.avif$/i.test(sourceFile)) { return; } var downloadFolder = package.getDownloadFolder().replace(/\//g, "\\"); var destFile = downloadFolder + "\\" + fileName + ".jpg"; // Prevent overwriting an existing file if (getPath(destFile).exists()) { throw new Error("The destination file already exists"); } var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath").replace(/\//g, "\\"); callSync(ffmpeg, "-y", "-i", sourceFile, "-q:v", "1", destFile); // Ensure the destination file was created successfully if (!getPath(destFile).exists()) { throw new Error("File conversion failed, destination file not found: " + destFile); } // Delete the source file if conversion was successful if (deleteSourceFile) { deleteFile(sourceFile, false); } // Change filename in JDownloader if enabled if (changeFilenameInJDownloaderOnSuccess) { link.setName(fileName + ".jpg"); } } catch (e) { if (writeErrorToLogfile) { var logFilePath = package.getDownloadFolder().replace(/\//g, "\\") + "\\" + fileName + ".txt"; writeFile(logFilePath, e.name + ": " + e.message, true); } throw e; } } // Execute the function run(); Code:
Change the following script so that it converts .avif files to .jpg: In the comments, only change the bare minimum e.g. all mentions of the old .webp to .jpg functionality. Code:
libre-software.net/wp-content/uploads/AVIF/AVIF%20Test%20picture%20%28JPEG%20converted%20to%20AVIF%20with%20Convertio%29.avif
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
#8
|
|||
|
|||
![]()
Thank you very much!
It's working now! ![]() I've replaced FFmpeg with new one in JD install folder and now it's working fine! Regards! |
#9
|
||||
|
||||
![]()
Thanks for your feedback.
__________________
JD Supporter, Plugin Dev. & Community Manager
Erste Schritte & Tutorials || JDownloader 2 Setup Download |
![]() |
Thread Tools | |
Display Modes | |
|
|