xvideosx 1.6.1 → 1.6.3

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/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const axios = require('axios');
2
2
 
3
- const BASE_URL = 'https://www.xvideos.com';
3
+ const BASE_URL = 'https://www.xvideos3.com';
4
4
 
5
5
  const createRequest = (options = {}) => {
6
6
  return axios.create({ baseURL: BASE_URL, ...options });
@@ -1,68 +1,13 @@
1
- const cheerio = require('cheerio');
2
- const puppeteer = require('puppeteer');
1
+ const base = require("../../base");
2
+ const parseResponse = require('./parseResponse')
3
3
 
4
- const details = async ({ url, puppeteerConfig } = {}) => {
5
- let browser;
4
+ const details = async ({url = ''} = {}) => {
6
5
  try {
7
- browser = await puppeteer.launch(puppeteerConfig);
8
- const page = await browser.newPage();
9
- await page.goto(url, { waitUntil: 'networkidle2' });
10
- const html = await page.content();
6
+ const request = base.createRequest();
7
+ return parseResponse(await request.get(url))
11
8
 
12
- const $ = cheerio.load(html);
13
-
14
- const title = $('meta[property="og:title"]').attr('content');
15
- const duration = $('meta[property="og:duration"]').attr('content');
16
- const image = $('meta[property="og:image"]').attr('content');
17
- const videoType = $('meta[property="og:video:type"]').attr('content');
18
- const videoWidth = $('meta[property="og:video:width"]').attr('content');
19
- const videoHeight = $('meta[property="og:video:height"]').attr('content');
20
- const views = $('#nb-views-number').text();
21
- const relatedContentItems = $('div[class=mozaique]').html();
22
- const newData = cheerio.load(relatedContentItems);
23
- const varios = newData('.thumb-block');
24
- const videos = varios.map((index, element) => {
25
- const $element = newData(element);
26
-
27
- const title = $element.find('.title a').text();
28
- const duration = $element.find('.duration').text();
29
- const channel = $element.find('.metadata .name').text();
30
- const url = `https://www.xvideos.com${$element.find('.title a').attr('href')}`;
31
- const thumbNail = $element.find('.thumb img').attr('src');
32
- return {
33
- title,
34
- duration,
35
- channel,
36
- thumbNail,
37
- url,
38
- };
39
- }).get();
40
-
41
- const videoScript = $('#video-player-bg > script:nth-child(6)').html();
42
- const files = {
43
- low: (videoScript.match('html5player.setVideoUrlLow\\(\'(.*?)\'\\);') || [])[1],
44
- high: videoScript.match('html5player.setVideoUrlHigh\\(\'(.*?)\'\\);' || [])[1],
45
- HLS: videoScript.match('html5player.setVideoHLS\\(\'(.*?)\'\\);' || [])[1],
46
- thumb: videoScript.match('html5player.setThumbUrl\\(\'(.*?)\'\\);' || [])[1],
47
- thumb69: videoScript.match('html5player.setThumbUrl169\\(\'(.*?)\'\\);' || [])[1],
48
- thumbSlide: videoScript.match('html5player.setThumbSlide\\(\'(.*?)\'\\);' || [])[1],
49
- thumbSlideBig: videoScript.match('html5player.setThumbSlideBig\\(\'(.*?)\'\\);' || [])[1],
50
- };
51
-
52
- return {
53
- title,
54
- url,
55
- duration,
56
- image,
57
- views,
58
- videoType,
59
- videoWidth,
60
- videoHeight,
61
- files,
62
- videos,
63
- };
64
- } finally {
65
- if (browser) await browser.close();
9
+ } catch (error) {
10
+ throw new Error(error)
66
11
  }
67
12
  };
68
13
 
@@ -0,0 +1,10 @@
1
+ const parseCategory = ($) => {
2
+ const metadata = $('.video-metadata .is-keyword');
3
+ const keywordTexts = metadata.map((index, element) => {
4
+ return $(element).text();
5
+ }).get();
6
+
7
+ return keywordTexts;
8
+
9
+ }
10
+ module.exports = parseCategory
@@ -0,0 +1,22 @@
1
+ const parseModels = ($) => {
2
+ const $metadata = $('.video-metadata');
3
+
4
+ const mainUploader = $metadata.find('li.main-uploader a span.name').text();
5
+ const mainUploaderCount = $metadata.find('li.main-uploader a span.count').text();
6
+
7
+ const models = $metadata.find('li.model a span.name').map((index, element) => $(element).text()).get();
8
+ const modelsCounts = $metadata.find('li.model a span.count').map((index, element) => $(element).text()).get();
9
+
10
+ return {
11
+ mainUploader: {
12
+ name: mainUploader,
13
+ count: mainUploaderCount
14
+ },
15
+ models: models.map((name, index) => ({
16
+ name,
17
+ count: modelsCounts[index]
18
+ })),
19
+ };
20
+ }
21
+
22
+ module.exports = parseModels
@@ -0,0 +1,25 @@
1
+ const fs = require('fs')
2
+
3
+ const parseRelated = ($) =>{
4
+ const scriptContent = $('#video-player-bg script').html();
5
+ const startIndex = scriptContent.indexOf('[');
6
+ const endIndex = scriptContent.lastIndexOf(']');
7
+ const jsonContent = scriptContent.substring(startIndex, endIndex + 1);
8
+
9
+ const videoRelated = JSON.parse(jsonContent);
10
+
11
+ return videoRelated.map(video => {
12
+ return {
13
+ title: video.tf,
14
+ short_title: video.t,
15
+ duration : video.d,
16
+ channel: video.pn,
17
+ thumbNail: video.i,
18
+ poster: video.ip,
19
+ url: video.u,
20
+ views: video.n,
21
+ }
22
+ })
23
+ }
24
+
25
+ module.exports = parseRelated
@@ -0,0 +1,44 @@
1
+ const cheerio = require('cheerio');
2
+ const parseVideo = require('./parseVideo');
3
+ const parseRelated = require('./parseRelated');
4
+ const parseCategory = require('./parseCategory');
5
+ const parseModels = require('./parseModels');
6
+
7
+
8
+ const getVideo = ($) =>{
9
+ return parseVideo($);
10
+ }
11
+ const getRelated = ($) => {
12
+ return parseRelated($);
13
+ }
14
+ const getCategories = ($) =>{
15
+ return parseCategory($);
16
+ }
17
+ const getModels = ($) =>{
18
+ return parseModels($);
19
+ }
20
+ const parseResponse = ({ data }) => {
21
+ const $ = cheerio.load(data);
22
+ const video = getVideo($);
23
+ const related = getRelated($);
24
+ const categories = getCategories($);
25
+ const models = getModels($);
26
+
27
+
28
+ return{
29
+ title: video.title,
30
+ duration: video.duration,
31
+ image: video.image,
32
+ categories,
33
+ channel: models.mainUploader,
34
+ models: models.models,
35
+ videoType: video.videoType,
36
+ videoWidth: video.videoWidth,
37
+ videoHeight: video.videoHeight,
38
+ views: video.views,
39
+ files: video.files,
40
+ videos: related
41
+ }
42
+ }
43
+
44
+ module.exports = parseResponse
@@ -0,0 +1,31 @@
1
+ const parseVideo = ($) => {
2
+ const title = $('meta[property="og:title"]').attr('content');
3
+ const duration = $('meta[property="og:duration"]').attr('content');
4
+ const image = $('meta[property="og:image"]').attr('content');
5
+ const videoType = $('meta[property="og:video:type"]').attr('content');
6
+ const videoWidth = $('meta[property="og:video:width"]').attr('content');
7
+ const videoHeight = $('meta[property="og:video:height"]').attr('content');
8
+ const views = $('.mobile-show-inline:nth-child(3)').text();
9
+ const videoScript = $('#video-player-bg > script:nth-child(6)').html();
10
+ const files = {
11
+ low: (videoScript.match('html5player.setVideoUrlLow\\(\'(.*?)\'\\);') || [])[1],
12
+ high: videoScript.match('html5player.setVideoUrlHigh\\(\'(.*?)\'\\);' || [])[1],
13
+ HLS: videoScript.match('html5player.setVideoHLS\\(\'(.*?)\'\\);' || [])[1],
14
+ thumb: videoScript.match('html5player.setThumbUrl\\(\'(.*?)\'\\);' || [])[1],
15
+ thumb69: videoScript.match('html5player.setThumbUrl169\\(\'(.*?)\'\\);' || [])[1],
16
+ thumbSlide: videoScript.match('html5player.setThumbSlide\\(\'(.*?)\'\\);' || [])[1],
17
+ thumbSlideBig: videoScript.match('html5player.setThumbSlideBig\\(\'(.*?)\'\\);' || [])[1],
18
+ };
19
+ return {
20
+ title,
21
+ duration,
22
+ image,
23
+ videoType,
24
+ videoWidth,
25
+ videoHeight,
26
+ views,
27
+ files,
28
+ }
29
+ }
30
+
31
+ 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.6.1",
4
+ "version": "1.6.3",
5
5
  "main": "index.js",
6
6
  "license": "BSD-3-Clause",
7
7
  "repository": {