xvideosx 1.5.9 → 1.6.1

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/README.md CHANGED
@@ -30,6 +30,20 @@ console.log(fresh.pagination.pages); // [1, 2, 3, 4, 5...]
30
30
  console.log(fresh.hasNext()); // true
31
31
  console.log(fresh.hasPrevious()); // false
32
32
 
33
+ const newFresh = await xvideos.videos.newFresh({ page: 1 });
34
+ console.log(fresh.videos)
35
+ /*{
36
+ title,
37
+ url,
38
+ thumbNail,
39
+ preview,
40
+ path,
41
+ duration,
42
+ channel,
43
+ views,
44
+ };
45
+ */
46
+
33
47
  const nextPage = await fresh.next();
34
48
  console.log(nextPage.pagination.current); // 2
35
49
  console.log(nextPage.hasNext()); // true
@@ -1,42 +1,20 @@
1
- /* eslint-disable linebreak-style */
2
- /* eslint-disable no-unused-vars */
3
- /* eslint-disable no-undef */
4
- const puppeteer = require('puppeteer');
5
- const cheerio = require('cheerio');
6
-
7
- const newFresh = async ({ url, puppeteerConfig } = {}) => {
8
- let browser;
9
-
10
- try {
11
- browser = await puppeteer.launch(puppeteerConfig);
12
- const page = await browser.newPage();
13
- await page.goto('https://www.xvideos.com/');
14
- const html = await page.content();
15
- const $ = cheerio.load(html);
16
- const $getVideos = cheerio.load($.html());
17
- const mozaique = $getVideos('.thumb-block');
18
- const videos = mozaique.map((index, element) => {
19
- const $element = $getVideos(element);
20
- const title = $element.find('.title a').attr('title');
21
- const url = `https://www.xvideos.com${$element.find('.title a').attr('href')}`;
22
- const thumbNail = $element.find('.thumb img').attr('src');
23
- const duration = $element.find('.duration').text();
24
- const channel = $element.find('.metadata .name').text();
25
-
26
- return {
27
- title,
28
- url,
29
- thumbNail,
30
- duration,
31
- channel,
32
- };
33
- }).get();
34
- return videos;
35
- } catch (e) {
36
- console.log(e);
37
- } finally {
38
- if (browser) await browser.close();
39
- }
40
- };
41
-
42
- module.exports = newFresh;
1
+ const base = require('../../base');
2
+ const parseResponse = require('./parseResponse');
3
+
4
+ const PATH = '/new/';
5
+
6
+ const newFresh = async ({ page = 1 } = {}) => {
7
+ if (page < 1 || page > Number.MAX_SAFE_INTEGER) {
8
+ throw new Error(`Invalid page: ${page}`);
9
+ }
10
+ try {
11
+ const request = base.createRequest();
12
+ const verificationPath = page > 1 ? `${PATH}${page}` : '';
13
+
14
+ return parseResponse(page, await request.get(`${verificationPath}`));
15
+ } catch (e) {
16
+ console.log(e);
17
+ }
18
+ };
19
+
20
+ module.exports = newFresh;
@@ -7,8 +7,10 @@ const createHasPreviousFunction = require('./createHasPreviousFunction');
7
7
  const createPreviousFunction = require('./createPreviousFunction');
8
8
 
9
9
  const getVideos = ($) => {
10
- return $('#content > .mozaique > .thumb-block')
11
- .map((i, video) => parseVideo($, video))
10
+ return $('.thumb-block')
11
+ .map((i, video) => {
12
+ return parseVideo($, video);
13
+ })
12
14
  .get();
13
15
  };
14
16
 
@@ -1,25 +1,43 @@
1
1
  const base = require('../../base');
2
2
 
