Hotfix: mzitu (#1002)

- 修复图片无法查看问题
- 更改数据获取方式,国外(应该)也可以访问了
- 路由做了轻微调整,部分不向前兼容
This commit is contained in:
凉凉
2018-10-31 00:35:39 +08:00
committed by DIYgod
parent 9cb0105222
commit 5e8c5aaab1
7 changed files with 118 additions and 161 deletions
+8 -14
View File
@@ -823,27 +823,21 @@ GitHub 官方也提供了一些 RSS:
### 妹子图
::: warning 注意
<route name="首页(最新)" author="gee1k xyqfer" example="/mzitu/home" path="/mzitu/home/:type?" :paramsDesc="['类型,默认最新,可选`hot`最热']"/>
该网站在国外无法访问, 由于 RSSHub 演示部署于国外, 故以下演示无效.
<route name="分类" author="gee1k xyqfer" example="/mzitu/category/hot" path="/mzitu/category/:category" :paramsDesc="['分类名']">
:::
<route name="首页(最新)" author="gee1k" example="/mzitu" path="/mzitu/index"/>
<route name="分类" author="gee1k" example="/mzitu/category/hot" path="/mzitu/category/:category" :paramsDesc="['分类名']">
| 热门 | 推荐 | 性感妹子 | 日本妹子 | 台湾妹子 | 清纯妹子 |
| ---- | ---- | -------- | -------- | -------- | -------- |
| hot | best | xinggan | japan | taiwan | mm |
| 性感妹子 | 日本妹子 | 台湾妹子 | 清纯妹子 |
| -------- | -------- | -------- | -------- |
| xinggan | japan | taiwan | mm |
</route>
<route name="所有专题" author="gee1k" example="/mzitu/tags" path="/mzitu/tags"/>
<route name="所有专题" author="gee1k xyqfer" example="/mzitu/tags" path="/mzitu/tags"/>
<route name="专题详情" author="gee1k" example="/mzitu/tag/shishen" path="/mzitu/tag/:tag" :paramsDesc="['专题名, 可在专题页 URL 中找到']"/>
<route name="专题详情" author="gee1k xyqfer" example="/mzitu/tag/shishen" path="/mzitu/tag/:tag" :paramsDesc="['专题名, 可在专题页 URL 中找到']"/>
<route name="详情" author="gee1k" example="/mzitu/post/129452" path="/mzitu/post/:id" :paramsDesc="['详情 id, 可在详情页 URL 中找到']"/>
<route name="详情" author="gee1k xyqfer" example="/mzitu/post/129452" path="/mzitu/post/:id" :paramsDesc="['详情 id, 可在详情页 URL 中找到']"/>
### 煎蛋
+1 -1
View File
@@ -168,7 +168,7 @@ router.get('/zhihu/question/:questionId', require('./routes/zhihu/question'));
router.get('/zhihu/topic/:topicId', require('./routes/zhihu/topic'));
// 妹子图
router.get('/mzitu', require('./routes/mzitu/category'));
router.get('/mzitu/home/:type?', require('./routes/mzitu/home'));
router.get('/mzitu/tags', require('./routes/mzitu/tags'));
router.get('/mzitu/category/:category', require('./routes/mzitu/category'));
router.get('/mzitu/post/:id', require('./routes/mzitu/post'));
+28 -31
View File
@@ -1,43 +1,40 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let category = ctx.params.category;
category = category === undefined || category === 'undefined' ? '' : category;
const url = `http://www.mzitu.com/${category}`;
const { category } = ctx.params;
const mapper = {
xinggan: {
name: '性感妹子',
id: 4,
},
japan: {
name: '日本妹子',
id: 3,
},
taiwan: {
name: '台湾妹子',
id: 344,
},
mm: {
name: '清纯妹子',
id: 2,
},
};
const url = `http://adr.meizitu.net/wp-json/wp/v2/posts?categories=${mapper[category].id}&per_page=20`;
const response = await axios({
method: 'get',
url: url,
headers: {
Referer: url,
},
url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('#pins li');
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
item:
list &&
list
.map((item, index) => {
item = $(index);
const linkA = item.find('a');
const previewImg = linkA.find('img');
return {
title: previewImg.attr('alt'),
description: `描述:${previewImg.attr('alt')}<br><img referrerpolicy="no-referrer" src="${previewImg.data('original')}">`,
pubDate: new Date(item.find('.time').text()).toUTCString(),
link: linkA.attr('href'),
};
})
.get(),
title: `妹子图-${mapper[category].name}`,
link: `http://www.mzitu.com/${category}`,
item: data.map((item) => ({
title: item.title,
description: `<img referrerpolicy="no-referrer" src="${item.thumb_src}">`,
link: `http://www.mzitu.com/${item.id}`,
})),
};
};
+34
View File
@@ -0,0 +1,34 @@
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
const { type = '' } = ctx.params;
let url;
if (type === 'hot') {
url = 'http://adr.meizitu.net/wp-json/wp/v2/hot';
} else {
url = 'http://adr.meizitu.net/wp-json/wp/v2/posts?per_page=20';
}
const response = await axios({
method: 'get',
url,
});
const data = response.data;
ctx.state.data = {
title: '妹子图',
link: `http://www.mzitu.com/${type}`,
item: data.map((item) => {
if (type === 'hot') {
item.thumb_src = item.thumb_src_min;
}
return {
title: item.title,
description: `<img referrerpolicy="no-referrer" src="${item.thumb_src}">`,
link: `http://www.mzitu.com/${item.id}`,
};
}),
};
};
+21 -60
View File
@@ -1,74 +1,35 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const { id } = ctx.params;
const url = `http://www.mzitu.com/${id}`;
const contentUrl = `http://adr.meizitu.net/wp-json/wp/v2/i?id=${id}`;
const postUrl = `http://adr.meizitu.net/wp-json/wp/v2/posts/${id}`;
const link = `http://www.mzitu.com/${id}`;
const response = await axios({
const contentResponse = await axios({
method: 'get',
url: url,
headers: {
Referer: url,
},
url: contentUrl,
});
const content = contentResponse.data.content.split(',');
const data = response.data;
const $ = cheerio.load(data);
const img = $('.main-image > p > a > img');
const imgUrl = img.attr('src');
const prefix = imgUrl.substr(0, imgUrl.lastIndexOf('01.'));
const suffix = imgUrl.substr(imgUrl.lastIndexOf('.'));
let totalPage = $('.pagenavi > a:nth-last-child(2)')
.find('span')
.text();
totalPage = +totalPage;
const list = [
{
url,
imgUrl,
page: 1,
},
];
for (let i = 2; i <= totalPage; i++) {
const p = i < 10 ? `0${i}` : i;
const nextImgUrl = `${prefix}${p}${suffix}`;
const nextUrl = `${url}/${i}`;
list.push({
url: nextUrl,
imgUrl: nextImgUrl,
page: i,
});
}
const title = $('title').text();
const reg = /[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d/;
const postResponse = await axios({
method: 'get',
url: postUrl,
});
const { title } = postResponse.data;
ctx.state.data = {
title: title,
link: url,
description: $('meta[name="description"]').attr('content') || title,
item:
list &&
list.map((item) => {
let date = new Date();
const dateStr = $('.main-meta > span:nth-child(2)').text();
if (reg.test(dateStr)) {
date = new Date(dateStr.match(reg)[0]);
}
link,
item: content.map((url, index) => {
url = url.replace(/"/g, '');
return {
title: `${title}(${item.page})`,
description: `分类:${$('.main-meta > span:nth-child(1) > a').text()}<br>描述:${title}(${item.page})<br><img referrerpolicy="no-referrer" src="${item.imgUrl}">`,
pubDate: date.toUTCString(),
link: item.url,
};
}),
return {
title: `${title}(${index + 1})`,
description: `<img referrerpolicy="no-referrer" src="${url}">`,
link: url,
};
}),
};
};
+17 -29
View File
@@ -1,42 +1,30 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let tag = ctx.params.tag;
tag = tag === undefined || tag === 'undefined' ? '' : tag;
const url = `http://www.mzitu.com/tag/${tag}`;
const response = await axios({
const tagsUrl = `http://adr.meizitu.net/wp-json/wp/v2/tags?slug=${tag}`;
const tagsResponse = await axios({
method: 'get',
url: url,
headers: {
Referer: url,
},
url: tagsUrl,
});
const { id, name } = tagsResponse.data[0] || {};
const data = response.data;
const $ = cheerio.load(data);
const list = $('#pins li');
const tagUrl = `http://adr.meizitu.net/wp-json/wp/v2/posts?tags=${id}&per_page=20`;
const tagResponse = await axios({
method: 'get',
url: tagUrl,
});
const data = tagResponse.data;
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
item:
list &&
list
.map((item, index) => {
item = $(index);
const linkA = item.find('a');
const previewImg = linkA.find('img');
return {
title: previewImg.attr('alt'),
description: `描述:${previewImg.attr('alt')}<br><img referrerpolicy="no-referrer" src="${previewImg.data('original')}">`,
pubDate: new Date(item.find('.time').text()).toUTCString(),
link: linkA.attr('href'),
};
})
.get(),
title: name,
link: `http://www.mzitu.com/tag/${tag}`,
item: data.map((item) => ({
title: item.title,
description: `<img referrerpolicy="no-referrer" src="${item.thumb_src}">`,
link: `http://www.mzitu.com/${item.id}`,
})),
};
};
+9 -26
View File
@@ -1,39 +1,22 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'http://www.mzitu.com/zhuanti';
const url = 'http://adr.meizitu.net/wp-json/wp/v2/tags?orderby=count&order=desc&per_page=100';
const response = await axios({
method: 'get',
url: url,
headers: {
Referer: url,
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.main-content > div.postlist > dl > dd');
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
item:
list &&
list
.map((item, index) => {
item = $(index);
const linkA = item.find('a');
const previewImg = linkA.find('img');
return {
title: previewImg.attr('alt'),
description: `${item.find('i').text()}<br>描述:${previewImg.attr('alt')}<br><img referrerpolicy="no-referrer" src="${previewImg.data('original')}">`,
pubDate: '',
link: linkA.attr('href'),
};
})
.get(),
title: '妹子图专题',
link: 'http://www.mzitu.com/zhuanti',
description: '妹子图美女专题栏目,为您精心准备各种美女图片专题,包括名站美女写真,妹子特点分类,美女大全等专题。',
item: data.map((item) => ({
title: item.name,
description: `${item.name}`,
link: `http://www.mzitu.com/tag/${item.slug}`,
})),
};
};