* * all columns form DB with some exceptions that are overwritten or new
* * formats content is moved in assets
* * assets => list of associative lists where each one represents a
- * video asset having keys: "src", "def" and "ext". Value of key "src" is
- * the video torrent formated as
- * {name}_{format}.{default_video_ext}.{default_torrent_ext}
+ * video asset having keys: "src", "res", "par" and "ext". Value of key
+ * "src" is the video torrent formated as
+ * {name}_{format}.{video_ext}.{default_torrent_ext}
* * user_name => TODO: user name from `users` table
* * category_title => a human-friendly category name
* * tags => associative list of "tag => score"
unset($video['formats']);
$video['tags'] = json_decode($video['tags'], TRUE);
asort($video['tags']);
- $video['tags'] = array_reverse($video['tags'], true);
+ $video['tags'] = array_reverse($video['tags'], TRUE);
// Torrents
$video['url'] = array();
foreach ($video['assets'] as & $asset)
{
- $ext = isset($asset['ext']) ?
- $asset['ext'] : $this->config->item('default_video_ext');
+ $def = substr($asset['res'], strpos($asset['res'], 'x') + 1) . 'p';
$asset['src'] = site_url('data/torrents/'. $video['name'] . '_'
- . $asset['def'] . '.'. $ext
+ . $def . '.'. $asset['ext']
. '.'. $this->config->item('default_torrent_ext'));
}
});
// Switch video plugin facilities
- $('#video-widget-tabs').tabs(); /*{
- ajaxOptions: {
- type: "POST",
- data: { url: "<?php //echo $video['url'][0] ?>" },
- error: function(xhr, status, index, anchor) {
- $(anchor.hash).html('Could not load the video plugin.');
- }
- }
- });*/
+ $('#video-widget-tabs').tabs();
$('#switch-to-ns-html5')
.click(function() {
$('#video-widget')
$('#video-widget')
.nsvideo('type', 'ns-vlc');
});
-
+
// Video widget
- $('#video-widget').nsvideo({
- type: "<?php echo $plugin_type ?>",
- definition:
- "<?php echo $video['assets'][ $asset_index ]['def'] ?>",
- src: {
- <?php
- for ($i=0; $i < count($video['assets']); $i++)
- {
- $asset = $video['assets'][$i];
- echo '"'. $asset['def'] . '": ';
- echo '"'. $asset['src'] . '"';
- echo ($i == count($video['assets']) - 1) ? '' : ', ';
- }
- ?>
- }
- });
+ $('#video-widget')
+ .nsvideo({
+ type: "<?php echo $plugin_type ?>",
+ src: <?php echo json_encode($video['assets']) ?>,
+ //width: videoWidth,
+ //height: videoHeight
+ minWidth: 1200,
+ maxWidth: 1400
+ })
+ .resize(function(e) {
+ $('#video-widget-tabs')
+ .css('width', $('#video-widget').css('width'));
+ console.log($('#video-widget').css('width'));
+ });
+
+ $('#video-widget-tabs')
+ .css('width', $('#video-widget').css('width'));
});
</script>
\ No newline at end of file
version: "1.0.0 beta",
options: {
type: 'ns-html5',
- width: 320,
- height: 240,
+ srcIndex: 0,
+ width: 0,
+ height: 0,
+ minWidth: 0,
+ maxWidth: 0,
showStatus: true,
refreshInterval: 0.1, // seconds
autoplay: false
widget.videoPlugin('fullscreen');
});
- // Video definition buttonset
+ // Video format buttonset
if (typeof widget.options.src == 'object')
{
- var $definitions = $('<form><div class="ui-nsvideo-definitions ui-nsvideo-control-right"></div></form>')
+ var $formats = $('<form><div class="ui-nsvideo-formats ui-nsvideo-control-right"></div></form>')
.appendTo(widget.$controls);
- $definitions = $('.ui-nsvideo-definitions', $definitions[0]);
+ $formats = $('.ui-nsvideo-formats', $formats[0]);
$.each(widget.options.src, function(index, value) {
- id = widget.element.attr('id') + '-def-' + index;
- $('<input type="radio" id="' + id + '" name="definition" />')
- .appendTo($definitions)
- .attr('checked', (index == widget.options.definition))
+ id = widget.element.attr('id') + '-format-' + index;
+ definition = value.res.substring(value.res.indexOf('x')+1)+'p';
+ $('<input type="radio" id="' + id + '" name="format" />')
+ .appendTo($formats)
+ .attr('checked', (index == widget.options.srcIndex))
.click(function() {
widget.videoPlugin('pause');
- widget.definition(index);
+ widget.srcIndex(index);
});
- $('<label for="' + id + '">' + index + '</label>')
- .appendTo($definitions);
+ $('<label for="' + id + '">' + definition + '</label>')
+ .appendTo($formats);
});
- $definitions.buttonset();
+ $formats.buttonset();
}
// Volume
// Initialize video plugin
widget.$video.ready(function() {
- widget.videoPlugin('init');
+ //widget.videoPlugin('init');
});
},
// Select video source.
// If src option is string, that's the source.
- // If src is an object, properties are definitions and values are
- // sources.
+ // If src is an object, there is a list of associative arrays, each
+ // one having the mandatory keys "src" and "res" (resolution).
var src = widget.crtSrc();
if (src == null)
return widget;
widget.$video.css('position', 'relative');
+ // Adjust video size for auto-resizing within ranges minWidth and
+ // maxWidth.
+ if (widget.options.minWidth != 0 && widget.options.maxWidth != 0
+ && typeof widget.options.src == 'object'
+ && (typeof widget.options.src[ widget.options.srcIndex ].res)
+ != 'undefined'
+ && (typeof widget.options.src[ widget.options.srcIndex ].dar)
+ != 'undefined')
+ {
+ var resolution = widget.options.src[ widget.options.srcIndex ].res;
+ var dar = widget.options.src[ widget.options.srcIndex ].dar;
+ var darL = parseInt(
+ dar.substring(0, dar.indexOf(':')));
+ var darR = parseInt(
+ dar.substring(dar.indexOf(':') + 1));
+ var videoHeight = parseInt(
+ resolution.substring(resolution.indexOf('x') + 1));
+ var videoWidth = Math.round(videoHeight * darL / darR);
+ // Video width must be between minWidth and maxWidth pixels.
+ if (videoWidth > widget.options.maxWidth)
+ {
+ videoHeight = Math.round(widget.options.maxWidth / videoWidth
+ * videoHeight);
+ videoWidth = widget.options.maxWidth;
+ }
+ else if (videoWidth < widget.options.minWidth)
+ {
+ videoHeight = Math.round(widget.options.minWidth / videoWidth
+ * videoHeight);
+ videoWidth = widget.options.minWidth;
+ }
+ console.log(videoWidth + ' ' + videoHeight);
+ widget.$video.css('width', videoWidth);
+ widget.$video.css('height', videoHeight);
+ }
+
widget._setWidgetWidth();
},
+ 'px');
}
else
+ {
widget.element.css('width',
- widget.$video.width + 8 + 'px');
+ widget.$video.width() + 8 + 'px');
+ widget.$video.css('left', '0');
+ }
},
setPlayButton: function() {
return null;
},
- definition: function(def) {
+ srcIndex: function(srcIndex) {
var widget = this;
- if (typeof def == 'undefined')
- return widget.options.definition;
+ if (typeof srcIndex == 'undefined')
+ return widget.options.srcIndex;
+
+ widget.options.srcIndex = srcIndex;
- widget.options.definition = def;
+ // Refresh.
widget.video();
return widget;
src = widget.options.src;
else if (typeof widget.options.src == 'object')
{
- if (typeof widget.options.definition == 'undefined')
+ if (typeof widget.options.srcIndex == 'undefined')
return null;
- if (typeof widget.options.src[ widget.options.definition ]
+ if (typeof widget.options.src[ widget.options.srcIndex ].src
== 'undefined')
return null;
- src = widget.options.src[ widget.options.definition ];
+ src = widget.options.src[ widget.options.srcIndex ].src;
}
if (widget.options.type == 'ns-html5')