Backends

exception embed_video.backends.EmbedVideoException[source]

Parental class for all embed_video exceptions

class embed_video.backends.SoundCloudBackend(url)[source]

Backend for SoundCloud URLs.

height
Return type:str
width
Return type:str
exception embed_video.backends.UnknownBackendException[source]

Exception thrown if video backend is not recognized.

exception embed_video.backends.UnknownIdException[source]

Exception thrown if backend is detected, but video ID cannot be parsed.

class embed_video.backends.VideoBackend(url)[source]

Base class used as parental class for backends.

Backend variables:

url URL of video.
code Code of video.
thumbnail URL of video thumbnail.
query String transformed to QueryDict appended to url.
info Additional information about video.
is_secure Decides if secured protocol (HTTPS) is used.
protocol Protocol used to generate URL.
template_name Name of embed code template used by get_embed_code().
class MyBackend(VideoBackend):
    ...
allow_https = True

Sets if HTTPS version allowed for specific backend.

Type:bool
code

Code of video.

default_query = ''

Default query string or QueryDict appended to url

Type:str
get_code()[source]

Returns video code matched from given url by re_code.

Return type:str
get_embed_code(width, height)[source]

Returns embed code rendered from template template_name.

Return type:str
get_info()[source]
Return type:dict
get_thumbnail_url()[source]

Returns thumbnail URL folded from pattern_thumbnail_url and parsed code.

Return type:str
get_url()[source]

Returns URL folded from pattern_url and parsed code.

info

Additional information about video. Not implemented in all backends.

is_secure = False

Decides if secured protocol (HTTPS) is used.

Type:bool
classmethod is_valid(url)[source]

Class method to control if passed url is valid for current backend. By default it is done by re_detect regex.

pattern_thumbnail_url = None

Pattern in which the code is inserted to get thumbnail url.

Example: http://static.myvideo.com/thumbs/%s

Type:str
pattern_url = None

Pattern in which the code is inserted.

Example: http://myvideo.com?code=%s

Type:str
protocol

Protocol used to generate URL.

query

String transformed to QueryDict appended to url.

re_code = None

Compiled regex (re.compile()) to search code in URL.

Example: re.compile(r'myvideo\.com/\?code=(?P<code>\w+)')

re_detect = None

Compilede regec (re.compile()) to detect, if input URL is valid for current backend.

Example: re.compile(r'^http://myvideo\.com/.*')

set_options(options)[source]
template_name = 'embed_video/embed_code.html'

Name of embed code template used by get_embed_code().

Passed template variables: {{ backend }} (instance of VideoBackend), {{ width }}, {{ height }}

Type:str
thumbnail

URL of video thumbnail.

url

URL of video.

exception embed_video.backends.VideoDoesntExistException[source]

Exception thrown if video doesn’t exist

class embed_video.backends.VimeoBackend(url)[source]

Backend for Vimeo URLs.

class embed_video.backends.YoutubeBackend(url)[source]

Backend for YouTube URLs.

get_thumbnail_url()[source]

Returns thumbnail URL folded from pattern_thumbnail_url and parsed code.

Return type:str
embed_video.backends.detect_backend(url)[source]

Detect the right backend for given URL.

Goes over backends in settings.EMBED_VIDEO_BACKENDS, calls is_valid() and returns backend instance.

Parameters:url (str) – URL which is passed to is_valid methods of VideoBackends.
Returns:Returns recognized VideoBackend
Return type:VideoBackend