xvideosx 1.4.4 → 1.4.7
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.
- package/lib/api/videos/newfresh/createNextFunction.js +12 -0
- package/lib/api/videos/newfresh/createPreviousFunction.js +12 -0
- package/lib/api/videos/newfresh/createRefreshFunction.js +11 -0
- package/lib/api/videos/newfresh/newfresh.spec.js +139 -0
- package/lib/api/videos/newfresh/parseResponse.js +45 -0
- package/lib/api/videos/newfresh/parseVideo.js +27 -0
- package/package.json +1 -1
@@ -0,0 +1,12 @@
|
|
1
|
+
const nextFunction = (currentPage) => () => {
|
2
|
+
const fresh = require('./fresh');
|
3
|
+
const next = currentPage + 1;
|
4
|
+
return fresh({ page: next });
|
5
|
+
};
|
6
|
+
|
7
|
+
const createNextFunction = (pagination) => {
|
8
|
+
const { page } = pagination;
|
9
|
+
return nextFunction(page);
|
10
|
+
};
|
11
|
+
|
12
|
+
module.exports = createNextFunction;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
const previousFunction = (currentPage) => () => {
|
2
|
+
const fresh = require('./fresh');
|
3
|
+
const previous = currentPage - 1;
|
4
|
+
return fresh({ page: previous });
|
5
|
+
};
|
6
|
+
|
7
|
+
const createPreviousFunction = (pagination) => {
|
8
|
+
const { page } = pagination;
|
9
|
+
return previousFunction(page);
|
10
|
+
};
|
11
|
+
|
12
|
+
module.exports = createPreviousFunction;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const refreshFunction = (currentPage) => () => {
|
2
|
+
const fresh = require('./fresh');
|
3
|
+
return fresh(currentPage);
|
4
|
+
};
|
5
|
+
|
6
|
+
const createRefreshFunction = (pagination) => {
|
7
|
+
const { page } = pagination;
|
8
|
+
return refreshFunction(page);
|
9
|
+
};
|
10
|
+
|
11
|
+
module.exports = createRefreshFunction;
|
@@ -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
|
+
});
|
@@ -0,0 +1,45 @@
|
|
1
|
+
const cheerio = require('cheerio');
|
2
|
+
const parseVideo = require('./parseVideo');
|
3
|
+
const createRefreshFunction = require('./createRefreshFunction');
|
4
|
+
const createHasNextFunction = require('./createHasNextFunction');
|
5
|
+
const createNextFunction = require('./createNextFunction');
|
6
|
+
const createHasPreviousFunction = require('./createHasPreviousFunction');
|
7
|
+
const createPreviousFunction = require('./createPreviousFunction');
|
8
|
+
|
9
|
+
const getVideos = ($) => {
|
10
|
+
return $('#content > .mozaique > .thumb-block')
|
11
|
+
.map((i, video) => parseVideo($, video))
|
12
|
+
.get();
|
13
|
+
};
|
14
|
+
|
15
|
+
const getPages = ($) => {
|
16
|
+
return $('.pagination > ul > li > a')
|
17
|
+
.map((i, page) => $(page)
|
18
|
+
.text())
|
19
|
+
.filter((i, page) => !isNaN(page))
|
20
|
+
.map((i, page) => Number(page) - 1)
|
21
|
+
.get();
|
22
|
+
};
|
23
|
+
|
24
|
+
const parseResponse = (page, { data }) => {
|
25
|
+
const $ = cheerio.load(data);
|
26
|
+
|
27
|
+
const videos = getVideos($);
|
28
|
+
|
29
|
+
const pagination = {
|
30
|
+
page,
|
31
|
+
pages: getPages($),
|
32
|
+
};
|
33
|
+
|
34
|
+
return {
|
35
|
+
videos,
|
36
|
+
pagination,
|
37
|
+
refresh: createRefreshFunction(pagination),
|
38
|
+
hasNext: createHasNextFunction(pagination),
|
39
|
+
next: createNextFunction(pagination),
|
40
|
+
hasPrevious: createHasPreviousFunction(pagination),
|
41
|
+
previous: createPreviousFunction(pagination),
|
42
|
+
};
|
43
|
+
};
|
44
|
+
|
45
|
+
module.exports = parseResponse;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
const base = require('../../base');
|
2
|
+
|
3
|
+
const parseVideo = ($, video) => {
|
4
|
+
const $video = $(video);
|
5
|
+
|
6
|
+
const title = $video.find('p:not(.metadata) a').attr('title');
|
7
|
+
const path = $video.find('.thumb > a').attr('href');
|
8
|
+
const url = `${base.BASE_URL}${path}`;
|
9
|
+
const views = $video.find('p.metadata > span > span:not(.duration)').text();
|
10
|
+
const duration = $video.find('p.metadata > span.bg > span.duration').text();
|
11
|
+
const profileElement = $video.find('p.metadata > span > a');
|
12
|
+
const profile = {
|
13
|
+
name: profileElement.text(),
|
14
|
+
url: `${base.BASE_URL}${profileElement.attr('href')}`,
|
15
|
+
};
|
16
|
+
|
17
|
+
return {
|
18
|
+
url,
|
19
|
+
path,
|
20
|
+
title,
|
21
|
+
duration,
|
22
|
+
profile,
|
23
|
+
views,
|
24
|
+
};
|
25
|
+
};
|
26
|
+
|
27
|
+
module.exports = parseVideo;
|