Skip to content

Commit

Permalink
feat(route): add elite babes (DIYgod#6997)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Mar 2, 2021
1 parent f0b1d1d commit 903a4e9
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/en/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ pageClass: routes

<RouteEn name="Daily Strip" author="Maecenas" example="/dilbert/strip" path="/dilbert/strip"/>

## Elite Babes

### Home

<RouteEn author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['Category, see below, Home by default']">

| Home | Hot | Popular | Recent |
| ---- | --- | ------- | ------ |
| | hot | popular | recent |

</Route>

### Videos

<RouteEn author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['Sort, see below, Popular by default']">

| Popular | Recent |
| ------- | ------ |
| popular | recent |

</Route>

### Search

<RouteEn author="nczitzk" example="/elitebabes/search/pose" path="/elitebabes/search/:keyword?" :paramsDesc="['Keyword']"/>

## GoComics Comic Strips

<RouteEn author="stjohnjohnson" example="/gocomics/foxtrot" path="/gocomics/:strip" :paramsDesc="['URL path of the strip on gocomics.com']" />
Expand Down
26 changes: 26 additions & 0 deletions docs/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ pageClass: routes

</Route>

## Elite Babes

### Home

<Route author="nczitzk" example="/elitebabes" path="/elitebabes/:category?" :paramsDesc="['分类,见下表,默认为 Home']">

| Home | Hot | Popular | Recent |
| ---- | --- | ------- | ------ |
| | hot | popular | recent |

</Route>

### Videos

<Route author="nczitzk" example="/elitebabes/videos" path="/elitebabes/videos/:sort?" :paramsDesc="['排序,见下表,默认为 Popular']">

| Popular | Recent |
| ------- | ------ |
| popular | recent |

</Route>

### Search

<Route author="nczitzk" example="/elitebabes/search/pose" path="/elitebabes/search/:keyword?" :paramsDesc="['关键字']"/>

## Fantia

### 搜索
Expand Down
5 changes: 5 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3978,6 +3978,11 @@ router.get('/iyiou', require('./routes/iyiou'));
// 香港商报
router.get('/hkcd/pdf', require('./routes/hkcd/pdf'));

// Elite Babes
router.get('/elitebabes/videos/:sort?', require('./routes/elitebabes/videos'));
router.get('/elitebabes/search/:keyword?', require('./routes/elitebabes/search'));
router.get('/elitebabes/:category?', require('./routes/elitebabes/index'));

// Trakt.tv
router.get('/trakt/collection/:username/:type?', require('./routes/trakt/collection'));

Expand Down
30 changes: 30 additions & 0 deletions lib/routes/elitebabes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const utils = require('./utils');

const categories = {
hot: {
url: 'trending',
title: 'Hot',
},
popular: {
url: 'most-viewed',
title: 'Popular',
},
recent: {
url: 'latest-updates',
title: 'Recent',
},
};

module.exports = async (ctx) => {
const category = ctx.params.category || '';
const title = `${category ? `${categories[category].title} - ` : ''}Elite Babes`;

const currentUrl = `${utils.rootUrl}/${category ? categories[category].url : ''}`;

ctx.state.data = {
title,
link: currentUrl,
itunes_author: title,
item: await utils.fetch(ctx.cache, currentUrl),
};
};
15 changes: 15 additions & 0 deletions lib/routes/elitebabes/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const utils = require('./utils');

module.exports = async (ctx) => {
const keyword = ctx.params.keyword || '';
const title = `${keyword ? `Search ${keyword} - ` : ''}Elite Babes`;

const currentUrl = `${utils.rootUrl}/${keyword ? `?s=${keyword}` : ''}`;

ctx.state.data = {
title,
link: currentUrl,
itunes_author: title,
item: await utils.fetch(ctx.cache, currentUrl),
};
};
89 changes: 89 additions & 0 deletions lib/routes/elitebabes/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

const rootUrl = 'https://www.elitebabes.com';

const fetch = async (cache, currentUrl) => {
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

$('.clip-a, .displayblock').remove();

const list = $('.gallery-a li')
.slice(0, 50)
.map((_, item) => {
item = $(item).children('a').eq(0);
const image = item.find('img').eq(0);

return {
link: item.attr('href'),
title: item.attr('title') || image.attr('alt'),
itunes_item_image: image.attr('src').replace('_200', '_400'),
pubDate: (item.next()[0] ? new Date(item.next().text()) : new Date()).toUTCString(),
};
})
.get();

const items = await Promise.all(
list.map(
async (item) =>
await cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);

content('input, .link-btn, .m-pagination').remove();
content('.mobile-hide, .wide-hide').remove();

if (item.link.indexOf(`${rootUrl}/model/`) === 0) {
item.author = content('.fn').text();
item.description = content('#content').html();
return item;
}

const authors = [];
const video = content('video');

item.description = '';

if (video.length > 0) {
const poster = detailResponse.data.match(/posterImage: "(.*)",/);
item.itunes_item_image = (poster ? poster[1] : video.attr('poster')) || item.itunes_item_image;

item.enclosure_type = 'video/mp4';
item.enclosure_url = video.children('source').attr('src');
item.description = `<video controls loop preload="auto"><source src=${item.enclosure_url} type="video/mp4"/></video><img src="${item.itunes_item_image}">`;
}

content('.link-btn h2 a').each(function () {
authors.push(content(this).text());
});

item.author = authors.join(', ');

content('.list-justified2 li a').each(function () {
item.description += `<img src="${content(this).attr('href')}">`;
});

return item;
} catch (e) {
return Promise.resolve('');
}
})
)
);

return items;
};

module.exports = {
rootUrl,
fetch,
};
26 changes: 26 additions & 0 deletions lib/routes/elitebabes/videos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const utils = require('./utils');

const sorts = {
popular: {
url: '',
title: 'Popular',
},
recent: {
url: 'latest',
title: 'Recent',
},
};

module.exports = async (ctx) => {
const sort = ctx.params.sort || '';
const title = `${sort ? sorts[sort].title : 'Popular'} videos - Elite Babes`;

const currentUrl = `${utils.rootUrl}/videos${sort ? `?sort=${sorts[sort].url}` : ''}`;

ctx.state.data = {
title,
link: currentUrl,
itunes_author: title,
item: await utils.fetch(ctx.cache, currentUrl),
};
};

0 comments on commit 903a4e9

Please sign in to comment.