Example #1
0
 /**
  * Gather tags from audio files.
  * @param int $limit
  * @return array
  */
 public function gather_song_tags($limit = 5)
 {
     // We need the filenames
     $album = new Album($this->uid);
     // grab the songs and define our results
     $songs = $album->get_songs();
     $data = array();
     // Foreach songs in this album
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         $data = array_merge($data, $this->gather_media_tags($song));
         if ($limit && count($data) >= $limit) {
             return array_slice($data, 0, $limit);
         }
     }
     return $data;
 }
Example #2
0
     }
     break;
 case 'artist_random':
     $artist = new Artist($_REQUEST['artist_id']);
     $media_ids = $artist->get_random_songs();
     break;
 case 'album_random':
     $album = new Album($_REQUEST['album_id']);
     $media_ids = $album->get_random_songs();
     break;
 case 'album':
     debug_event('stream.php', 'Playing/Adding all songs of album(s) {' . $_REQUEST['album_id'] . '}...', '5');
     $albums_array = explode(',', $_REQUEST['album_id']);
     foreach ($albums_array as $a) {
         $album = new Album($a);
         $songs = $album->get_songs();
         foreach ($songs as $song) {
             $media_ids[] = array('object_type' => 'song', 'object_id' => $song);
         }
     }
     break;
 case 'playlist':
     $playlist = new Playlist($_REQUEST['playlist_id']);
     $songs = $playlist->get_songs();
     foreach ($songs as $song) {
         $media_ids[] = array('object_type' => 'song', 'object_id' => $song);
     }
     break;
 case 'smartplaylist':
     $playlist = new Search('song', $_REQUEST['playlist_id']);
     $items = $playlist->get_items();
Example #3
0
 /**
  * album_songs
  * This returns the songs of a specified album
  */
 public static function album_songs($input)
 {
     $album = new Album($input['filter']);
     $songs = $album->get_songs();
     // Set the offset
     XML_Data::set_offset($input['offset']);
     XML_Data::set_limit($input['limit']);
     ob_end_clean();
     echo XML_Data::songs($songs);
 }
Example #4
0
 /**
  * update_single_item
  * updates a single album,artist,song from the tag data
  * this can be done by 75+
  */
 public static function update_single_item($type, $id)
 {
     // Because single items are large numbers of things too
     set_time_limit(0);
     $songs = array();
     switch ($type) {
         case 'album':
             $album = new Album($id);
             $songs = $album->get_songs();
             break;
         case 'artist':
             $artist = new Artist($id);
             $songs = $artist->get_songs();
             break;
         case 'song':
             $songs[] = $id;
             break;
     }
     // end switch type
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         $info = self::update_media_from_tags($song, '', '');
         if ($info['change']) {
             $file = scrub_out($song->file);
             echo "<dl>\n\t<dd>";
             echo "<strong>{$file} " . T_('Updated') . "</strong>\n";
             echo $info['text'];
             echo "\t</dd>\n</dl><hr align=\"left\" width=\"50%\" />";
             flush();
         } else {
             echo "<dl>\n\t<dd>";
             echo "<strong>" . scrub_out($song->file) . "</strong><br />" . T_('No Update Needed') . "\n";
             echo "\t</dd>\n</dl><hr align=\"left\" width=\"50%\" />";
             flush();
         }
     }
     // foreach songs
     self::gc();
 }
Example #5
0
 /**
  * gather_tags
  * This looks for the art in the meta-tags of the file
  * itself
  */
 public function gather_tags($limit = 5)
 {
     // We need the filenames
     $album = new Album($this->uid);
     // grab the songs and define our results
     $songs = $album->get_songs();
     $data = array();
     // Foreach songs in this album
     foreach ($songs as $song_id) {
         $song = new Song($song_id);
         // If we find a good one, stop looking
         $getID3 = new getID3();
         try {
             $id3 = $getID3->analyze($song->file);
         } catch (Exception $error) {
             debug_event('getid3', $error->getMessage(), 1);
         }
         if (isset($id3['asf']['extended_content_description_object']['content_descriptors']['13'])) {
             $image = $id3['asf']['extended_content_description_object']['content_descriptors']['13'];
             $data[] = array('song' => $song->file, 'raw' => $image['data'], 'mime' => $image['mime']);
         }
         if (isset($id3['id3v2']['APIC'])) {
             // Foreach in case they have more then one
             foreach ($id3['id3v2']['APIC'] as $image) {
                 $data[] = array('song' => $song->file, 'raw' => $image['data'], 'mime' => $image['mime']);
             }
         }
         if ($limit && count($data) >= $limit) {
             return array_slice($data, 0, $limit);
         }
     }
     // end foreach
     return $data;
 }
