Changeset 6

Show
Ignore:
Timestamp:
05/16/07 04:56:59
Author:
ed
Message:

adding support of playlist with audio (xspf format)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xmlautoindex/trunk/Apache/XmlAutoIndex/Audio.pm

    r1 r6  
    2929                return Apache2::Const::OK(); 
    3030        } 
     31        elsif($format eq 'audioPlaylist') 
     32        { 
     33                $this->request->content_type( "text/xml"); 
     34                $this->request->print( $this->getAudioPlayList( ) ); 
     35                return Apache2::Const::OK(); 
     36        } 
    3137        else 
    3238        { 
     
    3541} 
    3642 
     43# TODO: migrate audioPlaylist into RSS... 
    3744sub allowedFormat 
    3845{ 
    3946        my $this = shift; 
    40         return qw{ thumb fmxml meta }; 
     47        return qw{ thumb fmxml audioPlaylist meta }; 
    4148} 
    4249                 
     
    8491EOF 
    8592} 
     93 
     94sub getAudioPlayList 
     95{ 
     96        my $this = shift; 
     97        my $uri = $this->request->uri(); 
     98         
     99        my $directory = $this->request()->filename(); 
     100 
     101        my @files; 
     102        my @directories; 
     103        my @xml; 
     104 
     105        $directory =~ s/\/([^\/]*)$//; 
     106        my $selected = $1; 
     107 
     108 
     109        my $dir=IO::Dir->new( $directory); 
     110        unless ($dir)  
     111        { 
     112                $this->request->warn( "unable to read $directory: $!"); 
     113                return undef; 
     114        } 
     115        while ($_ = $dir->read()) 
     116        { 
     117                next if /^\./; #ignore hidden files 
     118                 
     119                if    ( -f "$directory/$_" ) 
     120                { 
     121                        push @files, $_; 
     122                } 
     123        } 
     124        $dir->close(); 
     125 
     126        @files      = sort @files; 
     127 
     128        my $count = 0; 
     129 
     130        FILE: foreach my $file (@files, @files)  
     131        { 
     132 
     133                last if ($count == scalar @files); # terminates once we have reached made the entire loop 
     134 
     135                next if ($count == 0 and $file ne $selected); # next until we reached the selected file 
     136 
     137                $count++; # count next file 
     138                 
     139 
     140                #XXX: need to use lookup_dirent, but this method is not supported at this time 
     141                my $subrequest  = $this->request()->lookup_file($file); 
     142                my $file_status = $subrequest->status(); 
     143 
     144                #if forbidden, ignore this file #TODO: should not put a warn in logs... 
     145                next if ($file_status >= 400 and $file_status < 500); 
     146         
     147                my $object = Apache::XmlAutoIndex::core->new(  
     148                                request    => $subrequest,  
     149                                cgi        => $this->cgi, 
     150                                type       => $subrequest->content_type(), 
     151                                selected   => ($file eq $selected), 
     152                ); 
     153                 
     154                # XXX /!\ XXX order is important because first match is taken... 
     155                foreach my $class ( 'Apache::XmlAutoIndex::Audio' ) 
     156                { 
     157                        bless( $object, $class); #perl pseudo OO tip: change class without copying data... 
     158                        next FILE if $object->hidden(); 
     159                        last if $object->match(); 
     160                } 
     161 
     162                push @xml, $object->xmlTrack(); 
     163        } 
     164 
     165 
     166        return  
     167                "<?xml version='1.0' encoding='iso-8859-1' ?>\n". 
     168                "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n". 
     169                "  <trackList>\n". 
     170                join("\n", @xml). 
     171                "  </trackList>\n". 
     172                "</playlist>"; 
     173 
     174} 
    86175# -------------------------  
    87176 
     177sub xmlTrack  
     178{ 
     179        my $this = shift; 
     180        my $uri    = $this->request->uri(); 
     181        my $title  = $this->request->filename();# TODO 
     182        $title =~ s/.*\///; 
     183        my $artist = ""; # TODO 
     184        my $id = $title; 
     185         
     186        $id = 'selected' if $this->selected(); 
     187 
     188        return <<EOF; 
     189                <track> 
     190                        <title>$title</title> 
     191                        <!-- creator>Artist</creator --> 
     192                        <location>$uri</location> 
     193                        <identifier>$id</identifier> 
     194                </track> 
     195EOF 
     196} 
    88197return 1; 
  • xmlautoindex/trunk/Apache/XmlAutoIndex/Default.pm

    r1 r6  
    2727        my $icon; 
    2828 
    29         if ( $this->type =~ /directory/
     29        if ($format eq 'thumb'
    3030        { 
    31                 if ( $this->request->uri =~ /\/(photo|image|picture)s?$/ ) 
     31                if ( $this->type =~ /directory/ ) 
    3232                { 
    33                         $icon = "/specials/emblem-pictures.png"; 
     33                        if ( $this->request->uri =~ /\/(photo|image|picture)s?$/ ) 
     34                        { 
     35                                $icon = "/specials/emblem-pictures.png"; 
     36                        } 
     37                        elsif ( $this->request->uri =~ /\/(video|movie|film)s?$/ ) 
     38                        { 
     39                                $icon = "/specials/emblem-camera.png"; 
     40                        } 
     41                        elsif ( $this->request->uri =~ /\/(document|doc)s?$/)  
     42                        { 
     43                                $icon = "/specials/emblem-documents.png"; 
     44                        } 
     45                        elsif ( $this->request->uri =~ /\/(audio|musique|music|zik|zic)s?$/)  
     46                        { 
     47                                $icon = "/specials/emblem-audio.png"; 
     48                        } 
     49                        elsif ( $this->request->uri =~ /\/(perso|private|prive)s?$/ ) 
     50                        { 
     51                                $icon = "/specials/emblem-nowrite.png"; 
     52                        } 
     53                        elsif ( $this->request->uri =~ /\/(site|web|website|blog|wiki)s?$/ ) 
     54                        { 
     55                                $icon = "/specials/emblem-web.png"; 
     56                        } 
     57 
     58                        return $this->getIconsUri().$icon if ($icon and -e $this->getIconsLocalPath().$icon); 
    3459                } 
    35                 elsif ( $this->request->uri =~ /\/(video|movie|film)s?$/ ) 
    36                 { 
    37                         $icon = "/specials/emblem-camera.png"; 
    38                 } 
    39                 elsif ( $this->request->uri =~ /\/(document|doc)s?$/)  
    40                 { 
    41                         $icon = "/specials/emblem-documents.png"; 
    42                 } 
    43                 elsif ( $this->request->uri =~ /\/(audio|musique|music|zik|zic)s?$/)  
    44                 { 
    45                         $icon = "/specials/emblem-audio.png"; 
    46                 } 
    47                 elsif ( $this->request->uri =~ /\/(perso|private|prive)s?$/ ) 
    48                 { 
    49                         $icon = "/specials/emblem-nowrite.png"; 
    50                 } 
    51                 elsif ( $this->request->uri =~ /\/(site|web|website)s?$/ ) 
    52                 { 
    53                         $icon = "/specials/emblem-web.png"; 
    54                 } 
    55  
    56                 return $this->getIconsUri().$icon if ($icon and -e $this->getIconsLocalPath().$icon); 
    57         } 
    58                  
    59         $thumb = $this->type; 
    60         $thumb =~ s/\//\-/; 
    61         $thumb .= ".png"; 
    62         if (not -e $this->getIconsLocalPath()."/".$thumb)  
    63         { 
     60                         
    6461                $thumb = $this->type; 
    65                 $thumb =~ s/\/.*$//; 
     62                $thumb =~ s/\//\-/; 
    6663                $thumb .= ".png"; 
    6764                if (not -e $this->getIconsLocalPath()."/".$thumb)  
    6865                { 
    69                         $thumb = $unknown; 
     66                        $thumb = $this->type; 
     67                        $thumb =~ s/\/.*$//; 
     68                        $thumb .= ".png"; 
     69                        if (not -e $this->getIconsLocalPath()."/".$thumb)  
     70                        { 
     71                                $thumb = $unknown; 
     72                        } 
    7073                } 
     74                return $this->getIconsUri()."/".$thumb; 
    7175        } 
    72         return $this->getIconsUri()."/".$thumb; 
     76        else 
     77        { 
     78                return $this->SUPER::getThumb( $format); 
     79        } 
    7380} 
    7481 
  • xmlautoindex/trunk/Apache/XmlAutoIndex/core.pm

    r1 r6  
    349349 
    350350        require utf8;    
    351         utf8::decode( $data); 
     351        utf8::upgrade( $data); 
    352352 
    353353        require HTML::Entities;