basic functionality, no estetics: videos are listed in index; can be watched with...
authorCalin Burloiu <calin.burloiu@gmail.com>
Thu, 21 Jul 2011 08:38:44 +0000 (11:38 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Thu, 21 Jul 2011 08:38:44 +0000 (11:38 +0300)
application/config/p2p-tube.php
application/controllers/catalog.php
application/controllers/video.php
application/models/videos_model.php
application/views/video/ns-html5_plugin_view.php [new file with mode: 0644]
application/views/video/ns-vlc_plugin_view.php [new file with mode: 0644]
application/views/video/watch_view.php
javascript/NextShare_VLC_plugin.js [moved from javascript/NextSharePC-interface.js with 85% similarity]
javascript/default.js [new file with mode: 0644]
javascript/video.js [new file with mode: 0644]
stylesheets/NextShare_VLC_plugin.css [moved from stylesheets/NextSharePC-interface.css with 100% similarity]

index ec7eb3a..6f33bec 100644 (file)
@@ -51,13 +51,14 @@ $config['default_javascript'] = '';
 |
 | Sets the default video file extension, which must be set without '.' prefix. 
 | This extension is going to be added to the `name` field from the DB in
-| order to deduce the video file name if not stated otherwise. Possible values:
+| order to deduce the video file name if not stated otherwise in the format.
+| Possible values:
 |
 |      ogv
 |      ogg
 |
 */
-$config['default_video_ext'] = 'ogg';  // TODO: Change to 'ogv'!
+$config['default_video_ext'] = 'ogv';
 
 /*
 |--------------------------------------------------------------------------
index e748d95..37b1a6c 100644 (file)
@@ -33,11 +33,12 @@ class Catalog extends CI_Controller {
        {
                $this->load->helper('url');
                
-               $format = 'Calin Andrei ';
-               $pos = strpos($format, ' ');
-               if($pos !== FALSE)
-                       $format = substr($format, 0, $pos);     
-               echo $format;
+               echo '<a href="/">link</a>';
+       }
+       
+       public function search($query_str)
+       {
+               echo $query_str;
        }
 }
 
index cb19035..64a1e63 100644 (file)
@@ -24,7 +24,7 @@ class Video extends CI_Controller {
         *
         * @param       string $id      DB id of the video
         * @param       string $name    `name` of the video from DB
-        * @param       string $plugin  video plugin ('vlc', 'html5'). If it's set 
+        * @param       string $plugin  video plugin ('ns-vlc', 'ns-html5'). If it's set 
         * to NULL or 'auto', the plugin is automatically selected.
         */
        public function watch($id, $name = NULL, $plugin = NULL)
@@ -39,8 +39,8 @@ class Video extends CI_Controller {
                // Display page.
                $params = array(        'title' => $data['video']['title'] . ' -- '
                                                                . $this->config->item('site_name'),
-                                                       'stylesheets' => array('jquery-ui.css', 'NextSharePC-interface.css'),
-                                                       'javascripts' => array('jquery.min.js', 'jquery-ui.min.js', 'NextSharePC-interface.js'),
+                                                       'stylesheets' => array('jquery-ui.css', 'NextShare_VLC_plugin.css'),
+                                                       'javascripts' => array('jquery.min.js', 'jquery-ui.min.js', 'NextShare_VLC_plugin.js', 'video.js'),
                                                        //'metas' => array('description'=>'','keywords'=>'')
                                                        );
                $this->load->library('html_head_params', $params);
@@ -52,6 +52,22 @@ class Video extends CI_Controller {
                $this->load->view('footer');
                $this->load->view('html_end');
        }
+       
+       /**
+        * AJAX page which retrieves a video plugin.
+        *
+        * The associated with this controller should be parameter type
+        * concatenated with '_plugin_view' and must be located in
+        * 'application/views/video'.
+        *
+        * @param       string $type    'ns-vlc', 'ns-html5'
+        */
+       public function plugin($type)
+       {
+               $data['url'] = $this->input->post('url', TRUE);
+               
+               $this->load->view('video/'. $type . '_plugin_view', $data);
+       }
 }
 
 /* End of file video.php */
index 59ff7d3..0ae47b1 100644 (file)
@@ -46,7 +46,7 @@ class Videos_model extends CI_Model {
                                $video['id'], $video['name']));
                        
                        // Thumbnails
-                       $video['thumbs'] = $this->getThumbs($video['name'], 
+                       $video['thumbs'] = $this->get_thumbs($video['name'], 
                                $video['thumbs_count']);
                }
                
