cover update2

This commit is contained in:
Loic Houpert 2021-01-14 16:24:53 +01:00
parent 93aed4db7a
commit 9b34bf899d
No known key found for this signature in database
GPG Key ID: 420C6A6671A9F480

View File

@ -7,7 +7,7 @@
# been added through custom entries in the function my_parse_index. # been added through custom entries in the function my_parse_index.
# 3) Fix the cover image so it doesnt disappear from the Kindle menu # 3) Fix the cover image so it doesnt disappear from the Kindle menu
# ( cover image format is changed to .jpeg) # ( cover image format is changed to .jpeg)
# # 14 Jan 2021 - Add Mediapart Logo url as masthead_url
from __future__ import unicode_literals from __future__ import unicode_literals
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -18,6 +18,7 @@ Mediapart
import re import re
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
from time import strftime
from calibre.web.feeds import feeds_from_index from calibre.web.feeds import feeds_from_index
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
@ -50,6 +51,7 @@ class Mediapart(BasicNewsRecipe):
remove_tags = [classes('login-subscribe print-source_url')] remove_tags = [classes('login-subscribe print-source_url')]
conversion_options = {'smarten_punctuation': True} conversion_options = {'smarten_punctuation': True}
masthead_url = "https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart_masthead.png"
cover_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg' cover_url = 'https://raw.githubusercontent.com/lhoupert/calibre_contrib/main/mediapart.jpeg'
# -- # --
@ -240,3 +242,22 @@ class Mediapart(BasicNewsRecipe):
br['password'] = self.password br['password'] = self.password
br.submit() br.submit()
return br return br
def default_cover(self, cover_file):
"""
Create a generic cover for recipes that don't have a cover
This override adds time to the cover
"""
try:
from calibre.ebooks import calibre_cover
title = self.title if isinstance(self.title, unicode) else \
self.title.decode('utf-8', 'replace')
date = strftime(self.timefmt)
time = strftime('%a %d %b %Y %-H:%M')
img_data = calibre_cover(title, date, time)
cover_file.write(img_data)
cover_file.flush()
print(f'title: {title}\ndate: {date}\ntime: {time}')
except:
self.log.exception('Failed to generate default cover')
return False