示例#1
0
 /**
  * gather_art
  *
  * This runs through all of the albums and finds art for them
  * This runs through all of the needs art albums and trys
  * to find the art for them from the mp3s
  */
 public function gather_art()
 {
     // Make sure they've actually got methods
     $art_order = AmpConfig::get('art_order');
     if (!count($art_order)) {
         debug_event('gather_art', 'art_order not set, Catalog::gather_art aborting', 3);
         return true;
     }
     // Prevent the script from timing out
     set_time_limit(0);
     $search_count = 0;
     $albums = $this->get_album_ids();
     // Run through them and get the art!
     foreach ($albums as $album_id) {
         $art = new Art($album_id, 'album');
         $album = new Album($album_id);
         // We're going to need the name here
         $album->format();
         debug_event('gather_art', 'Gathering art for ' . $album->name, 5);
         $options = array('album_name' => $album->full_name, 'artist' => $album->artist_name, 'keyword' => $album->artist_name . ' ' . $album->full_name);
         $results = $art->gather($options, 1);
         if (count($results)) {
             // Pull the string representation from the source
             $image = Art::get_from_source($results[0], 'album');
             if (strlen($image) > '5') {
                 $art->insert($image, $results[0]['mime']);
                 // If they've enabled resizing of images generate a thumbnail
                 if (AmpConfig::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'], '275x275');
                     }
                 }
             } else {
                 debug_event('gather_art', 'Image less than 5 chars, not inserting', 3);
             }
         }
         // Stupid little cutesie thing
         $search_count++;
         if (UI::check_ticker()) {
             UI::update_text('count_art_' . $this->id, $search_count);
             UI::update_text('read_art_' . $this->id, scrub_out($album->name));
         }
         unset($found);
     }
     // foreach albums
     // One last time for good measure
     UI::update_text('count_art_' . $this->id, $search_count);
 }
示例#2
0
 /**
  * _clean_chunk
  * This is the clean function, its broken into
  * said chunks to try to save a little memory
  */
 private function _clean_chunk($media_type, $chunk, $chunk_size)
 {
     debug_event('clean', "Starting chunk {$chunk}", 5);
     $dead = array();
     $count = $chunk * $chunk_size;
     $sql = "SELECT `id`, `file` FROM `{$media_type}` " . "WHERE `catalog`='{$this->id}' LIMIT {$count},{$chunk_size}";
     $db_results = Dba::read($sql);
     while ($results = Dba::fetch_assoc($db_results)) {
         debug_event('clean', 'Starting work on ' . $results['file'] . '(' . $results['id'] . ')', 5);
         $count++;
         if (UI::check_ticker()) {
             $file = str_replace(array('(', ')', '\''), '', $results['file']);
             UI::update_text('clean_count_' . $this->id, $count);
             UI::update_text('clean_dir_' . $this->id, scrub_out($file));
         }
         $file_info = Core::get_filesize(Core::conv_lc_file($results['file']));
         if (!file_exists(Core::conv_lc_file($results['file'])) || $file_info < 1) {
             debug_event('clean', 'File not found or empty: ' . $results['file'], 5);
             AmpError::add('general', sprintf(T_('Error File Not Found or 0 Bytes: %s'), $results['file']));
             // Store it in an array we'll delete it later...
             $dead[] = $results['id'];
         } else {
             if (!Core::is_readable(Core::conv_lc_file($results['file']))) {
                 debug_event('clean', $results['file'] . ' is not readable, but does exist', 1);
             }
         }
     }
     return $dead;
 }
示例#3
0
 /**
  * verify_catalog
  * This function verify the catalog
  */
 public function verify_catalog()
 {
     if (!defined('SSE_OUTPUT')) {
         require AmpConfig::get('prefix') . UI::find_template('show_verify_catalog.inc.php');
         ob_flush();
         flush();
     }
     $verified = $this->verify_catalog_proc();
     if (!defined('SSE_OUTPUT')) {
         UI::show_box_top();
     }
     UI::update_text('', sprintf(T_('Catalog Verify Done. %d of %d files updated.'), $verified['updated'], $verified['total']));
     if (!defined('SSE_OUTPUT')) {
         UI::show_box_bottom();
     }
     return true;
 }
示例#4
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog()
 {
     $songsadded = 0;
     try {
         $api = $this->createClient();
         if ($api != null) {
             // Get all liked songs
             $songs = json_decode($api->get('me/favorites'));
             if ($songs) {
                 foreach ($songs as $song) {
                     if ($song->streamable == true && $song->kind == 'track') {
                         $data = array();
                         $data['artist'] = $song->user->username;
                         $data['album'] = $data['artist'];
                         $data['title'] = $song->title;
                         $data['year'] = $song->release_year;
                         $data['mode'] = 'vbr';
                         $data['genre'] = explode(' ', $song->genre);
                         $data['comment'] = $song->description;
                         $data['file'] = $song->stream_url . '.mp3';
                         // Always stream as mp3, if evolve => $song->original_format;
                         $data['size'] = $song->original_content_size;
                         $data['time'] = intval($song->duration / 1000);
                         if ($this->check_remote_song($data)) {
                             debug_event('soundcloud_catalog', 'Skipping existing song ' . $data['file'], 5);
                         } else {
                             $data['catalog'] = $this->id;
                             debug_event('soundcloud_catalog', 'Adding song ' . $data['file'], 5, 'ampache-catalog');
                             if (!Song::insert($data)) {
                                 debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1);
                                 AmpError::add('general', T_('Unable to Insert Song - %s'), $data['file']);
                             } else {
                                 $songsadded++;
                             }
                         }
                     }
                 }
                 UI::update_text('', T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
                 // Update the last update value
                 $this->update_last_update();
             } else {
                 AmpError::add('general', T_('API Error: cannot get song list.'));
             }
         } else {
             AmpError::add('general', T_('API Error: cannot connect to SoundCloud.'));
         }
     } catch (Exception $ex) {
         AmpError::add('general', T_('SoundCloud exception: ') . $ex->getMessage());
     }
     return true;
 }