Example #6
0
 /**
  * advanced
  * This processes the results of a post from a form and returns an
  * array of song items that were returned from said randomness
  */
 public static function advanced($type, $data)
 {
     /* Figure out our object limit */
     $limit = intval($data['random']);
     // Generate our matchlist
     /* If they've passed -1 as limit then get everything */
     $limit_sql = "";
     if ($data['random'] == "-1") {
         unset($data['random']);
     } else {
         $limit_sql = "LIMIT " . Dba::escape($limit);
     }
     $search_data = Search::clean_request($data);
     $search_info = false;
     if (count($search_data) > 1) {
         $search = new Search(null, $type);
         $search->parse_rules($search_data);
         $search_info = $search->to_sql();
     }
     $sql = "";
     switch ($type) {
         case 'song':
             $sql = "SELECT `song`.`id`, `size`, `time` " . "FROM `song` ";
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             break;
         case 'album':
             $sql = "SELECT `album`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `album` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`album`=`album`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `album`.`id`';
             break;
         case 'artist':
             $sql = "SELECT `artist`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `artist` ";
             if (!$search_info || !$search_info['join']['song']) {
                 $sql .= "LEFT JOIN `song` ON `song`.`artist`=`artist`.`id` ";
             }
             if ($search_info) {
                 $sql .= $search_info['table_sql'];
             }
             if (AmpConfig::get('catalog_disable')) {
                 $sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
                 $sql .= " WHERE `catalog`.`enabled` = '1'";
             }
             if ($search_info) {
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= ' AND ' . $search_info['where_sql'];
                 } else {
                     $sql .= ' WHERE ' . $search_info['where_sql'];
                 }
             }
             $sql .= ' GROUP BY `artist`.`id`';
             break;
     }
     $sql .= " ORDER BY RAND() {$limit_sql}";
     // Run the query generated above so we can while it
     $db_results = Dba::read($sql);
     $results = array();
     $size_total = 0;
     $fuzzy_size = 0;
     $time_total = 0;
     $fuzzy_time = 0;
     while ($row = Dba::fetch_assoc($db_results)) {
         // If size limit is specified
         if ($data['size_limit']) {
             // Convert
             $new_size = $row['size'] / 1024 / 1024;
             // Only fuzzy 100 times
             if ($fuzzy_size > 100) {
                 break;
             }
             // Add and check, skip if over size
             if ($size_total + $new_size > $data['size_limit']) {
                 $fuzzy_size++;
                 continue;
             }
             $size_total = $size_total + $new_size;
             $results[] = $row['id'];
             // If we are within 4mb of target then jump ship
             if ($data['size_limit'] - floor($size_total) < 4) {
                 break;
             }
         }
         // if size_limit
         // If length really does matter
         if ($data['length']) {
             // base on min, seconds are for chumps and chumpettes
             $new_time = floor($row['time'] / 60);
             if ($fuzzy_time > 100) {
                 break;
             }
             // If the new one would go over skip!
             if ($time_total + $new_time > $data['length']) {
                 $fuzzy_time++;
                 continue;
             }
             $time_total = $time_total + $new_time;
             $results[] = $row['id'];
             // If there are less then 2 min of free space return
             if ($data['length'] - $time_total < 2) {
                 return $results;
             }
         }
         // if length does matter
         if (!$data['size_limit'] && !$data['length']) {
             $results[] = $row['id'];
         }
     }
     // end while results
     switch ($type) {
         case 'song':
             return $results;
         case 'album':
             $songs = array();
             foreach ($results as $result) {
                 $album = new Album($result);
                 $songs = array_merge($songs, $album->get_songs());
             }
             return $songs;
         case 'artist':
             $songs = array();
             foreach ($results as $result) {
                 $artist = new Artist($result);
                 $songs = array_merge($songs, $artist->get_songs());
             }
             return $songs;
         default:
             return false;
     }
 }
Example #7
0
 public static function addShare($xml, $share)
 {
     $xshare = $xml->addChild('share');
     $xshare->addAttribute('id', $share->id);
     $xshare->addAttribute('url', $share->public_url);
     $xshare->addAttribute('description', $share->description);
     $user = new User($share->user);
     $xshare->addAttribute('username', $user->username);
     $xshare->addAttribute('created', date("c", $share->creation_date));
     if ($share->lastvisit_date > 0) {
         $xshare->addAttribute('lastVisited', date("c", $share->lastvisit_date));
     }
     if ($share->expire_days > 0) {
         $xshare->addAttribute('expires', date("c", $share->creation_date + $share->expire_days * 86400));
     }
     $xshare->addAttribute('visitCount', $share->counter);
     if ($share->object_type == 'song') {
         $song = new Song($share->object_id);
         self::addSong($xshare, $song, "entry");
     } elseif ($share->object_type == 'playlist') {
         $playlist = new Playlist($share->object_id);
         $songs = $playlist->get_songs();
         foreach ($songs as $id) {
             $song = new Song($id);
             self::addSong($xshare, $song, "entry");
         }
     } elseif ($share->object_type == 'album') {
         $album = new Album($share->object_id);
         $songs = $album->get_songs();
         foreach ($songs as $id) {
             $song = new Song($id);
             self::addSong($xshare, $song, "entry");
         }
     }
 }
