// ==VimperatorPlugin== // @name Fetch YouTube Video // @description Fetch YouTube Video (fmt=22) // @license Creative Commons 2.1 (Attribution + Share Alike) // @version 1.1.1 // @author anekos (anekos@snca.net) // @minVersion 2.3pre // @maxVersion 2.3pre // ==/VimperatorPlugin== // // Usage: // :fetchyoutube // Download YouTube video to default download directory. // (pref: browser.download.dir) // // Links: // http://d.hatena.ne.jp/nokturnalmortum/20081118#1227004197 // // Refs: // http://creazy.net/2008/11/another_way_to_find_youtube_hd_file.html (function () { 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 makeURL (s) { var url = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURL); url.spec = s; return url; } function fetch (arg) { let doc = content.document; if (!doc.location.href.match(/^http:\/\/(?:[^.]+\.)?youtube\.com\/watch/)) return; let filepath = arg.string; let as = content.document.defaultView.wrappedJSObject.swfArgs; let title = doc.title.replace(/^YouTube - /, ''); // XXX 今が、fmt=22 じゃなかったら確認した方が良い? let fmt = /^22/.test(as.fmt_map) ? '22' : '18'; let url = 'http://www.youtube.com/get_video?fmt=' + fmt + '&video_id=' + as.video_id + '&t=' + as.t; 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; if (filepath) { file = io.File(io.expandPath(filepath)); } else { file = dm.userDownloadsDirectory; } if (file.isDirectory()) file.appendRelativePath(fixFilename(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; wbp.saveURI(makeURL(url), null, null, null, null, file); liberator.echo('maybe downloading started'); } commands.addUserCommand( ['fetchyoutube', 'fetchyt'], 'fecth YouTube HD video', fetch, {argCount: '*', completer: function (context) completion.file(context)}, true ); // fetch({}); })(); // vim:sw=2 ts=2 et si fdm=marker:
path: root/opener.js
blob: 768d2eaf4039aa0948aaed9abd4db9458c3c620d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119