diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f47aa73 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/example/example.js b/example/example.js new file mode 100644 index 0000000..898c685 --- /dev/null +++ b/example/example.js @@ -0,0 +1,11 @@ +'use strict'; + +const pornsearch = require('../lib/pornsearch'); + +pornsearch.videos('boobs') + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.log(error); + }); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..612cb12 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./lib/pornsearch'); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..9ec5fe8 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/pornsearch.js b/src/pornsearch.js new file mode 100644 index 0000000..9ce3337 --- /dev/null +++ b/src/pornsearch.js @@ -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; \ No newline at end of file