diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 3855e3828..f45f885c1 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -532,3 +532,113 @@ def get_posts(api_key, blogname, offset=0): ['economics'], 'published', 'article', 'html')], posts, posts) + + @patch("pelican.tools.pelican_import._get_tumblr_posts") + def test_video_embed(self, get): + def get_posts(api_key, blogname, offset=0): + if offset > 0: + return [] + + return [ + { + "type": "video", + "blog_name": "testy", + "slug": "the-slug", + "date": "2017-07-07 20:31:41 GMT", + "timestamp": 1499459501, + "state": "published", + "format": "html", + "tags": [], + "source_url": "https://href.li/?https://www.youtube.com/a", + "source_title": "youtube.com", + "caption": "

Caption

", + "player": [ + { + "width": 250, + "embed_code": + "" + }, + { + "width": 400, + "embed_code": + "" + }, + { + "width": 500, + "embed_code": + "" + } + ], + "video_type": "youtube", + } + ] + get.side_effect = get_posts + + posts = list(tumblr2fields("api_key", "blogname")) + self.assertEqual( + [('youtube.com', + '

via

\n

Caption

' + '\n' + '\n' + '\n', + '2017-07-07-the-slug', + '2017-07-07 20:31:41', 'testy', ['video'], [], 'published', + 'article', 'html')], + posts, + posts) + + @patch("pelican.tools.pelican_import._get_tumblr_posts") + def test_broken_video_embed(self, get): + def get_posts(api_key, blogname, offset=0): + if offset > 0: + return [] + + return [ + { + "type": "video", + "blog_name": "testy", + "slug": "the-slug", + "date": "2016-08-14 16:37:35 GMT", + "timestamp": 1471192655, + "state": "published", + "format": "html", + "tags": [ + "interviews" + ], + "source_url": + "https://href.li/?https://www.youtube.com/watch?v=b", + "source_title": "youtube.com", + "caption": + "

Caption

", + "player": [ + { + "width": 250, + # If video is gone, embed_code is False + "embed_code": False + }, + { + "width": 400, + "embed_code": False + }, + { + "width": 500, + "embed_code": False + } + ], + "video_type": "youtube", + } + ] + get.side_effect = get_posts + + posts = list(tumblr2fields("api_key", "blogname")) + self.assertEqual( + [('youtube.com', + '

via

\n

Caption

' + '

(This video isn\'t available anymore.)

\n', + '2016-08-14-the-slug', + '2016-08-14 16:37:35', 'testy', ['video'], ['interviews'], + 'published', 'article', 'html')], + posts, + posts) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 474b5cba0..16ce63054 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -459,8 +459,16 @@ def tumblr2fields(api_key, blogname): fmtstr = '

via

\n' source = fmtstr % post.get('source_url') caption = post.get('caption') - players = '\n'.join(player.get('embed_code') - for player in post.get('player')) + players = [ + # If embed_code is False, couldn't get the video + player.get('embed_code') or None + for player in post.get('player')] + # If there are no embeddable players, say so, once + if len(players) > 0 and all( + player is None for player in players): + players = "

(This video isn't available anymore.)

\n" + else: + players = '\n'.join(players) content = source + caption + players elif type == 'answer': title = post.get('question')