protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all';
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $media_scanner = new MediaScan();
     $fill_words = file_get_contents(dirname(__FILE__) . '/fill_words.txt');
     $fill_words = explode(' ', str_replace(array("\r", "\n", "\t", ",", "."), '', $fill_words));
     $fwslots = count($fill_words) - 9;
     if (!$options['no-confirmation'] && !$this->askConfirmation(array_merge(array(sprintf('This command will append data in the following "%s" connection(s):', $options['env']), ''), array('', 'Are you sure you want to proceed? (y/N)')), 'QUESTION_LARGE', false)) {
         exit;
     }
     $counter = 1;
     for ($i = 0; $i < (int) $options['count']; $i++) {
         if ($counter >= $group_size) {
             $start_index = mt_rand(0, $fwslots);
             $artist_name = join(' ', array_slice($fill_words, $start_index, mt_rand(1, 8)));
             $start_index = mt_rand(0, $fwslots);
             $album_name = join(' ', array_slice($fill_words, $start_index, mt_rand(1, 8)));
             $start_index = mt_rand(0, $fwslots);
             $genre_name = join(' ', array_slice($fill_words, $start_index, mt_rand(1, 8)));
             $start_index = mt_rand(0, $fwslots);
             $label_name = join(' ', array_slice($fill_words, $start_index, mt_rand(1, 8)));
             $group_size = mt_rand(1, (int) $options['max_album_size']);
             $bitrate = mt_rand(48, 512);
             $yearpublished = mt_rand(1900, 2069);
             $counter = 1;
         }
         $start_index = mt_rand(0, $fwslots);
         $song_name = join(' ', array_slice($fill_words, $start_index, mt_rand(1, 8)));
         $song_array = array();
         @($song_array['artist_name'] = $artist_name);
         @($song_array['album_name'] = $album_name);
         @($song_array['song_name'] = $song_name);
         @($song_array['song_length'] = mt_rand(0, 60) . ':' . mt_rand(11, 60));
         @($song_array['accurate_length'] = mt_rand(1, 30409092));
         @($song_array['genre_name'] = $genre_name);
         @($song_array['filesize'] = mt_rand(256, 3141592653));
         @($song_array['bitrate'] = $bitrate);
         @($song_array['yearpublished'] = $yearpublished);
         @($song_array['tracknumber'] = $counter);
         @($song_array['label'] = $label_name);
         @($song_array['mtime'] = mt_rand(1, 3141592653));
         @($song_array['atime'] = mt_rand(1, 3141592653));
         @($song_array['filename'] = 'file://localhost/home/user/' . $artist_name . '/' . $album_name . '/' . $song_name . '.mp3');
         $media_scanner->add_song($song_array);
         $counter++;
     }
     echo sprintf('Filled Database %s with %d record%s', $options['env'], $i, $i == 1 ? '' : 's');
     echo "\r\n";
 }
Exemple #2
0
$t = new lime_test(24, new lime_output_color());
$valid_test_song = array('artist_name' => 'Gorillaz', 'album_name' => 'Gorillaz Compilation', 'genre_name' => 'Electronic', 'song_name' => 'Clint Eastwood', 'song_length' => '2:05', 'accurate_length' => '125000', 'filesize' => 3000024, 'bitrate' => 128, 'yearpublished' => 2010, 'tracknumber' => 7, 'label' => 'EMI', 'mtime' => 1293300000, 'atime' => 1293300011, 'filename' => 'file://localhost/home/notroot/music/test.mp3');
$utf8_test_song = array('artist_name' => 'Sigur Rós', 'album_name' => 'með suð í eyrum við spilum endalaust', 'genre_name' => 'Русский', 'song_name' => 'dót widget', 'song_length' => '3:05', 'accurate_length' => 185000, 'filesize' => 3002332, 'bitrate' => 128, 'yearpublished' => 2005, 'tracknumber' => 1, 'label' => 'ンスの映像を世界に先がけて', 'mtime' => 1293300023, 'atime' => 1293300011, 'filename' => 'file://localhost/home/notroot/music/Fließgewässer.mp3');
$media_scan = new MediaScan();
$t->comment('->construct()');
$t->like($media_scan->get_last_scan_id(), '/\\d+/', 'Entered a new scan id successfully.');
$t->comment('->is_scanned()');
$t->is($media_scan->is_scanned('file://localhost/home/notroot/music/test.mp3', '1293300000'), false, 'Song should not exist yet');
$first_insert_id = $media_scan->add_song($valid_test_song);
$t->like($first_insert_id, '/\\d+/', 'Successfully added a song to the database');
$t->comment('->add_song()');
$media_scan = new MediaScan();
$second_insert_id = $media_scan->add_song($utf8_test_song);
$t->like($second_insert_id, '/\\d+/', 'Successfully added a UTF-8 Song entry.');
$t->is($media_scan->is_scanned('file://localhost/home/notroot/music/test.mp3', '1293300000'), true, 'Updated old record to new scan id number');
$media_scan = new MediaScan();
$second_insert_id = $media_scan->add_song($utf8_test_song);
//Test Data Integrity after add
$song_integrity_test = Doctrine_Core::getTable('Song')->find(2);
$artist_integrity_test = Doctrine_Core::getTable('Artist')->find(2);
$album_integrity_test = Doctrine_Core::getTable('Album')->find(2);
$genre_integrity_test = Doctrine_Core::getTable('Genre')->find(127);
$t->is($song_integrity_test->id, 2, 'integrity: primary id');
$t->is($song_integrity_test->scan_id, 2, 'integrity: last_scan_id id');
$t->is($song_integrity_test->artist_id, 2, 'integrity: artist_id');
$t->is($artist_integrity_test->name, 'Sigur Rós', 'integrity: artist_name');
$t->is($song_integrity_test->album_id, 2, 'integrity: album_id');
$t->is($album_integrity_test->name, 'með suð í eyrum við spilum endalaust', 'integrity: album_name');
$t->is($genre_integrity_test->name, 'Русский', 'integrity: album_name');
$t->is($song_integrity_test->length, '3:05', 'integrity: song length ');
$t->is($song_integrity_test->accurate_length, 185000, 'integrity: song length in milliseconds');
<?php

/**
 * mediaScanItunes
 * 
 * Itunes media ingest process
 * 
 * @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'));
$media_scanner = new MediaScan();
$itunes_parser = new StreemeItunesTrackParser($itunes_music_library);
while ($value = $itunes_parser->getTrack()) {
    //if it's not a valid filetype, ignore
    if (!in_array(strtolower(substr($value['Location'], -3)), $allowed_filetypes)) {
        continue;
    }
    //decode the itunes file scheme for checking is_readable
    $location = StreemeUtil::itunes_format_decode($value['Location'], StreemeUtil::is_windows(), $mapped_drive_locations);
    //convert it from user's filesystem value to UTF-8 for the database
    $value['Location'] = iconv(sfConfig::get(app_filesystem_encoding, 'ISO-8859-1'), 'UTF-8//TRANSLIT', $location);
    //if this file's scanned already and nothing about the file has been modified, ignore
    if ($media_scanner->is_scanned($value['Location'], strtotime($value['Date Modified']))) {
        continue;
    }
    //smooth times from itunes format to minutes:seconds
    $minutes = floor($value['Total Time'] / 1000 / 60);