View Single Post
  #1888  
Old 30.09.2021, 08:31
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,553
Default

Quote:
Originally Posted by mirino View Post
@mgpai: Here is my first try, more the idea, not a working script. Can you help me, to make it work?
Good first try.
  1. The method does not contain folder separator at the end.
  2. Returns the contents of the 'comment' field of link property, which is either set automatically by the plugin, or manually by the user.
  3. Better to use 'stopped' trigger and run script only after link is 'finished'.
  4. Check example in my script.
  5. 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.
Reply With Quote