Quote:
Originally Posted by mirino
@mgpai: Here is my first try, more the idea, not a working script. Can you help me, to make it work?
|
Good first try.
- The method does not contain folder separator at the end.
- Returns the contents of the 'comment' field of link property, which is either set automatically by the plugin, or manually by the user.
- Better to use 'stopped' trigger and run script only after link is 'finished'.
- Check example in my script.
- Can use 'myDownloadLink.getLinkInfo()' method.
Notes on your script:
- link.name returns file name. To access the download url, you have to query contentURL and use pluginURL as fallback if necessary.
- Better to remove existing file or append it. If you use rename, it will throw an error, if a previously renamed 'bak' file already exists on disk. Or, use addition error handling for such cases.
Code:
/*
Write link info to file
Trigger: A download stopped
*/
if (link.finished && link.host == "joinpeertube.org") {
var ext = getPath(link.downloadPath).extension;
var file = link.downloadPath.replace(ext, "txt");
var data = [link.contentURL, link.name + "\n", link.comment].join("\n");
try {
writeFile(file, data, true);
} catch (e) {};
}
Note: I use dot notations (undocumented) wherever possible, to access the properties instead of the documented object methods.