dmhy-subscribe
Advanced tools
Comparing version 0.1.0 to 0.2.0
60
index.js
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const path = require('path') | ||
const axios = require('axios') | ||
@@ -10,3 +11,3 @@ const cheerio = require('cheerio') | ||
// const CWD = process.cwd() | ||
const CWD = process.cwd() | ||
// Make cwd to source | ||
@@ -151,8 +152,4 @@ process.chdir(__dirname) | ||
const fakedb = JSON.parse(fs.readFileSync('fakedb.json')) | ||
// console.log('fakedb', fakedb) | ||
const db = new Database(fakedb) | ||
// .option('-i, --input <list.json>', 'The json contains list with keywords.') | ||
// .option('-o, --output <list.json>', '') | ||
program | ||
@@ -163,3 +160,3 @@ .version(pkg.version) | ||
.command('add [anime...]') | ||
.usage('[anime...]') | ||
.option('-f, --file <path>', 'Add from file.') | ||
.description(` | ||
@@ -174,12 +171,24 @@ Add <anime> to subscribe. | ||
Simple: | ||
Direct: | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' 'pop team epic,極影,BIG5' | ||
Multiple: | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' 'pop team epic,極影,BIG5' | ||
File: | ||
$ dmhy ls -addable > a.txt | ||
$ dmhy rm --all | ||
$ dmhy add --file a.txt | ||
`) | ||
.action(function (animes) { | ||
if (!animes.length) { | ||
.action(function (animes, cmd) { | ||
if (!animes.length && !cmd.file) { | ||
this.help() | ||
} else { | ||
if (cmd.file) { | ||
const file = fs.readFileSync(path.normalize(path.join(CWD, cmd.file)), 'utf8') | ||
for (const a of file.split(/\r?\n/)) { | ||
if (a) { | ||
animes.push(a) | ||
} | ||
} | ||
} | ||
for (const a of animes) { | ||
@@ -189,2 +198,3 @@ const anime = db.createAnime(a) | ||
db.push(anime) | ||
console.log(`Add ${anime.name} successfully.`) | ||
} else { | ||
@@ -202,3 +212,3 @@ console.error(`Anime ${anime.name} has existed.`) | ||
.alias('rm') | ||
.usage('[vid...]') | ||
.option('-a, --all', 'Remove all subscribed <anime>.') | ||
.description(` | ||
@@ -208,11 +218,19 @@ Unsubscribe <anime> by <vid>. | ||
The <vid> are listed at \`$ dmhy list\`. | ||
Examples: | ||
$ dmhy rm XYZ ABC | ||
$ dmhy rm -a | ||
`) | ||
.action(function (vids) { | ||
if (!vids.length) { | ||
.action(function (vids, cmd) { | ||
if (!vids.length && !cmd.all) { | ||
this.help() | ||
} else { | ||
if (cmd.all) { | ||
vids = [...db].map(anime => anime.vid) | ||
} | ||
for (const vid of vids) { | ||
const anime = db.query('vid', vid) | ||
console.log('Remove', anime.name) | ||
if (anime) { | ||
console.log('Remove', anime.name) | ||
db.pop(anime) | ||
@@ -258,7 +276,15 @@ } else { | ||
.alias('ls') | ||
.option('-a, --addable', 'List addable format.') | ||
.description(` | ||
List all <anime> which are subscribed. | ||
`) | ||
.action(function () { | ||
db.list() | ||
.action(function (cmd) { | ||
if (cmd.addable) { | ||
for (const anime of db) { | ||
console.log([anime.name, ...anime.keywords].join()) | ||
} | ||
} else { | ||
db.list() | ||
} | ||
process.exit() | ||
@@ -265,0 +291,0 @@ }) |
{ | ||
"name": "dmhy-subscribe", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"bin": { | ||
@@ -5,0 +5,0 @@ "dmhy": "./index.js" |
@@ -25,43 +25,52 @@ # dmhy-subscribe | ||
``` | ||
Usage: dmhy [options] [command] | ||
Usage: dmhy [options] [command] | ||
Options: | ||
-V, --version output the version number | ||
-h, --help output usage information | ||
Options: | ||
Commands: | ||
-V, --version output the version number | ||
-h, --help output usage information | ||
add [anime...] | ||
Add <anime> to subscribe. | ||
A <anime> contains a name and following keywords | ||
to identify series you want to download, then | ||
joins them by CSV format in a string. | ||
Commands: | ||
Examples: | ||
add [options] [anime...] | ||
Add <anime> to subscribe. | ||
Simple: | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' | ||
A <anime> contains a name and following keywords | ||
to identify series you want to download, then | ||
joins them by CSV format in a string. | ||
Multiple: | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' 'pop team epic,極影,BIG5' | ||
Examples: | ||
remove|rm [vid...] | ||
Unsubscribe <anime> by <vid>. | ||
Direct: | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' | ||
$ dmhy add '紫羅蘭永恆花園,動漫國,繁體,1080P' 'pop team epic,極影,BIG5' | ||
The <vid> are listed at `$ dmhy list`. | ||
File: | ||
$ dmhy ls -addable > a.txt | ||
$ dmhy rm --all | ||
$ dmhy add --file a.txt | ||
download|dl [epid...] | ||
Download <episode> of <anime> which are subscribed. | ||
remove|rm [options] [vid...] | ||
Unsubscribe <anime> by <vid>. | ||
The epid format: <vid>-<ep> | ||
<ep> : int | float | 'all' | <ep>..<ep> | <ep>,<ep> | ||
The <vid> are listed at `$ dmhy list`. | ||
Examples: | ||
$ dmhy download ABC-01 | ||
$ dmhy dl XYZ-5.5 QWE-all ZZZ-1,3..5,6,8 | ||
Examples: | ||
$ dmhy rm XYZ ABC | ||
$ dmhy rm -a | ||
list|ls | ||
List all <anime> which are subscribed. | ||
download|dl [epid...] | ||
Download <episode> of <anime> which are subscribed. | ||
The epid format: <vid>-<ep> | ||
<ep> : int | float | 'all' | <ep>..<ep> | <ep>,<ep> | ||
Examples: | ||
$ dmhy download ABC-01 | ||
$ dmhy dl XYZ-5.5 QWE-all ZZZ-1,3..5,6,8 | ||
list|ls [options] | ||
List all <anime> which are subscribed. | ||
``` |
11252
290
76