Skip to content

Commit

Permalink
feat(route/qingting): return first page program instead of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Dec 2, 2024
1 parent 310515b commit 4c09251
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
18 changes: 9 additions & 9 deletions lib/routes/qingting/channel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';

Expand All @@ -18,18 +18,18 @@ export const route: Route = {
supportScihub: false,
},
name: '专辑',
maintainers: ['nczitzk'],
maintainers: ['nczitzk', 'pseudoyu'],
handler,
};

async function handler(ctx) {
const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.req.param('id')}`;
let response = await got(channelUrl);
const title = response.data.data.title;
const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`;
response = await got(programUrl);
let response = await ofetch(channelUrl);
const title = response.data.title;
const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.v}?curpage=1&order=asc`;
response = await ofetch(programUrl);

const items = response.data.data.programs.map((item) => ({
const items = response.data.programs.map((item) => ({
title: item.title,
link: `https://www.qingting.fm/channels/${ctx.req.param('id')}/programs/${item.id}/`,
pubDate: timezone(parseDate(item.update_time), +8),
Expand All @@ -41,8 +41,8 @@ async function handler(ctx) {
item: await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
response = await got(item.link);
const data = JSON.parse(response.data.match(/},"program":(.*?),"plist":/)[1]);
response = await ofetch(item.link);
const data = JSON.parse(response.match(/},"program":(.*?),"plist":/)[1]);
item.description = data.richtext;
return item;
})
Expand Down
36 changes: 13 additions & 23 deletions lib/routes/qingting/podcast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import crypto from 'crypto';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { config } from '@/config';
Expand Down Expand Up @@ -29,7 +29,7 @@ export const route: Route = {
},
],
name: '播客',
maintainers: ['RookieZoe', 'huyyi'],
maintainers: ['RookieZoe', 'huyyi', 'pseudoyu'],
handler,
description: `获取的播放 URL 有效期只有 1 天,需要开启播客 APP 的自动下载功能。`,
};
Expand All @@ -44,35 +44,27 @@ async function handler(ctx) {
const channelId = ctx.req.param('id');

const channelUrl = `https://i.qingting.fm/capi/v3/channel/${channelId}`;
const response = await got({
method: 'get',
url: channelUrl,
const response = await ofetch(channelUrl, {
headers: {
Referer: 'https://www.qingting.fm/',
},
});

const title = response.data.data.title;
const channel_img = response.data.data.thumbs['400_thumb'];
const authors = response.data.data.podcasters.map((author) => author.nick_name).join(',');
const desc = response.data.data.description;
const programUrl = `https://i.qingting.fm/capi/channel/${channelId}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`;
const title = response.data.title;
const channel_img = response.data.thumbs['400_thumb'];
const authors = response.data.podcasters.map((author) => author.nick_name).join(',');
const desc = response.data.description;
const programUrl = `https://i.qingting.fm/capi/channel/${channelId}/programs/${response.data.v}?curpage=1&pagesize=10&order=asc`;

const {
data: {
data: { programs },
},
} = await got({
method: 'get',
url: programUrl,
data: { programs },
} = await ofetch(programUrl, {
headers: {
Referer: 'https://www.qingting.fm/',
},
});

const {
data: { data: channelInfo },
} = await got(`https://i.qingting.fm/capi/v3/channel/${channelId}?user_id=${qingtingId}`);
const { data: channelInfo } = await ofetch(`https://i.qingting.fm/capi/v3/channel/${channelId}?user_id=${qingtingId}`);

const isCharged = channelInfo.purchase?.item_type !== 0;

Expand All @@ -83,15 +75,13 @@ async function handler(ctx) {
const data = (await cache.tryGet(`qingting:podcast:${channelId}:${item.id}`, async () => {
const link = `https://www.qingting.fm/channels/${channelId}/programs/${item.id}/`;

const detailRes = await got({
method: 'get',
url: link,
const detailRes = await ofetch(link, {
headers: {
Referer: 'https://www.qingting.fm/',
},
});

const detail = JSON.parse(detailRes.data.match(/},"program":(.*?),"plist":/)[1]);
const detail = JSON.parse(detailRes.match(/},"program":(.*?),"plist":/)[1]);

const rssItem = {
title: item.title,
Expand Down

0 comments on commit 4c09251

Please sign in to comment.