Exemple #1
0
 /**
  * get_missing_albums
  * Get list of library's missing albums from MusicBrainz
  * @param Artist|null $artist
  * @param string $mbid
  * @return array
  */
 public static function get_missing_albums($artist, $mbid = '')
 {
     $mb = new MusicBrainz(new RequestsHttpAdapter());
     $includes = array('release-groups');
     $types = explode(',', AmpConfig::get('wanted_types'));
     try {
         $martist = $mb->lookup('artist', $artist ? $artist->mbid : $mbid, $includes);
     } catch (Exception $e) {
         return null;
     }
     $owngroups = array();
     $wartist = array();
     if ($artist) {
         $albums = $artist->get_albums();
         foreach ($albums as $id) {
             $album = new Album($id);
             if (trim($album->mbid_group)) {
                 $owngroups[] = $album->mbid_group;
             } else {
                 if (trim($album->mbid)) {
                     $malbum = $mb->lookup('release', $album->mbid, array('release-groups'));
                     if ($malbum->{'release-group'}) {
                         if (!in_array($malbum->{'release-group'}->id, $owngroups)) {
                             $owngroups[] = $malbum->{'release-group'}->id;
                         }
                     }
                 }
             }
         }
     } else {
         $wartist['mbid'] = $mbid;
         $wartist['name'] = $martist->name;
         parent::add_to_cache('missing_artist', $mbid, $wartist);
         $wartist = self::get_missing_artist($mbid);
     }
     $results = array();
     foreach ($martist->{'release-groups'} as $group) {
         if (in_array(strtolower($group->{'primary-type'}), $types)) {
             $add = true;
             for ($i = 0; $i < count($group->{'secondary-types'}) && $add; ++$i) {
                 $add = in_array(strtolower($group->{'secondary-types'}[$i]), $types);
             }
             if ($add) {
                 if (!in_array($group->id, $owngroups)) {
                     $wantedid = self::get_wanted($group->id);
                     $wanted = new Wanted($wantedid);
                     if ($wanted->id) {
                         $wanted->format();
                     } else {
                         $wanted->mbid = $group->id;
                         if ($artist) {
                             $wanted->artist = $artist->id;
                         } else {
                             $wanted->artist_mbid = $mbid;
                         }
                         $wanted->name = $group->title;
                         if (!empty($group->{'first-release-date'})) {
                             if (strlen($group->{'first-release-date'}) == 4) {
                                 $wanted->year = $group->{'first-release-date'};
                             } else {
                                 $wanted->year = date("Y", strtotime($group->{'first-release-date'}));
                             }
                         }
                         $wanted->accepted = false;
                         $wanted->link = AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $group->id;
                         if ($artist) {
                             $wanted->link .= "&artist=" . $wanted->artist;
                         } else {
                             $wanted->link .= "&artist_mbid=" . $mbid;
                         }
                         $wanted->f_link = "<a href=\"" . $wanted->link . "\" title=\"" . $wanted->name . "\">" . $wanted->name . "</a>";
                         $wanted->f_artist_link = $artist ? $artist->f_link : $wartist['link'];
                         $wanted->f_user = $GLOBALS['user']->f_name;
                     }
                     $results[] = $wanted;
                 }
             }
         }
     }
     return $results;
 }
Exemple #2
0
 /**
  * artist_albums
  * This returns the albums of an artist
  */
 public static function artist_albums($input)
 {
     $artist = new Artist($input['filter']);
     $albums = $artist->get_albums(null, true);
     // Set the offset
     XML_Data::set_offset($input['offset']);
     XML_Data::set_limit($input['limit']);
     ob_end_clean();
     echo XML_Data::albums($albums);
 }
Exemple #3
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);
 }
Exemple #4
0
     if (!Catalog::can_remove($artist)) {
         debug_event('artist', 'Unauthorized to remove the artist `.' . $artist->id . '`.', 1);
         UI::access_denied();
         exit;
     }
     if ($artist->remove_from_disk()) {
         show_confirmation(T_('Artist Deletion'), T_('Artist has been deleted.'), AmpConfig::get('web_path'));
     } else {
         show_confirmation(T_('Artist Deletion'), T_('Cannot delete this artist.'), AmpConfig::get('web_path'));
     }
     break;
 case 'show':
     $artist = new Artist($_REQUEST['artist']);
     $artist->format();
     if (AmpConfig::get('album_release_type')) {
         $multi_object_ids = $artist->get_albums($_REQUEST['catalog'], false, true);
     } else {
         $object_ids = $artist->get_albums($_REQUEST['catalog']);
     }
     $object_type = 'album';
     require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php';
     break;
 case 'show_all_songs':
     $artist = new Artist($_REQUEST['artist']);
     $artist->format();
     $object_type = 'song';
     $object_ids = $artist->get_songs();
     require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php';
     break;
 case 'update_from_tags':
     $type = 'artist';
Exemple #5
0
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
require_once 'lib/init.php';
UI::show_header();
/**
 * Display Switch
 */
switch ($_REQUEST['action']) {
    case 'show':
        $artist = new Artist($_REQUEST['artist']);
        $artist->format();
        $object_ids = $artist->get_albums($_REQUEST['catalog']);
        $object_type = 'album';
        require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php';
        break;
    case 'show_all_songs':
        $artist = new Artist($_REQUEST['artist']);
        $artist->format();
        $object_type = 'song';
        $object_ids = $artist->get_songs();
        require_once AmpConfig::get('prefix') . '/templates/show_artist.inc.php';
        break;
    case 'update_from_tags':
        $type = 'artist';
        $object_id = intval($_REQUEST['artist']);
        $target_url = AmpConfig::get('web_path') . "/artists.php?action=show&amp;artist=" . $object_id;
        require_once AmpConfig::get('prefix') . '/templates/show_update_items.inc.php';