Skip to content

Commit

Permalink
Merge pull request #5 from LucasLeandro1204/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
LucasLeandro1204 authored Aug 2, 2017
2 parents d64df54 + 0250c5a commit a115236
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 335 deletions.
140 changes: 69 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ Easy way to search for porn content

## Simple search

You can do it in two ways:

```js
const pornsearch = require('pornsearch');
const pornhub = pornsearch.load('pornhub');
const Pornsearch = require('pornsearch');
const Searcher = new Pornsearch('tits');

Searcher.videos()
.then(videos => console.log(videos));
```

pornhub.videos('boobs')
.then(response => console.log(response));
or (my favourite)

pornhub.gifs('pov')
.then(response => console.log(response));
```js
const Pornsearch = require('pornsearch').search('ass');

Pornsearch.gifs()
.then(gifs => console.log(gifs));
```

## Support
Expand Down Expand Up @@ -49,99 +57,89 @@ What will return in gif search

## Installation

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

## Output

#### Videos
If has success, the return will be an array with videos, structured as
```js
{
title: 'video title',
url: 'video url',
duration: 'video duration',
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*
Via GIT:
```bash
$ git clone git://github.com/LucasLeandro1204/api.git node_modules/pornsearch
```

**Check the support table to know exactly what will be returned**

#### Gifs
## Usage

If has success, the return will be an array with gifs, structured as
There's two ways to use Pornsearch:

__PORNHUB gifs in general are extremely heavy, so be a nice person and share webm__ (sex.com gifs are nice)
You can create a new instance with two parameters: the first one is the query, what you want to search, the second one is the driver (Pornhub default).

```js
{
title: 'gif title',
url: 'gif url',
webm: 'gif webm url'
}
const Pornsearch = require('pornsearch');
const Searcher = new Pornsearch(query, driver = 'pornhub');
```
If has error, will be returned a message like
```Markdown
No results for search related to *relation* in page *page*
```

**Check the support table to know exactly what will be returned**

## Usage
Or you can use the static search method, but you can pass only the query, the driver will be pornhub.
```js
const Pornsearch = require('pornsearch').search(query);
```

First require Pornsearch
But you always can change the current driver:
```js
const pornsearch = require('pornsearch');
Pornsearch.driver(driver);
```
Then pass the website you want to search on (like 'pornhub')

**An error will be thrown if Pornsearch don't support the driver you passed in**

To know the current driver
```js
const pornhub = pornsearch.load('pornhub');
Pornsearch.current();
```
**Check the [support table](#support) to know what you can do**

**An error will be thrown if don't support**

Search for related only
## Search

It's easy to search for porn content with Pornsearch =)

**Check the [support table](#support) to know what you can do**

```js
pornhub.videos('boobs')
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});

pornhub.gifs('pussy')
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
Pornsearch.videos()
.then(videos => console.log(videos)
.then(() => Pornsearch.gifs())
.then(gifs => console.log(gifs));
```
Specify the page number to search on
Specify the page to search on
```js
pornhub.videos('ass', 3);
Pornsearch.gifs(3);
```
pornhub.gifs('teta', 7);
Change de query
```js
Pornsearch.search('pussy')
.gifs(gifs => console.log(gifs));
```
Log only url
```js
pornhub.gifs('teen')
.then((gifs) => {
console.log(gifs.map(gif => gif.url));
});
Pornsearch.gifs(3)
.then(gifs => console.log(gifs.map(gif => gif.url)));
```
## Output
#### Videos
To know what the current driver will return in video search check the [videos structure](#videos-structure)
#### Gifs
To know what the current driver will return in gif search check the [gifs structure](#gifs-structure)
__PORNHUB gifs in general are extremely heavy, so be a nice person and share webm__ (sex.com gifs are nice)
If has error in whenever search, will be throw an error:
```Markdown
No results for search related to *query* in page *page*
```
15 changes: 7 additions & 8 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict';

const pornsearch = require('../');
const pornhub = pornsearch.load('pornhub');
const Pornsearch = require('../').search();

pornhub.videos('boobs')
.then((response) => {
console.log(response);
Pornsearch.driver('sex').gifs()
.then((gifs) => {
console.log(gifs);

return Pornsearch.videos();
})
.catch((error) => {
console.log(error);
});
.then(videos => console.log(videos));
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

module.exports = require('./src/pornsearch');
module.exports = require('./src/Pornsearch');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pornsearch",
"version": "1.2.3",
"description": "Easy way to search for porn content on Pornhub",
"description": "Easy way to search for porn content on internet",
"main": "src/pornsearch.js",
"scripts": {
"test": "node ./example/example"
Expand Down
41 changes: 41 additions & 0 deletions src/Core/AbstractModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

class AbstractModule {
constructor () {
this.query = '';
}

get name () {
throw new Error('This function must be overwrite');
}

get firstpage () {
throw new Error('This function must be overwrite');
}

videoUrl () {
throw new Error(`${this.name} doesn't support video search`);
}

gifUrl () {
throw new Error(`${this.name} doesn't support gif search`);
}

videoParser () {
throw new Error('This function must be overwrite');
}

gifParser () {
throw new Error('This function must be overwrite');
}

static extendsToMe (module) {
if (! (module instanceof this)) {
throw new Error(`Module should be an instance of Abstract module`);
}

return module;
}
};

module.exports = AbstractModule;
58 changes: 58 additions & 0 deletions src/Modules/Pornhub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const AbstractModule = require('../Core/AbstractModule');

class Pornhub extends AbstractModule {
get name () {
return 'Pornhub';
}

get firstpage () {
return 1;
}

videoUrl (page) {
return `http://www.pornhub.com/video/search?search=${this.query}&page=${page || this.firstpage}`;
}

gifUrl (page) {
return `http://www.pornhub.com/gifs/search?search=${this.query}&page=${page || this.firstpage}`;
}

videoParser ($) {
let videos = $('ul.videos.search-video-thumbs li');

return videos.map((i, video) => {
video = $(video);

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

return data.length
? {
title: data.find('img').attr('title'),
url: 'http://pornhub.com/' + data.attr('href'),
duration: data.find('.duration').text(),
thumb: data.find('img').attr('data-mediumthumb').replace('(m=ecuK8daaaa)', '')
}
: undefined;
}).get();
}

gifParser ($) {
let gifs = $('ul.gifs.gifLink li');

return gifs.map((i, gif) => {
gif = $(gif);

let data = gif.find('a');

return {
title: data.find('span').text(),
url: 'http://dl.phncdn.com#id#.gif'.replace('#id#', data.attr('href')),
webm: data.find('video').attr('data-webm')
};
}).get();
}
};

module.exports = Pornhub;
30 changes: 30 additions & 0 deletions src/Modules/Redtube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const AbstractModule = require('../Core/AbstractModule');

class Redtube extends AbstractModule {
get name () {
return 'Redtube';
}

get firstpage () {
return 1;
}

videoUrl (page) {
return `https://api.redtube.com/?data=redtube.Videos.searchVideos&output=json&search=${this.query}&thumbsize=big&page=${page || this.firstpage}`;
}

videoParser ($, { videos }) {
return videos.map(({ video }) => {
return {
title: video.title,
url: video.url,
duration: video.duration,
thumb: video.default_thumb,
};
});
}
};

module.exports = Redtube;
Loading

0 comments on commit a115236

Please sign in to comment.