Skip to content

Commit

Permalink
feat(player): Add suport play chapter in mpv
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Aug 15, 2016
1 parent 5381b3f commit 301ae3d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const chalk = require('chalk');
const updateNotifier = require('update-notifier');
const pkg = require('../package.json');
const ora = require('ora');
const spawn = require('child_process').spawn;

updateNotifier({pkg}).notify();

Expand All @@ -17,6 +18,7 @@ program
.description('CLI to get a chapter link')
.option('-a, --anime [anime]', 'Add name')
.option('-c, --chapter [chapter]', 'Add chapter')
.option('-k, --mpv', 'Play chapter in mpv')
.parse(process.argv);

if (program.anime && program.chapter) {
Expand All @@ -25,9 +27,15 @@ if (program.anime && program.chapter) {
animeDl.getLinksByNameAndChapter(program.anime, program.chapter).then((data) => {
spinner.stop();
if (data.urls.length === 0) return console.log(chalk.red('No links found'));
console.log(chalk.green('Run any of these links in your video player'));
for (let url of data.urls) {
console.log(chalk.green(url));
if (program.mpv) {
const url = data.urls[0];
console.log(chalk.green(`Playing ${url} in mpv`));
spawn('mpv', [url], {detached: true, stdio: 'ignore'});
} else {
console.log(chalk.green('Run any of these links in your video player'));
for (let url of data.urls) {
console.log(chalk.green(url));
}
}
}).catch((err) => {
spinner.stop();
Expand Down

0 comments on commit 301ae3d

Please sign in to comment.