xvideosx 1.4.3 → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,4 +5,5 @@ module.exports = {
5
5
  fresh: require('./fresh'),
6
6
  verified: require('./verified'),
7
7
  search: require('./search'),
8
+ newFresh: require('./newfresh'),
8
9
  };
@@ -0,0 +1,2 @@
1
+ /* eslint-disable linebreak-style */
2
+ module.exports = require('./newfresh');
@@ -0,0 +1,42 @@
1
+ /* eslint-disable linebreak-style */
2
+ /* eslint-disable no-undef */
3
+ const puppeteer = require('puppeteer');
4
+
5
+ const newFresh = async ({ url, puppeteerConfig } = {}) => {
6
+ let browser;
7
+ try {
8
+ browser = await puppeteer.launch(puppeteerConfig);
9
+ const page = await browser.newPage();
10
+ await page.goto(url, { waitUntil: 'networkidle2' });
11
+
12
+ const result = await page.evaluate(() => {
13
+ const thumbs = document.querySelectorAll('.thumb');
14
+ const titles = document.querySelectorAll('.title');
15
+ const data = [];
16
+ thumbs.forEach((thumb, index) => {
17
+ const anchor = thumb.querySelector('a');
18
+ const img = thumb.querySelector('img');
19
+ const text = titles[index];
20
+ const url = anchor ? anchor.href : null;
21
+ let title;
22
+ if (text) {
23
+ title = text.textContent;
24
+ }
25
+ if (img) {
26
+ const thumb = img.src;
27
+ data.push({
28
+ thumb,
29
+ title,
30
+ url,
31
+ });
32
+ }
33
+ return result;
34
+ });
35
+ return data;
36
+ });
37
+ } finally {
38
+ if (browser) await browser.close();
39
+ }
40
+ };
41
+
42
+ module.exports = newFresh;
@@ -0,0 +1,139 @@
1
+ /* eslint-disable import/no-unresolved */
2
+ /* eslint-disable padded-blocks */
3
+
4
+ const chai = require('chai');
5
+ const fresh = require('./fresh');
6
+
7
+ before(() => {
8
+ chai.should();
9
+ });
10
+
11
+ describe('api/videos/newFresh', () => {
12
+
13
+ it('should list fresh video pages', async () => {
14
+ const list = await fresh({ page: 2 });
15
+
16
+ list.should.be.an('object');
17
+ list.pagination.should.be.an('object');
18
+ list.pagination.page.should.be.equals(2);
19
+ list.pagination.pages.should.be.an('array');
20
+ list.pagination.pages[0].should.be.a('number');
21
+ list.hasNext.should.be.a('function');
22
+ list.hasNext().should.be.equals(true);
23
+ list.hasPrevious.should.be.a('function');
24
+ list.hasPrevious().should.be.equals(true);
25
+ list.next.should.be.a('function');
26
+ list.previous.should.be.a('function');
27
+ list.videos.should.be.an('array');
28
+ list.videos.forEach((video) => {
29
+ video.should.be.an('object');
30
+ video.should.have.ownPropertyDescriptor('duration');
31
+ video.duration.should.be.a('string');
32
+ video.should.have.ownPropertyDescriptor('path');
33
+ video.path.should.be.a('string');
34
+ video.should.have.ownPropertyDescriptor('profile');
35
+ video.profile.should.be.an('object');
36
+ video.profile.should.have.ownPropertyDescriptor('name');
37
+ video.profile.name.should.be.an('string');
38
+ video.profile.should.have.ownPropertyDescriptor('url');
39
+ video.profile.url.should.be.an('string');
40
+ video.should.have.ownPropertyDescriptor('title');
41
+ video.title.should.be.a('string');
42
+ video.should.have.ownPropertyDescriptor('url');
43
+ video.url.should.be.a('string');
44
+ video.should.have.ownPropertyDescriptor('views');
45
+ video.views.should.be.a('string');
46
+ });
47
+
48
+ const previous = await list.previous();
49
+ previous.should.be.an('object');
50
+ previous.pagination.should.be.an('object');
51
+ previous.pagination.page.should.be.equals(1);
52
+ previous.pagination.pages.should.be.an('array');
53
+ previous.pagination.pages[0].should.be.a('number');
54
+ previous.hasNext.should.be.a('function');
55
+ previous.hasNext().should.be.equals(true);
56
+ previous.hasPrevious.should.be.a('function');
57
+ previous.hasPrevious().should.be.equals(false);
58
+ previous.next.should.be.a('function');
59
+ previous.previous.should.be.a('function');
60
+ previous.videos.should.be.an('array');
61
+ previous.videos.forEach((video) => {
62
+ video.should.be.an('object');
63
+ video.should.have.ownPropertyDescriptor('duration');
64
+ video.duration.should.be.a('string');
65
+ video.should.have.ownPropertyDescriptor('path');
66
+ video.path.should.be.a('string');
67
+ video.should.have.ownPropertyDescriptor('profile');
68
+ video.profile.should.be.an('object');
69
+ video.profile.should.have.ownPropertyDescriptor('name');
70
+ video.profile.name.should.be.an('string');
71
+ video.profile.should.have.ownPropertyDescriptor('url');
72
+ video.profile.url.should.be.an('string');
73
+ video.should.have.ownPropertyDescriptor('title');
74
+ video.title.should.be.a('string');
75
+ video.should.have.ownPropertyDescriptor('url');
76
+ video.url.should.be.a('string');
77
+ video.should.have.ownPropertyDescriptor('views');
78
+ video.views.should.be.a('string');
79
+ });
80
+
81
+ const next = await list.next();
82
+ next.should.be.an('object');
83
+ next.pagination.should.be.an('object');
84
+ next.pagination.page.should.be.equals(3);
85
+ next.pagination.pages.should.be.an('array');
86
+ next.pagination.pages[0].should.be.a('number');
87
+ next.hasNext.should.be.a('function');
88
+ next.hasNext().should.be.equals(true);
89
+ next.hasPrevious.should.be.a('function');
90
+ next.hasPrevious().should.be.equals(true);
91
+ next.next.should.be.a('function');
92
+ next.previous.should.be.a('function');
93
+ next.videos.should.be.an('array');
94
+ next.videos.forEach((video) => {
95
+ video.should.be.an('object');
96
+ video.should.have.ownPropertyDescriptor('duration');
97
+ video.duration.should.be.a('string');
98
+ video.should.have.ownPropertyDescriptor('path');
99
+ video.path.should.be.a('string');
100
+ video.should.have.ownPropertyDescriptor('profile');
101
+ video.profile.should.be.an('object');
102
+ video.profile.should.have.ownPropertyDescriptor('name');
103
+ video.profile.name.should.be.an('string');
104
+ video.profile.should.have.ownPropertyDescriptor('url');
105
+ video.profile.url.should.be.an('string');
106
+ video.should.have.ownPropertyDescriptor('title');
107
+ video.title.should.be.a('string');
108
+ video.should.have.ownPropertyDescriptor('url');
109
+ video.url.should.be.a('string');
110
+ video.should.have.ownPropertyDescriptor('views');
111
+ video.views.should.be.a('string');
112
+ });
113
+
114
+ await list.refresh();
115
+ }).timeout(10000);
116
+
117
+ it('should fail when page parameter is beyond limit', async () => {
118
+ let err;
119
+ try {
120
+ await fresh({ page: Number.MAX_SAFE_INTEGER + 1 });
121
+ } catch (error) {
122
+ err = error;
123
+ } finally {
124
+ err.should.be.an('error');
125
+ }
126
+ }).timeout(10000);
127
+
128
+ it('should fail when page parameter is less than 1', async () => {
129
+ let err;
130
+ try {
131
+ await fresh({ page: 0 });
132
+ } catch (error) {
133
+ err = error;
134
+ } finally {
135
+ err.should.be.an('error');
136
+ }
137
+ }).timeout(10000);
138
+
139
+ });
@@ -1,5 +1,3 @@
1
- /* eslint-disable padded-blocks */
2
-
3
1
  const chai = require('chai');
4
2
  const xvideos = require('.');
5
3
 
@@ -8,7 +6,6 @@ before(() => {
8
6
  });
9
7
 
10
8
  describe('xvideos', () => {
11
-
12
9
  it('should have xvideos api functions', async () => {
13
10
  xvideos.should.be.an('object');
14
11
  xvideos.videos.should.be.an('object');
@@ -17,6 +14,6 @@ describe('xvideos', () => {
17
14
  xvideos.videos.best.should.be.a('function');
18
15
  xvideos.videos.verified.should.be.a('function');
19
16
  xvideos.videos.details.should.be.a('function');
17
+ xvideos.videos.newFresh.should.be.a('function');
20
18
  }).timeout(10000);
21
-
22
19
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "xvideosx",
3
3
  "description": "xvideos.com api implementation.",
4
- "version": "1.4.3",
4
+ "version": "1.4.5",
5
5
  "main": "index.js",
6
6
  "license": "BSD-3-Clause",
7
7
  "repository": {