Changeset 24155
- Timestamp:
- 11/18/08 21:24:16 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/fetchyoutube.js
r24132 r24155 19 19 (function () { 20 20 21 function fetch () { 22 function fixFilename (filename) { 23 const badChars = /[\\\/:;\*\?\"\<\>\|]/g; 24 return filename.replace(badChars, '_'); 25 } 21 function fixFilename (filename) { 22 const badChars = /[\\\/:;\*\?\"\<\>\|]/g; 23 return filename.replace(badChars, '_'); 24 } 26 25 27 function makeFile (s) {28 var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);29 file.initWithPath(s);30 return file;31 }26 function makeFile (s) { 27 var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); 28 file.initWithPath(s); 29 return file; 30 } 32 31 33 function makeURL (s) {34 var url = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURL);35 url.spec = s;36 return url;37 }32 function makeURL (s) { 33 var url = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURL); 34 url.spec = s; 35 return url; 36 } 38 37 38 function fetch (arg) { 39 let filepath = arg.string; 39 40 let dir = options.getPref('browser.download.dir'); 40 41 let as = content.document.defaultView.wrappedJSObject.swfArgs; … … 48 49 let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist); 49 50 50 let file = dm.userDownloadsDirectory; 51 file.appendRelativePath(title + '.mp4'); 51 let file; 52 if (filepath) { 53 filepath = io.expandPath(filepath); 54 file = io.getFile(filepath); 55 if (file.isDirectory()) 56 file.appendRelativePath(title + '.mp4'); 57 } else { 58 file = dm.userDownloadsDirectory; 59 file.appendRelativePath(title + '.mp4'); 60 } 61 if (file.exists()) 62 return liberator.echoerr('The file already exists! -> ' + file.path); 52 63 file = makeFileURI(file); 64 53 65 54 66 let dl = dm.addDownload(0, makeURL(url, null, null), file, title, null, null, null, null, wbp); … … 60 72 //fetch(); 61 73 62 commands.addUserCommand(['fetchyoutube', 'fetchyt'], 'fecth youtube HD video', fetch, {}, true); 74 commands.addUserCommand( 75 ['fetchyoutube', 'fetchyt'], 76 'fecth youtube HD video', 77 fetch, 78 {argCount: '*', completer: completion.file}, 79 true 80 ); 63 81 64 82 })();
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)