diff --git a/docs/picture.md b/docs/picture.md index 66e4cde5851c45..1c4965ec81a1c6 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -364,9 +364,13 @@ R18 显示 ## 国家地理 +### 每日精选 + + + ### 每日一图 - + ## 煎蛋 diff --git a/lib/router.js b/lib/router.js index 9bf400d3ffdab8..c4b7b13bc13f93 100644 --- a/lib/router.js +++ b/lib/router.js @@ -407,6 +407,7 @@ router.get('/sexinsex/:id/:type?', require('./routes/sexinsex/index')); router.get('/gcores/category/:category', require('./routes/gcores/category')); // 国家地理 +router.get('/natgeo/dailyselection', require('./routes/natgeo/dailyselection')); router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto')); router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo')); diff --git a/lib/routes/natgeo/dailyphoto.js b/lib/routes/natgeo/dailyphoto.js index 8e6c1695d931c2..94275008c8c9d4 100644 --- a/lib/routes/natgeo/dailyphoto.js +++ b/lib/routes/natgeo/dailyphoto.js @@ -1,27 +1,36 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { - const today = new Date(); - const year = today.getFullYear(); - const month = today.getMonth() + 1; + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + const link = 'https://www.nationalgeographic.com/photo-of-the-day/media-spotlight/'; + await page.goto(link); + const html = await page.evaluate( + () => + document.querySelector('div.InlineGallery').innerHTML + ); + browser.close(); - const api = `https://www.nationalgeographic.com/content/photography/en_US/photo-of-the-day/_jcr_content/.gallery.${year}-${month}.json`; - const response = await got.get(api); - const items = response.data.items; + const $ = cheerio.load(html); - const out = items.slice(0, 10).map((item) => { - const info = { - title: item.image.title, - author: item.image.credit && item.image.credit.replace('Photograph by ', ''), - link: item.pageUrl, - description: `` + item.image.caption, - }; - return info; - }); + const imgUrl = $('img').attr('src'); + const title = $('p.Caption__Title').text(); + const description = $('span.RichText').text(); + const author = $('span.Caption__Credit').text(); + + const out = new Array; + + const info = { + title: title, + link: link, + description: `
` + 'Photography by: ' + author + '
' + description, + }; + out.push(info); ctx.state.data = { - title: 'Photo of the Day', - link: 'https://www.nationalgeographic.com/photography/photo-of-the-day/', + title: 'Photo Of The Day', + link: link, item: out, }; }; diff --git a/lib/routes/natgeo/dailyselection.js b/lib/routes/natgeo/dailyselection.js new file mode 100644 index 00000000000000..ce5c5d3aaf96e4 --- /dev/null +++ b/lib/routes/natgeo/dailyselection.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { + parseDate +} = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const host = 'http://dili.bdatu.com/jiekou/mains/p1.html'; + const data = await got.get(host); + + let sort = 0; + let addtime = ''; + + for (let i = 0; i < data.data.album.length; i++) { + if (parseInt(data.data.album[i].ds) === 1) { + sort = data.data.album[i].sort; + addtime = data.data.album[i].addtime; + break; + } + } + const api = 'http://dili.bdatu.com/jiekou/albums/a' + sort + '.html'; + const response = await got.get(api); + const items = response.data.picture; + const out = new Array; + + items.map((item) => { + const info = { + title: item.title, + link: item.url, + description: `
` + item.content, + pubDate: timezone(parseDate(addtime), +0), + guid: item.id, + }; + out.push(info); + return info; + }); + + ctx.state.data = { + title: 'Photo of the Daily Selection', + link: api, + item: out, + }; +};