3
+ const extractorUrl = (imageUrl) => {
4
+ const regex = /\/thumbs169ll(\/(?:[0-9a-f]{2}\/){3}[0-9a-f]{32})\//i;
5
+ const match = imageUrl.match(regex);
6
+ if (match && match[1]) {
7
+ const extractedPart = match[1];
8
+ const newUrl = `https://gcore-pic.xvideos-cdn.com/videos/videopreview${extractedPart}_169.mp4`;
9
+ return newUrl;
10
+ } return null;
11
+ };
12
+ const viewsExtractor = (views) => {
13
+ const regex = /(\d+(?:[,.]\d+)?[MK])/i;
14
+ const match = views.match(regex);
15
+ if (match && match[1]) {
16
+ const views = match[1];
17
+ return views;
18
+ } return null;
19
+ };
20
+
3
21
  const parseVideo = ($, video) => {
4
22
  const $video = $(video);
5
-
6
- const title = $video.find('p:not(.metadata) a').attr('title');
23
+ const title = $video.find('.title a').attr('title');
7
24
  const path = $video.find('.thumb > a').attr('href');
8
25
  const url = `${base.BASE_URL}${path}`;
9
- const views = $video.find('p.metadata > span > span:not(.duration)').text();
26
+ const thumbNail = $video.find('div.thumb img').attr('data-src');
27
+ const preview = extractorUrl(thumbNail);
10
28
  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
- };
29
+ const channel = $video.find('.metadata .name').text();
30
+ const viewsData = $video.find('p.metadata > span.bg > span:nth-child(2)').text().trim();
31
+ const views = viewsExtractor(viewsData);
16
32
 
17
33
  return {
34
+ title,
18
35
  url,
36
+ thumbNail,
37
+ preview,
19
38
  path,
20
- title,
21
39
  duration,
22
- profile,
40
+ channel,
23
41
  views,
24
42
  };
25
43
  };
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "xvideosx",
3
- "description": "xvideos.com api implementation.",
4
- "version": "1.5.9",
5
- "main": "index.js",
6
- "license": "BSD-3-Clause",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/4CROS2/xvideos.git"
10
- },
11
- "keywords": [
12
- "crawler",
13
- "porn",
14
- "spider",
15
- "scrapper",
16
- "api",
17
- "xvideos",
18
- "api",
19
- "library"
20
- ],
21
- "scripts": {
22
- "eslint": "eslint . --ext .js",
23
- "test": "cross-env NODE_ENV=test mocha --exit lib/**/*.spec.js",
24
- "coverage": "nyc --reporter=html --reporter=lcov npm test"
25
- },
26
- "dependencies": {
27
- "axios": "^0.21.4",
28
- "cheerio": "^1.0.0-rc.12",
29
- "puppeteer": "^22.0.0"
30
- },
31
- "devDependencies": {
32
- "chai": "^4.3.4",
33
- "codeclimate-test-reporter": "^0.5.1",
34
- "cross-env": "^7.0.3",
35
- "eslint": "^7.23.0",
36
- "eslint-config-airbnb-base": "^14.2.1",
37
- "eslint-plugin-import": "^2.22.1",
38
- "mocha": "^9.1.4",
39
- "nyc": "^15.1.0"
40
- },
41
- "engines": {
42
- "node": ">=7.6.0"
43
- }
44
- }
1
+ {
2
+ "name": "xvideosx",
3
+ "description": "xvideos.com api implementation.",
4
+ "version": "1.6.1",
5
+ "main": "index.js",
6
+ "license": "BSD-3-Clause",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/4CROS2/xvideos.git"
10
+ },
11
+ "keywords": [
12
+ "crawler",
13
+ "porn",
14
+ "spider",
15
+ "scrapper",
16
+ "api",
17
+ "xvideos",
18
+ "api",
19
+ "library"
20
+ ],
21
+ "scripts": {
22
+ "eslint": "eslint . --ext .js",
23
+ "test": "cross-env NODE_ENV=test mocha --exit lib/**/*.spec.js",
24
+ "coverage": "nyc --reporter=html --reporter=lcov npm test"
25
+ },
26
+ "dependencies": {
27
+ "axios": "^0.21.4",
28
+ "cheerio": "^1.0.0-rc.12",
29
+ "puppeteer": "^22.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "chai": "^4.3.4",
33
+ "codeclimate-test-reporter": "^0.5.1",
34
+ "cross-env": "^7.0.3",
35
+ "eslint": "^7.23.0",
36
+ "eslint-config-airbnb-base": "^14.2.1",
37
+ "eslint-plugin-import": "^2.22.1",
38
+ "mocha": "^9.1.4",
39
+ "nyc": "^15.1.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=7.6.0"
43
+ }
44
+ }