Skip to content

Commit

Permalink
feat(xmoj): improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Molmin committed Jan 31, 2024
1 parent d052e3c commit e1ea2f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion xmoj-crawl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function main() {
if (res.judge.output !== '标准输出')
throw new Error(`Error format at ${problem.problemId}`)
}
else if (!/^[a-z]+?\.in$/.test(res.judge.input))
else if (!/^[a-z0-9]+?\.in$/.test(res.judge.input))
throw new Error(`Error format at ${problem.problemId}`)
else if (res.judge.input.split('.')[0] + '.out' !== res.judge.output)
throw new Error(`Error format at ${problem.problemId}`)
Expand Down
5 changes: 3 additions & 2 deletions xmoj-crawl/video.crawl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWriteStream, readFileSync } from 'node:fs'
import { createWriteStream, existsSync, readFileSync } from 'node:fs'
import superagent from 'superagent'
import { ensureDirSync } from "fs-extra"
import { JSDOM } from 'jsdom'
Expand Down Expand Up @@ -55,6 +55,8 @@ async function main() {
console.log(`Found ${scripts.length} videos in contest ${contestId}`)
for (let i = 0; i < scripts.length; i++) {
tasks.push(downloadQueue.waitForTask(async () => {
const target = `data/video/${contestId}${scripts.length <= 1 ? '' : `-${i + 1}`}.mp4`
if (existsSync(target) && config.skipDownloadedVideo) return
const script = (await getVideos(contestId))[i]
let data
try {
Expand All @@ -68,7 +70,6 @@ async function main() {
if (Object.entries(data).length != 10) throw new Error(`Found error in contest ${contestId}`)
const url = getVideoUrl(data)
const { body: video } = await superagent.get(url)
const target = `data/video/${contestId}${scripts.length <= 1 ? '' : `-${i + 1}`}.mp4`
console.log(`Start downloading contest ${contestId} video #${i + 1}`)
await downloadFile(video.PlayInfoList.PlayInfo[0].PlayURL, target)
console.log(`Downloaded contest ${contestId} video #${i + 1}`)
Expand Down

0 comments on commit e1ea2f4

Please sign in to comment.