Skip to content

Adds searchType #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions lib/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ 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=='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 = {
url: newUrl,
Expand Down