From 1cdc450b42480b2a950ec81ac26bc36f9b46b5e8 Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 3 Apr 2019 17:30:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=89=80=E6=9C=89=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=BA=90=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sites/book.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) 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({