Creating a Media Provider: A Vimeo Provider =========================================== A provider class solves a simple use case: the management of a very specific type of media. A youtube video and an image file are two very different types of media and each cannot be managed by a single class. In the ``MediaBundle``, each is represented by two provider classes: ``YoutubeProvider`` and ``ImageProvider``. A provider class is responsible for handling common things related to a media asset: * thumbnails * path * editing the media with a form * storing the media information (metadata) A provider class is always linked to a ``Filesystem`` and a ``CDN``. The filesystem abstraction uses the ``Gaufrette`` library. For now there is only 2 abstracted filesystem available: ``Local`` and ``FTP``. The ``CDN`` is used to generated the media asset public URL. By default the filesystem and the CDN use the local filesystem and the current server for the CDN. In other words, when you create a provider, you don't need to worry about how media assets are going to be store on the filesystem. Media Entity ------------ The ``Media`` entity comes with common media fields: ``size``, ``length``, ``width`` and ``height``. However the provider might require you to add more information. As it is not possible to store all of the possible information into database columns, the provider class can use the ``provider_metadata`` field to store metadata as a serialized array. The ``Media`` entity has 3 other provider fields: * ``provider_name``: the service name linked to the media * ``provider_status``: the media status * ``provider_reference``: the internal provider reference (the video sig for instance) Case Study ---------- Before starting, we need to collect information about some asset on vimeo. Take this video, for example: * video identifier format: 21216091 * video player documentation: https://developer.vimeo.com/player/sdk .. code-block:: json { "type":"video", "version":"1.0", "provider_name":"Vimeo", "provider_url":"http:\/\/vimeo.com\/", "title":"Blinky", "author_name":"Ruairi Robinson", "author_url":"http:\/\/vimeo.com\/ruairirobinson", "is_plus":"1", "html":" .. tip:: You should test the provider class. There are many examples in the ``tests`` folder. The source code is available in the class ``Sonata\MediaBundle\Provider\VimeoProvider``.