const sqlite3 = require('sqlite3').verbose(); // 数据库连接 const db = new sqlite3.Database('goguryeo_video.db'); // 重新分配视频到不同分类 const redistributionPlan = [ // 将一些动物视频重新分类为传统艺术(表演类) { videoIds: [17], // 巨肺狗子(表演性质) newCategory: 2, // 传统艺术 reason: '表演性质的内容' }, // 将一些动物视频重新分类为语言学习(教育性质) { videoIds: [11, 15], // 小牛叫妈妈、水獭 newCategory: 3, // 语言学习 reason: '教育和学习性质的内容' }, // 将一些动物视频重新分类为考古发现(自然探索) { videoIds: [9, 18], // 小老虎、小象 newCategory: 4, // 考古发现 reason: '自然探索和发现类内容' }, // 将一些动物视频重新分类为其他 { videoIds: [16, 20], // 小肥啾、小猫咪 newCategory: 6, // 其他 reason: '综合性内容' } ]; // 更新视频分类 function updateVideoCategory(videoId, newCategory) { return new Promise((resolve, reject) => { const sql = 'UPDATE videos SET category = ? WHERE id = ?'; db.run(sql, [newCategory, videoId], function(err) { if (err) { reject(err); } else { resolve(this.changes); } }); }); } // 获取视频信息 function getVideoInfo(videoId) { return new Promise((resolve, reject) => { const sql = 'SELECT id, title, category FROM videos WHERE id = ?'; db.get(sql, [videoId], (err, row) => { if (err) { reject(err); } else { resolve(row); } }); }); } // 主函数 async function main() { try { console.log('开始重新分配视频分类...'); for (const plan of redistributionPlan) { console.log(`\n重新分配到分类 ${plan.newCategory}: ${plan.reason}`); for (const videoId of plan.videoIds) { try { // 获取视频信息 const videoInfo = await getVideoInfo(videoId); if (!videoInfo) { console.log(`视频 ID ${videoId} 不存在`); continue; } console.log(` ${videoInfo.title} (ID: ${videoId}) 从分类 ${videoInfo.category} -> ${plan.newCategory}`); // 更新分类 await updateVideoCategory(videoId, plan.newCategory); } catch (error) { console.error(`更新视频 ${videoId} 失败:`, error.message); } } } console.log('\n重新分配完成!'); // 显示最终的分类统计 console.log('\n=== 最终分类统计 ==='); const sql = ` SELECT c.name, COUNT(v.id) as video_count FROM categories c LEFT JOIN videos v ON c.id = v.category GROUP BY c.id, c.name ORDER BY c.id `; db.all(sql, [], (err, rows) => { if (err) { console.error('查询统计失败:', err); } else { rows.forEach(row => { console.log(`${row.name}: ${row.video_count} 个视频`); }); } db.close(); }); } catch (error) { console.error('重新分配失败:', error); db.close(); } } // 运行脚本 if (require.main === module) { main(); } module.exports = { main };