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

class Sex extends AbstractModule.with(Gif, Video) {
  get name () {
    return 'Sex';
  }

  get firstpage () {
    return 1;
  }

  videoUrl (page) {
    return `http://www.sex.com/search/videos?query=${this.query}&page=${page || this.firstpage}`;
  }

  gifUrl (page) {
    return `http://www.sex.com/search/gifs?query=${this.query}&page=${page || this.firstpage}`;
  }

  videoParser ($) {
    const videos = $('#masonry_container .masonry_box').has('.duration');

    return videos.map((i, video) => {
      const cached = $(video);
      const title = cached.find('.title a');

      return {
        title: title.text(),
        url: `http://www.sex.com${title.attr('href')}`,
        duration: cached.find('.duration').text(),
        thumb: cached.find('.image').data('src'),
      };
    }).get();
  }

  gifParser ($) {
    const gifs = $('#masonry_container .masonry_box').not('.ad_box');

    return gifs.map((i, gif) => {
      const data = $(gif).find('.image');

      return {
        title: data.attr('alt'),
        url: data.data('src'),
      };
    }).get();
  }
}

export default Sex;

@@ -566,25 +566,8 @@
 ox')
-.has('.duration')
 ;%0A%0A 
@@ -646,21 +646,20 @@
   const 
-title
+link
  = cache
@@ -674,24 +674,171 @@
 .title a');%0A
+      const title = link.text();%0A      const duration = cached.find('.duration').text();%0A%0A      if (!title %7C%7C !duration) %7B%0A        return;%0A      %7D%0A
 %0A      retur
@@ -858,22 +858,8 @@
 itle
-: title.text()
 ,%0A  
@@ -890,21 +890,20 @@
 ex.com$%7B
-title
+link
 .attr('h
@@ -931,41 +931,8 @@
 tion
-: cached.find('.duration').text()
 ,%0A  
@@ -1166,48 +1166,46 @@
 nd('
+a
 .image
+_wrapper
 ');%0A
-%0A
       
-return %7B%0A       
+const
  title
-:
+ =
  dat
@@ -1216,44 +1216,160 @@
 tr('
-alt'),
+title');
 %0A      
- 
+const
  url
-:
+ =
  data.
-data('src')
+find('img').data('src');%0A%0A      if (!title %7C%7C !url) %7B%0A        return;%0A      %7D%0A%0A      return %7B%0A        title,%0A        url
 ,%0A  

fix sex