category page made, but without pagination
authorCalin Burloiu <calin.burloiu@gmail.com>
Mon, 25 Jul 2011 15:03:42 +0000 (18:03 +0300)
committerCalin Burloiu <calin.burloiu@gmail.com>
Mon, 25 Jul 2011 15:03:42 +0000 (18:03 +0300)
.htaccess
application/config/p2p-tube.php
application/config/routes.php
application/controllers/catalog.php
application/models/videos_model.php
application/views/catalog/category_view.php [new file with mode: 0644]
application/views/video/watch_view.php
img/thumb_container.png [new file with mode: 0644]
scripts/auto-publishing/publish_videos.py
stylesheets/catalog.css [new file with mode: 0644]
stylesheets/default.css [new file with mode: 0644]

index 284794a..d9fdd6a 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -20,5 +20,5 @@
 </Files>
 
 RewriteEngine on
-RewriteCond $1 !^(index\.php|images|stylesheets|javascript|data|robots\.txt)
+RewriteCond $1 !^(index\.php|img|stylesheets|javascript|data|robots\.txt)
 RewriteRule ^(.*)$ index.php/$1 [L]
index 6f33bec..b17610a 100644 (file)
@@ -75,3 +75,14 @@ $config['default_video_ext'] = 'ogv';
 */
 $config['default_torrent_ext'] = 'tstream';
 
+/*
+|--------------------------------------------------------------------------
+| Categories
+|--------------------------------------------------------------------------
+|
+| An associative list with the video categories of the site. IDs are used
+| in DB (for example in `videos` table), and value are human-friendly names
+| for categories. IDs must be numeric and must preferably start from 1.
+|
+*/
+$config['categories'] = array(1 => 'Movies', 2 => 'TechTalks', 3 => 'Events', 4 => 'Karaoke');
index 36fc124..4397b79 100644 (file)
@@ -41,6 +41,9 @@
 $route['default_controller'] = "catalog";
 $route['404_override'] = '';
 
+$route['watch/([\d]+)/?'] = "video/watch/$1";
+$route['watch/([\d]+)/(.+)'] = "video/watch/$1/$2";
+
 
 /* End of file routes.php */
 /* Location: ./application/config/routes.php */
\ No newline at end of file
index 37b1a6c..e6d2c0d 100644 (file)
@@ -36,6 +36,30 @@ class Catalog extends CI_Controller {
                echo '<a href="/">link</a>';
        }
        