@@ -97,26 +97,27 @@ class Videos_model extends CI_Model {
                // Convert JSON encoded string to arrays.
                $video['formats'] = json_decode($video['formats'], TRUE);
                $video['tags'] = json_decode($video['tags'], TRUE);
+               asort($video['tags']);
+               $video['tags'] = array_reverse($video['tags'], true);
                
                // Torrents
                $video['torrents'] = array();
                foreach ($video['formats'] as $format)
                {
-                       $pos = strpos($format, ' ');
-                       if($pos !== FALSE)
-                               $format = substr($format, 0, $pos);
+                       $ext = isset($format['ext']) ? 
+                               $format['ext'] : $this->config->item('default_video_ext');
                        $video['torrents'][] = site_url('data/torrents/'. $video['name'] . '_'
-                               . $format . '.'. $this->config->item('default_video_ext')
+                               . $format['def'] . '.'. $ext
                                . '.'. $this->config->item('default_torrent_ext'));
                }
                
                // Thumbnails
-               $video['thumbs'] = $this->getThumbs($video['name'], $video['thumbs_count']);
+               $video['thumbs'] = $this->get_thumbs($video['name'], $video['thumbs_count']);
                
                return $video;
        }
        
-       public function getThumbs($name, $count)
+       public function get_thumbs($name, $count)
        {
                $thumbs = array();
                
diff --git a/application/views/video/ns-html5_plugin_view.php b/application/views/video/ns-html5_plugin_view.php
new file mode 100644 (file)
index 0000000..4275b85
--- /dev/null
@@ -0,0 +1,4 @@
+<video controls="controls" width="800" height="600" preload="auto">
+       <source src="<?php echo $url ?>" type="video/ogg" />
+    Error: Your browser does not support HTML5 or the video format!
+</video>
\ No newline at end of file
diff --git a/application/views/video/ns-vlc_plugin_view.php b/application/views/video/ns-vlc_plugin_view.php
new file mode 100644 (file)
index 0000000..adcd415
--- /dev/null
@@ -0,0 +1,31 @@
+<div id="vlc_container">No VLC</div>
+<table id="nsTable">
+       <tr><td id="nsPlaybackCell"><input type=button value="Play" onClick="play();" />
+       <input type=button value="Pause" onClick="pause();" />
+       <input type=button value="Stop" onclick="stop();" /></td>
+       <td id="nsTimeCell"><span id="nsTime">-</span></td>
+       <td><div id="nsVol"></div></td>
+       <td><input type=button value="Fullscreen" onclick="fullscreen();" /></td></tr>
+       <tr><td colspan="4"><div id="nsSlider"></div></td></tr>
+</table>
+
+<script type="text/javascript">
+       if (navigator.appName == "Netscape")
+       {
+               $('#vlc_container').html(
+                       '<embed type="application/x-ns-stream" name="vlc" id="vlc" autoplay="no" loop="no" width="' + getPluginWidth() + '" height="' + getPluginHeight() + '" target="<?php echo $url ?>" />');
+       }
+       else
+       {
+               $('$vlc_container').html(
+                       '<object classid="clsid:1800B8AF-4E33-43C0-AFC7-894433C13538" codebase="http://trial.p2p-next.org/download/SwarmPlugin_IE_1.0.4.cab" width="' + getPluginWidth() + '" height="' + getPluginHeight() + '" id="vlc" name="vlc" events="True" target="">'
+                       + '<param name="Src" value="<?php echo $url ?>" />'
+                       + '<param name="ShowDisplay" value="True" />'
+                       + '<param name="Loop" value="False" />'
+                       + '<param name="AutoPlay" value="False" />'
+                       + '<param name="Toolbar" value="True" />'
+                       + '</object>');
+       }
+       
+       loadControls();
+</script>
\ No newline at end of file
index d459378..2b01730 100644 (file)
@@ -1,3 +1,5 @@
+<script type="text/javascript">siteUrl = '<?php echo site_url() ?>';</script>
+
 <div id="body">
        <!-- Invalid name in URL-->
        <?php if (isset($video['err'])):
        <!-- Correct URL-->
        <?php else: ?>
                <h1><?php echo $video['title'] ?></h1>
-               <script type="text/javascript"> displayNextSharePC("<?php 
-               //echo $video['torrents'][0];   // VLC
-               echo 'tribe://'. $video['torrents'][0];         // HTML5
-               ?>", true); </script>
-       <?php endif ?>
+               
+               <ul>
+                       <li><a href="javascript: void(0)" onclick="getNsVlcPlugin('<? echo $video['torrents'][0] ?>')">VLC</a></li>
+               
+                       <li><a href="javascript: void(0)" onclick="getNsHtml5Plugin('<?php echo 'tribe://'. $video['torrents'][0] ?>')">HTML5</a></li>
+               </ul>
+               
+               <div id="video_plugin"></div>
+               <!--TODO preload user preferred plugin-->
+               <script type="text/javascript"> getNsHtml5Plugin('<?php echo 'tribe://'. $video['torrents'][0] ?>') </script>
+               
+               <!--TODO user name-->
+               <!--TODO change format controls-->
+               <div id="video_date"><?php echo $video['date'] ?></div>
+               <div id="video_views"><?php echo $video['views'] ?> views</div>
+               <div id="video_likes"><?php echo $video['likes'] ?> likes</div>
+               <div id="video_dislikes"><?php echo $video['dislikes'] ?> dislikes</div>
+               <div id="video_description"><?php echo $video['description'] ?></div>
+               <!-- TODO <div id="video_category">Category: <?php echo $video['category_name'] ?></div>-->
+               <div id="video_tags">Tags:
+               <?php foreach($video['tags'] as $tag => $score): ?>
+                       <a href="<?php site_url('catalog/search/'. $tag) ?>">
+                       <?php echo "$tag($score)" ?>
+                       </a>
+               <?php endforeach ?>
+               <div id="video_license"><?php echo $video['license'] ?></div>
+               
+
+       <?php endif // if (isset($video['err'])): ?>
 </div>
\ No newline at end of file
similarity index 85%
rename from javascript/NextSharePC-interface.js
rename to javascript/NextShare_VLC_plugin.js
index 9db050b..dffb2cd 100644 (file)
@@ -1,4 +1,4 @@
-// NextSharePC plugin controls\r
+// NextSharePC plugin controls\r
 // Author: Calin-Andrei Burloiu, calin.burloiu@gmail.com\r
 // 2011\r
 \r
@@ -16,6 +16,17 @@ function getURLParam( name )
                return results[1];\r
 }\r
 \r
+function pad(number, length) \r
+{\r
+       var str = '' + number;\r
+       while (str.length < length) \r
+       {\r
+               str = '0' + str;\r
+       }\r
+\r
+       return str;\r
+}\r
+\r
 function getPluginWidth()\r
 {\r
        return 800;\r
@@ -68,19 +79,11 @@ function update()
        timerHandle = setTimeout("update()", updateInterval);\r
 }\r
 \r
-function displayNextSharePC(torrent, html5)\r
+function displayNextSharePC(torrent)\r
 {\r
-       if(html5 == true)\r
-       {\r
-               document.write('<video src="'+torrent+'" controls="controls" width="800" height="600">');\r
-               document.write('    Error: Your browser does not support HTML5!');\r
-               document.write('</video>');\r
-               document.write('<br /><br /><p><a href="' + window.location.href.replace('&html5=1', '') + '">');\r
-               document.write('Play video using VLC with NextSharePC</a></p>');\r
-\r
-               return true;\r
-       }\r
-\r
+       //document.write('popârțac');\r
+       //return;\r
+       \r
        if (navigator.appName == "Netscape")\r
        {\r
                document.write('<embed type="application/x-ns-stream"');\r
@@ -123,11 +126,6 @@ function displayNextSharePC(torrent, html5)
                + '<td><input type=button value="Fullscreen" onclick="fullscreen();" /></td></tr>'\r
                + '<tr><td colspan="4"><div id="nsSlider"></div></td></tr>'\r
                + '</table>');\r
-               \r
-       $("nsTable").css("width", getPluginWidth());\r
-\r
-       document.write('<br /><p><a href="' + window.location.href + '&html5=1">');\r
-       document.write('Play video using HTML5 with SwarmPlayer</a></p>');\r
 \r
        return true;\r
 }\r
@@ -155,17 +153,6 @@ function onSliderStop(event, ui)
        timerHandle = setTimeout("update()", updateInterval);\r
 }\r
 \r
-function pad(number, length) \r
-{\r
-       var str = '' + number;\r
-       while (str.length < length) \r
-       {\r
-               str = '0' + str;\r
-       }\r
-\r
-       return str;\r
-}\r
-\r
 function onSliderSlide(event, ui)\r
 {\r
        updateTime(true);\r
@@ -180,11 +167,13 @@ function onVolChange(event, ui)
        document.vlc.audio.volume = val;\r
 }\r
 \r
-$(document).ready(function() \r
+function loadControls()\r
 {\r
        if(document.vlc == null)\r
                return;\r
        \r
+       $("nsTable").css("width", getPluginWidth());\r
+       \r
        // Progress Slider\r
        $("#nsSlider").slider({ animate: true });\r
        $("#nsSlider").slider({ min: 0 });\r
@@ -208,7 +197,7 @@ $(document).ready(function()
        $("#nsVol").slider();\r
        \r
        timerHandle = setTimeout("update()", updateInterval);\r
-});  \r
+}\r
 \r
 function play()\r
 {\r
diff --git a/javascript/default.js b/javascript/default.js
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/javascript/video.js b/javascript/video.js
new file mode 100644 (file)
index 0000000..284e7ee
--- /dev/null
@@ -0,0 +1,24 @@
+// Usually replaced in PHP
+siteUrl = '/';
+
+function getNsVlcPlugin(videoUrl)
+{
+       $.post(
+               siteUrl + 'video/plugin/ns-vlc',
+               {url: videoUrl},
+               function(data) {
+                       $('#video_plugin').html(data);
+               }
+       );
+}
+
+function getNsHtml5Plugin(videoUrl)
+{
+       $.post(
+               siteUrl + 'video/plugin/ns-html5',
+               {url: videoUrl},
+               function(data) {
+                       $('#video_plugin').html(data);
+               }
+       );
+}
\ No newline at end of file