Merge pull request #247 from elelay/gtk3-store-html-description

store episode's description_html (schema change)
This commit is contained in:
Adam Voss 2017-04-08 12:31:19 -05:00 committed by GitHub
commit ed1fa69b19
3 changed files with 25 additions and 12 deletions

View File

@ -201,7 +201,14 @@ class gPodderShownotesHTML(gPodderShownotes):
else:
self._base_uri = episode.channel.url
self._loaded = False
self.html_view.load_html(episode.description_html, self._base_uri)
description = episode.description_html
if not description:
description = self.coerce_text_to_html(episode.description)
self.html_view.load_html(description, self._base_uri)
def coerce_text_to_html(self, text):
return text.replace('\n', '<br>')
def on_mouse_over(self, webview, hit_test_result, modifiers):
if hit_test_result.context_is_link():

View File

@ -144,7 +144,14 @@ class PodcastEpisode(PodcastModelObject):
episode.guid = entry['guid']
episode.title = entry['title']
episode.link = entry['link']
episode.description = entry.get('description_html', entry.get('description'))
episode.description = entry['description']
if entry.get('description_html'):
episode.description_html = entry['description_html']
# XXX: That's not a very well-informed heuristic to check
# if the description already contains HTML. Better ideas?
# TODO: This really should be handled in podcastparser and not here.
elif '<' in entry['description']:
episode.description_html = entry['description']
episode.total_time = entry['total_time']
episode.published = entry['published']
episode.payment_url = entry['payment_url']
@ -202,6 +209,7 @@ class PodcastEpisode(PodcastModelObject):
self.mime_type = 'application/octet-stream'
self.guid = ''
self.description = ''
self.description_html = ''
self.link = ''
self.published = 0
self.download_filename = None
@ -333,14 +341,6 @@ class PodcastEpisode(PodcastModelObject):
age_prop = property(fget=get_age_string)
@property
def description_html(self):
# XXX: That's not a very well-informed heuristic to check
# if the description already contains HTML. Better ideas?
if '<' in self.description:
return self.description
return self.description.replace('\n', '<br>')
def one_line_description(self):
MAX_LINE_LENGTH = 120
@ -632,7 +632,7 @@ class PodcastEpisode(PodcastModelObject):
return '-'
def update_from(self, episode):
for k in ('title', 'url', 'description', 'link', 'published', 'guid', 'file_size', 'payment_url'):
for k in ('title', 'url', 'description', 'description_html', 'link', 'published', 'guid', 'file_size', 'payment_url'):
setattr(self, k, getattr(episode, k))

View File

@ -47,6 +47,7 @@ EpisodeColumns = (
'current_position_updated',
'last_playback',
'payment_url',
'description_html',
)
PodcastColumns = (
@ -69,7 +70,7 @@ PodcastColumns = (
'cover_thumb',
)
CURRENT_VERSION = 6
CURRENT_VERSION = 7
# SQL commands to upgrade old database versions to new ones
@ -103,6 +104,11 @@ UPGRADE_SQL = [
(5, 6, """
ALTER TABLE podcast ADD COLUMN cover_thumb BLOB NULL DEFAULT NULL
"""),
# Version 7: Add HTML description
(6, 7, """
ALTER TABLE episode ADD COLUMN description_html TEXT NOT NULL DEFAULT ''
"""),
]
def initialize_database(db):