Skip to content

Commit

Permalink
tumblr_backup: Make video embedding more robust to missing player
Browse files Browse the repository at this point in the history
  • Loading branch information
cebtenzzre committed Oct 27, 2020
1 parent b5a9ebc commit 0f8ec9a
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tumblr_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,21 @@ def append_try(elt, fmt=u'%s'):
src, "Your browser does not support the video element.", src, "Video file"
))
else:
append(post['player'][-1]['embed_code'])
player = get_try('player')
if player:
append(player[-1]['embed_code'])
else:
append_try('video_url')
append_try('caption')

elif self.typ == 'audio':
src = ''
def make_player(src_):
append(u'<p><audio controls><source src="%s" type=audio/mpeg>%s<br>\n<a href="%s">%s</a></audio></p>'
% (src_, "Your browser does not support the audio element.", src_, "Audio file"))

src = None
audio_url = get_try('audio_url') or get_try('audio_source_url')
if options.save_audio:
audio_url = get_try('audio_url') or get_try('audio_source_url')
if post['audio_type'] == 'tumblr':
if audio_url.startswith('https://a.tumblr.com/'):
src = self.get_media_url(audio_url, '.mp3')
Expand All @@ -771,12 +779,13 @@ def append_try(elt, fmt=u'%s'):
src = self.get_media_url(audio_url, '.mp3')
elif post['audio_type'] == 'soundcloud':
src = self.get_media_url(audio_url, '.mp3')
player = get_try('player')
if src:
append(u'<p><audio controls><source src="%s" type=audio/mpeg>%s<br>\n<a href="%s">%s</a></audio></p>' % (
src, "Your browser does not support the audio element.", src, "Audio file"
))
else:
append(post['player'])
make_player(src)
elif player:
append(player)
elif audio_url:
make_player(audio_url)
append_try('caption')

elif self.typ == 'answer':
Expand Down

0 comments on commit 0f8ec9a

Please sign in to comment.