diff --git a/src/sites/book.js b/src/sites/book.js index dd7b61f..79a367b 100644 --- a/src/sites/book.js +++ b/src/sites/book.js @@ -152,29 +152,28 @@ const parseOneBook = async (book) => { if (!book.data || !book.data.sites || book.data.sites.length === 0) { return; } - let siteId = book.data.sites[0].site; - let chapterList; + let hasChapter = false; // 书籍章节列表 // 有些源无法获取到章节列表, 所以挨个获取,直到获取到数据 - for(let site of book.data.sites) { - let chapterListData = await bookChapterList(bookId, site.site); - if (chapterListData.code === 1) { - chapterList = chapterListData.data; - site = site.site; - break; + if (book.data.sites && book.data.sites.length > 0) { + for(let site of book.data.sites) { + let chapterListData = await bookChapterList(bookId, site.site); + if (chapterListData.code === 1) { + hasChapter = true; + chapterListData.book_id = bookId; + chapterListData.site = siteId; + let chapterRecord = new SpiderData({ + data: chapterListData, + type: 'book_chapter' + }); + await chapterRecord.save(); + } } } - if (!siteId) { - return ; + if (hasChapter) { + book.status = 2; + await book.save(); } - let chapterRecord = new SpiderData({ - data: {list: chapterList, - book_id: bookId, - site: siteId, - }, - type: 'book_chapter' - }); - await chapterRecord.save(); // let bar = multi.newBar(' '+book.data.name+' [:bar] :percent :etas', { // complete: '=', // incomplete: ' ', @@ -188,8 +187,6 @@ const parseOneBook = async (book) => { // chapter.book_id = bookId; // chapter.site = siteId; // } - book.status = 2; - await book.save(); } const parseAllBookList = async (sex, ltype) => { let bookList = await SpiderData.find({