/** * Remove and replace all playlist files for a given playlist or add a new playlist * from scratch. * * @param playlist_name str: new playlist name * $param playlist_files arr: the files to be added to the playlist * @param scan_id int: the scan id for a service scanner * @param service_name str: the name of the service this playlist comes from eg.itunes * @param service_unique_id str: any metadata key string to make the playlist more unique * @return int: playlist_id */ public function add_playlist($playlist_name, $playlist_files = array(), $playlist_id = 0, $scan_id = 0, $service_name = null, $service_unique_id = null) { if (isset($playlist_name) && strlen($playlist_name) > 0 && $playlist_id === 0 && is_array($playlist_files) && count($playlist_files) > 0) { $this->added_playlists++; $playlist_id = PlaylistTable::getInstance()->addPlaylist($playlist_name, (int) $scan_id, $service_name, $service_unique_id); PlaylistFilesTable::getInstance()->addFiles($playlist_id, $playlist_files); } else { if (isset($playlist_name) && strlen($playlist_name) > 0 && $playlist_id !== 0 && is_array($playlist_files) && count($playlist_files) > 0) { $this->updated_playlists++; PlaylistFilesTable::getInstance()->deleteAllPlaylistFiles($playlist_id); PlaylistFilesTable::getInstance()->addFiles($playlist_id, $playlist_files); } else { $this->skipped_playlists++; } } return $playlist_id; }
* @package streeme * @author Richard Hoar * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ */ $itunes_music_library = sfConfig::get('app_itunes_xml_location'); $mapped_drive_locations = sfConfig::get('app_mdl_mapped_drive_locations'); $allowed_filetypes = array_map('strtolower', sfConfig::get('app_aft_allowed_file_types')); $itunes_parser = new StreemeItunesPlaylistParser($itunes_music_library); $playlist_scan = new PlaylistScan('itunes'); $playlist_name = $itunes_playlist_id = null; $playlist_songs = array(); function mapItunes($collection) { return array('filename' => iconv(sfConfig::get(app_filesystem_encoding, 'ISO-8859-1'), 'UTF-8//TRANSLIT', StreemeUtil::itunes_format_decode($collection['filename'], StreemeUtil::is_windows(), sfConfig::get('app_mdl_mapped_drive_locations')))); } while ($itunes_parser->getPlaylist($playlist_name, $itunes_playlist_id, $playlist_songs)) { //There's no point scanning the entire library again, so we'll exclude the first record in iTunes if (!isset($first_skipped)) { $first_skipped = true; continue; } //convert itunes filenames to system specific paths $playlist_songs = array_map(mapItunes, $playlist_songs); //update playlists if (count($playlist_songs) > 0) { $playlist_id = $playlist_scan->is_scanned($playlist_scan->get_service_name(), $playlist_name, $itunes_playlist_id); $playlist_id = $playlist_scan->add_playlist($playlist_name, $playlist_songs, $playlist_id, $playlist_scan->get_last_scan_id(), $playlist_scan->get_service_name(), $itunes_playlist_id); } } $playlist_scan->finalize_scan(PlaylistFilesTable::getInstance()); echo $playlist_scan->get_summary();
<?php include dirname(__FILE__) . '/../bootstrap/doctrine.php'; // Initialize the test object $t = new lime_test(26, new lime_output_color()); Doctrine::loadData(sfConfig::get('sf_test_dir') . '/fixtures/80_PlaylistScan'); if (Doctrine_Manager::getInstance()->getCurrentConnection()->getDriverName() === 'Pgsql') { $dbh = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh(); $query = 'SELECT setval(\'playlist_id_seq\', 3)'; $dbh->query($query); $query = 'SELECT setval(\'playlist_files_id_seq\', 3)'; $dbh->query($query); } $playlist_scan = new PlaylistScan('itunes'); $playlist = PlaylistTable::getInstance(); $playlist_files = PlaylistFilesTable::getInstance(); $itunes_parser = new StreemeItunesPlaylistParser(dirname(__FILE__) . '/../files/iTunes Music Library.xml'); $t->comment('->construct()'); $playlist_scan = new PlaylistScan('itunes'); $t->comment('->get_last_scan_id()'); $t->is($playlist_scan->get_last_scan_id(), 2, 'Got valid playlist scan id'); $t->comment('->get_service_name()'); $t->is($playlist_scan->get_service_name(), 'itunes', 'got valid source name'); $t->comment('->is_scanned()'); $playlist_id = $playlist_scan->is_scanned($playlist_scan->get_service_name(), '90\'s Rock', 'B16E9C5DFFC4695D'); $t->is($playlist_id, '1', 'Targeted the correct playlist'); $t->is($playlist_scan->get_total_playlists(), 1, 'Playlist count incremented'); $t->comment('->add_playlist()'); $playlist_scan = new PlaylistScan('itunes'); $t->comment('Adding New...'); $new_stuff_files = array(array('filename' => 'file://localhost/home/music/new1.mp3'));
$t->is($first_insert_id, 5, 'Successfully added a playlist entry.'); $t->comment('Adding a playlist from a service like itunes'); $result = $playlist_table->find(5); $t->is($result->name, 'A Playlist', 'Correct Name'); $t->is($result->scan_id, 0, 'Correct Scan ID'); $t->is($result->service_name, null, 'Correct Service Name'); $t->is($result->service_unique_id, null, 'correct service id'); $second_insert_id = $playlist_table->addPlaylist('Nineties Rock', 2, 'itunes', 'B16E9C5DFFC4695D'); $t->is($second_insert_id, 6, 'Successfully added a playlist entry.'); $result = $playlist_table->find(6); $t->is($result->name, 'Nineties Rock', 'Correct Name'); $t->is($result->scan_id, 2, 'Correct Scan ID'); $t->is($result->service_name, 'itunes', 'Correct Service Name'); $t->is($result->service_unique_id, 'B16E9C5DFFC4695D', 'correct service id'); $t->comment('->deletePlaylist'); $deleted_row_count = $playlist_table->deletePlaylist(PlaylistFilesTable::getInstance(), $first_insert_id); $t->is($deleted_row_count, 1, 'Successfully deleted a playlist entry'); $t->comment('->getList'); $list = $playlist_table->getList(); $count = count($list); $t->is($count, 3, 'Correct list size'); $t->comment('->updateScanId'); $playlist_table->updateScanId('itunes', 'Itunes 90\'s Playlist', 'B16E9C5DFFC4695D', 2); $updated_record = $playlist_table->find(2); $t->is($updated_record->scan_id, 2, 'Record updated to correct scan id'); $id = $playlist_table->updateScanId('itunes', 'Itunes Don\'t Exist', 'AC29CC9100DF56F', 2); $t->is(id, 0, 'Correct Id for missing playlist'); $playlist_table->updateScanId('wjukebox', 'WJukebox Retro Playlist', null, 3); $updated_record = $playlist_table->find(4); $t->is($updated_record->scan_id, 3, 'Record updated to correct scan id'); $t->comment('->finalizeScan');