From 261a53dc44af312a32bedaf44e35c58c05905ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Castro?= Date: Sat, 14 Oct 2017 00:56:27 -0300 Subject: [PATCH 1/3] adds searchType google.searchType accepts video or news --- lib/google.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/google.js b/lib/google.js index bf5d0f0..4da6a67 100644 --- a/lib/google.js +++ b/lib/google.js @@ -43,6 +43,14 @@ var igoogle = function (query, start, callback) { if (google.timeSpan) { URL = URL.indexOf('tbs=qdr:') >= 0 ? URL.replace(/tbs=qdr:[snhdwmy]\d*/, 'tbs=qdr:' + google.timeSpan) : URL.concat('&tbs=qdr:', google.timeSpan) } + + if (google.searchType=='video') { + URL+='&tbm=vid' + } + else if (google.searchType=='news'){ + URL+='&tbm=nws' + } + var newUrl = util.format(URL, google.protocol, google.tld, google.lang, querystring.escape(query), start, google.resultsPerPage) var requestOptions = { url: newUrl, From 5179627fe9e61c9fda9209246ca233280b34b64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Castro?= Date: Sat, 14 Oct 2017 01:01:54 -0300 Subject: [PATCH 2/3] adds books to searchType --- lib/google.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/google.js b/lib/google.js index 4da6a67..c2c6188 100644 --- a/lib/google.js +++ b/lib/google.js @@ -44,12 +44,15 @@ var igoogle = function (query, start, callback) { URL = URL.indexOf('tbs=qdr:') >= 0 ? URL.replace(/tbs=qdr:[snhdwmy]\d*/, 'tbs=qdr:' + google.timeSpan) : URL.concat('&tbs=qdr:', google.timeSpan) } - if (google.searchType=='video') { + if (google.searchType=='videos') { URL+='&tbm=vid' } else if (google.searchType=='news'){ URL+='&tbm=nws' } + else if (google.searchType=='books'){ + URL+='&tbm=bks' + } var newUrl = util.format(URL, google.protocol, google.tld, google.lang, querystring.escape(query), start, google.resultsPerPage) var requestOptions = { From 83a31179e11fa02b42bf2ba3b41bf2c412b7f2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Castro?= Date: Sat, 14 Oct 2017 01:04:23 -0300 Subject: [PATCH 3/3] adds serachType to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 92b0fd7..e5bd8d7 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ google('node.js best practices', function (err, res){ ``` +### Search Within Different Categories + +You can also specify the type of the Google search. + +```js +var google = require('google') + +google.searchType = 'videos' + +google('node.js best practices', function (err, res){ + … +}) +``` + + ### Set Request Options You can specify the options to be passed to request, see the [request module](https://github.com/request/request) for all available options.