Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed May 14, 2016
1 parent 41b5dd4 commit f02b959
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 40 deletions.
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
src
.*
LICENSE
test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v5
v6
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
node_js:
- "0.12"
- "4"
- "5"
- "6"
notifications:
email: false
after_success:
- npm run coveralls
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![npm version](https://img.shields.io/npm/v/anime-dl.svg?style=flat-square)](https://www.npmjs.com/package/anime-dl)
[![npm downloads](https://img.shields.io/npm/dm/anime-dl.svg?style=flat-square)](https://www.npmjs.com/package/anime-dl)
[![Build Status](https://img.shields.io/travis/lgaticaq/anime-dl.svg?style=flat-square)](https://travis-ci.org/lgaticaq/anime-dl)
[![Coverage Status](https://img.shields.io/coveralls/lgaticaq/anime-dl/master.svg?style=flat-square)](https://coveralls.io/github/lgaticaq/anime-dl?branch=master)
[![dependency Status](https://img.shields.io/david/lgaticaq/anime-dl.svg?style=flat-square)](https://david-dm.org/lgaticaq/anime-dl#info=dependencies)
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/anime-dl.svg?style=flat-square)](https://david-dm.org/lgaticaq/anime-dl#info=devDependencies)
[![Join the chat at https://gitter.im/lgaticaq/anime-dl](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=flat-square)](https://gitter.im/lgaticaq/anime-dl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand All @@ -19,7 +20,7 @@ npm i -S anime-dl

[Try on Tonic](https://tonicdev.com/npm/anime-dl)
```js
import anime from 'anime-dl'
import anime from 'anime-dl';

const name: 'one piece';
const chapter = '732',
Expand Down
32 changes: 9 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
"name": "anime-dl",
"version": "2.0.3",
"description": "Search and get anime video url",
"main": "lib",
"main": "src",
"scripts": {
"prepublish": "npm run build -s",
"prebuild": "npm run lint -s && npm run clean -s",
"build": "babel src --out-dir lib --source-maps",
"lint": "eslint src && eslint test",
"clean": "rimraf lib",
"pretest": "npm run build -s",
"test": "mocha --compilers js:babel-core/register"
"pretest": "eslint src",
"test": "istanbul cover _mocha",
"coveralls": "coveralls < coverage/lcov.info"
},
"engines": {
"node": ">=0.12"
"node": ">=4"
},
"repository": {
"type": "git",
Expand All @@ -33,14 +29,12 @@
"cloudscraper": "^1.2.2"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.7.7",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"eslint": "2.10.1",
"coveralls": "^2.11.9",
"eslint": "^2.10.1",
"istanbul": "^0.4.3",
"mocha": "^2.4.5",
"nock": "^8.0.0",
"rimraf": "^2.5.2"
"nock": "^8.0.0"
},
"eslintConfig": {
"env": {
Expand All @@ -49,9 +43,6 @@
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
2,
Expand All @@ -71,10 +62,5 @@
]
}
},
"babel": {
"presets": [
"es2015"
]
},
"tonicExampleFilename": "example.js"
}
18 changes: 10 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

import cheerio from 'cheerio';
import cloudscraper from 'cloudscraper';
import querystring from 'querystring';
const cheerio = require('cheerio');
const cloudscraper = require('cloudscraper');
const querystring = require('querystring');

const userAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36';

const getLinksByUrl = (uri) => {
const getLinksByUrl = uri => {
return new Promise((resolve, reject) => {
const options = {
method: 'GET',
Expand All @@ -20,7 +20,9 @@ const getLinksByUrl = (uri) => {
const validRegex = /http:\/\/jkanime\.net\/([\w\d-_]+)\/(\d+)/;
if (!validRegex.test(uri)) resolve(null);
const title = $('.vervideo').text().split(' - ')[0];
const [codeName, chapter] = validRegex.exec(uri).slice(1, 3);
const _exec = validRegex.exec(uri).slice(1, 3);
const codeName = _exec[0];
const chapter = _exec[1];
const regex = /https:\/\/jkanime\.net\/jk\.php\?u=stream\/jkmedia\/([0-9a-f]{32}\/[0-9a-f]{32}\/1\/[0-9a-f]{32})\//;
const urls = $('.player_conte').map(function() {
return $(this).attr('src');
Expand All @@ -30,7 +32,7 @@ const getLinksByUrl = (uri) => {
});
};

const getLastChapter = (name) => {
const getLastChapter = name => {
return new Promise((resolve, reject) => {
const options = {
method: 'GET',
Expand All @@ -48,7 +50,7 @@ const getLastChapter = (name) => {
});
};

const searchAnime = (keyword) => {
const searchAnime = keyword => {
return new Promise((resolve, reject) => {
const options = {
method: 'GET',
Expand All @@ -70,7 +72,7 @@ const searchAnime = (keyword) => {
});
};

const getName = (keyword) => {
const getName = keyword => {
keyword = keyword.trim();
return searchAnime(keyword).then(animes => {
if (animes.length === 0) throw new Error(`Not found anime with keyword "${keyword}"`);
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

import anime from '../src';
import {expect} from 'chai';
import path from 'path';
import nock from 'nock';
const anime = require('../src');
const expect = require('chai').expect;
const path = require('path');
const nock = require('nock');

describe('anime-dl', function() {
this.timeout(20000);
Expand Down

0 comments on commit f02b959

Please sign in to comment.