Esempio n. 1
0
    def test_parse_videos(self):
        parser = role_loader.RoleMetaParser({
            'galaxy_info': {
                'video_links': [{
                    'title':
                    'Google Drive Video',
                    'url':
                    'https://drive.google.com/'
                    'file/d/gxH17k3EzzJP3g/browse',
                }, {
                    'title': 'Vimeo Video',
                    'url': 'https://vimeo.com/1733124',
                }, {
                    'title': 'Youtube Video',
                    'url': 'https://youtu.be/TxHPpfkGms9eDQ',
                }]
            },
            'dependencies': []
        })

        videos = parser.parse_videos()

        assert videos == [
            models.VideoLink(
                'https://drive.google.com/file/d/gxH17k3EzzJP3g/preview',
                'Google Drive Video'),
            models.VideoLink('https://player.vimeo.com/video/1733124',
                             'Vimeo Video'),
            models.VideoLink('https://www.youtube.com/embed/TxHPpfkGms9eDQ',
                             'Youtube Video'),
        ]
Esempio n. 2
0
 def parse_videos(self):
     videos = []
     meta_videos = self.metadata.get('video_links', [])
     for video in meta_videos:
         if not isinstance(video, dict):
             self.log.warning(
                 'Expected item in video_links to be dictionary')
             continue
         if set(video) != {'url', 'title'}:
             self.log.warning("Expected item in video_links to contain "
                              "only keys 'url' and 'title'")
             continue
         for name, expr in six.iteritems(self.VIDEO_REGEXP):
             match = expr.match(video['url'])
             if match:
                 file_id = match.group(1)
                 embed_url = self.VIDEO_EMBED_URLS[name].format(file_id)
                 videos.append(models.VideoLink(embed_url, video['title']))
                 break
         else:
             self.log.warning(
                 "URL format '{0}' is not recognized. "
                 "Expected it be a shared link from Vimeo, YouTube, "
                 "or Google Drive.".format(video['url']))
             continue
     return videos
Esempio n. 3
0
 def parse_videos(self):
     videos = []
     meta_videos = self.metadata.get('video_links', [])
     for video in meta_videos:
         if not isinstance(video, dict):
             continue
         if set(video) != {'url', 'title'}:
             continue
         for name, expr in six.iteritems(self.VIDEO_REGEXP):
             match = expr.match(video['url'])
             if match:
                 file_id = match.group(1)
                 embed_url = self.VIDEO_EMBED_URLS[name].format(file_id)
                 videos.append(models.VideoLink(embed_url, video['title']))
                 break
     return videos