From 134b3e720c39fbc46ee773ea8d22af73dfb15ebd Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Mon, 28 Sep 2015 09:01:03 +0000 Subject: [PATCH 1/7] Under :construction: --- cli.js | 2 ++ index.js | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 cli.js create mode 100644 index.js diff --git a/cli.js b/cli.js new file mode 100644 index 0000000..49952cf --- /dev/null +++ b/cli.js @@ -0,0 +1,2 @@ +var hell = require('./'); +hell.first(); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..6d96e5d --- /dev/null +++ b/index.js @@ -0,0 +1,102 @@ +'use strict' +var subd = module.exports; +var crypto = require('crypto'); +var fs = require('fs'); +var path = require('path'); +var http = require('http'); +var Q = require('q'); +var ProgressBar = require('progress'); +var isVideo = require('is-video'); +var chalk = require('chalk'); +var meow = require('meow'); +var p = process.cwd(); +var filesArray = []; + +subd.subdownload = function(filelist, opts) { + var opts = opts || {}; + console.log("first called"); +}; + +var processFiles = function (fileList, index) { + return Q.resolve('val').then(function () { + if (index === fileList.length) { + return 'done'; + } + if (index <= fileList.length) { + getHash(fileList[index]).then(function (d) { + return downloadSubtitle(fileList[index], d); + }).then(function () { + index++; + return processFiles(fileList, index); + }); + } + }); +}; + +var getHash = function (file) { + var defered = Q.defer(); + var shasum = crypto.createHash('md5'); + var s = fs.createReadStream(file, {start: 0, end: (64 * 1024) - 1}); + s.on('data', function (d) { + shasum.update(d); + }); + s.on('end', function () { + var stats = fs.statSync(file); + var sNew = fs.createReadStream(file, {start: stats.size - (64 * 1024), end: stats.size - 1}); + sNew.on('data', function (d) { + shasum.update(d); + }); + sNew.on('end', function () { + var d = shasum.digest('hex'); + defered.resolve(d); + }); + }); + return defered.promise; +}; + +var downloadSubtitle = function (fileName, hash) { + var defered = Q.defer(); + var srtFileName = path.basename(fileName, path.extname(fileName)) + '.srt'; + var srtFilePathName = path.dirname(fileName) + '/' + srtFileName; + var progressBarMessage = 'Downloading ' + chalk.bgBlue.bold(srtFileName) + ' [:bar] :percent :etas | :current of :total bytes'; + var finalData = ''; + var green = '\u001b[42m \u001b[0m'; + var options = { + hostname: 'api.thesubdb.com', + path: '/?action=download&hash=' + hash + '&language=en', + method: 'GET', + headers: {'user-agent': 'SubDB/1.0'} + }; + http.get(options, function (res) { + var len = parseInt(res.headers['content-length'], 10); + var bar = new ProgressBar(progressBarMessage, { + complete: green, + incomplete: '-', + width: 10, + total: len + }); + res.statusCode = '' + (res.statusCode).toString(); + res.setEncoding('utf8'); + res.on('data', function (chunk) { + bar.tick(chunk.length); + finalData += chunk; + }); + res.on('end', function () { + if (res.statusCode === '200') { + fs.writeFile(srtFilePathName, finalData, function (err) { + if (err) { + console.log(err); + } + console.log('\n---------------------------------------------------------------------------------------------\n'); + defered.resolve(fileName); + }); + } else { + console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(fileName)); + console.log('\n---------------------------------------------------------------------------------------------\n'); + console.log(); + defered.resolve('error'); + } + }); + }); + return defered.promise; +}; \ No newline at end of file From bf3a87a0720c847ca192c49b0a77f7fb9b6d9517 Mon Sep 17 00:00:00 2001 From: beatfreaker Date: Tue, 29 Sep 2015 00:16:08 +0530 Subject: [PATCH 2/7] under :construction: --- cli.js | 3 ++- index.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index 49952cf..75ec2f6 100644 --- a/cli.js +++ b/cli.js @@ -1,2 +1,3 @@ var hell = require('./'); -hell.first(); \ No newline at end of file +var arr = ['Narcos.S01E01.WEBRip.x264-TASTETV.mp4']; +hell.subdownload(arr).then(function(val){console.log("val :: " + val);}); \ No newline at end of file diff --git a/index.js b/index.js index 6d96e5d..73ed6a0 100644 --- a/index.js +++ b/index.js @@ -12,9 +12,11 @@ var meow = require('meow'); var p = process.cwd(); var filesArray = []; -subd.subdownload = function(filelist, opts) { +subd.subdownload = function(fileList, opts) { + var defered = Q.defer(); var opts = opts || {}; - console.log("first called"); + processFiles(fileList, 0).then(function(){console.log("hell");defered.resolve('done');}); + return defered.promise; }; var processFiles = function (fileList, index) { From 203c9d05de12debf37507acf21d3f2b8f93ec733 Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Tue, 29 Sep 2015 12:17:51 +0000 Subject: [PATCH 3/7] under :construction: --- cli.js | 3 +- index.js | 173 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 93 insertions(+), 83 deletions(-) diff --git a/cli.js b/cli.js index 75ec2f6..250cdfa 100644 --- a/cli.js +++ b/cli.js @@ -1,3 +1,4 @@ var hell = require('./'); var arr = ['Narcos.S01E01.WEBRip.x264-TASTETV.mp4']; -hell.subdownload(arr).then(function(val){console.log("val :: " + val);}); \ No newline at end of file +//hell.subdownload(arr).then(function(val){console.log("val :: " + val);}); +hell.subdownload(); \ No newline at end of file diff --git a/index.js b/index.js index 73ed6a0..e13e17c 100644 --- a/index.js +++ b/index.js @@ -1,104 +1,113 @@ 'use strict' -var subd = module.exports; +var Promise = require('pinkie-promise'); var crypto = require('crypto'); var fs = require('fs'); var path = require('path'); var http = require('http'); -var Q = require('q'); var ProgressBar = require('progress'); -var isVideo = require('is-video'); var chalk = require('chalk'); -var meow = require('meow'); -var p = process.cwd(); -var filesArray = []; +var arr = ['package.json','subdownloader.js']; -subd.subdownload = function(fileList, opts) { - var defered = Q.defer(); - var opts = opts || {}; - processFiles(fileList, 0).then(function(){console.log("hell");defered.resolve('done');}); - return defered.promise; -}; +var exp = module.exports; -var processFiles = function (fileList, index) { - return Q.resolve('val').then(function () { - if (index === fileList.length) { - return 'done'; - } - if (index <= fileList.length) { - getHash(fileList[index]).then(function (d) { - return downloadSubtitle(fileList[index], d); - }).then(function () { - index++; - return processFiles(fileList, index); - }); - } +exp.subdownload = function () { + return new Promise(function(resolve, reject) { + processFile(0).then(function(data){console.log('called');}); }); -}; +} + +var processFile = function (index) { + console.log("index :: " + index); + if(index == arr.length) { + console.log("returning"); + return Promise(function(resolve, reject){ + resolve('done'); + }); + } else { + getHash(arr[index]).then(function(fileName, hash) { + return downloadSubtitle(fileName, hash); + }).then(function(data) { + processFile(++index); + }); + } +} + var getHash = function (file) { - var defered = Q.defer(); - var shasum = crypto.createHash('md5'); - var s = fs.createReadStream(file, {start: 0, end: (64 * 1024) - 1}); - s.on('data', function (d) { - shasum.update(d); - }); - s.on('end', function () { - var stats = fs.statSync(file); - var sNew = fs.createReadStream(file, {start: stats.size - (64 * 1024), end: stats.size - 1}); - sNew.on('data', function (d) { + console.log("Generating Hash :: " + file); + return new Promise(function (resolve, reject) { + var shasum = crypto.createHash('md5'); + var s = fs.createReadStream(file, {start: 0, end: (64 * 1024) - 1}); + s.on('data', function (d) { shasum.update(d); }); - sNew.on('end', function () { - var d = shasum.digest('hex'); - defered.resolve(d); + s.on('end', function () { + var stats = fs.statSync(file); + var sNew = fs.createReadStream(file, {start: stats.size - (64 * 1024), end: stats.size - 1}); + sNew.on('data', function (d) { + shasum.update(d); + }); + sNew.on('end', function () { + var d = shasum.digest('hex'); + resolve(file, d); + }); }); }); - return defered.promise; }; + var downloadSubtitle = function (fileName, hash) { - var defered = Q.defer(); - var srtFileName = path.basename(fileName, path.extname(fileName)) + '.srt'; - var srtFilePathName = path.dirname(fileName) + '/' + srtFileName; - var progressBarMessage = 'Downloading ' + chalk.bgBlue.bold(srtFileName) + ' [:bar] :percent :etas | :current of :total bytes'; - var finalData = ''; - var green = '\u001b[42m \u001b[0m'; - var options = { - hostname: 'api.thesubdb.com', - path: '/?action=download&hash=' + hash + '&language=en', - method: 'GET', - headers: {'user-agent': 'SubDB/1.0'} - }; - http.get(options, function (res) { - var len = parseInt(res.headers['content-length'], 10); - var bar = new ProgressBar(progressBarMessage, { - complete: green, - incomplete: '-', - width: 10, - total: len - }); - res.statusCode = '' + (res.statusCode).toString(); - res.setEncoding('utf8'); - res.on('data', function (chunk) { - bar.tick(chunk.length); - finalData += chunk; - }); - res.on('end', function () { - if (res.statusCode === '200') { - fs.writeFile(srtFilePathName, finalData, function (err) { - if (err) { - console.log(err); - } + console.log("Downloading subtitle :: " + fileName); + return new Promise(function (resolve, reject) { + var srtFileName = path.basename(fileName, path.extname(fileName)) + '.srt'; + var srtFilePathName = path.dirname(fileName) + '/' + srtFileName; + var progressBarMessage = 'Downloading ' + chalk.bgBlue.bold(srtFileName) + ' [:bar] :percent :etas | :current of :total bytes'; + var finalData = ''; + var green = '\u001b[42m \u001b[0m'; + var options = { + hostname: 'api.thesubdb.com', + path: '/?action=download&hash=' + hash + '&language=en', + method: 'GET', + headers: {'user-agent': 'SubDB/1.0'} + }; + http.get(options, function (res) { + var len = parseInt(res.headers['content-length'], 10); + var bar = new ProgressBar(progressBarMessage, { + complete: green, + incomplete: '-', + width: 10, + total: len + }); + res.statusCode = '' + (res.statusCode).toString(); + res.setEncoding('utf8'); + res.on('data', function (chunk) { + bar.tick(chunk.length); + finalData += chunk; + }); + res.on('end', function () { + if (res.statusCode === '200') { + fs.writeFile(srtFilePathName, finalData, function (err) { + if (err) { + console.log(err); + } + console.log('\n---------------------------------------------------------------------------------------------\n'); + resolve(fileName); + }); + } else { + console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(fileName)); console.log('\n---------------------------------------------------------------------------------------------\n'); - defered.resolve(fileName); - }); - } else { - console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(fileName)); - console.log('\n---------------------------------------------------------------------------------------------\n'); - console.log(); - defered.resolve('error'); - } + console.log(); + resolve('error'); + } + }); }); }); - return defered.promise; -}; \ No newline at end of file +}; + + +var tell = function (val) { + console.log("tell :: " + val); + return new Promise(function (resolve, reject) { + setTimeout(function(){resolve('finished')}, 1000); + }); +} From 833b70d0d5d9166e219ef7a378700313baaafab1 Mon Sep 17 00:00:00 2001 From: beatfreaker Date: Wed, 30 Sep 2015 22:16:11 +0530 Subject: [PATCH 4/7] add api --- cli.js | 88 ++++++++++++++++++++++-- index.js | 81 ++++++++++------------ package.json | 11 ++- subdownloader.js | 172 ----------------------------------------------- 4 files changed, 126 insertions(+), 226 deletions(-) delete mode 100644 subdownloader.js diff --git a/cli.js b/cli.js index 250cdfa..248c380 100644 --- a/cli.js +++ b/cli.js @@ -1,4 +1,84 @@ -var hell = require('./'); -var arr = ['Narcos.S01E01.WEBRip.x264-TASTETV.mp4']; -//hell.subdownload(arr).then(function(val){console.log("val :: " + val);}); -hell.subdownload(); \ No newline at end of file +#! /usr/bin/env node +'use strict'; +var subd = require('./'); +var fs = require('fs'); +var path = require('path'); +var Q = require('q'); +var isVideo = require('is-video'); +var meow = require('meow'); +var p = process.cwd(); +var filesArray = []; + +var cli = meow({ + help: [ + 'Help\n', + ' > subdownload\n', + ' To download subtitles for all the files present in current folder\n', + ' > subdownload --deep\n', + ' To download subtitles for all the files present in current folder as well as in subfolder\n', + ' > subdownload "File Name.mkv"\n', + ' To download subtitles for specific file\n', + ' > subdownload "File1.mkv" "File2.avi" .... "Filen"\n', + ' To download subtitles for more then one file\n' + ] +}); + +var filterFiles = function (files) { + try { + return files.filter(function (file) { + return fs.statSync(file).isFile() && isVideo(file); + }); + } catch (err) { + console.log('Please check if all the file name given exists or not.'); + } +}; + +var getFileList = function () { + var fileList; + var counter = 1; + var defered = Q.defer(); + fs.readdir(p, function (err, files) { + if (err) { + throw err; + } + if (cli.input.length === 0) { + fileList = filterFiles(files); + } else { + fileList = filterFiles(cli.input); + } + if (fileList) { + fileList.forEach(function (file) { + filesArray.push(file); + counter++; + if (counter > fileList.length) { + defered.resolve(filesArray); + } + }); + } + }); + return defered.promise; +}; + +var getDeepFiles = function (currentDir) { + fs.readdirSync(currentDir).forEach(function (name) { + var filePath = path.join(currentDir, name); + var stat = fs.statSync(filePath); + if (stat.isFile() && isVideo(filePath)) { + filesArray.push(filePath); + } else if (stat.isDirectory()) { + getDeepFiles(filePath); + } + }); +}; + +var getPara = function () { + if (cli.flags.deep) { + getDeepFiles(p); + subd.subdownload(filesArray); + } else { + getFileList().then(function (data) { + subd.subdownload(data); + }); + } +}; +getPara(); diff --git a/index.js b/index.js index e13e17c..0eafe5d 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; var Promise = require('pinkie-promise'); var crypto = require('crypto'); var fs = require('fs'); @@ -6,67 +6,42 @@ var path = require('path'); var http = require('http'); var ProgressBar = require('progress'); var chalk = require('chalk'); -var arr = ['package.json','subdownloader.js']; - +var obj = {fileName: '', hash: ''}; +var returnObj = {success: [], failed: []}; var exp = module.exports; -exp.subdownload = function () { - return new Promise(function(resolve, reject) { - processFile(0).then(function(data){console.log('called');}); - }); -} - -var processFile = function (index) { - console.log("index :: " + index); - if(index == arr.length) { - console.log("returning"); - return Promise(function(resolve, reject){ - resolve('done'); - }); - } else { - getHash(arr[index]).then(function(fileName, hash) { - return downloadSubtitle(fileName, hash); - }).then(function(data) { - processFile(++index); - }); - } -} - - -var getHash = function (file) { - console.log("Generating Hash :: " + file); +var getHash = function (obj) { return new Promise(function (resolve, reject) { var shasum = crypto.createHash('md5'); - var s = fs.createReadStream(file, {start: 0, end: (64 * 1024) - 1}); + var s = fs.createReadStream(obj.fileName, {start: 0, end: (64 * 1024) - 1}); s.on('data', function (d) { shasum.update(d); }); s.on('end', function () { - var stats = fs.statSync(file); - var sNew = fs.createReadStream(file, {start: stats.size - (64 * 1024), end: stats.size - 1}); + var stats = fs.statSync(obj.fileName); + var sNew = fs.createReadStream(obj.fileName, {start: stats.size - (64 * 1024), end: stats.size - 1}); sNew.on('data', function (d) { shasum.update(d); }); sNew.on('end', function () { var d = shasum.digest('hex'); - resolve(file, d); + obj.hash = d; + resolve(obj); }); }); }); }; - -var downloadSubtitle = function (fileName, hash) { - console.log("Downloading subtitle :: " + fileName); +var downloadSubtitle = function (obj) { return new Promise(function (resolve, reject) { - var srtFileName = path.basename(fileName, path.extname(fileName)) + '.srt'; - var srtFilePathName = path.dirname(fileName) + '/' + srtFileName; + var srtFileName = path.basename(obj.fileName, path.extname(obj.fileName)) + '.srt'; + var srtFilePathName = path.dirname(obj.fileName) + '/' + srtFileName; var progressBarMessage = 'Downloading ' + chalk.bgBlue.bold(srtFileName) + ' [:bar] :percent :etas | :current of :total bytes'; var finalData = ''; var green = '\u001b[42m \u001b[0m'; var options = { hostname: 'api.thesubdb.com', - path: '/?action=download&hash=' + hash + '&language=en', + path: '/?action=download&hash=' + obj.hash + '&language=en', method: 'GET', headers: {'user-agent': 'SubDB/1.0'} }; @@ -90,24 +65,36 @@ var downloadSubtitle = function (fileName, hash) { if (err) { console.log(err); } - console.log('\n---------------------------------------------------------------------------------------------\n'); - resolve(fileName); + returnObj.success.push(obj.fileName); + resolve(obj); }); } else { - console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(fileName)); - console.log('\n---------------------------------------------------------------------------------------------\n'); - console.log(); + console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(obj.fileName)); + returnObj.failed.push(obj.fileName); resolve('error'); } + console.log('\n'); }); }); }); }; +var processFiles = function (arr) { + return arr.reduce(function (promise, file) { + return promise.then(function () { + obj.fileName = file; + return getHash(obj).then(function (obj) { + return downloadSubtitle(obj); + }); + }); + }, Promise.resolve()); +}; -var tell = function (val) { - console.log("tell :: " + val); +exp.subdownload = function (fileList, opt) { + opt = opt || {}; return new Promise(function (resolve, reject) { - setTimeout(function(){resolve('finished')}, 1000); + processFiles(fileList).then(function () { + resolve(returnObj); + }); }); -} +}; diff --git a/package.json b/package.json index 65d55a9..8d4f551 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "subdownloader", "description": "Painless subtitles downloader", - "version": "1.1.0", + "version": "2.0.0", "author": { "name": "Chintan Radia", "email": "radiachints1512@gmail.com", "url": "http://beatfreaker.github.io/" }, "bin": { - "subdownload": "subdownloader.js", - "sd": "subdownloader.js" + "subdownload": "cli.js", + "sd": "cli.js" }, "bugs": { "url": "https://github.com/beatfreaker/subdownloader/issues" @@ -22,12 +22,17 @@ "is-video": "^1.0.1", "meow": "^3.3.0", "path": "^0.11.14", + "pinkie-promise": "^1.0.0", "progress": "^1.1.8", "q": "^1.4.1" }, "devDependencies": { "tape": "^4.2.0" }, + "files": [ + "cli.js", + "index.js" + ], "homepage": "https://github.com/beatfreaker/subdownloader", "keywords": [ "cli", diff --git a/subdownloader.js b/subdownloader.js deleted file mode 100644 index 37201d7..0000000 --- a/subdownloader.js +++ /dev/null @@ -1,172 +0,0 @@ -#! /usr/bin/env node -'use strict'; -var crypto = require('crypto'); -var fs = require('fs'); -var path = require('path'); -var http = require('http'); -var Q = require('q'); -var ProgressBar = require('progress'); -var isVideo = require('is-video'); -var chalk = require('chalk'); -var meow = require('meow'); -var p = process.cwd(); -var filesArray = []; - -var cli = meow({ - help: [ - 'Help\n', - ' > subdownload\n', - ' To download subtitles for all the files present in current folder\n', - ' > subdownload --deep\n', - ' To download subtitles for all the files present in current folder as well as in subfolder\n', - ' > subdownload "File Name.mkv"\n', - ' To download subtitles for specific file\n', - ' > subdownload "File1.mkv" "File2.avi" .... "Filen"\n', - ' To download subtitles for more then one file\n' - ] -}); - -var filterFiles = function (files) { - try { - return files.filter(function (file) { - return fs.statSync(file).isFile() && isVideo(file); - }); - } catch (err) { - console.log('Please check if all the file name given exists or not.'); - } -}; - -var getFileList = function () { - var fileList; - var counter = 1; - var defered = Q.defer(); - fs.readdir(p, function (err, files) { - if (err) { - throw err; - } - if (cli.input.length === 0) { - fileList = filterFiles(files); - } else { - fileList = filterFiles(cli.input); - } - if (fileList) { - fileList.forEach(function (file) { - filesArray.push(file); - counter++; - if (counter > fileList.length) { - defered.resolve(filesArray); - } - }); - } - }); - return defered.promise; -}; - -var downloadSubtitle = function (fileName, hash) { - var defered = Q.defer(); - var srtFileName = path.basename(fileName, path.extname(fileName)) + '.srt'; - var srtFilePathName = path.dirname(fileName) + '/' + srtFileName; - var progressBarMessage = 'Downloading ' + chalk.bgBlue.bold(srtFileName) + ' [:bar] :percent :etas | :current of :total bytes'; - var finalData = ''; - var green = '\u001b[42m \u001b[0m'; - var options = { - hostname: 'api.thesubdb.com', - path: '/?action=download&hash=' + hash + '&language=en', - method: 'GET', - headers: {'user-agent': 'SubDB/1.0'} - }; - http.get(options, function (res) { - var len = parseInt(res.headers['content-length'], 10); - var bar = new ProgressBar(progressBarMessage, { - complete: green, - incomplete: '-', - width: 10, - total: len - }); - res.statusCode = '' + (res.statusCode).toString(); - res.setEncoding('utf8'); - res.on('data', function (chunk) { - bar.tick(chunk.length); - finalData += chunk; - }); - res.on('end', function () { - if (res.statusCode === '200') { - fs.writeFile(srtFilePathName, finalData, function (err) { - if (err) { - console.log(err); - } - console.log('\n---------------------------------------------------------------------------------------------\n'); - defered.resolve(fileName); - }); - } else { - console.log('Sorry no subitles were found for ====> ' + chalk.bgRed.bold(fileName)); - console.log('\n---------------------------------------------------------------------------------------------\n'); - console.log(); - defered.resolve('error'); - } - }); - }); - return defered.promise; -}; - -var getHash = function (file) { - var defered = Q.defer(); - var shasum = crypto.createHash('md5'); - var s = fs.createReadStream(file, {start: 0, end: (64 * 1024) - 1}); - s.on('data', function (d) { - shasum.update(d); - }); - s.on('end', function () { - var stats = fs.statSync(file); - var sNew = fs.createReadStream(file, {start: stats.size - (64 * 1024), end: stats.size - 1}); - sNew.on('data', function (d) { - shasum.update(d); - }); - sNew.on('end', function () { - var d = shasum.digest('hex'); - defered.resolve(d); - }); - }); - return defered.promise; -}; - -var processFiles = function (fileList, index) { - return Q.resolve('val').then(function () { - if (index === fileList.length) { - return 'done'; - } - if (index <= fileList.length) { - getHash(fileList[index]).then(function (d) { - return downloadSubtitle(fileList[index], d); - }).then(function () { - index++; - return processFiles(fileList, index); - }); - } - }); -}; - -var getDeepFiles = function (currentDir) { - fs.readdirSync(currentDir).forEach(function (name) { - var filePath = path.join(currentDir, name); - var stat = fs.statSync(filePath); - if (stat.isFile() && isVideo(filePath)) { - filesArray.push(filePath); - } else if (stat.isDirectory()) { - getDeepFiles(filePath); - } - }); -}; - -var getPara = function () { - if (cli.flags.deep) { - getDeepFiles(p); - processFiles(filesArray, 0); - } else { - getFileList().then(function (data) { - processFiles(data, 0); - }); - } -}; - -getPara(); From 069285835d58b104f05fb6b236e55df66135426c Mon Sep 17 00:00:00 2001 From: beatfreaker Date: Wed, 30 Sep 2015 23:33:20 +0530 Subject: [PATCH 5/7] add api doc --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 731bcf9..b7586f6 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,8 @@ npm install -g subdownloader ## How to use -- After installation navigate to the folder `cd subdownloader` -- Execute `npm link` -- Now navigate to any folder where movies or TV series files are present through command prompt and execute `subdownload` command and let all the magic happens. +- Navigate to the folder in which you have the file for which you want to download subtitles through command prompt. +- Execute `subdownload` command and let all the magic happens. - `sd` is a shorthand command. You can use `sd` instead of `subdownload` ## Options @@ -31,6 +30,19 @@ npm install -g subdownloader `subdownload --deep` - Use `subdownload --help` for listing all the options available. +##API + +```js +var subd = require('subdownloader'); + +//filesArray - is the array of path to the files for which you want to download the subtitles +//obj - in return you will return an object having success and failed files array +subd.subdownload(filesArray).then(function(obj){ + console.log(obj); + //=> { success: [successfile1,successfile2], failed: [failedfile1]} +}); +``` + ## Demo ![Demo image](https://github.com/beatfreaker/subdownloader/blob/master/demo/demo.gif) From 8348230545e59250add163892b759f2b353037ae Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Wed, 30 Sep 2015 23:37:55 +0530 Subject: [PATCH 6/7] minor tweaks --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b7586f6..4716b0f 100644 --- a/README.md +++ b/README.md @@ -18,24 +18,25 @@ npm install -g subdownloader - To download subtitles for all the movies in a folder execute. - `subdownload` + `> subdownload` - To download subtitles for single movie execute. - `subdownload "Movie Name"` + `> subdownload "Movie Name"` - To download subtitles for more then one movie but not all movies in a folder execute. - `subdownload "Movie 1" "Movie 2" .... "Movie n"` + `> subdownload "Movie 1" "Movie 2" .... "Movie n"` - To enable deep download means to download subtitles for files in a folder as well as subfolders. - `subdownload --deep` -- Use `subdownload --help` for listing all the options available. + `> subdownload --deep` +- Use `> subdownload --help` for listing all the options available. ##API ```js var subd = require('subdownloader'); -//filesArray - is the array of path to the files for which you want to download the subtitles +//filesArray - is the array of path to the files for which +//you want to download the subtitles //obj - in return you will return an object having success and failed files array subd.subdownload(filesArray).then(function(obj){ console.log(obj); From 4dc718f1d98d7e6096de4a7fb263187087a11057 Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Wed, 30 Sep 2015 23:49:15 +0530 Subject: [PATCH 7/7] minor tweaks --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index f2f7761..0aaaa3d 100644 --- a/test/test.js +++ b/test/test.js @@ -4,7 +4,7 @@ var childProcess = require('child_process'); test('Invalid file name', function (t) { t.plan(1); - childProcess.execFile('../subdownloader.js', ['randomfilename'], {cwd: __dirname}, function (err, stdout) { + childProcess.execFile('../cli.js', ['randomfilename'], {cwd: __dirname}, function (err, stdout) { t.equal('Please check if all the file name given exists or not.\n', stdout, 'Both strings are equal'); }); });