Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Chinese/Japanese comment downloads support.

  • Loading branch information...
commit 4e7edd3956d5ce231414550cde86de7daf9a732c 1 parent 1a32d0e
@littlebtc authored
View
11 content/prefPaneDownload.xul
@@ -7,6 +7,8 @@
<preference id="pref-save_path" name="extensions.nicofox.save_path" type="file"/>
<preference id="pref-filename_scheme" name="extensions.nicofox.filename_scheme" accesskey="S" type="unichar" />
<preference id="pref-download_comment" name="extensions.nicofox.download_comment" type="bool" />
+ <preference id="pref-download_comment_zh-tw" name="extensions.nicofox.download_comment_zh-tw" type="bool" />
+ <preference id="pref-download_comment_en-us" name="extensions.nicofox.download_comment_en-us" type="bool" />
<preference id="pref-download_thumbnail" name="extensions.nicofox.download_thumbnail" type="bool" />
<preference id="pref-download_max" name="extensions.nicofox.download_max" type="int" />
<preference id="pref-video_bypass_cache" name="extensions.nicofox.video_bypass_cache" type="bool" />
@@ -37,9 +39,16 @@
<textbox width="200" id="filename_scheme" preference="pref-filename_scheme" />
</row>
<row>
+ <label value="&downloader.download_comment_variants;" />
+ <hbox>
+ <checkbox id="download_comment" preference="pref-download_comment" label="&downloader.download_comment.label;" accesskey="&downloader.download_comment.accesskey;" />
+ <checkbox id="download_comment_zh-tw" preference="pref-download_comment_zh-tw" label="&downloader.download_comment_zh-tw.label;" accesskey="&downloader.download_comment_zh-tw.accesskey;" />
+ <checkbox id="download_comment_en-us" preference="pref-download_comment_en-us" label="&downloader.download_comment_en-us.label;" accesskey="&downloader.download_comment_en-us.accesskey;" />
+ </hbox>
+ </row>
+ <row>
<label value="&downloader.also_download;" />
<vbox>
- <checkbox id="download_comment" preference="pref-download_comment" label="&downloader.download_comment.label;" accesskey="&downloader.download_comment.accesskey;" />
<checkbox id="uploader_comment" preference="pref-uploader_comment" label="&downloader.uploader_comment.label;" accesskey="&downloader.uploader_comment.accesskey;" />
<checkbox id="download_thumbnail" preference="pref-download_thumbnail" label="&downloader.download_thumbnail.label;" accesskey="&downloader.download_thumbnail.accesskey;" />
</vbox>
View
4 defaults/preferences/nicofox.js
@@ -32,6 +32,10 @@ pref("extensions.nicofox.thumbnail_check", false);
// New in 0.7a
pref("extensions.nicofox.toolbar_check", false);
+// New in 1.0b4
+pref("extensions.nicofox.download_comment_zh-tw", true);
+pref("extensions.nicofox.download_comment_en-us", true);
+
/////////////////////////////////////////// NicoMonkey
// pref("extensions.nicofox.nicomonkey.enable", true); // Removed in 0.7a
// pref("extensions.nicofox.nicomonkey.toolbar", true); // Removed in 0.7a
View
9 locale/en-US/prefwindow.dtd
@@ -17,9 +17,14 @@
<!ENTITY downloader.save_path.browse.accesskey "B">
<!ENTITY downloader.filename_scheme.label "File Name Scheme:">
<!ENTITY downloader.filename_scheme.accesskey "N">
+<!ENTITY downloader.download_comment_variants "Comments to Download:">
+<!ENTITY downloader.download_comment.label "Japanese">
+<!ENTITY downloader.download_comment.accesskey "J">
+<!ENTITY downloader.download_comment_en-us.label "English (United States)">
+<!ENTITY downloader.download_comment_en-us.accesskey "G">
+<!ENTITY downloader.download_comment_zh-tw.label "Chinese (Taiwan)">
+<!ENTITY downloader.download_comment_zh-tw.accesskey "I">
<!ENTITY downloader.also_download "Also Download:">
-<!ENTITY downloader.download_comment.label "Comments">
-<!ENTITY downloader.download_comment.accesskey "C">
<!ENTITY downloader.uploader_comment.label "Uploader Comments">
<!ENTITY downloader.uploader_comment.accesskey "U">
<!ENTITY downloader.download_thumbnail.label "Thumbnail">
View
9 locale/ja/prefwindow.dtd
@@ -17,9 +17,14 @@
<!ENTITY downloader.save_path.browse.accesskey "B">
<!ENTITY downloader.filename_scheme.label "ファイルの命名記法:">
<!ENTITY downloader.filename_scheme.accesskey "N">
+<!ENTITY downloader.download_comment_variants "コメントダウンロード:">
+<!ENTITY downloader.download_comment.label "日本語">
+<!ENTITY downloader.download_comment.accesskey "J">
+<!ENTITY downloader.download_comment_en-us.label "英語(アメリカ合衆国)">
+<!ENTITY downloader.download_comment_en-us.accesskey "G">
+<!ENTITY downloader.download_comment_zh-tw.label "中国語(台湾)">
+<!ENTITY downloader.download_comment_zh-tw.accesskey "I">
<!ENTITY downloader.also_download "以下のも一緒に落とす:">
-<!ENTITY downloader.download_comment.label "コメント">
-<!ENTITY downloader.download_comment.accesskey "C">
<!ENTITY downloader.uploader_comment.label "投稿者コメント">
<!ENTITY downloader.uploader_comment.accesskey "U">
<!ENTITY downloader.download_thumbnail.label "サムネイル">
View
9 locale/zh-CN/prefwindow.dtd
@@ -17,9 +17,14 @@
<!ENTITY downloader.save_path.browse.accesskey "B">
<!ENTITY downloader.filename_scheme.label "文件命名方式:">
<!ENTITY downloader.filename_scheme.accesskey "N">
+<!ENTITY downloader.download_comment_variants "下载评论:">
+<!ENTITY downloader.download_comment.label "日文">
+<!ENTITY downloader.download_comment.accesskey "J">
+<!ENTITY downloader.download_comment_en-us.label "英文(美国)">
+<!ENTITY downloader.download_comment_en-us.accesskey "G">
+<!ENTITY downloader.download_comment_zh-tw.label "中文(台湾)">
+<!ENTITY downloader.download_comment_zh-tw.accesskey "I">
<!ENTITY downloader.also_download "一并下载:">
-<!ENTITY downloader.download_comment.label "评论">
-<!ENTITY downloader.download_comment.accesskey "C">
<!ENTITY downloader.uploader_comment.label "投稿者专用评论">
<!ENTITY downloader.uploader_comment.accesskey "U">
<!ENTITY downloader.download_thumbnail.label "缩略图">
View
9 locale/zh-TW/prefwindow.dtd
@@ -17,9 +17,14 @@
<!ENTITY downloader.save_path.browse.accesskey "B">
<!ENTITY downloader.filename_scheme.label "檔案命名方式:">
<!ENTITY downloader.filename_scheme.accesskey "N">
+<!ENTITY downloader.download_comment_variants "下載評論:">
+<!ENTITY downloader.download_comment.label "日文">
+<!ENTITY downloader.download_comment.accesskey "J">
+<!ENTITY downloader.download_comment_en-us.label "英文(美國)">
+<!ENTITY downloader.download_comment_en-us.accesskey "G">
+<!ENTITY downloader.download_comment_zh-tw.label "中文(台灣)">
+<!ENTITY downloader.download_comment_zh-tw.accesskey "I">
<!ENTITY downloader.also_download "一併下載:">
-<!ENTITY downloader.download_comment.label "評論">
-<!ENTITY downloader.download_comment.accesskey "C">
<!ENTITY downloader.uploader_comment.label "投稿者專用評論">
<!ENTITY downloader.uploader_comment.accesskey "U">
<!ENTITY downloader.download_thumbnail.label "縮圖">
View
63 modules/DownloadUtils.jsm
@@ -153,6 +153,8 @@ DownloadUtils.nico.prototype = {
_filesCreated: false,
/* Whether to download comment, uploader comment or thumbnail? */
_getComment: false,
+ _getCommentZhTw: false,
+ _getCommentEnUs: false,
_getUploaderComment: false,
_getThumbnail: false,
/* Store video download progress */
@@ -185,6 +187,8 @@ DownloadUtils.nico.prototype = {
/* Initialize download for specific URL. */
init: function(url) {
this._getComment = Core.prefs.getBoolPref("download_comment");
+ this._getCommentZhTw = Core.prefs.getBoolPref("download_comment_zh-tw");
+ this._getCommentEnUs = Core.prefs.getBoolPref("download_comment_en-us");
this._getThumbnail = Core.prefs.getBoolPref("download_thumbnail");
/* Save the URL to the instance */
@@ -316,8 +320,27 @@ DownloadUtils.nico.prototype = {
params.video_file = this._fileBundle.files.video.path;
params.video_economy = (this._economy)?1:0;
params.video_type = this.videoType;
- if(this._getComment) {
+ var commentVariants = [];
+ if(this._getComment) {
params.comment_file = this._fileBundle.files.comment.path;
+ commentVariants.push("ja");
+ }
+ // Older version compatibility: when only comments from other language were downloaded,
+ // use it in the comment_file field.
+ // Need to handle other cases like re-downloading comments if is is implemented.
+ if(this._getCommentZhTw) {
+ if (!this._getComment) {
+ params.comment_file = this._fileBundle.files.commentZhTw.path;
+ }
+ commentVariants.push("zh-tw");
+ }
+ if(this._getCommentEnUs) {
+ // Older version compatibility: when only zh-TW comments were downloaded, use it in the comment_file field.
+ // Need to handle other cases like re-downloading comments if is is implemented.
+ if (!this._getComment && !params.comment_file) {
+ params.comment_file = this._fileBundle.files.commentEnUs.path;
+ }
+ commentVariants.push("en-us");
}
if(this._getUploaderComment) {
params.uploader_comment_file = this._fileBundle.files.uploaderComment.path;
@@ -325,6 +348,8 @@ DownloadUtils.nico.prototype = {
if(this._getThumbnail) {
params.thumbnail_file = this._fileBundle.files.thumbnail.path;
}
+ // Write all comment variants into the info field.
+ params.info = JSON.stringify({ "comment_variants": commentVariants });
this._filesCreated = true;
/* Run the callback */
this.callback("file_ready", params);
@@ -394,16 +419,30 @@ DownloadUtils.nico.prototype = {
var commentQueryString = '<packet>'+
'<thread click_revision="0" user_id="'+this._getFlvParams.user_id+'" res_from="-1000" version="20061206" thread="'+this._getFlvParams.thread_id+'"/>'+
'</packet>';
+ var commentZhTwQueryString = '<packet>'+
+ '<thread click_revision="0" user_id="'+this._getFlvParams.user_id+'" res_from="-1000" version="20061206" thread="'+this._getFlvParams.thread_id+'" language="2"/>'+
+ '</packet>';
+ var commentEnUsQueryString = '<packet>'+
+ '<thread click_revision="0" user_id="'+this._getFlvParams.user_id+'" res_from="-1000" version="20061206" thread="'+this._getFlvParams.thread_id+'" language="1"/>'+
+ '</packet>';
var uploaderCommentQueryString =
'<thread click_revision="0" fork="1" user_id="'+this._getFlvParams.user_id+'" res_from="-1000" version="20061206" thread="'+this._getFlvParams.thread_id+'"/>';
}
/* Get all extra items */
this._extraItemPromises = [];
+ /* Because we may need to modify the content in the comment XML file, use nsIXMLHttpRequest to get contents and process it. */
+ /* TODO: Don't parse to XML if none of the contents need to be overwritten for performance */
if(this._getComment) {
- /* Because we may need to modify the content in the comment XML file, use nsIXMLHttpRequest to get contents and process it. */
- /* TODO: Don't parse to XML if none of the contents need to be overwritten for performance */
var xhrDeferred = Network.fetchXml(this._getFlvParams.ms, commentQueryString);
- this._extraItemPromises.push(xhrDeferred.then(this.processNicoComment.bind(this)));
+ this._extraItemPromises.push(xhrDeferred.then(this.processNicoComment.bind(this, "ja")));
+ }
+ if(this._getCommentZhTw) {
+ var xhrDeferredZhTw = Network.fetchXml(this._getFlvParams.ms, commentZhTwQueryString);
+ this._extraItemPromises.push(xhrDeferredZhTw.then(this.processNicoComment.bind(this, "zh-tw")));
+ }
+ if(this._getCommentEnUs) {
+ var xhrDeferredEnUs = Network.fetchXml(this._getFlvParams.ms, commentEnUsQueryString);
+ this._extraItemPromises.push(xhrDeferredEnUs.then(this.processNicoComment.bind(this, "en-us")));
}
if(this._getUploaderComment) {
this._extraItemPromises.push(new persistWorker({ url: this._getFlvParams.ms, file: this._fileBundle.files.uploaderComment, postQueryString: uploaderCommentQueryString }));
@@ -505,6 +544,12 @@ DownloadUtils.nico.prototype = {
if(this._getComment && this._fileBundle.files.comment.exists()) {
this._fileBundle.files.comment.remove(false);
}
+ if(this._getCommentZhTw && this._fileBundle.files.commentZhTw.exists()) {
+ this._fileBundle.files.commentZhTw.remove(false);
+ }
+ if(this._getCommentEnUs && this._fileBundle.files.commentEnUs.exists()) {
+ this._fileBundle.files.commentEnUs.remove(false);
+ }
if(this._getUploaderComment && this._fileBundle.files.uploaderComment.exists()) {
this._fileBundle.files.uploaderComment.remove(false);
}
@@ -513,7 +558,7 @@ DownloadUtils.nico.prototype = {
}
},
/* Add <!--BoonSutazioData=Video.v --> to file, make BOON Player have ability to update; filter replace support */
- processNicoComment: function(result) {
+ processNicoComment: function(variant, result) {
if (this._canceled) { return; }
var commentsDoc = result.xml;
var boonComment = Core.prefs.getBoolPref('boon_comment');
@@ -550,7 +595,13 @@ DownloadUtils.nico.prototype = {
var xmlSerializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Ci.nsIDOMSerializer);
var content = xmlSerializer.serializeToString(commentsDoc);
/* Prepare the input/output stream to write back to file */
- var outputStream = FileUtils.openSafeFileOutputStream(this._fileBundle.files.comment);
+ var commentFile = this._fileBundle.files.comment;
+ if (variant == "zh-tw") {
+ commentFile = this._fileBundle.files.commentZhTw;
+ } else if (variant == "en-us") {
+ commentFile = this._fileBundle.files.commentEnUs;
+ }
+ var outputStream = FileUtils.openSafeFileOutputStream(commentFile);
var os = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "utf-8";
View
4 modules/FileBundle.jsm
@@ -76,6 +76,8 @@ FileBundle.nico = function(info) {
this.files.thumbnail = createFileInstanceWithPath(savePath, this.fileTitle + "[ThumbImg].jpeg");
this.files.comment = createFileInstanceWithPath(savePath, this.fileTitle + ".xml");
+ this.files.commentZhTw = createFileInstanceWithPath(savePath, this.fileTitle + "[zh-tw].xml");
+ this.files.commentEnUs = createFileInstanceWithPath(savePath, this.fileTitle + "[en-us].xml");
this.files.uploaderComment = createFileInstanceWithPath(savePath, this.fileTitle + "[Owner].xml");
}
@@ -92,7 +94,7 @@ FileBundle.nico.prototype.occupied = function() {
var variantExists = false;
this.files.comment = createFileInstanceWithPath(savePath, this.fileTitle + ".xml");
this.files.uploaderComment = createFileInstanceWithPath(savePath, this.fileTitle + "[Owner].xml");
- if (this.files.comment.exists() || this.files.uploaderComment.exists()) {
+ if (this.files.comment.exists() || this.files.commentZhTw.exists() || this.files.commentEnUs.exists() || this.files.uploaderComment.exists()) {
variantExists = true;
}

0 comments on commit 4e7edd3

Please sign in to comment.
Something went wrong with that request. Please try again.