Comparing version 1.6.2 to 1.7.0
@@ -29,3 +29,3 @@ 'use strict'; | ||
HOST = 'http://www.collinsdictionary.com'; | ||
url = HOST + '/search/autocomplete/AMERICAN_LEARNER_DICTIONARY?term=' + word; | ||
url = HOST + '/autocomplete/?dictCode=english&q=' + word; | ||
_context.next = 7; | ||
@@ -32,0 +32,0 @@ return fetch(url, { |
@@ -29,3 +29,3 @@ 'use strict'; | ||
HOST = 'http://www.collinsdictionary.com'; | ||
url = HOST + '/search/autocomplete/AMERICAN_DICTIONARY?term=' + word; | ||
url = HOST + '/autocomplete/?dictCode=english&q=' + word; | ||
_context.next = 7; | ||
@@ -93,3 +93,3 @@ return fetch(url, { | ||
// get the word page | ||
url = HOST + '/dictionary/american/' + word.replace(/ /g, '-'); | ||
url = HOST + '/dictionary/english/' + word.replace(/ /g, '-'); | ||
_context.next = 32; | ||
@@ -96,0 +96,0 @@ return fetch(url, { |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var util = require('util'); | ||
var fetch = require('node-fetch'); | ||
@@ -12,9 +11,14 @@ var cheerio = require('cheerio'); | ||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(word) { | ||
var url, res, err, html, $, map, list; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
var _this = this; | ||
var HOST, url, res, err, urlList, map, _loop, i, _ret, list, _err; | ||
return regeneratorRuntime.wrap(function _callee$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
HOST = 'http://www.merriam-webster.com'; | ||
if (!(typeof word !== 'string' || word.length === 0)) { | ||
_context.next = 2; | ||
_context2.next = 3; | ||
break; | ||
@@ -25,9 +29,8 @@ } | ||
case 2: | ||
case 3: | ||
// replace '_' to ' ', and convert to lower case | ||
word = word.replace(/_/g, ' ').toLowerCase(); | ||
url = 'http://www.merriam-webster.com/dictionary/' + word; | ||
_context.next = 6; | ||
url = HOST + '/autocomplete?term=' + word + '&ref=dictionary'; | ||
_context2.next = 7; | ||
return fetch(url, { | ||
@@ -37,11 +40,11 @@ timeout: 10 * 1000 | ||
case 6: | ||
res = _context.sent; | ||
case 7: | ||
res = _context2.sent; | ||
if (!(res.status !== 200)) { | ||
_context.next = 11; | ||
_context2.next = 12; | ||
break; | ||
} | ||
err = new Error(word + ' is not found from webster'); | ||
err = new Error('request to ' + url + ' failed, status code = ' + res.status + ' (' + res.statusText + ')'); | ||
@@ -51,38 +54,115 @@ err.code = 'ENOENT'; | ||
case 11: | ||
_context.next = 13; | ||
return res.text(); | ||
case 12: | ||
_context2.next = 14; | ||
return res.json(); | ||
case 13: | ||
html = _context.sent; | ||
$ = cheerio.load(html); | ||
case 14: | ||
_context2.t0 = function (arr, item) { | ||
if (item.label.toLowerCase() === word) { | ||
// show_cat: false, link: "/dictionary/sherry" | ||
// show_cat: true, link: "http://www.spanishcentral.com/translate/sherry" | ||
var link = (item.show_cat ? '' : HOST) + item.link; | ||
arr.push(link); | ||
} | ||
return arr; | ||
}; | ||
_context2.t1 = []; | ||
urlList = _context2.sent.reduce(_context2.t0, _context2.t1); | ||
map = {}; | ||
list = []; | ||
_loop = regeneratorRuntime.mark(function _loop(i) { | ||
var url, res, $; | ||
return regeneratorRuntime.wrap(function _loop$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
url = urlList[i]; | ||
_context.next = 3; | ||
return fetch(url, { | ||
timeout: 10 * 1000 | ||
}); | ||
$('.word-and-pronunciation .play-pron').each(function (index, element) { | ||
var ele = $(element); | ||
var audio = util.format('http://media.merriam-webster.com/audio/prons/%s/mp3/%s/%s.mp3', ele.attr('data-lang').replace(/_/g, '/'), ele.attr('data-dir'), ele.attr('data-file')); | ||
case 3: | ||
res = _context.sent; | ||
if (map.hasOwnProperty(audio) === false) { | ||
map[audio] = true; | ||
list.push(audio); | ||
} | ||
if (!(res.status !== 200)) { | ||
_context.next = 7; | ||
break; | ||
} | ||
console.error('request to ' + url + ' failed, status code = ' + res.status + ' (' + res.statusText + ')'); | ||
return _context.abrupt('return', 'continue'); | ||
case 7: | ||
_context.t0 = cheerio; | ||
_context.next = 10; | ||
return res.text(); | ||
case 10: | ||
_context.t1 = _context.sent; | ||
$ = _context.t0.load.call(_context.t0, _context.t1); | ||
$('.word-and-pronunciation .play-pron').each(function (index, element) { | ||
var ele = $(element); | ||
var lang = ele.attr('data-lang').replace(/_/g, '/'); | ||
var dir = ele.attr('data-dir'); | ||
var file = ele.attr('data-file'); | ||
var audio = 'http://media.merriam-webster.com/audio/prons/' + lang + '/mp3/' + dir + '/' + file + '.mp3'; | ||
if (map.hasOwnProperty(audio) === false) { | ||
map[audio] = true; | ||
} | ||
}); | ||
case 13: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _loop, _this); | ||
}); | ||
i = 0; | ||
if (!(list.length === 0)) { | ||
_context.next = 22; | ||
case 20: | ||
if (!(i < urlList.length)) { | ||
_context2.next = 28; | ||
break; | ||
} | ||
err = new Error(word + ' is not found from webster'); | ||
err.code = 'ENOENT'; | ||
throw err; | ||
return _context2.delegateYield(_loop(i), 't2', 22); | ||
case 22: | ||
_ret = _context2.t2; | ||
if (!(_ret === 'continue')) { | ||
_context2.next = 25; | ||
break; | ||
} | ||
return _context2.abrupt('continue', 25); | ||
case 25: | ||
i++; | ||
_context2.next = 20; | ||
break; | ||
case 28: | ||
list = Object.keys(map); | ||
if (!(list.length === 0)) { | ||
_context2.next = 33; | ||
break; | ||
} | ||
_err = new Error(word + ' is not found from webster'); | ||
_err.code = 'ENOENT'; | ||
throw _err; | ||
case 33: | ||
// show all the audio url | ||
if (list.length > 1) { | ||
list.forEach(function (audio, i) { | ||
i++; | ||
console.log(i + '. ' + audio); | ||
console.log(i + 1 + '. ' + audio); | ||
}); | ||
@@ -92,7 +172,7 @@ } | ||
// return the first audio from list | ||
return _context.abrupt('return', list[0]); | ||
return _context2.abrupt('return', list[0]); | ||
case 24: | ||
case 35: | ||
case 'end': | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
@@ -99,0 +179,0 @@ } |
@@ -9,5 +9,5 @@ 'use strict'; | ||
collinsEducation: { | ||
collins: { | ||
type: 'dic', | ||
getUrl: require('./dic/collins-education') | ||
getUrl: require('./dic/collins') | ||
}, | ||
@@ -20,7 +20,2 @@ | ||
collins: { | ||
type: 'dic', | ||
getUrl: require('./dic/collins') | ||
}, | ||
google: { | ||
@@ -27,0 +22,0 @@ type: 'tts', |
@@ -5,2 +5,4 @@ 'use strict'; | ||
require('babel-polyfill'); | ||
var path = require('path'); | ||
@@ -10,3 +12,3 @@ var util = require('util'); | ||
var program = require('commander'); | ||
var exec = require('child_process').execSync; | ||
var child = require('child_process'); | ||
var getAudio = require('./getAudio'); | ||
@@ -16,2 +18,14 @@ var config = require('../config.json'); | ||
function exec(command) { | ||
return new Promise(function (resolve, reject) { | ||
child.exec(command, function (err, stdout, stderr) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(stdout | stderr); | ||
} | ||
}); | ||
}); | ||
} | ||
function list() { | ||
@@ -69,3 +83,4 @@ for (var key in config) { | ||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(process_argv) { | ||
var service, audios, i, word, reg, cli; | ||
var service, audios, i, word, reg, cli, _i, audio, cmd; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -81,3 +96,3 @@ while (1) { | ||
// 2. parse command | ||
program.usage('<words...>').version(pkg.version).option('-w, --webster', "force download audio from webster").option('-y, --yahoo', "force download audio from yahoo").option('-C, --collins', "force download audio from collins").option('-c, --collins-edu', "force download audio from collins education").option('-g, --google', "force download audio from google").option('-i, --ispeech', "force download audio from ispeech").option('-v, --voicerss', "force download audio from voicerss").option('-a, --audio <cli>', "the command line to play .mp3 audio. set defaults to 'afplay'", setAudioCli).option('-d, --dir <path>', "set the download directory. set defaults to '~/vocabulary'", setAudioDirectory).option('-l, --list', "list all the configuration", list).option('-r, --reset', "reset configuration to default", reset).parse(process_argv); | ||
program.usage('<words...>').version(pkg.version).option('-w, --webster', "force download audio from webster").option('-y, --yahoo', "force download audio from yahoo").option('-c, --collins', "force download audio from collins").option('-g, --google', "force download audio from google").option('-i, --ispeech', "force download audio from ispeech").option('-v, --voicerss', "force download audio from voicerss").option('-a, --audio <cli>', "the command line to play .mp3 audio. set defaults to 'afplay'", setAudioCli).option('-d, --dir <path>', "set the download directory. set defaults to '~/vocabulary'", setAudioDirectory).option('-l, --list', "list all the configuration", list).option('-r, --reset', "reset configuration to default", reset).parse(process_argv); | ||
@@ -112,5 +127,4 @@ // show help info if input is empty | ||
if (program.yahoo) service = 'yahoo'; | ||
if (program.collins) service = 'collins'; | ||
if (program.yahoo) service = 'yahoo'; | ||
if (program.collinsEdu) service = 'collinsEducation'; | ||
if (program.webster) service = 'webster'; | ||
@@ -125,5 +139,5 @@ if (program.google) service = 'google'; | ||
case 21: | ||
case 20: | ||
if (!(i < program.args.length)) { | ||
_context.next = 39; | ||
_context.next = 38; | ||
break; | ||
@@ -147,17 +161,17 @@ } | ||
_context.prev = 26; | ||
_context.next = 29; | ||
_context.prev = 25; | ||
_context.next = 28; | ||
return getAudio(word, config.directory, service); | ||
case 29: | ||
case 28: | ||
audios[i].path = _context.sent; | ||
_context.next = 36; | ||
_context.next = 35; | ||
break; | ||
case 32: | ||
_context.prev = 32; | ||
_context.t1 = _context['catch'](26); | ||
case 31: | ||
_context.prev = 31; | ||
_context.t1 = _context['catch'](25); | ||
if (!(_context.t1.code !== 'ENOENT')) { | ||
_context.next = 36; | ||
_context.next = 35; | ||
break; | ||
@@ -168,14 +182,16 @@ } | ||
case 36: | ||
case 35: | ||
i++; | ||
_context.next = 21; | ||
_context.next = 20; | ||
break; | ||
case 39: | ||
case 38: | ||
// 6. test audio player command line | ||
cli = config.audio_cli.split(' ')[0]; | ||
_context.prev = 40; | ||
_context.prev = 39; | ||
_context.next = 42; | ||
return exec('which ' + cli); | ||
exec('which ' + cli); | ||
case 42: | ||
_context.next = 59; | ||
@@ -186,3 +202,3 @@ break; | ||
_context.prev = 44; | ||
_context.t2 = _context['catch'](40); | ||
_context.t2 = _context['catch'](39); | ||
@@ -212,16 +228,33 @@ console.log('\naudio player command line "' + cli + '" is not found.\n'); | ||
case 59: | ||
_i = 0; | ||
// 7. play audio | ||
audios.forEach(function (audio) { | ||
if (audio.path === null) { | ||
console.log("'%s' is not found%s", audio.word, service ? ' from ' + service : ''); | ||
return; | ||
} | ||
case 60: | ||
if (!(_i < audios.length)) { | ||
_context.next = 72; | ||
break; | ||
} | ||
console.log("play '%s' ...", path.basename(audio.path)); | ||
var cmd = util.format('%s "%s"', config.audio_cli, audio.path); | ||
exec(cmd); | ||
}); | ||
audio = audios[_i]; | ||
case 60: | ||
if (!(audio.path === null)) { | ||
_context.next = 65; | ||
break; | ||
} | ||
console.log("'%s' is not found%s", audio.word, service ? ' from ' + service : ''); | ||
return _context.abrupt('return'); | ||
case 65: | ||
console.log("play '%s' ...", path.basename(audio.path)); | ||
cmd = util.format('%s "%s"', config.audio_cli, audio.path); | ||
_context.next = 69; | ||
return exec(cmd); | ||
case 69: | ||
_i++; | ||
_context.next = 60; | ||
break; | ||
case 72: | ||
case 'end': | ||
@@ -231,3 +264,3 @@ return _context.stop(); | ||
} | ||
}, _callee, this, [[3, 7], [26, 32], [40, 44]]); | ||
}, _callee, this, [[3, 7], [25, 31], [39, 44]]); | ||
})); | ||
@@ -234,0 +267,0 @@ |
{ | ||
"name": "voc-cli", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "download and play English vocabularies' audio via command line", | ||
@@ -37,21 +37,21 @@ "main": "bin/getAudio.js", | ||
"dependencies": { | ||
"babel-polyfill": "^6.6.1", | ||
"babel-polyfill": "^6.9.1", | ||
"cheerio": "^0.20.0", | ||
"commander": "^2.9.0", | ||
"node-fetch": "^1.3.3" | ||
"node-fetch": "^1.5.3" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.6.5", | ||
"babel-eslint": "^6.0.0-beta.5", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-cli": "^6.9.0", | ||
"babel-eslint": "^6.0.4", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.6.5", | ||
"chai": "^3.4.1", | ||
"chai-as-promised": "^5.2.0", | ||
"coveralls": "^2.11.6", | ||
"eslint": "^2.2.0", | ||
"babel-register": "^6.9.0", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.3.0", | ||
"coveralls": "^2.11.9", | ||
"eslint": "^2.11.1", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"mocha": "^2.3.4", | ||
"mocha": "^2.5.3", | ||
"rewire": "^2.5.1" | ||
} | ||
} |
# voc | ||
[![NPM](https://nodei.co/npm/voc-cli.png)](https://nodei.co/npm/voc-cli/) | ||
[![][npm-img]][npm-url] | ||
[![Dependency Status](https://david-dm.org/zlargon/voc.svg)](https://david-dm.org/zlargon/voc) | ||
[![devDependency Status](https://david-dm.org/zlargon/voc/dev-status.svg)](https://david-dm.org/zlargon/voc#info=devDependencies) | ||
[![][dependency-img]][dependency-url] | ||
[![][dependency-dev-img]][dependency-dev-url] | ||
[![Travis Status](https://travis-ci.org/zlargon/voc.svg)](https://travis-ci.org/zlargon/voc) | ||
[![Appveyor Status](https://ci.appveyor.com/api/projects/status/p6b7umww30aaf6pg?svg=true)](https://ci.appveyor.com/project/zlargon/voc) | ||
[![Coverage Status](https://coveralls.io/repos/github/zlargon/voc/badge.svg)](https://coveralls.io/github/zlargon/voc) | ||
[![][travis-img]][travis-url] | ||
[![][appveyor-img]][appveyor-url] | ||
[![][coverage-img]][coverage-url] | ||
@@ -28,2 +28,6 @@ > Download and play English vocabulary's audio via command line. | ||
## Changed History | ||
[see CHANGELOG](https://github.com/zlargon/voc/blob/master/CHANGELOG.md) | ||
## Installation | ||
@@ -54,4 +58,3 @@ | ||
-y, --yahoo force download audio from yahoo | ||
-C, --collins force download audio from collins | ||
-c, --collins-edu force download audio from collins education | ||
-c, --collins force download audio from collins | ||
-g, --google force download audio from google | ||
@@ -100,1 +103,19 @@ -i, --ispeech force download audio from ispeech | ||
MIT | ||
[npm-url]: https://nodei.co/npm/voc-cli | ||
[npm-img]: https://nodei.co/npm/voc-cli.png | ||
[dependency-url]: https://david-dm.org/zlargon/voc | ||
[dependency-img]: https://img.shields.io/david/zlargon/voc.svg | ||
[dependency-dev-url]: https://david-dm.org/zlargon/voc#info=devDependencies | ||
[dependency-dev-img]: https://img.shields.io/david/dev/zlargon/voc.svg | ||
[travis-url]: https://travis-ci.org/zlargon/voc | ||
[travis-img]: https://img.shields.io/travis/zlargon/voc.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSItMTQyLjUgLTE0Mi41IDI4NSAyODUiPjxjaXJjbGUgcj0iMTQxLjciIGZpbGw9IiNERDQ4MTQiLz48ZyBpZD0iYSIgZmlsbD0iI0ZGRiI%2BPGNpcmNsZSBjeD0iLTk2LjQiIHI9IjE4LjkiLz48cGF0aCBkPSJNLTQ1LjYgNjguNGMtMTYuNi0xMS0yOS0yOC0zNC00Ny44IDYtNSA5LjgtMTIuMyA5LjgtMjAuNnMtMy44LTE1LjctOS44LTIwLjZjNS0xOS44IDE3LjQtMzYuNyAzNC00Ny44bDEzLjggMjMuMkMtNDYtMzUuMi01NS4zLTE4LjctNTUuMyAwYzAgMTguNyA5LjMgMzUuMiAyMy41IDQ1LjJ6Ii8%2BPC9nPjx1c2UgeGxpbms6aHJlZj0iI2EiIHRyYW5zZm9ybT0icm90YXRlKDEyMCkiLz48dXNlIHhsaW5rOmhyZWY9IiNhIiB0cmFuc2Zvcm09InJvdGF0ZSgyNDApIi8%2BPC9zdmc%2B | ||
[appveyor-url]: https://ci.appveyor.com/project/zlargon/voc | ||
[appveyor-img]: https://img.shields.io/appveyor/ci/zlargon/voc.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjEyOCIgaGVpZ2h0PSIxMjgiIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48ZyBmaWxsPSIjMUJBMUUyIiB0cmFuc2Zvcm09InNjYWxlKDgpIj48cGF0aCBkPSJNMCAyLjI2NWw2LjUzOS0uODg4LjAwMyA2LjI4OC02LjUzNi4wMzd6Ii8%2BPHBhdGggZD0iTTYuNTM2IDguMzlsLjAwNSA2LjI5My02LjUzNi0uODk2di01LjQ0eiIvPjxwYXRoIGQ9Ik03LjMyOCAxLjI2MWw4LjY3LTEuMjYxdjcuNTg1bC04LjY3LjA2OXoiLz48cGF0aCBkPSJNMTYgOC40NDlsLS4wMDIgNy41NTEtOC42Ny0xLjIyLS4wMTItNi4zNDV6Ii8%2BPC9nPjwvc3ZnPg== | ||
[coverage-url]: https://coveralls.io/r/zlargon/voc | ||
[coverage-img]: https://img.shields.io/coveralls/zlargon/voc.svg |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48905
18
1144
119
13
Updatedbabel-polyfill@^6.9.1
Updatednode-fetch@^1.5.3