MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / getVideos

Function getVideos

tech-study.js:4155–4186  ·  view source on GitHub ↗

* @description 获取视频列表

()

Source from the content-addressed store, hash-verified

4153 * @description 获取视频列表
4154 */
4155async function getVideos() {
4156 // 需要学习的视频数量
4157 const need = taskConfig[TaskType.WATCH].need < maxVideoNum
4158 ? taskConfig[TaskType.WATCH].need
4159 : maxVideoNum;
4160 log(`剩余 ${need} 个视频`);
4161 // 获取视频
4162 const data = await getVideoList();
4163 if (data && data.length) {
4164 // 索引
4165 let i = 0;
4166 // 最新视频
4167 const latestItems = data.slice(0, 100);
4168 // 当前年份
4169 const currentYear = new Date().getFullYear().toString();
4170 // 查找今年视频
4171 while (i < need) {
4172 const randomIndex = ~~(Math.random() * latestItems.length);
4173 // 新闻
4174 const item = latestItems[randomIndex];
4175 // 是否存在
4176 if (item.publishTime.startsWith(currentYear) &&
4177 (item.type === 'shipin' || item.type === 'juji')) {
4178 videos[i] = item;
4179 i++;
4180 }
4181 }
4182 }
4183 else {
4184 videos = [];
4185 }
4186}
4187/**
4188 * @description 阅读文章
4189 */

Callers 1

watchVideoFunction · 0.70

Calls 2

logFunction · 0.70
getVideoListFunction · 0.70

Tested by

no test coverage detected