Skip to content

Commit

Permalink
Merge pull request #1 from pheyvaer/feature/refactor+cli
Browse files Browse the repository at this point in the history
Major refactor
  • Loading branch information
pheyvaer authored Oct 31, 2018
2 parents 35048ce + c5840f7 commit ea5d921
Show file tree
Hide file tree
Showing 11 changed files with 865 additions and 388 deletions.
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# MIT License

Copyright © 2018 Between Our Worlds

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# kitsu-downloader

This tool downloads the anime and character data from [Kitsu](https://kitsu.io).
Linked Data can then be generated from this data via the corresponding [rules](https://github.com/betweenourworlds/generation-rules).

## Installation

1. Clone this repo
2. Navigate into the folder: `cd kitsu-downloader`
3. Install Node dependencies: `npm i`
4. Link the bin: `npm link`

## Usage

The tool takes the following arguments

- `-V, --version`: output the version number
- `-e, --entity [entity]`: Choose between "anime" and "character"
- `-s, --start [start]`: Number of start page
- `-t, --stop [stop]`: Number of stop page
- `-o, --output [output]`: Path to output folder (default: "")
- `-v, --verbose`: Make the application more talkative
- `-h, --help`: output usage information

When you execute `kitsu-downloader -e anime -s 0 -t 199 -o test`,
the first 200 pages of anime data will be downloaded and the 200 files will be put in the folder `test`.

## License

2018 Between Our Worlds, [MIT License](https://github.com/betweenourworlds/kitsu-downloader/blob/master/LICENSE.md)
44 changes: 44 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#! /usr/bin/env node

const program = require('commander');
const logger = require('../lib/logger');
const AnimeDownloader = require('../lib/animeDownloader');
const CharacterDownloader = require('../lib/characterDownloader');
const Writer = require('../lib/writer');

program
.version('0.0.1')
.option('-e, --entity [entity]', 'Choose between "anime" and "character"')
.option('-s, --start [start]', 'Number of start page')
.option('-t, --stop [stop]', 'Number of stop page')
.option('-o, --output [output]', 'Path to output folder', '')
.option('-v, --verbose', 'Make the application more talkative', '')
.parse(process.argv);

if (program.verbose) {
//todo set level of logger
}

if (program.entity === undefined || program.start === undefined || program.start === undefined) {
logger.error('Not all required parameters are provided.');
process.exit(1);
} else {
if (program.output === undefined) {
program.output = process.cwd();
}

const writer = new Writer(program.output);
let Downloader;

if (program.entity === 'anime') {
Downloader = AnimeDownloader;
} else if (program.entity === 'character') {
Downloader = CharacterDownloader;
} else {
logger.error(`-e expects the value "anime" or "character"`);
process.exit(1);
}

const downloader = new Downloader(writer);
downloader.downloadRecursive(parseInt(program.start), parseInt(program.stop));
}
Loading

0 comments on commit ea5d921

Please sign in to comment.