蓝影论坛 Logo
16浏览量
1参与者
活动 102天
✨这是 parkertaylor 首次发帖 - 让我们欢迎他/她加入社区吧!
parkertaylor
楼主
如果下载速度太快,导致空间占满种子报错,可以用这个vt定时脚本重启种子,周期可设为每分钟一次。 ~~~ async () => { const CONFIG = { recoverFreeSpace: 30 * 1024 * 1024 * 1024, invalidTrackerMessages: [ 'torrent banned', 'torrent not exists', 'torrent not registered with this tracker', 'unregistered torrent', 'invalid torrent', 'passkey', 'not authorized', 'forbidden' ] } const formatSize = (bytes) => { const units = ['B', 'KB', 'MB', 'GB', 'TB'] let value = Number(bytes) || 0 let index = 0 while (value >= 1024 && index < units.length - 1) { value /= 1024 index++ } return `${value.toFixed(index === 0 ? 0 : 2)}${units[index]}` } const isErrorState = (torrent) => { const state = String(torrent.state || '').toLowerCase() return state.includes('error') } const isInvalidTrackerError = (torrent) => { const message = [ torrent.trackerStatus, torrent.tracker_status, torrent.message, torrent.error ].filter(Boolean).join(' ').toLowerCase() if (!message) return false return CONFIG.invalidTrackerMessages.some((text) => message.includes(text)) } if (global.restartErrorTorrentsRunning) { logger.info('[错误种子恢复] 上一轮仍在运行,跳过本轮') return } global.restartErrorTorrentsRunning = true try { const clients = global.runningClient || {} const clientIds = Object.keys(clients) if (clientIds.length === 0) { logger.error('[错误种子恢复] 未找到正在运行的下载器') return } let totalScanned = 0 let totalMatched = 0 let totalResumed = 0 let totalFailed = 0 let totalSkippedInvalid = 0 for (const clientId of clientIds) { const client = clients[clientId] const maindata = client && client.maindata const serverState = maindata && (maindata.serverState || maindata.server_state) if (!client || !maindata || !maindata.torrents || !serverState) { logger.error(`[错误种子恢复] Client ${clientId} 信息不完整,跳过`) continue } const freeSpace = Number(serverState.free_space_on_disk || 0) if (freeSpace < CONFIG.recoverFreeSpace) { logger.info(`[错误种子恢复] [${clientId}] 剩余空间 ${formatSize(freeSpace)} < 恢复阈值 ${formatSize(CONFIG.recoverFreeSpace)},跳过恢复`) continue } const torrents = Array.isArray(maindata.torrents) ? maindata.torrents : Object.values(maindata.torrents) let clientMatched = 0 let clientResumed = 0 let clientFailed = 0 let clientSkippedInvalid = 0 for (const torrent of torrents) { totalScanned++ if (!isErrorState(torrent)) continue totalMatched++ clientMatched++ if (isInvalidTrackerError(torrent)) { totalSkippedInvalid++ clientSkippedInvalid++ logger.info(`[错误种子恢复] [${clientId}] 跳过站点/种子无效错误: ${torrent.name || torrent.hash}`) continue } try { logger.info(`[错误种子恢复] [${clientId}] 空间已恢复,尝试恢复: ${torrent.name || torrent.hash}`) await client.resumeTorrent(torrent.hash) totalResumed++ clientResumed++ logger.info(`[错误种子恢复] [${clientId}] 恢复成功: ${torrent.name || torrent.hash}`) } catch (error) { totalFailed++ clientFailed++ logger.error(`[错误种子恢复] [${clientId}] 恢复失败: ${torrent.name || torrent.hash} | ${error.message || error}`) } } logger.info(`[错误种子恢复] [${clientId}] 扫描 ${torrents.length} 个种子,错误 ${clientMatched} 个,恢复 ${clientResumed} 个,跳过无效 ${clientSkippedInvalid} 个,失败 ${clientFailed} 个,剩余空间 ${formatSize(freeSpace)}`) } logger.info(`[错误种子恢复] 本轮完成:扫描 ${totalScanned} 个,错误 ${totalMatched} 个,恢复 ${totalResumed} 个,跳过无效 ${totalSkippedInvalid} 个,失败 ${totalFailed} 个`) } finally { global.restartErrorTorrentsRunning = false } } ~~~
102天
相关话题回复浏览量活动