diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-03-21 22:04:15 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-03-21 22:04:15 +0000 |
commit | b2dca6394051826dc6eb639484636c4eab168545 (patch) | |
tree | b14694db645b22b33116766befebbbce6754b2ae | |
parent | 329aecfdb908ac512596f544b8067a7a497de90d (diff) | |
download | ampache-b2dca6394051826dc6eb639484636c4eab168545.tar.gz ampache-b2dca6394051826dc6eb639484636c4eab168545.tar.bz2 ampache-b2dca6394051826dc6eb639484636c4eab168545.zip |
Add ability to generate thumbnails via catalog_update and also generate thumbnails during art add
-rw-r--r-- | bin/catalog_update.inc | 23 | ||||
-rwxr-xr-x | docs/CHANGELOG | 2 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 75 |
3 files changed, 85 insertions, 15 deletions
diff --git a/bin/catalog_update.inc b/bin/catalog_update.inc index ade19b1e..9d7b6277 100644 --- a/bin/catalog_update.inc +++ b/bin/catalog_update.inc @@ -31,6 +31,8 @@ ob_end_flush(); $catclean = 0; //All off by default $catverify = 0; $catadd = 0; +$thumbadd =0; +$artadd = 0; if (count($_SERVER['argv']) == 0) { $operations_string = "\n\t- All Catalog Operations"; @@ -55,6 +57,10 @@ if (count($_SERVER['argv']) > 0) { $operations_string .= "\n\t- Catalog Art Gather"; $artadd = 1; } + elseif ($_SERVER['argv'][$x] == '-t') { + $operations_string .= "\n\t- Generate Thumbnails"; + $thumbadd = 1; + } else { if ($where) $where .= " OR "; $where .= "name LIKE '%" . Dba::escape(preg_replace("/[^a-z0-9\. -]/i", "", $_SERVER['argv'][$x])) . "%'"; @@ -62,16 +68,17 @@ if (count($_SERVER['argv']) > 0) { } } -if (count($_SERVER['argv']) != 0 AND $artadd != 1 && $catclean != 1 && $catverify != 1 && $catadd != 1) { +if (count($_SERVER['argv']) != 0 AND $artadd != 1 && $catclean != 1 && $catverify != 1 && $catadd != 1 && $thumbadd != 1) { usage(); exit; } -if ($artadd == 0 && $catclean == 0 && $catverify == 0 && $catadd == 0) { //didn't pass any clean/verify/add arguments +if ($thumbadd == 0 && $artadd == 0 && $catclean == 0 && $catverify == 0 && $catadd == 0) { //didn't pass any clean/verify/add arguments $catclean = 1; //set them all to on $catverify = 1; $catadd = 1; $artadd = 1; + $thumbadd = 1; } echo "Starting Catalog Operations... $operations_string\n"; @@ -122,6 +129,14 @@ while ($row = Dba::fetch_row($db_results)) { echo "----------------\n\n"; } + if ($thumbadd == 1) { + // Generate the thumbnails + echo _('Generating Thumbnails'); + echo "\n"; + $catalog->generate_thumbnails(); + echo "----------------\n\n"; + } + } // end foreach ob_end_flush(); echo "\n"; @@ -140,7 +155,7 @@ function ob_html_strip($string) { function usage() { echo _("- Catalog Update -"); echo "\n"; - echo _("Usage: catalog_update.inc [CATALOG NAME] [-c|-v|-a|-g]"); + echo _("Usage: catalog_update.inc [CATALOG NAME] [-c|-v|-a|-g|-t]"); echo "\n\t"; echo _("Default behavior is to do all"); echo "\n-c\t"; @@ -151,6 +166,8 @@ function usage() { echo _('Add to Catalogs'); echo "\n-g\t"; echo _('Gather Art'); + echo "\n-t\t"; + echo _('Generate Thumbnails'); echo "\n"; echo "----------------------------------------------------------"; echo "\n"; diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 5ad0dde7..dae90d53 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.6-Alpha1 + - Add -t to catalog_update.inc for generating thumbnails + - Generate Thumbnails during catalog art operations - Fixed transcode seeking of Flacs by switching to MM:SS format for flacs being transcoded - Change album_art_order to art_order to reflect general nature of diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 96766b92..38bc462e 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -344,7 +344,7 @@ class Catalog extends database_object { $catalog_id = $this->id; require Config::get('prefix') . '/templates/show_gather_art.inc.php'; flush(); - $this->get_album_art('',1); + $this->get_art('',1); } if ($options['parse_m3u'] AND count($this->_playlists)) { @@ -664,16 +664,15 @@ class Catalog extends database_object { } // get_album_ids /** - * get_album_art + * get_art * This runs through all of the needs art albums and trys * to find the art for them from the mp3s */ - public function get_album_art($catalog_id=0,$all='') { - + public function get_art($catalog_id=0,$all='') { // Make sure they've actually got methods - $album_art_order = Config::get('album_art_order'); - if (empty($album_art_order)) { + $art_order = Config::get('art_order'); + if (!count($art_order)) { return true; } @@ -697,7 +696,8 @@ class Catalog extends database_object { foreach ($albums as $album_id) { // Create the object - $album = new Album($album_id); + $art = new Art($album_id,'album'); + $album = new Album($album_id); // We're going to need the name here $album->format(); @@ -711,13 +711,19 @@ class Catalog extends database_object { ); // Return results - $results = $album->find_art($options,1); + $results = $art->gather($options,1); if (count($results)) { // Pull the string representation from the source - $image = Album::get_image_from_source($results['0']); + $image = Art::get_from_source($results['0']); if (strlen($image) > '5') { - $album->insert_art($image,$results['0']['mime']); + $art->insert($image,$results['0']['mime']); + // If they've enabled resizing of images generate the thumbnail now + if (Config::get('resize_images')) { + $thumb = $art->generate_thumb($image,array('width'=>275,'height'=>275),$results['0']['mime']); + if (is_array($thumb)) { $art->save_thumb($thumb['thumb'],$thumb['thumb_mime']); } + } + } else { debug_event('album_art','Image less then 5 chars, not inserting','3'); @@ -748,7 +754,52 @@ class Catalog extends database_object { self::$_art_albums = array(); - } // get_album_art + } // get_art + + /** + * generate_thumbnails + * This generates the thumbnails from the images for object + * of this catalog + */ + public function generate_thumbnails($override=false) { + + $limit = $override ? '' : ' AND `thumb_mime` IS NULL'; + + // Albums first + $albums = $this->get_album_ids(); + + $idlist = '(' . implode(',', $albums) . ')'; + + $sql = "SELECT `album_id`,`art`,`art_mime` FROM `album_data` WHERE `album_id` IN $idlist $limit"; + $db_results = Dba::read($sql); + + // Start the ticker + $ticker = time(); + $thumb_count = 0; + + while ($row = Dba::fetch_assoc($db_results)) { + $art = new Art($row['album_id'],'album'); + $data = $art->generate_thumb($row['art'],array('width'=>275,'height'=>275),$row['art_mime']); + $art->save_thumb($data['thumb'],$data['thumb_mime']); + + /* Stupid little cutesie thing */ + $thumb_count++; + if ( time() > $ticker+1) { + echo "<script type=\"text/javascript\">\n"; + echo "update_txt('" . $search_count ."','count_thumb_" . $this->id . "');"; + echo "\n</script>\n"; + flush(); + $ticker = time(); + } //echos thumb count + + } // end while albums + + echo "<script type=\"text/javascript\">\n"; + echo "update_txt('" . $search_count ."','count_thumb_" . $this->id . "');"; + echo "\n</script>\n"; + flush(); + + } // generate_thumbnails /** * get_catalog_albums() @@ -1242,7 +1293,7 @@ class Catalog extends database_object { $catalog_id = $this->id; require Config::get('prefix') . '/templates/show_gather_art.inc.php'; flush(); - $this->get_album_art(); + $this->get_art(); /* Update the Catalog last_update */ $this->update_last_add(); |