示例#5
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog()
 {
     debug_event('subsonic_catalog', 'Updating remote catalog...', 5);
     $subsonic = $this->createClient();
     $songsadded = 0;
     // Get all artists
     $artists = $subsonic->getIndexes();
     if ($artists['success']) {
         foreach ($artists['data']['indexes']['index'] as $index) {
             foreach ($index['artist'] as $artist) {
                 // Get albums for artist
                 $albums = $subsonic->getMusicDirectory(array('id' => $artist['id']));
                 if ($albums['success']) {
                     foreach ($albums['data']['directory']['child'] as $album) {
                         if (is_array($album)) {
                             $songs = $subsonic->getMusicDirectory(array('id' => $album['id']));
                             if ($songs['success']) {
                                 foreach ($songs['data']['directory']['child'] as $song) {
                                     if (is_array($song)) {
                                         $data = array();
                                         $data['artist'] = html_entity_decode($song['artist']);
                                         $data['album'] = html_entity_decode($song['album']);
                                         $data['title'] = html_entity_decode($song['title']);
                                         $data['bitrate'] = $song['bitRate'] * 1000;
                                         $data['size'] = $song['size'];
                                         $data['time'] = $song['duration'];
                                         $data['track'] = $song['track'];
                                         $data['disk'] = $song['discNumber'];
                                         $data['mode'] = 'vbr';
                                         $data['genre'] = explode(' ', html_entity_decode($song['genre']));
                                         $data['file'] = $this->uri . '/rest/stream.view?id=' . $song['id'] . '&filename=' . urlencode($song['path']);
                                         if ($this->check_remote_song($data)) {
                                             debug_event('subsonic_catalog', 'Skipping existing song ' . $data['path'], 5);
                                         } else {
                                             $data['catalog'] = $this->id;
                                             debug_event('subsonic_catalog', 'Adding song ' . $song['path'], 5, 'ampache-catalog');
                                             if (!Song::insert($data)) {
                                                 debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1);
                                                 AmpError::add('general', T_('Unable to Insert Song - %s'), $song['path']);
                                             } else {
                                                 $songsadded++;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 debug_event('subsonic_catalog', 'Song error:' . $songs['error'], 3);
                                 AmpError::add('general', T_('Song Error.') . ": " . $songs['error']);
                             }
                         }
                     }
                 } else {
                     debug_event('subsonic_catalog', 'Album error:' . $albums['error'], 3);
                     AmpError::add('general', T_('Album Error.') . ": " . $albums['error']);
                 }
             }
         }
         UI::update_text('', T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
         // Update the last update value
         $this->update_last_update();
     } else {
         debug_event('subsonic_catalog', 'Artist error:' . $artists['error'], 3);
         AmpError::add('general', T_('Artist Error.') . ": " . $artists['error']);
     }
     debug_event('subsonic_catalog', 'Catalog updated.', 5);
     return true;
 }
示例#6
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog($type = 0)
 {
     set_time_limit(0);
     $remote_handle = $this->connect();
     if (!$remote_handle) {
         return false;
     }
     // Get the song count, etc.
     $remote_catalog_info = $remote_handle->info();
     // Tell 'em what we've found, Johnny!
     UI::update_text('', sprintf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']));
     // Hardcoded for now
     $step = 500;
     $current = 0;
     $total = $remote_catalog_info['songs'];
     while ($total > $current) {
         $start = $current;
         $current += $step;
         try {
             $songs = $remote_handle->send_command('songs', array('offset' => $start, 'limit' => $step));
         } catch (Exception $e) {
             AmpError::add('general', $e->getMessage());
             AmpError::display('general');
             flush();
         }
         // Iterate over the songs we retrieved and insert them
         foreach ($songs as $data) {
             if ($this->check_remote_song($data['song'])) {
                 debug_event('remote_catalog', 'Skipping existing song ' . $data['song']['url'], 5);
             } else {
                 $data['song']['catalog'] = $this->id;
                 $data['song']['file'] = preg_replace('/ssid=.*?&/', '', $data['song']['url']);
                 if (!Song::insert($data['song'])) {
                     debug_event('remote_catalog', 'Insert failed for ' . $data['song']['self']['id'], 1);
                     AmpError::add('general', T_('Unable to Insert Song - %s'), $data['song']['title']);
                     AmpError::display('general');
                     flush();
                 }
             }
         }
     }
     // end while
     UI::update_text('', T_('Completed updating remote catalog(s).'));
     // Update the last update value
     $this->update_last_update();
     return true;
 }
示例#7
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog()
 {
     $client = $this->createClient();
     if ($client != null) {
         $this->count = 0;
         $this->add_files($client, $this->path);
         UI::update_text('', sprintf(T_('Catalog Update Finished.  Total Media: [%s]'), $this->count));
         if ($this->count == 0) {
             Error::add('general', T_('No media updated, do you respect the patterns?'));
         }
     } else {
         Error::add('general', T_('API Error: cannot connect to Dropbox.'));
     }
     return true;
 }