tiansh / us-danmaku

Firefox 扩展版本见 https://github.com/tiansh/ass-danmaku ;在线转换见 https://tiansh.github.io/ass-danmaku-online/ ;【用户脚本已停止维护】用户脚本 以ass格式下载 AcFun 和 bilibili 的弹幕
210 stars 48 forks source link

批量下载功能 #12

Closed tiansh closed 8 years ago

tiansh commented 8 years ago

@jyf007 commented 2016年2月15日 GMT+8 下午4:07

我想捐助一下搞个批量下载弹幕的工具,比如现在这个av3118402有177个,我想离线看,有空用支付宝联系一下。

tiansh commented 8 years ago

@iMyon commented 2016年2月15日 GMT+8 下午4:19

我想捐助一下搞个批量下载弹幕的工具,比如现在这个av3118402有177个,我想离线看,有空用支付宝联系一下。

你要是火狐的话我倒是可以自荐一下BiliAss.myon.uc.js, uc脚本。 danmaku.zip

tiansh commented 8 years ago

使用暴力的方式另开了一个帖子,感觉很爽(×

我一时也没啥兴趣实现这功能,随手写了个很难用且很暴力的 node 脚本,目测没 @iMyon 那个好使,不过总之能用的样子。

依赖 node、firefox 依赖模块: npm install selenium-webdriver

var webdriver = require('selenium-webdriver');
var fs = require('fs');

var homeURL = 'http://tiansh.github.io/us-danmaku/bilibili/';
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities['firefox']()).build();
driver.get(homeURL);
var runInPage = (f, callback, ...args) => {
  var sargs = args.map(x => JSON.stringify(x)).join(',');
  var script = 'return (' + f + '(' + sargs + '))';
  driver.executeScript(script).then(function (result) {
    callback(result);
  });
};

var xml2ass = function (xmlfile, assfile) {
  console.log('xml2ass: ' + xmlfile + ' -> ' + assfile);
  var content = String(fs.readFileSync(xmlfile));
  runInPage(function (xml) {
    var danmaku = parseFile(xml);
    var ass = generateASS(setPosition(danmaku), {
      'title': document.title,
      'ori': name,
    });
    return ass;
  }, function (ass) {
    fs.writeFileSync(assfile, '\ufeff' + ass);
  }, content);
};

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on('line', function (line) {
  var xml = line;
  if (!xml.match(/\.xml$/)) return;
  var ass = xml.replace(/\.xml$/, '.ass');
  xml2ass(xml, ass);
});

/* 使用方法
 * 这是个node脚本,先保证装有firefox可以用,node相关的模块也装上了
 * 然后 node --harmony <这个文件的文件名>.js 打开这文件
 * 等网页加载好之后,把本地下载好的xml文件每行一个,粘贴到控制台里面
 * 沏杯茶,等一会儿
 * Ctrl-Break 关掉这个程序
 * 回去xml文件那找ass文件……
 */

总之最后得到的结果是这样的 av3843387.tar.gz

ghost commented 8 years ago

发支付宝来吧,我要砸钱。

ghost commented 8 years ago

@iMyon 胜出

ghost commented 8 years ago

使用node后如何把下载的弹幕自动命名为子标题>>> fs.writeFileSync(assfile, '\ufeff' + ass);是这一行吗?

tiansh commented 8 years ago

assfile是文件名,后面是内容。