diff options
author | anekos | 2008-11-18 12:24:16 +0000 |
---|---|---|
committer | anekos | 2008-11-18 12:24:16 +0000 |
commit | 4cd2f4825631821bec16d508377a9ae669a4923a (patch) | |
tree | 98c89371d5f3611045544dbf8563403c91f0dd14 /fetchyoutube.js | |
parent | 99602bd0b9da4a6ddb4c45448c69eb14cbe81d5c (diff) | |
download | vimperator-plugins-4cd2f4825631821bec16d508377a9ae669a4923a.tar.bz2 |
保存先を指定できるようにした。
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@24155 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'fetchyoutube.js')
-rw-r--r-- | fetchyoutube.js | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/fetchyoutube.js b/fetchyoutube.js index 2082120..58eb55c 100644 --- a/fetchyoutube.js +++ b/fetchyoutube.js @@ -18,24 +18,25 @@ (function () { - function fetch () { - function fixFilename (filename) { - const badChars = /[\\\/:;\*\?\"\<\>\|]/g; - return filename.replace(badChars, '_'); - } + function fixFilename (filename) { + const badChars = /[\\\/:;\*\?\"\<\>\|]/g; + return filename.replace(badChars, '_'); + } - function makeFile (s) { - var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); - file.initWithPath(s); - return file; - } + function makeFile (s) { + var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); + file.initWithPath(s); + return file; + } - function makeURL (s) { - var url = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURL); - url.spec = s; - return url; - } + function makeURL (s) { + var url = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURL); + url.spec = s; + return url; + } + function fetch (arg) { + let filepath = arg.string; let dir = options.getPref('browser.download.dir'); let as = content.document.defaultView.wrappedJSObject.swfArgs; let doc = content.document; @@ -47,10 +48,21 @@ let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager); let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist); - let file = dm.userDownloadsDirectory; - file.appendRelativePath(title + '.mp4'); + let file; + if (filepath) { + filepath = io.expandPath(filepath); + file = io.getFile(filepath); + if (file.isDirectory()) + file.appendRelativePath(title + '.mp4'); + } else { + file = dm.userDownloadsDirectory; + file.appendRelativePath(title + '.mp4'); + } + if (file.exists()) + return liberator.echoerr('The file already exists! -> ' + file.path); file = makeFileURI(file); + let dl = dm.addDownload(0, makeURL(url, null, null), file, title, null, null, null, null, wbp); wbp.progressListener = dl; wbp.persistFlags |= wbp.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION; @@ -59,7 +71,13 @@ } //fetch(); - commands.addUserCommand(['fetchyoutube', 'fetchyt'], 'fecth youtube HD video', fetch, {}, true); + commands.addUserCommand( + ['fetchyoutube', 'fetchyt'], + 'fecth youtube HD video', + fetch, + {argCount: '*', completer: completion.file}, + true + ); })(); |