diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index ec8c7651..6ff829c3 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -1932,6 +1932,23 @@ add_to_output_css: white-space: pre-wrap; } +extra_valid_entries:dedication, authorcomment, likes, follows, reviews, bookmarks, numcollections, pages + +dedication_label:Посвящение +authorcomment_label:Примечания +likes_label:Нравится +follows_label:Подписаться +reviews_label:Отзывы +bookmarks_label:В сборник +numcollections_label:Сборниках +pages_label:Страницы + +# likes, follows, reviews, bookmarks, numcollections, pages +extra_titlepage_entries: dedication, authorcomment + +# headnotes,footnotes +exclude_notes: + [fiction.live] ## Recommended if you include images, fiction.live tends to have many ## duplicated images. diff --git a/fanficfare/adapters/adapter_ficbooknet.py b/fanficfare/adapters/adapter_ficbooknet.py index c5705b14..7836145c 100644 --- a/fanficfare/adapters/adapter_ficbooknet.py +++ b/fanficfare/adapters/adapter_ficbooknet.py @@ -219,8 +219,44 @@ class FicBookNetAdapter(BaseSiteAdapter): self.story.addToList('characters',stripHTML(paira)) summary=soup.find('div', itemprop='description') - self.setDescription(url,summary) - #self.story.setMetadata('description', summary.text) + # To get rid of an empty div on the title page. + if summary.get_text(): + self.setDescription(url,summary) + #self.story.setMetadata('description', summary.text) + + stats = soup.find('div', {'class' : 'mb-15 text-center'}) + targetdata = stats.find_all('span', {'class' : 'main-info'}) + for data in targetdata: + if data.find('svg', {'class' : 'ic_thumbs-up'}): + self.story.setMetadata('likes', stripHTML(data)) + if data.find('svg', {'class' : 'ic_bubble-dark'}): + self.story.setMetadata('reviews', stripHTML(data)) + if data.find('svg', {'class' : 'ic_bookmark'}): + self.story.setMetadata('bookmarks', stripHTML(data)) + + follows = stats.find('fanfic-follow-button')[':follow-count'] + if follows: + self.story.setMetadata('follows', follows) + + collection = soup.find('fanfic-collections-link').find_parent('div') + if collection: + self.story.setMetadata('numcollections', collection.find('fanfic-collections-link')[':initial-count']) + + targetpages = soup.find('strong',string='Размер:').find_next('div') + if targetpages: + pages = re.findall(r'([\d,]+)\s+страницы', targetpages.text) + self.story.setMetadata('pages', pages) + + # Find dedication. + ded = soup.find('div', {'class' : 'js-public-beta-dedication'}) + if ded != None: + self.story.setMetadata('dedication',stripHTML(ded)) + + # Find author comment + comm = soup.find('div', {'class' : 'js-public-beta-author-comment'}) + if comm != None: + self.story.setMetadata('authorcomment',stripHTML(comm)) + # grab the text for an individual chapter. def getChapterText(self, url): @@ -241,34 +277,37 @@ class FicBookNetAdapter(BaseSiteAdapter): for ads in chapter.find_all('div', {'class' : 'ads-in-text'}): ads.extract() - # Find the headnote - head_note = soup.find('div', {'class': 'part-comment-top'}) - if head_note: - head_notes_content = head_note.find('div', {'class': 'js-public-beta-comment-before'}).get_text(strip=True) - # Create the structure for the headnote - head_notes_div_tag = soup.new_tag('div', attrs={'class': 'fff_chapter_notes fff_head_notes'}) - head_b_tag = soup.new_tag('b') - head_b_tag.string = 'Примечания:' - head_blockquote_tag = soup.new_tag('blockquote') - head_blockquote_tag.string = head_notes_content - head_notes_div_tag.append(head_b_tag) - head_notes_div_tag.append(head_blockquote_tag) - # Prepend the headnotes to the chapter - chapter.insert(0, head_notes_div_tag) + exclude_notes=self.getConfigList('exclude_notes') + if 'headnotes' not in exclude_notes: + # Find the headnote + head_note = soup.find('div', {'class': 'part-comment-top'}) + if head_note: + head_notes_content = head_note.find('div', {'class': 'js-public-beta-comment-before'}).get_text(strip=True) + # Create the structure for the headnote + head_notes_div_tag = soup.new_tag('div', attrs={'class': 'fff_chapter_notes fff_head_notes'}) + head_b_tag = soup.new_tag('b') + head_b_tag.string = 'Примечания:' + head_blockquote_tag = soup.new_tag('blockquote') + head_blockquote_tag.string = head_notes_content + head_notes_div_tag.append(head_b_tag) + head_notes_div_tag.append(head_blockquote_tag) + # Prepend the headnotes to the chapter + chapter.insert(0, head_notes_div_tag) - # Find the endnote - end_note = soup.find('div', {'class': 'part-comment-bottom'}) - if end_note: - end_notes_content = end_note.find('div', {'class': 'js-public-beta-comment-after'}).get_text(strip=True) - # Create the structure for the footnote - end_notes_div_tag = soup.new_tag('div', attrs={'class': 'fff_chapter_notes fff_foot_notes'}) - end_b_tag = soup.new_tag('b') - end_b_tag.string = 'Примечания:' - end_blockquote_tag = soup.new_tag('blockquote') - end_blockquote_tag.string = end_notes_content - end_notes_div_tag.append(end_b_tag) - end_notes_div_tag.append(end_blockquote_tag) - # Append the endnotes to the chapter - chapter.append(end_notes_div_tag) + if 'footnotes' not in exclude_notes: + # Find the endnote + end_note = soup.find('div', {'class': 'part-comment-bottom'}) + if end_note: + end_notes_content = end_note.find('div', {'class': 'js-public-beta-comment-after'}).get_text(strip=True) + # Create the structure for the footnote + end_notes_div_tag = soup.new_tag('div', attrs={'class': 'fff_chapter_notes fff_foot_notes'}) + end_b_tag = soup.new_tag('b') + end_b_tag.string = 'Примечания:' + end_blockquote_tag = soup.new_tag('blockquote') + end_blockquote_tag.string = end_notes_content + end_notes_div_tag.append(end_b_tag) + end_notes_div_tag.append(end_blockquote_tag) + # Append the endnotes to the chapter + chapter.append(end_notes_div_tag) return self.utf8FromSoup(url,chapter) diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 6ec42b93..d099d3ed 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -1927,6 +1927,24 @@ add_to_output_css: white-space: pre-wrap; } +extra_valid_entries:dedication, authorcomment, likes, follows, reviews, bookmarks, numcollections, pages + +dedication_label:Посвящение +authorcomment_label:Примечания +likes_label:Нравится +follows_label:Подписаться +reviews_label:Отзывы +bookmarks_label:В сборник +numcollections_label:Сборниках +pages_label:Страницы + +# likes, follows, reviews, bookmarks, numcollections, pages +extra_titlepage_entries: dedication, authorcomment + +# headnotes,footnotes +exclude_notes: + + [fiction.live] ## Recommended if you include images, fiction.live tends to have many ## duplicated images.