UNPKG

rsshub

Version:
83 lines (81 loc) 3.31 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/sina/utils.ts init_esm_shims(); const getRollNewsList = (pageid, lid, limit) => got_default("https://feed.mix.sina.com.cn/api/roll/get", { headers: { referer: "https://news.sina.com.cn/" }, searchParams: { pageid, lid, k: "", num: limit, page: 1, r: Math.random(), _: Date.now() } }); const parseRollNewsList = (data) => data.map((item) => ({ title: item.title, description: item.intro, link: item.url.replace("http://", "https://"), author: item.media_name, pubDate: parseDate(item.intime, "X"), updated: parseDate(item.mtime, "X") })); const parseArticle = (item, tryGet) => tryGet(item.link, async () => { const $ = load((await got_default(item.link)).data); $("#left_hzh_ad, .appendQr_wrap, .app-kaihu-qr, .tech-quotation").remove(); const metaPublishTime = $("meta[property=\"article:published_time\"]"); const htmlPubDate = $("#pub_date, .date"); const htmlDate = htmlPubDate.length ? timezone(parseDate(htmlPubDate.text(), ["YYYY年MM月DD日 HH:mm", "YYYY年MM月DD日HH:mm"]), 8) : null; const metaDate = metaPublishTime.length ? parseDate(metaPublishTime.attr("content")) : htmlDate; item.pubDate = item.pubDate ?? metaDate; item.author = $("meta[property=\"article:author\"]").attr("content"); if (item.link.startsWith("https://slide.sports.sina.com.cn/") || item.link.startsWith("https://slide.tech.sina.com.cn/")) { const slideData = JSON.parse($("script").text().match(/var slide_data = ({.*?})\s/)[1]); item.description = art(path.join(__dirname, "templates/slide-5c74a843.art"), { slideData }); } else if (item.link.startsWith("https://video.sina.com.cn/")) { const videoId = $("script").text().match(/video_id:'?(.*?)'?,/)[1]; const { data: videoResponse } = await got_default("https://api.ivideo.sina.com.cn/public/video/play", { searchParams: { video_id: videoId, appver: "V11220.210521.03", appname: "sinaplayer_pc", applt: "web", tags: "sinaplayer_pc", jsonp: "", plid: 2021012801, prid: "", uid: "", tid: "", pid: 1, ran: Math.random(), r: item.link, ssid: `gusr_pc_${Date.now()}`, preload: 0, uu: "", isAuto: 1 } }); const videoData = videoResponse.data; const poster = videoData.image; const videoUrl = videoData.videos.find((v) => v.type === "mp4").dispatch_result.url; item.description = art(path.join(__dirname, "templates/video-68dabc54.art"), { poster, videoUrl }); item.pubDate = parseDate(videoData.create_time, "X"); } else if (item.link.startsWith("https://news.sina.com.cn/") || item.link.startsWith("https://mil.news.sina.com.cn/")) { item.description = $("#article").html(); item.category = $("meta[name=\"keywords\"]").attr("content").split(","); } else { item.description = $("#artibody").html(); item.category = $("#keywords").data("wbkey")?.split(","); } return item; }); //#endregion export { parseArticle as n, parseRollNewsList as r, getRollNewsList as t };