From 0db52dbd375c6569d868015adf8f2bca1316ba6f Mon Sep 17 00:00:00 2001 From: Calin Burloiu Date: Mon, 25 Jul 2011 18:03:42 +0300 Subject: [PATCH] category page made, but without pagination --- .htaccess | 2 +- application/config/p2p-tube.php | 11 ++++++ application/config/routes.php | 3 ++ application/controllers/catalog.php | 24 ++++++++++++ application/models/videos_model.php | 19 ++++++--- application/views/catalog/category_view.php | 28 +++++++++++++ application/views/video/watch_view.php | 6 ++- img/thumb_container.png | Bin 0 -> 890 bytes scripts/auto-publishing/publish_videos.py | 24 ++++++------ stylesheets/catalog.css | 41 ++++++++++++++++++++ stylesheets/default.css | 27 +++++++++++++ 11 files changed, 166 insertions(+), 19 deletions(-) create mode 100644 application/views/catalog/category_view.php create mode 100644 img/thumb_container.png create mode 100644 stylesheets/catalog.css create mode 100644 stylesheets/default.css diff --git a/.htaccess b/.htaccess index 284794a..d9fdd6a 100644 --- a/.htaccess +++ b/.htaccess @@ -20,5 +20,5 @@ 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] diff --git a/application/config/p2p-tube.php b/application/config/p2p-tube.php index 6f33bec..b17610a 100644 --- a/application/config/p2p-tube.php +++ b/application/config/p2p-tube.php @@ -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'); diff --git a/application/config/routes.php b/application/config/routes.php index 36fc124..4397b79 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -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 diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 37b1a6c..e6d2c0d 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -36,6 +36,30 @@ class Catalog extends CI_Controller { echo 'link'; } + 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; diff --git a/application/models/videos_model.php b/application/models/videos_model.php index f42eb74..223def7 100644 --- a/application/models/videos_model.php +++ b/application/models/videos_model.php @@ -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 index 0000000..d4e8127 --- /dev/null +++ b/application/views/catalog/category_view.php @@ -0,0 +1,28 @@ +
+
+ +

+ +
+ +
+ +
+ +
+
+
+
+ + +
+
+ +
+ +
+ +
+
diff --git a/application/views/video/watch_view.php b/application/views/video/watch_view.php index 2b01730..98aac30 100644 --- a/application/views/video/watch_view.php +++ b/application/views/video/watch_view.php @@ -37,11 +37,13 @@
Tags: - $score): ?> + + $score): ?> - +
diff --git a/img/thumb_container.png b/img/thumb_container.png new file mode 100644 index 0000000000000000000000000000000000000000..0a3a70f846d5e9be3a60d9af5449aabc351ada41 GIT binary patch literal 890 zcmeAS@N?(olHy`uVBq!ia0vp^4M3d0!3HF+R#kZdDVAa<&kznEsNqQI0P;BtJR*yM z>aT+^qm#z$3ZS55iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$QVa}C-#uL% zLn`LHy}mbF#8Kwh$Mp2R-8*Kh#z|=(T*6u5`{)Xr%Nv$zX~)?ij{m1l5sQlA`ld9) z%z53Ukn#mn&pu7vocwOb+>Jp=xkcS}=a>IAJS=>x^tZ~soY6xLHH z`suvUF`rF3);Y7% z$qWVz5BA>Qc+F0Rhpp<*|A;^l2_Ck}<(DggqKpl19z1y9H!U^Z%*-tB#Yf8)fr65f zFUm_xt}|3zd;fi{+4xs%V_J9Wxyxz6c4U`$0tW#w-8 zv-f35mjKhMRkP;KnR6z&XZ@Vw_4RlEb1*RM`M#aeX6v;)<^tc#ccMO|?R2_!>perw lWs~`gdy3E1?ydRHS+V}{r1DeK<^%HygQu&X%Q~loCIFUN literal 0 HcmV?d00001 diff --git a/scripts/auto-publishing/publish_videos.py b/scripts/auto-publishing/publish_videos.py index 2b63c52..965c874 100755 --- a/scripts/auto-publishing/publish_videos.py +++ b/scripts/auto-publishing/publish_videos.py @@ -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 index 0000000..3ee4581 --- /dev/null +++ b/stylesheets/catalog.css @@ -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 index 0000000..4ed1cd3 --- /dev/null +++ b/stylesheets/default.css @@ -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; +} -- 2.20.1