Media Preview

Media Preview plugins can be used to change the behavior of matching which browser will match to which preview version

IMediaPreviewList

class portal.generic.plugin_interfaces.IMediaPreviewList

Return a list of dictionaries that contain strings that can be matched to help display different templates for helping to preview different media.

Requires:
  • __call__(media_type_support_list, incoming_request):

Args:
  • media_type_support_list - list of dictionaries

  • incoming_request - a dictionary with the current browser

  • media_type - the type of item requested

Returns:
  • media_type_support_list - list of dictionaries

A typical media_type_support_list might look like this:

media_type_support_list = [
    {'media_type':'image',  'template':'media/previews/image.html'},
    {'media_type':'video',  'template':'media/previews/video.html'},
    {'media_type':'audio',  'template':'media/previews/audio.html'},
    {'media_type':'data',   'template':'media/previews/data.html'}
]

Though you can list more details on to which we will search for the closest match to the current string coming in. An example of the formatting of an incoming request:

{
 'media_type':'image',
 'flavor': {'version': 'X 10.7.0', 'name': 'MacOS'},
 'os': {'name': 'Macintosh'}, 
 'browser': {'version': '12.0.742.122','name': 'Chrome'}
}

So you could match it by returning:

media_type_support_list = [
    {'media_type':'image',  'template':'media/previews/image.html'},
    {'media_type':'video',  'template':'media/previews/video.html'},
    {'media_type':'audio',  'template':'media/previews/audio.html'},
    {'media_type':'data',   'template':'media/previews/data.html'}
    {'media_type':'image', 'flavor':{'name':'MacOS'}, 'browser':{'name':'Chrome'},             'template':'media/previews/myimagetemplate.html'}
]

Which will cause the system to return “myimagetemplate.html” if that best matches the incoming request.

Player chooser

Media preview

Functions around the player, so that we can test what file is being called and what content will be needed.

  1. Detect what browser this is.

  2. Detect what type of item is being called up.

  3. Compile a list of types.

  4. Make sure that this can be overriden with plugins

  5. Work out which is the closest match to the incoming browser and .

Match -

OS, Browser, Number, Item Type, Item Formats.

portal.utils.player.browser_to_preview_template(HTTP_USER_AGENT_STRING, media_type)

Detect which browser it is and get the type, and return a dict of dicts like:

{'flavor': {'version': 'X 10.7.0', 'name': 'MacOS'},
 'os': {'name': 'Macintosh'},  'browser': {'version': '12.0.742.122',
 'name': 'Chrome'}}

Should match to a similiar structure like this:

[
{'media_type':'image','flavor': {'version': 'X 10.7.0',
 'name': 'MacOS'}, 'os': {'name': 'Macintosh'},
 'browser': {'version': '12.0.742.122', 'name': 'Chrome'},
 'template':'foobar.html'}, {'media_type':'video',
 'flavor': {'version': 'X 10.7.0', 'name': 'MacOS'},
 'os': {'name': 'Macintosh'}, 'browser': {'version': '12.0.742.122',
 'name': 'Chrome'}, 'template':'foof.html'},
{'media_type':'video',
 'flavor': {'version': 'X 10.6.8', 'name': 'MacOS'},
 'os': {'name': 'Macintosh'},
 'browser': {'version': '5', 'name': 'Firefox'},
 'template':'foo.html'},
]

We detect firstly based on media_type, then we try and do a best match over all the list items. Plugin interface IMediaPreviewList is available to add new media types.

portal.utils.player.sort_on_score(media_type_qualified_list, _browser)

Sort through the list depending the score that we have here return the best match.

>>> _list = [{'media_type':'image', 'template':'foobar.html'},
             {'media_type':'video', 'template':'foof.html'},
             {'media_type':'video', 'flavor': {'version': 'X 10.7.0',
              'name': 'MacOS'}, 'template':'1.html'},
             {'media_type':'video', 'flavor': {'version': 'X 10.7.0',
              'name': 'Windows'}, 'template':'2.html'},
             {'media_type':'audio',  'template':'foo.html'},
             {'media_type':'data', 'template':'foo.html'}]
>>> _browser = {'flavor': {'version': 'X 10.7.0', 'name': 'MacOS'},
                'os': {'name': 'Macintosh'},
                'browser': {'version': '12.0.742.122',
                'name': 'Chrome'}}
>>> sort_on_score(_list,_browser)
1.html