コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
<?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'));