def test_registration(self): class TestParser(BaseParser): pass parser_pool.register_parser(TestParser) self.assertIsInstance(parser_pool.get_parser('TestParser'), TestParser)
def test_registration(self): class TestParser(BaseParser): pass parser_pool.register_parser(TestParser) self.assertIsInstance(parser_pool.get_parser('TestParser'), TestParser)
return u"http://img.youtube.com/vi/%s/default.jpg" % self.video_id def get_image_file(self): resp = urllib2.urlopen("http://img.youtube.com/vi/%s/hqdefault.jpg" % self.video_id) assert resp.headers["Content-Type"] == "image/jpeg" return ("hqdefault.jpg", ContentFile(resp.read())) def get_video_markup(self, width, height): markup = """<iframe class="youtube-player" type="text/html" width="%d" height="%d" src="http://www.youtube.com/embed/%s" frameborder="0"> </iframe>""" % ( width, height, self.video_id, ) return mark_safe(markup) class YoutubeParser(RegexParser): parseable_tags = {"a": ["href"], "iframe": ["src"], "param": ["movie"], "embed": ["src"]} attribute_regex = re.compile( r'(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})' ) descriptor_class = YoutubeVideoDescriptor parser_pool.register_parser(YoutubeParser)
assert(resp.headers['Content-Type'] in ('image/jpeg', 'application/octet-stream')) return ('vimeo_thumbnail.jpg', ContentFile(resp.read())) def get_video_markup(self, width, height): markup = """<iframe src="http://player.vimeo.com/video/%s?title=0&byline=0&portrait=0&color=136485" width="%d" height="%d" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen> </iframe>""" % (self.video_id, width, height ) return mark_safe(markup) class VimeoParser(RegexParser): parseable_tags = {'a':['href'],'iframe': ['src']} attribute_regex = re.compile(r"""(?:[\w]+\.)* # Optional subdomains vimeo\.com # Match vimeo.com (?:[\/\w]*\/videos?)? # Optional video sub directory this handles groups links also \/ # Slash before Id ([0-9]+) # $1: VIDEO_ID is numeric""", re.VERBOSE) descriptor_class = VimeoVideoDescriptor parser_pool.register_parser(VimeoParser)