import Video from 'Core/VideoMixin';
import AbstractModule from 'Core/AbstractModule';

class Xvideos extends AbstractModule.with(Video) {
  get name () {
    return 'xVideos';
  }

  get firstpage () {
    return 0;
  }

  videoUrl (page) {
    return `https://www.xvideos.com/?k=${this.query}&p=${page || this.firstpage}`;
  }

  videoParser ($) {
    const videos = $('#content .mozaique .thumb-block');

    return videos.map((i, video) => {
      const description = $.load($(video).find('.thumb script').text().match(/(<.*>)/).pop()).find('p');

      return {
        title: description.eq(0).text(),
        url: `https://xvideos.com${$('a').attr('href')}`,
        duration: description.find('strong').text(),
        thumb: $('img').attr('src'),
      };
    }).get();
  }
}

export default Xvideos;

@@ -455,98 +455,68 @@
 nst 
-description = $.load($(video).find('.thumb script').text().match(/(%3C.*%3E)/).pop()).find('p'
+cache = $(video);%0A      const title = cache.find('p a').eq(0
 );%0A%0A
@@ -549,25 +549,13 @@
 le: 
-description.eq(0)
+title
 .tex
@@ -598,14 +598,13 @@
 om$%7B
-$('a')
+title
 .att
@@ -638,32 +638,29 @@
 on: 
-description.find('str
+cache.find('.durati
 on
-g
 ').t
@@ -685,26 +685,104 @@
 mb: 
-$('
+cache.find('.thumb 
 img').
+d
 at
-tr('src
+a('src').replace('thumbs169', 'thumbs169lll').replace('THUMBNUM', '5
 '),%0A

fix xvideos