This is a Snippet for MODX Evolution.
Bliptv Snippet is able to resize blip.tv videos and get any information from the embedded video: title, description, thumbnail, author, category, timestamp, etc.
Snippet developed by: Lorenzo Stanco.
1. Installation
To install Bliptv, go to "Elements > Manage Elements >
Snippets > New Snippet" and fill in the fields as follows:
Snippet Name: bliptv
Snippet Description: Resize video and get info from embed Blip.tv video
Snippet code (php):
<?php
/**
* Snippet Name: bliptv
* Short Desc: Resize video and get info from embed Blip.tv video
* Author: Lorenzo Stanco <www.lorenzostanco.com>
* Version: 0.0.5
* Last Edited: 25-09-2011
*/
// ---------------------------------------------------
// Config
// ---------------------------------------------------
// $type: [string] What to get. Can be one of:
// - 'video': video embedding
// - 'url': video thumbnail URL
// - 'thumb': video thumbnail URL
// - 'thumbnail120Url': video thumbnail URL 120
// - 'title': video title
// - 'description': video description
// - 'showName': show name (tv show)
// - 'category': video category
// - 'datestamp'
// - 'datestampUnixtime'
// - 'datestampDate'
// - 'datestampText'
// - 'postsId'
// - 'mediaUrl'
// $tvname: [string] Blip.tv share code
// $width: [int] width dimension in pixel for video embedding
// $height: [int] height dimension in pixel for video embedding
//
// [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`video` &width=`500` &height=`400`]]
// [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`url`]]
// [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`thumb`]]
// [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`thumbnail120Url`]]
// [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`title`]]
//-----------------------------------------------------
$video = str_replace(
array('##w#', '##e#', '##a#'),
array('?' , '=', '&' ),
$tvname
);
// Chiedo il player?
if ($type == 'video') {
// Ho già l'embed, cambio solo i parametri di dimensione
if (!empty($width) && !empty($height)) {
$pattern_w = '/ width=["]?([0-9]+)["]?/i';
$pattern_h = '/ height=["]?([0-9]+)["]?/i';
$video = preg_replace($pattern_w, ' width="'.intval($width).'"', $video);
$video = preg_replace($pattern_h, ' height="'.intval($height).'"', $video);
}
// Aggiungo wmode=transparent
$video = str_replace('<embed ', '<embed wmode="transparent" ', $video);
return $video;
}
// Chiedo dati JSON?
if ($type != 'video') {
// Se chiedo "url", chiedo in realtà la thumb
if ($type == 'url') $type = 'thumb';
if ($type == 'thumb') $type = 'thumbnailUrl';
// Prendo l'ID del video
$id = null;
$pattern = '/^<embed.*"http.*?\\/play\\/(.*?)"/i';
$target_share_code = trim($video);
if (preg_match($pattern, $target_share_code, $id)) {
$id = $id[1];
} else {
return 'Blip.tv error.';
}
// Chiedo tutti i dati in formato JSON
$json_url = 'http://blip.tv/player/episode/' . $id . '?skin=json&no_wrap=1&version=2';
$json = @file_get_contents($json_url);
if (!$json) return 'Blip.tv error.';
$json = json_decode($json);
$json = $json->Post;
// Ritorno quello che serve
return $json->{$type};
}
return 'Blip.tv error.';
?>
Now we have to install a PHx Extender:
Snippet Name: phx:escapemodx
Snippet Description: Escape special embed characters
Snippet code (php):
<?php
return str_replace(
array('?' , '=', '&' ),
array('##w#', '##e#', '##a#'),
$output
);
?>
2. Parameter &type=`video`
You can use the parameter in this way:
1) Create a Textarea TV and assign it to your Template.
2) Open a Resource and insert the Blip.tv embedded code in the Textarea TV.
3) Add the Bliptv Snippet Call on your Template:
[[bliptv? &tvname=`[*video01:escapemodx*]` &type=`video` &width=`500` &height=`400`]]
3. Parameters (others)
With this snippet, you can also get other video information, for example the thumbnail, the title, the description, the category, the timestamp, etc. Here are some examples:
[[bliptv? &tvname=`[*video01:escapemodx*]` &type=`url`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`thumb`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`thumbnail120url`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`title`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`description`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`showName`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`category`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`datestamp`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`datestampUnixtime`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`datestampDate`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`datestampText`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`postsId`]] [[bliptv? &tvname=`[*video01:escapemodx*]` &type=`mediaUrl`]]
Note: some of these parameteres may not work because sometimes Blip.tv updates the API.

