forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videos.js
46 lines (40 loc) · 1.83 KB
/
videos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const got = require('@/utils/got');
module.exports = async (ctx) => {
const keyword = ctx.params.keyword ? ctx.params.keyword : '';
let default_order, default_time;
if (keyword) {
default_order = 'mr';
default_time = 'a';
} else {
default_order = 'mv';
default_time = 'm';
}
const order = ctx.params.order ? ctx.params.order : default_order;
const time = ctx.params.time ? ctx.params.time : default_time;
const top = ctx.params.top ? ctx.params.top : 30;
const url = keyword ? `https://api.avgle.com/v1/search/${keyword}/0` : `https://api.avgle.com/v1/videos/0`;
const response = await got({
method: 'get',
url,
searchParams: {
o: order,
t: time,
limit: top,
},
});
const returnData = response.data.response.videos;
const compact_number = (number) => String(Intl.NumberFormat('en-US', { notation: 'compact', compactDisplay: 'short' }).format(number));
const like = (item) => `[${Math.round((item.likes / (item.likes + item.dislikes)) * 100)}%/${compact_number(item.likes + item.dislikes)}/${compact_number(item.viewnumber)}]`;
ctx.state.data = {
title: `Avgle ${order}/${time}`,
link: keyword ? `https://avgle.com/search/videos/${keyword}?o=${order}&t=${time}` : `https://avgle.com/videos?o=${order}&t=${time}`,
description: `Avgle ${order}/${time}`,
item: returnData.map((item) => ({
title: like(item) + item.title,
description: item.preview_video_url ? `<video controls loop ${item.preview_url ? `poster="${item.preview_url}"` : ''} src="${item.preview_video_url}" />` : '',
pubDate: new Date(item.addtime * 1000).toUTCString(),
link: item.video_url,
category: item.keyword.split(' '),
})),
};
};