+       public function category($category_id)
+       {
+               // Retrieve videos summary.
+               $this->load->model('videos_model');
+               $data['videos'] = $this->videos_model->get_videos_summary($category_id);
+               $categories = $this->config->item('categories');
+               $data['category'] = $categories[$category_id];
+               $data['category_id'] = $category_id;
+               
+               $params = array(        'title' => $this->config->item('site_name'),
+                                                       'stylesheets' => array('catalog.css'),
+                                                       //'javascripts' => array(),
+                                                       //'metas' => array('description'=>'','keywords'=>'')
+                                                       );
+               $this->load->library('html_head_params', $params);
+               $this->load->view('html_begin', $this->html_head_params);
+               $this->load->view('header');
+               
+               $this->load->view('catalog/category_view', $data);
+               
+               $this->load->view('footer');
+               $this->load->view('html_end');
+       }
+       
        public function search($query_str)
        {
                echo $query_str;
index f42eb74..223def7 100644 (file)
@@ -15,9 +15,9 @@ class Videos_model extends CI_Model {
                {
                        $this->load->library('singleton_db');
                        $this->db = $this->singleton_db->connect();
-                       
-                       $this->load->helper('url');
                }
+               
+               $this->load->helper('url');
        }
        
        /**
@@ -27,28 +27,37 @@ class Videos_model extends CI_Model {
         * TODO: filter, limit, ordering parameters
         * @return              array   a list of videos, each one being an assoc array with:
         *   * id, name, title, duration, thumbs_count, default_thumb, views => from DB
+        *   * shorted_title => ellipsized title
         *   * video_url => P2P-Tube video URl
         *   * TODO: user_id, user_name
         *   * thumbs => thumbnail images' URLs
         */
-       public function get_videos_summary()
+       public function get_videos_summary($category_id)
        {
+               $this->load->helper('text');
+               
                $query = $this->db->query(
                        'SELECT id, name, title, duration, user_id, views, thumbs_count,
                                default_thumb
                        FROM `videos`
-                       ORDER BY name'); // TODO summary order
+                       WHERE category_id = ?
+                       ORDER BY name', // TODO summary order 
+                       $category_id); 
                $videos = $query->result_array();
                
                foreach ($videos as & $video)
                {
                        // P2P-Tube Video URL
-                       $video['video_url'] = site_url(sprintf("video/watch/%d/%s",
+                       $video['video_url'] = site_url(sprintf("watch/%d/%s",
                                $video['id'], $video['name']));
                        
                        // Thumbnails
                        $video['thumbs'] = $this->get_thumbs($video['name'], 
                                $video['thumbs_count']);
+                               
+                       // Ellipsized title
+                       //$video['shorted_title'] = ellipsize($video['title'], 45, 0.75);
+                       $video['shorted_title'] = character_limiter($video['title'], 45);
                }
                
                return $videos;
diff --git a/application/views/catalog/category_view.php b/application/views/catalog/category_view.php
new file mode 100644 (file)
index 0000000..d4e8127
--- /dev/null
@@ -0,0 +1,28 @@
+<div id="body">
+<div id="content">
+
+<h1><?php echo $category ?></h1>
+
+<div class="video-list">
+<?php foreach($videos as $video):
+       $thumb_src = $video['thumbs'][ $video['default_thumb'] ];
+       ?>
+       <div class="video-icon">
+               <a href="<?php echo $video['video_url'] ?>">
+                       <div class="video-thumb">
+                               <img src="<?php echo $thumb_src ?>" />
+                               <div class="video-duration"><?php echo $video['duration'] ?></div>
+                       </div>
+               </a>
+               <div class="video-title">
+                       <a href="<?php echo $video['video_url'] ?>">                    
+                       <?php echo $video['shorted_title'] ?></a>
+               </div>          
+               <div class="video-views"><?php echo $video['views'] . ' views' ?></div>
+               <!--<div class="video-username"><?php echo 'TODO: print user name' ?></div>-->
+       </div>
+<?php endforeach ?>
+</div>
+
+</div>
+</div>
index 2b01730..98aac30 100644 (file)
                <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): ?>
+               <?php print_r($video['tags']) ?>
+               <?php if (isset($video['tags'])): 
+               foreach ($video['tags'] as $tag => $score): ?>
                        <a href="<?php site_url('catalog/search/'. $tag) ?>">
                        <?php echo "$tag($score)" ?>
                        </a>
-               <?php endforeach ?>
+               <?php endforeach; endif ?>
                <div id="video_license"><?php echo $video['license'] ?></div>
                
 
diff --git a/img/thumb_container.png b/img/thumb_container.png
new file mode 100644 (file)
index 0000000..0a3a70f
Binary files /dev/null and b/img/thumb_container.png differ
index 2b63c52..965c874 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright Calin-Andrei Burloiu, calin.burloiu@gmail.com
 #
 # Automatically publishes videos in P2P-Tube DB based on the video files and
-# a videos info file. Parameters: videos_info_file videos_directory category
+# a videos info file. Parameters: videos_info_file videos_directory category_id
 #
 import sys
 import MySQLdb
@@ -23,7 +23,7 @@ class VideosTable:
     directory = os.curdir
     default_video_ext = 'ogv'
 
-    def __init__(self, dbCur, directory, name, title, description, tags, category):
+    def __init__(self, dbCur, directory, name, title, description, tags, category_id):
         self.dbCur = dbCur
         self.directory = directory
 
@@ -32,12 +32,13 @@ class VideosTable:
         self.description = description
         self.duration, self.formats = self.findVideosMeta()
         self.formats_json = json.dumps(self.formats, separators=(',', ':'))
-        self.category = category
+        self.category_id = category_id
         
         tagList = tags.split(',')
         self.tags = {}
         for tag in tagList:
-            self.tags[tag.strip()] = 0
+            if tag != '':
+                self.tags[tag.strip()] = 0
         self.tags_json = json.dumps(self.tags, separators=(',', ':'))
         
     def getVideoDefinition(self, fileName):
@@ -94,13 +95,13 @@ class VideosTable:
     def insert(self):
         if self.duration == None or self.formats_json == None or self.tags_json == None:
             print "Bzzzz"
-        query = "INSERT INTO `" + self.tableName + "` (name, title, description, duration, formats, category, user_id, tags, date, thumbs_count, default_thumb) VALUES ('" + self.name + "', '" + self.title + "', '" + self.description + "', '" + self.duration + "', '" + self.formats_json + "', '" + self.category + "', " + str(self.user_id) + ", '" + self.tags_json + "', NOW(), " + str(self.thumbs_count) + ", " + str(self.default_thumb) + ")"
+        query = "INSERT INTO `" + self.tableName + "` (name, title, description, duration, formats, category_id, user_id, tags, date, thumbs_count, default_thumb) VALUES ('" + self.name + "', '" + self.title + "', '" + self.description + "', '" + self.duration + "', '" + self.formats_json + "', " + str(self.category_id) + ", " + str(self.user_id) + ", '" + self.tags_json + "', NOW(), " + str(self.thumbs_count) + ", " + str(self.default_thumb) + ")"
         self.dbCur.execute(query)    
     
     @staticmethod
-    def getAllNames(dbCur, category):
+    def getAllNames(dbCur, category_id):
         allNames = set()
-        query = "SELECT name FROM `" + VideosTable.tableName + "` WHERE category = '" + category + "'"
+        query = "SELECT name FROM `" + VideosTable.tableName + "` WHERE category_id = " + str(category_id)
         dbCur.execute(query)
 
         while(True):
@@ -123,13 +124,13 @@ class VideoDefException(Exception):
 def main():
     # Check arguments.
     if len(sys.argv) < 3:
-        sys.stdout.write('usage: ' + sys.argv[0] + ' videos_info_file videos_dir category\n')
+        sys.stdout.write('usage: ' + sys.argv[0] + ' videos_info_file videos_dir category_id\n')
         exit(1)
 
     # Command line arguments
     fileName = sys.argv[1]
     directory = sys.argv[2]
-    category = sys.argv[3]
+    category_id = int(sys.argv[3])
     if len(sys.argv) == 4:
         thumbsDir = sys.argv[3]
     else:
@@ -140,7 +141,7 @@ def main():
             passwd = 'ahmitairoo', db = 'koala_livinglab')
     dbCur = dbConn.cursor()
 
-    allNames = VideosTable.getAllNames(dbCur, category)
+    allNames = VideosTable.getAllNames(dbCur, category_id)
 
     # Open info file
     file = open(fileName, 'r')
@@ -157,7 +158,7 @@ def main():
         if not name in allNames:
             sys.stdout.write(str(i) + '. ' + name + '\r')
             try:
-                video = VideosTable(dbCur, directory, name, title, description, tags, category)
+                video = VideosTable(dbCur, directory, name, title, description, tags, category_id)
                 video.insert()
                 i = i+1
 
@@ -169,6 +170,7 @@ def main():
     # Clean-up
     dbCur.close()
     dbConn.close()
+    sys.stdout.write('\n')
 
     return 0
 
diff --git a/stylesheets/catalog.css b/stylesheets/catalog.css
new file mode 100644 (file)
index 0000000..3ee4581
--- /dev/null
@@ -0,0 +1,41 @@
+.video-list
+{
+       position: relative;
+}
+
+.video-icon
+{
+       position: relative;
+       display: block;
+       float: left;
+       width: 146px;
+       height: 190px;
+       margin-right: 8px;
+}
+.video-icon .video-thumb
+{
+       position: relative;
+       width: 128px;
+       height: 98px;
+       background: url('/LivingLab/img/thumb_container.png') no-repeat left top;
+}
+.video-icon .video-thumb > img
+{
+       position: absolute;
+       margin: auto;
+       left: 4px;
+       top: 4px;
+}
+.video-icon .video-thumb > .video-duration
+{
+       position: absolute;
+       right: 5px;
+       bottom: 5px;
+       font-size: 10px;
+       font-weight: bold;
+       color: white;
+       background: black;
+}
+
+Scorpions - Wind of Change / Gloria Gaynor - I Will Survive
+Independenta Romaniei: Rasboiul Romano-Ruso-Turc 1877
\ No newline at end of file
diff --git a/stylesheets/default.css b/stylesheets/default.css
new file mode 100644 (file)
index 0000000..4ed1cd3
--- /dev/null
@@ -0,0 +1,27 @@
+body
+{ 
+       font-size: 13px;
+}
+
+#header
+{
+       clear: both;
+}
+
+#body
+{
+       position: relative;
+}
+
+#content
+{
+       float: left;
+       width: 640px;
+       padding: 12px;
+       outline: 1px solid gray; /*TODO*/
+}
+
+#footer
+{
+       clear: both;
+}