Example #8
0
 public static function _musicChilds($prmPath, $prmQuery, $start, $count)
 {
     $mediaItems = array();
     $maxCount = 0;
     $queryData = array();
     parse_str($prmQuery, $queryData);
     $parent = 'amp://music' . $prmPath;
     $pathreq = explode('/', $prmPath);
     if ($pathreq[0] == '' && count($pathreq) > 0) {
         array_shift($pathreq);
     }
     switch ($pathreq[0]) {
         case 'artists':
             switch (count($pathreq)) {
                 case 1:
                     // Get artists list
                     //$artists = Catalog::get_artists();
                     //list($maxCount, $artists) = self::_slice($artists, $start, $count);
                     $artists = Catalog::get_artists(null, $count, $start);
                     list($maxCount, $artists) = array(999999, $artists);
                     foreach ($artists as $artist) {
                         $artist->format();
                         $mediaItems[] = self::_itemArtist($artist, $parent);
                     }
                     break;
                 case 2:
                     // Get artist's albums list
                     $artist = new Artist($pathreq[1]);
                     if ($artist->id) {
                         $album_ids = $artist->get_albums();
                         list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                         foreach ($album_ids as $album_id) {
                             $album = new Album($album_id);
                             $album->format();
                             $mediaItems[] = self::_itemAlbum($album, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'albums':
             switch (count($pathreq)) {
                 case 1:
                     // Get albums list
                     //!!$album_ids = Catalog::get_albums();
                     //!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
                     $album_ids = Catalog::get_albums($count, $start);
                     list($maxCount, $album_ids) = array(999999, $album_ids);
                     foreach ($album_ids as $album_id) {
                         $album = new Album($album_id);
                         $album->format();
                         $mediaItems[] = self::_itemAlbum($album, $parent);
                     }
                     break;
                 case 2:
                     // Get album's songs list
                     $album = new Album($pathreq[1]);
                     if ($album->id) {
                         $song_ids = $album->get_songs();
                         list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count);
                         foreach ($song_ids as $song_id) {
                             $song = new Song($song_id);
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'songs':
             switch (count($pathreq)) {
                 case 1:
                     // Get songs list
                     $catalogs = Catalog::get_catalogs();
                     foreach ($catalogs as $catalog_id) {
                         $catalog = Catalog::create_from_id($catalog_id);
                         $songs = $catalog->get_songs();
                         list($maxCount, $songs) = self::_slice($songs, $start, $count);
                         foreach ($songs as $song) {
                             $song->format();
                             $mediaItems[] = self::_itemSong($song, $parent);
                         }
                     }
                     break;
             }
             break;
         case 'playlists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Playlist::get_playlists();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Playlist($pl_id);
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Playlist($pathreq[1]);
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         case 'smartplaylists':
             switch (count($pathreq)) {
                 case 1:
                     // Get playlists list
                     $pl_ids = Search::get_searches();
                     list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
                     foreach ($pl_ids as $pl_id) {
                         $playlist = new Search($pl_id, 'song');
                         $playlist->format();
                         $mediaItems[] = self::_itemPlaylist($playlist, $parent);
                     }
                     break;
                 case 2:
                     // Get playlist's songs list
                     $playlist = new Search($pathreq[1], 'song');
                     if ($playlist->id) {
                         $items = $playlist->get_items();
                         list($maxCount, $items) = self::_slice($items, $start, $count);
                         foreach ($items as $item) {
                             if ($item['object_type'] == 'song') {
                                 $song = new Song($item['object_id']);
                                 $song->format();
                                 $mediaItems[] = self::_itemSong($song, $parent);
                             }
                         }
                     }
                     break;
             }
             break;
         default:
             $mediaItems[] = self::_musicMetadata('artists');
             $mediaItems[] = self::_musicMetadata('albums');
             $mediaItems[] = self::_musicMetadata('songs');
             $mediaItems[] = self::_musicMetadata('playlists');
             $mediaItems[] = self::_musicMetadata('smartplaylists');
             break;
     }
     if ($maxCount == 0) {
         $maxCount = count($mediaItems);
     }
     return array($maxCount, $mediaItems);
 }
Example #9
0
    }
} else {
    switch ($_REQUEST['action']) {
        case 'tmp_playlist':
            $media_ids = $GLOBALS['user']->playlist->get_items();
            $name = $GLOBALS['user']->username . ' - Playlist';
            break;
        case 'browse':
            $id = intval(scrub_in($_REQUEST['browse_id']));
            $browse = new Browse($id);
            $browse_media_ids = $browse->get_saved();
            foreach ($browse_media_ids as $media_id) {
                switch ($object_type) {
                    case 'album':
                        $album = new Album($media_id);
                        $media_ids = array_merge($media_ids, $album->get_songs());
                        break;
                    case 'song':
                        $media_ids[] = $media_id;
                        break;
                    case 'video':
                        $media_ids[] = array('object_type' => 'Video', 'object_id' => $media_id);
                        break;
                }
                // switch on type
            }
            // foreach media_id
            $name = 'Batch-' . date("dmY", time());
        default:
            // Rien a faire
            break;