xvideosx 1.4.5 → 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.
@@ -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,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;
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.5",
4
+ "version": "1.4.7",
5
5
  "main": "index.js",
6
6
  "license": "BSD-3-Clause",
7
7
  "repository": {