JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 10.01.2025, 01:37
SirJohnny SirJohnny is offline
Junior Loader
 
Join Date: Oct 2019
Posts: 14
Default How do I properly use callSync with parameters ?

i am trying to use exiftool to change the metadata of an audio file from youtube but i am misunderstaning how to use callSync.

Using the command line:
Code:
"C:/ExifTool/exiftool.exe" -artist="New Artist" -albumartist="New Participating Artist" -title="NewTtitle" -overwrite_original "SomeAudio.mp3"
On the eventscipter i have tried to follow this example:
Code:
    var program = ["C:\ExifTool\exiftool.exe"];
    var parameters = ["paremeter1", "parameter2", "paremeter..."].join(",");
    var file = getPath(link.downloadPath);
    
    callSync(program, parameters, file);
Could you clarify how the parameters variable work or point me to some documentation about callsync ?
Reply With Quote
  #2  
Old 10.01.2025, 10:40
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,831
Default

@SirJohnny: See example here
https://board.jdownloader.org/showpo...72&postcount=2
callsync method siganture is (String...) meaning that you just put the individual parts as Strings
Quote:
callSync("C:/ExifTool/exiftool.exe", "-artist=New Artist", "-albumartist=New Participating Artist", "-title=NewTtitle", "-overwrite_original", "SomeAudio.mp3");
It might be necessary to escape the values, eg
Quote:
"-artist="New Artist""
don't know if the quotes are necessary or not

Just give it a try and of course, just ask if you need help or got questions
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 11.01.2025, 04:28
SirJohnny SirJohnny is offline
Junior Loader
 
Join Date: Oct 2019
Posts: 14
Default

I have moved on from exiftool to ffmpeg. What I am trying to do is use ffmpeg to create a temporary file with the metadata I want, delete the original file and then rename the temporary file as the original.

I realize the error is in the callSync but I can't figure it out.


Code:
var file = getPath(link.downloadPath);
var fileName = link.getName();
var fileExtension = "." + fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
var downloadFolder = package.getDownloadFolder();
var tempFilename = downloadFolder + "/" + "temp" + fileExtension;

alert(callSync("ffmpeg","-i", file, "-metadata", "title=" + title,  "-metadata",  "artist=" + artist,  "-metadata",  "album_artist=" + artist, "-c", "copy", tempFilename,  "&&", "del", file, "&&", "rename", tempFilename, file));
Reply With Quote
  #4  
Old 11.01.2025, 11:36
SirJohnny SirJohnny is offline
Junior Loader
 
Join Date: Oct 2019
Posts: 14
Default

This is my full working script:

Code:
var linkIsFinished = link.finished;
var packageName = link.getPackage().getName();
var isPackageNameDiscography = packageName.includes("Discography");
var isHostYoutube = link.getHost() === "youtube.com";
var fileName = link.getName();
var isAudioFile = /\.(aac|m4a|ogg|opus|mp3)$/.test(fileName);


if (linkIsFinished && isPackageNameDiscography && isHostYoutube && isAudioFile) {
	
	// Get metadata values
	var artist = packageName.replace("[Discography] " , "");
	var title = fileName.split('.').slice(0, -1).join('.');
	alert("title:" + title);
	
	
	var file = getPath(link.downloadPath);
	
	// Temp file for ffmpeg
	var filenameNoExtension = fileName.split('.').slice(0, -1).join('.');
	
	var fileExtension = "." + fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
	var downloadFolder = package.getDownloadFolder();
	var tempFilename = downloadFolder + "\\" + "temp" + fileExtension;
	
	alert("filename:" + fileName);
	
	// Create temp file with provided meta data values with ffmpeg
	callSync("ffmpeg","-i", file, "-metadata", "title=" + title,  "-metadata",  "artist=" + artist,  "-metadata",  "album_artist=" + artist, tempFilename);
	
	// Delete original file
	callSync("cmd", "/c", "del", file);
	
	// Rename temp file with original name
	callSync("cmd", "/c", "rename", tempFilename, fileName);
}
Reply With Quote
  #5  
Old 11.01.2025, 14:36
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,831
Default

callSync is no cmd/bash/batch, you cannot make use of &&

You have to call those commands separately.
I would also recommend to not use cmd for delete and rename and make use of FilePath, see the list of available Objects/methods
Quote:
/* === FilePath === */
/* ========= Methods =========*/
var myBoolean = myFilePath.copyTo(myString, myString, myBoolean);
var myBoolean = myFilePath.copyTo(myString);
var myBoolean = myFilePath.delete();
var myBoolean = myFilePath.deleteRecursive();
var myBoolean = myFilePath.exists();
var myString = myFilePath.getAbsolutePath();
var myFilePath[] = myFilePath.getChildren();
var myLong = myFilePath.getCreatedDate();
var myString = myFilePath.getExtension();
var myLong = myFilePath.getFreeDiskSpace();
var myLinkInfo = myFilePath.getLinkInfo();
var myLong = myFilePath.getModifiedDate();
var myString = myFilePath.getName();
var myFilePath = myFilePath.getParent();
var myString = myFilePath.getPath();
var myString = myFilePath.getPathSeparator();
var myLong = myFilePath.getReservedDiskSpace();
var myLong = myFilePath.getSize();
var myBoolean = myFilePath.isDirectory();
var myBoolean = myFilePath.isFile();
var myBoolean = myFilePath.mkdirs();
var myBoolean = myFilePath.moveTo(myString);
var myFilePath = myFilePath.rename(myString);
var myFilePath = myFilePath.renameName(myString);
var myFilePath = myFilePath.renamePath(myString);
var myBoolean = myFilePath.renameTo(myString);
var myString = myFilePath.toString();
__________________
JD-Dev & Server-Admin
Reply With Quote
  #6  
Old 13.01.2025, 10:39
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,665
Default

Your script currently will (try to) delete and rename the file without checking if the ffmpeg command was successful. Better to use callAsync and check the exitCode OR redirect the errOut to stdOut in callsync OR use "&&" as in the example below.

Code:
callSync("cmd", "/c", "notepad", "&&", "dir")
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 11:16.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.