Skip to content

Commit

Permalink
Merge pull request #40 from JustalK/dev
Browse files Browse the repository at this point in the history
[FIX] Fixing the tests
  • Loading branch information
JustalK committed Dec 16, 2020
2 parents ee8f6e9 + 05d69f1 commit 8448799
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const video = await pornhub.page(url, ['title','pornstars','download_urls']);

- **Flexible:** The results are always return in a very specific javascrypt type making it easy to integrate to your need.

### Video page pornhub
### Scraping of a single video page pornhub

```js
async page(url, options)
Expand Down Expand Up @@ -81,17 +81,17 @@ async page(url, options)

</details>

### Search page pornhub
### Scraping of a search page pornhub

```js
async search(value, keys, options)
```

| name | type | description |
| :--- | :---------- | :--- |
| value | String | value search in pornhub |
| keys | Array or String if there is only one option | List of the keys |
| options | Array | [OPTIONNAL] List of the optional options |
| name | type | description |
| :------ | :----------------------------------------------- | :--------------------------------------- |
| value | String | value search in pornhub |
| keys | Array or String if there is only one option | List of the keys |
| options | Array | [OPTIONNAL] List of the optional options |

<details>
<summary><b>Lists of options available for a search</b> (click to show)</summary>
Expand All @@ -111,10 +111,10 @@ async search(value, keys, options)
<details>
<summary><b>Lists of keys available for a search by video</b> (click to show)</summary>

| name of keys | return type | description |
| :--- | :---------- | :--- |
| related_search | String | List of the related researches |
| related_pornstars | String | List of the related pornstars |
| name of keys | return type | description |
| :---------------- | :---------- | :----------------------------- |
| related_search | String | List of the related researches |
| related_pornstars | String | List of the related pornstars |

</details>

Expand Down Expand Up @@ -142,6 +142,43 @@ async search(value, keys, options)

</details>

### Scraping of a special search page by category

There are two kind of possible way to search on pornhub. The first one is to search by term and the second one is to search by filter. This call is for the search by category and subcategory.

```js
async video(keys, options)
```

| name | type | description | default |
| :------ | :----------------------------------------------- | :--------------------------------------- | :-------- |
| keys | Array or String if there is only one option | [OPTIONNAL] List of the keys | null |
| options | Array | [OPTIONNAL] List of the optional options | null |

<details>
<summary><b>Lists of keys available for a special search page by category</b> (click to show)</summary>

| name of keys | return type | description |
| :---------------- | :---------- | :----------------------------- |
| related_search | String | List of the related videos |
| related_pornstars | String | List of the related pornstars |
</details>

<details>
<summary><b>Lists of options available for a search</b> (click to show)</summary>

| name of options | return type | description | options | default |
| :-------------- | :---------- | :--------------------------------------------- | :------------------------------ | :-------- |
| page | Number | Number of page to scraper | - | 1 |
| production | String | Type of production targeted | homemade, professional | - |
| min_duration | Number | Minimum number of minute of the video searched | 10, 20, 30 | - |
| max_duration | Number | Maximum number of minute of the video searched | 10, 20, 30 | - |
| search | String | Type of search targeted | video, pornstars, gifs | video |
| promo | String | Category of video | premium, modelhub | - |
| filter | String | Filter of the page | MOST_VIEWED, HOTTEST, TOP_RATED | - |

</details>

### Model page pornhub

```js
Expand Down
17 changes: 8 additions & 9 deletions tests/dynamic/tests_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('[PAGE] Test page model with only a title', async t => {
});

test('[PAGE] Test page model', async t => {
const page = await m.page('https://www.pornhub.com/view_video.php?viewkey=ph56fc59c124c0c', [
const page = await m.page('https://www.pornhub.com/view_video.php?viewkey=2006034279', [
'title',
'description',
'views',
Expand All @@ -32,29 +32,28 @@ test('[PAGE] Test page model', async t => {
'related_videos'
]);

t.is(page.title, 'Hot Kissing Scene');
t.is(page.title, 'Kim Kardashian Sex Tape with Ray J');
t.not(page.description, undefined);
t.not(page.views, undefined);
t.not(page.up_votes, undefined);
t.not(page.down_votes, undefined);
t.not(page.percent, undefined);
t.is(page.author, 'lovewetkissing');
t.is(page.author, 'No Data');
t.not(page.author_subscriber, undefined);
t.not(page.author_subscriber, 0);
t.not(page.pornstars, undefined);
t.is(page.pornstars[0], 'Rocco Reed');
t.is(page.pornstars[0], 'Kim Kardashian');
t.not(page.categories, undefined);
t.is(page.categories[0], 'Babe');
t.is(page.categories[0], 'Amateur');
t.not(page.tags, undefined);
t.is(page.tags[0], 'kissing');
t.is(page.tags[0], 'big tits');
t.not(page.number_of_comment, undefined);
t.not(page.number_of_comment, 0);
t.is(page.production, 'professional');
t.is(page.duration, 266);
t.is(page.duration, 300);
t.not(page.thumbnail_url, undefined);
t.not(page.upload_date, undefined);
t.not(page.download_urls, undefined);
t.not(page.download_urls['720P'], undefined);
t.not(page.download_urls['480P'], undefined);
t.not(page.download_urls['240P'], undefined);
t.not(page.comments, undefined);
Expand Down Expand Up @@ -85,7 +84,7 @@ test('[SEARCH&PAGE] Chaining the search and page', async t => {
});

test('[PAGE] Test a specific page', async t => {
const page = await m.page('https://cn.pornhub.com/view_video.php?viewkey=ph5c41444a7bed7', ['title', 'duration', 'download_urls']);
const page = await m.page('https://cn.pornhub.com/view_video.php?viewkey=ph5b1169ea3eda1', ['title', 'duration', 'download_urls']);

t.not(page.title, undefined);
t.not(page.duration, undefined);
Expand Down
8 changes: 4 additions & 4 deletions tests/static/tests_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ test('[PAGE] Try call on a pornhub page with exception', async t => {

test('[PAGE] Try all selector on a pornhub page', async t => {
nock('https://www.pornhub.com')
.get('/view_video.php?viewkey=ph56fc59c124c0d')
.get('/view_video.php?viewkey=ph56fc59c124c0cdsds')
.replyWithFile(200, './tests/datas/page_pornhub.html');
const video = await m.page(url, [
const video = await m.page('https://www.pornhub.com/view_video.php?viewkey=ph56fc59c124c0cdsds', [
'title',
'description',
'views',
Expand All @@ -80,7 +80,7 @@ test('[PAGE] Try all selector on a pornhub page', async t => {
t.is(video.pornstars[0], 'Rocco Reed');
t.is(video.pornstars[1], 'Jessie Andrews');
t.is(video.author, 'lovewetkissing');
t.is(video.percent, 70);
t.is(video.percent, 69);
t.not(video.thumbnail_url, undefined);
t.assert(video.number_of_comment > 0);
t.is(video.tags[0], 'kissing');
Expand All @@ -90,7 +90,7 @@ test('[PAGE] Try all selector on a pornhub page', async t => {
t.is(video.comments[0].username, 'kingsignature');
t.is(video.comments[0].message, 'full video');
t.is(video.upload_date.getTime(), new Date('2016-03-30T22:59:58.000Z').getTime());
t.is(video.related_videos.length, 36);
t.is(video.related_videos.length, 32);
nock.cleanAll();
});

Expand Down

0 comments on commit 8448799

Please sign in to comment.