Changeset 696

Show
Ignore:
Timestamp:
07/25/08 03:44:17 (6 months ago)
Author:
arthus
Message:

Added tons of methods to last.fm plugin

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/lastfm/trunk/lastfm.plugin.php

    r695 r696  
    3737    function tags() { 
    3838        return $this->fetch('user.getTopTags', array('user' => User::identify()->info->lastfm__username)); 
     39    } 
     40     
     41    /* this SHOULD fetch all tracks from a user's library. except it is recursive and insanely processor intensive. use at your own risk */ 
     42     
     43    function tracks($page) { 
     44             
     45        $tracks= $this->fetch('library.getTracks', array('user' => User::identify()->info->lastfm__username, 'page' => $page)); 
     46         
     47        $results = array(); 
     48         
     49        foreach($tracks->tracks->track as $track) { 
     50            $props = array(); 
     51            $props['title'] = (string)$track->name; 
     52            $props['url'] = (string)$track->url; 
     53            $props['icon'] = (string)$track->image[1]; 
     54            $props['thumbnail_url'] = (string)$track->image[1]; 
     55            $props['image_url'] = (string)$track->image[2]; 
     56            $props['filetype'] = 'lastfm'; 
     57 
     58            $results[] = new MediaAsset( 
     59                lastfmSilo::SILO_NAME . '/songs/'. (string)$track->title, 
     60                false, 
     61                $props 
     62            );                       
     63        } 
     64         
     65        if($tracks->tracks['page'] != $tracks->tracks['totalPages']) { 
     66            $results = array_merge($results, $this->tracks($page + 1)); 
     67        } 
     68         
     69        return $results; 
    3970    } 
    4071     
     
    6697            'copyright' => '2008', 
    6798            ); 
     99    } 
     100 
     101    public function action_admin_footer() { 
     102        echo '<script type="text/javascript">'; 
     103        require('lastfm.js'); 
     104        echo '</script>';        
    68105    } 
    69106 
     
    145182                if($selected) { 
    146183                    if($artist = strtok('/')) { 
    147                         if(strtok('/')) { 
    148                             $albums= $this->api->fetch('artist.getTopAlbums', array('artist' => $artist)); 
    149  
    150                             foreach($albums->topalbums->album as $album) { 
    151                                 $props = array(); 
    152                                 $props['title'] = (string)$album->name; 
    153                                 $props['url'] = (string)$album->url; 
    154                                 $props['icon'] = (string)$album->image[0]; 
    155                                 $props['thumbnail_url'] = (string)$album->image[0]; 
    156                                 $props['image_url'] = (string)$album->image[3]; 
    157                                 $props['filetype'] = 'album'; 
     184                        if($level = strtok('/')) { 
     185                            if($level == 'albums') { 
     186                                $albums= $this->api->fetch('artist.getTopAlbums', array('artist' => $artist)); 
     187 
     188                                foreach($albums->topalbums->album as $album) { 
     189                                    $props = array(); 
     190                                    $props['title'] = (string)$album->name; 
     191                                    $props['url'] = (string)$album->url; 
     192                                    $props['icon'] = (string)$album->image[1]; 
     193                                    $props['thumbnail_url'] = (string)$album->image[1]; 
     194                                    $props['image_url'] = (string)$album->image[2]; 
     195                                    $props['filetype'] = 'lastfm'; 
     196 
     197                                    $results[] = new MediaAsset( 
     198                                        self::SILO_NAME . '/tags/' . $selected . '/' . $artist . '/' . (string)$album->mbid, 
     199                                        false, 
     200                                        $props 
     201                                    );                       
     202                                } 
     203                            } elseif($level == 'songs') { 
     204                                $tracks= $this->api->fetch('artist.getTopTracks', array('artist' => $artist)); 
    158205                                                                 
    159                                 $results[] = new MediaAsset( 
    160                                     self::SILO_NAME . '/tags/' . $selected . '/' . $artist . '/' . (string)$album->mbid, 
    161                                     false, 
    162                                     $props 
    163                                 );                       
     206                                foreach($tracks->toptracks->track as $track) { 
     207                                    $props = array(); 
     208                                    $props['title'] = (string)$track->name; 
     209                                    $props['url'] = (string)$track->url; 
     210                                    $props['icon'] = (string)$track->image[1]; 
     211                                    $props['thumbnail_url'] = (string)$track->image[1]; 
     212                                    $props['image_url'] = (string)$track->image[2]; 
     213                                    $props['filetype'] = 'lastfm'; 
     214 
     215                                    $results[] = new MediaAsset( 
     216                                        self::SILO_NAME . '/tags/' . $selected . '/' . $artist . '/' . (string)$track->name, 
     217                                        false, 
     218                                        $props 
     219                                    );                       
     220                                } 
    164221                            } 
    165222                        } else { 
     
    199256 
    200257                break; 
     258                 
     259            case 'artists': 
     260                if($artist = strtok('/')) { 
     261                    if($level = strtok('/')) { 
     262                        if($level == 'albums') { 
     263                            $albums= $this->api->fetch('artist.getTopAlbums', array('artist' => $artist)); 
     264 
     265                            foreach($albums->topalbums->album as $album) { 
     266                                $props = array(); 
     267                                $props['title'] = (string)$album->name; 
     268                                $props['url'] = (string)$album->url; 
     269                                $props['icon'] = (string)$album->image[1]; 
     270                                $props['thumbnail_url'] = (string)$album->image[1]; 
     271                                $props['image_url'] = (string)$album->image[2]; 
     272                                $props['filetype'] = 'lastfm'; 
     273 
     274                                $results[] = new MediaAsset( 
     275                                    self::SILO_NAME . '/artists/' . $artist . '/' . (string)$album->mbid, 
     276                                    false, 
     277                                    $props 
     278                                );                       
     279                            } 
     280                        } elseif($level == 'songs') { 
     281                            $tracks= $this->api->fetch('artist.getTopTracks', array('artist' => $artist)); 
     282                                                             
     283                            foreach($tracks->toptracks->track as $track) { 
     284                                $props = array(); 
     285                                $props['title'] = (string)$track->name; 
     286                                $props['url'] = (string)$track->url; 
     287                                $props['icon'] = (string)$track->image[1]; 
     288                                $props['thumbnail_url'] = (string)$track->image[1]; 
     289                                $props['image_url'] = (string)$track->image[2]; 
     290                                $props['filetype'] = 'lastfm'; 
     291 
     292                                $results[] = new MediaAsset( 
     293                                    self::SILO_NAME . '/artists/' . $artist . '/' . (string)$track->name, 
     294                                    false, 
     295                                    $props 
     296                                );                       
     297                            } 
     298                        } 
     299                    } else { 
     300                        $results[] = new MediaAsset( 
     301                            self::SILO_NAME . '/artists/' . $artist . '/albums', 
     302                            true, 
     303                            array('title' => 'Albums') 
     304                        ); 
     305                        $results[] = new MediaAsset( 
     306                            self::SILO_NAME . '/artists/' . $artist . '/songs', 
     307                            true, 
     308                            array('title' => 'Songs') 
     309                        ); 
     310                    } 
     311                } else { 
     312                    $artists= $this->api->fetch('user.getTopArtists', array('user' => User::identify()->info->lastfm__username)); 
     313 
     314                    foreach($artists->topartists->artist as $artist) { 
     315                        $results[] = new MediaAsset( 
     316                            self::SILO_NAME . '/artists/' . (string)$artist->name, 
     317                            true, 
     318                            array('title' => (string)$artist->name) 
     319                        ); 
     320                    }            
     321                } 
     322                break; 
     323                 
     324            case 'albums': 
     325                $albums= $this->api->fetch('library.getAlbums', array('user' => User::identify()->info->lastfm__username)); 
     326                                 
     327                foreach($albums->albums->album as $album) { 
     328                    $props = array(); 
     329                    $props['title'] = (string)$album->name; 
     330                    $props['url'] = (string)$album->url; 
     331                    $props['icon'] = (string)$album->image[1]; 
     332                    $props['thumbnail_url'] = (string)$album->image[1]; 
     333                    $props['image_url'] = (string)$album->image[2]; 
     334                    $props['filetype'] = 'lastfm'; 
     335 
     336                    $results[] = new MediaAsset( 
     337                        self::SILO_NAME . '/albums/'. (string)$album->mbid, 
     338                        false, 
     339                        $props 
     340                    );                       
     341                } 
     342                 
     343                break; 
     344                 
     345            case 'songs': 
     346                $tracks= $this->api->fetch('user.getTopTracks', array('user' => User::identify()->info->lastfm__username)); 
     347                                     
     348                foreach($tracks->toptracks->track as $track) { 
     349                    $props = array(); 
     350                    $props['title'] = (string)$track->name; 
     351                    $props['url'] = (string)$track->url; 
     352                    $props['icon'] = (string)$track->image[1]; 
     353                    $props['thumbnail_url'] = (string)$track->image[1]; 
     354                    $props['image_url'] = (string)$track->image[2]; 
     355                    $props['filetype'] = 'lastfm'; 
     356 
     357                    $results[] = new MediaAsset( 
     358                        self::SILO_NAME . '/songs/'. (string)$track->url, 
     359                        false, 
     360                        $props 
     361                    );                       
     362                } 
     363                 
     364                break; 
     365                 
     366            case 'recent': 
     367                $tracks= $this->api->fetch('user.getRecentTracks', array('user' => User::identify()->info->lastfm__username)); 
     368 
     369                foreach($tracks->recenttracks->track as $track) { 
     370                    $props = array(); 
     371                    $props['title'] = (string)$track->name; 
     372                    $props['url'] = (string)$track->url; 
     373                    $props['icon'] = (string)$track->image[1]; 
     374                    $props['thumbnail_url'] = (string)$track->image[1]; 
     375                    $props['image_url'] = (string)$track->image[2]; 
     376                    $props['filetype'] = 'lastfm'; 
     377 
     378                    $results[] = new MediaAsset( 
     379                        self::SILO_NAME . '/recent/'. (string)$track->url, 
     380                        false, 
     381                        $props 
     382                    );                       
     383                } 
     384 
     385                break; 
     386                 
     387            case 'favorites': 
     388                $tracks= $this->api->fetch('user.getLovedTracks', array('user' => User::identify()->info->lastfm__username)); 
     389 
     390                foreach($tracks->lovedtracks->track as $track) { 
     391                    $props = array(); 
     392                    $props['title'] = (string)$track->name; 
     393                    $props['url'] = (string)$track->url; 
     394                    $props['icon'] = (string)$track->image[1]; 
     395                    $props['thumbnail_url'] = (string)$track->image[1]; 
     396                    $props['image_url'] = (string)$track->image[2]; 
     397                    $props['filetype'] = 'lastfm'; 
     398 
     399                    $results[] = new MediaAsset( 
     400                        self::SILO_NAME . '/favorites/'. (string)$track->url, 
     401                        false, 
     402                        $props 
     403                    );                       
     404                } 
     405 
     406                break; 
     407                 
    201408            case '': 
    202409                $results[] = new MediaAsset( 
     
    225432                    array('title' => 'Recent Songs') 
    226433                ); 
     434                $results[] = new MediaAsset( 
     435                    self::SILO_NAME . '/favorites', 
     436                    true, 
     437                    array('title' => 'Favorites') 
     438                ); 
    227439                break; 
    228440        } 
    229441        return $results; 
     442    } 
     443 
     444    /** 
     445     * Provide controls for the media control bar 
     446     * 
     447     * @param array $controls Incoming controls from other plugins 
     448     * @param MediaSilo $silo An instance of a MediaSilo 
     449     * @param string $path The path to get controls for 
     450     * @param string $panelname The name of the requested panel, if none then emptystring 
     451     * @return array The altered $controls array with new (or removed) controls 
     452     * 
     453     * @todo This should really use FormUI, but FormUI needs a way to submit forms via ajax 
     454     */ 
     455    public function filter_media_controls( $controls, $silo, $path, $panelname ) 
     456    { 
     457        $controls = array(); 
     458        return $controls; 
     459    } 
     460 
     461    public function silo_upload_form() { 
    230462    } 
    231463 
     
    250482    public function silo_url($path, $qualities = null) 
    251483    { 
    252         $url = 'cool'; 
    253         return $url; 
    254484    } 
    255485