# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import re from djvideo.embed import EmbedGenerator, registry class Mp3FileEmbedGenerator(EmbedGenerator): """ Mp3FileEmbedGenerator handles urls ending with '.mp3' """ template = 'djvideo/files/mp3.html' supported_parameters = frozenset( ('title', 'width', 'height', 'autoplay', 'mime_type', 'poster')) def handles_video_url(self, url): "Returns True if the url ends in `.mp3`." return True if re.match(r'.*\.mp3', url) else False registry.register(Mp3FileEmbedGenerator)
class KalturaEmbedGenerator(EmbedGenerator): path_re = re.compile(r'^https?://cdnsecakmi.kaltura.com/p/' r'(?P<partner_id>[\d]+)/sp/(?P<subp_id>[\d]+)' r'/flvclipper/entry_id/(?P<entry_id>[\w]+)/' r'version/0(?:/ext/flv)?') template = 'djvideo/kaltura.html' default_context = {'width': 459, 'height': 344} def get_url_data(self, url): match = self.path_re.match(url) if match: return match.groupdict() raise UnhandledVideo(url) def get_context(self, url, context): c = super(KalturaEmbedGenerator, self).get_context(url, context) c.update(self.get_url_data(url)) return c def handles_video_url(self, url): try: self.get_url_data(url) except UnhandledVideo: return False return True registry.register(KalturaEmbedGenerator)
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from bs4 import BeautifulSoup from vidscraper.suites.blip import Suite from djvideo.embed import EmbedGenerator, registry class BlipEmbedGenerator(EmbedGenerator): suite = Suite() template = 'djvideo/blip.html' supported_parameters = frozenset() default_context = {'width': 550, 'height': 443} def get_context(self, url, context): c = super(BlipEmbedGenerator, self).get_context(url, context) embed_code = context['current_video'].embed_code soup = BeautifulSoup(embed_code) try: video_id = soup.embed['src'].rsplit("#", 1)[1] except (KeyError, TypeError, AttributeError, IndexError): video_id = '' c['video_id'] = video_id return c def handles_video_url(self, url): return self.suite.handles_video(url) registry.register(BlipEmbedGenerator)
from vidscraper.suites.youtube import PathMixin from djvideo.embed import EmbedGenerator, registry class YouTubeEmbedGenerator(PathMixin, EmbedGenerator): template = 'djvideo/youtube.html' # supported arguments listed at # https://developers.google.com/youtube/player_parameters#Parameters supported_parameters = frozenset( ('autohide', 'autoplay', 'cc_load_policy', 'color', 'controls', 'disablekb', 'enablejsapi', 'fs', 'iv_load_policy', 'list', 'listType', 'loop', 'modestbranding', 'origin', 'playerapiid', 'playlist', 'rel', 'showinfo', 'start', 'theme')) default_context = {'width': 459, 'height': 344} def get_context(self, url, context): c = super(YouTubeEmbedGenerator, self).get_context(url, context) c.update(self.get_url_data(url)) return c def handles_video_url(self, url): try: self.get_url_data(url) except UnhandledVideo: return False return True registry.register(YouTubeEmbedGenerator)
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import re from djvideo.embed import EmbedGenerator, registry class Mp3FileEmbedGenerator(EmbedGenerator): """ Mp3FileEmbedGenerator handles urls ending with '.mp3' """ template = 'djvideo/files/mp3.html' supported_parameters = frozenset(('title', 'width', 'height', 'autoplay', 'mime_type', 'poster')) def handles_video_url(self, url): "Returns True if the url ends in `.mp3`." return True if re.match(r'.*\.mp3', url) else False registry.register(Mp3FileEmbedGenerator)
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from vidscraper.exceptions import UnhandledVideo from vidscraper.suites.vimeo import PathMixin from djvideo.embed import EmbedGenerator, registry class VimeoEmbedGenerator(PathMixin, EmbedGenerator): template = 'djvideo/vimeo.html' # supported arguments generated w/ trial/error from # http://vimeo.com/21770650 supported_parameters = frozenset(( 'autoplay', 'byline', 'color', 'loop', 'portrait', 'title')) default_context = {'width': 400, 'height': 225} def get_context(self, url, context): c = super(VimeoEmbedGenerator, self).get_context(url, context) c.update(self.get_url_data(url)) return c def handles_video_url(self, url): try: self.get_url_data(url) except UnhandledVideo: return False return True registry.register(VimeoEmbedGenerator)
from vidscraper.suites.youtube import PathMixin from djvideo.embed import EmbedGenerator, registry class YouTubeEmbedGenerator(PathMixin, EmbedGenerator): template = 'djvideo/youtube.html' # supported arguments listed at # https://developers.google.com/youtube/player_parameters#Parameters supported_parameters = frozenset(( 'autohide', 'autoplay', 'cc_load_policy', 'color', 'controls', 'disablekb', 'enablejsapi', 'fs', 'iv_load_policy', 'list', 'listType', 'loop', 'modestbranding', 'origin', 'playerapiid', 'playlist', 'rel', 'showinfo', 'start', 'theme')) default_context = {'width': 459, 'height': 344} def get_context(self, url, context): c = super(YouTubeEmbedGenerator, self).get_context(url, context) c.update(self.get_url_data(url)) return c def handles_video_url(self, url): try: self.get_url_data(url) except UnhandledVideo: return False return True registry.register(YouTubeEmbedGenerator)
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from vidscraper.exceptions import UnhandledVideo from vidscraper.suites.vimeo import PathMixin from djvideo.embed import EmbedGenerator, registry class VimeoEmbedGenerator(PathMixin, EmbedGenerator): template = 'djvideo/vimeo.html' # supported arguments generated w/ trial/error from # http://vimeo.com/21770650 supported_parameters = frozenset( ('autoplay', 'byline', 'color', 'loop', 'portrait', 'title')) default_context = {'width': 400, 'height': 225} def get_context(self, url, context): c = super(VimeoEmbedGenerator, self).get_context(url, context) c.update(self.get_url_data(url)) return c def handles_video_url(self, url): try: self.get_url_data(url) except UnhandledVideo: return False return True registry.register(VimeoEmbedGenerator)