Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasLeandro1204 committed Mar 24, 2017
1 parent 5ddf49e commit 80bfc95
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#Pornsearch
Easy way to search for porn content on the [Pornhub](http://pornhub.com/)

##Simple search
```js
const pornsearch = require('../lib/pornsearch');

pornsearch.videos('boobs')
.then((response) => {
console.log(response);
});
```

##Installation
Via GIT:
```bash
$ git clone git://github.com/LucasLeandro1204/api.git node_modules/pornsearch
```
Via NPM:
```bash
$ npm install pornsearch
```

##Output
If has success, the return will be an array with ~~possibly less than~~ 20 videos, structured as
```js
{
title: 'video title',
url: 'video url',
thumb: 'video thumbnail'
}
```
If has error, will be returned a message like
```Markdown
No results for search related to *relation* in page *page* and category number *number*
```

##Usage
First require Pornsearch
```js
const pornsearch = require('../lib/pornsearch');
```
Search for related only

```js
pornsearch.videos('boobs')
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
```
Specify the page number to search on

```js
pornsearch.videos('ass', 3);
```
You can too search by category number (look at Pornhub and search through for it)

```js
pornsearch.videos('young', 5, 41);
```

###To do

- [ ] Search for GIF
11 changes: 11 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const pornsearch = require('../lib/pornsearch');

pornsearch.videos('boobs')
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./lib/pornsearch');
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "pornsearch",
"version": "0.1.0",
"description": "Easy way to search for porn content on the Pornhub",
"main": "src/pornsearch.js",
"scripts": {
"test": "node ./example/example"
},
"keywords": [
"porn",
"nsfw",
"pornhub",
"xvideos",
"boobs"
],
"repository": {
"type": "git",
"url": "git+https://github.com/LucasLeandro1204/api.git"
},
"author": "Lucas",
"license": "MIT",
"bugs": {
"url": "https://github.com/LucasLeandro1204/api/issues"
},
"homepage": "https://github.com/LucasLeandro1204/api#readme",
"devDependencies": {
"axios": "^0.15.3",
"cheerio": "^0.22.0"
}
}
46 changes: 46 additions & 0 deletions src/pornsearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const axios = require('axios');
const cheerio = require('cheerio');

const Pornsearch = {

videos(relation, page = 1, category = 0) {
let url = `http://www.pornhub.com/video/search?search=${relation}&page=${page}&filter_category=${category}`;

return new Promise((resolve, reject) => {
axios.get(url)
.then((response) => {
resolve(this.video.parse(response.data));
})
.catch((error) => {
reject(`No results for search related to ${relation} in page ${page} and category number ${0}`);
});
});
},

video: {
parse(body) {
const $ = cheerio.load(body);
let videos = $('ul.videos.search-video-thumbs li');

return videos.map((i, video) => this.format($(video))).get();
},

format(video) {
let data = video.find('a').eq(0);

if (data.length !== 1) {
return undefined;
}

return {
title: data.attr('title'),
url: data.attr('href'),
thumb: data.find('img').attr('data-mediumthumb')
};
}
}
};

module.exports = Pornsearch;

0 comments on commit 80bfc95

Please sign in to comment.