use zUtil;

sub spotify
{
    $html = shift;
    $site = shift;
    my( @rValue ) = ();
    my( $count, $row, $rank, $artist, $song );
    my( $done );

    print "=------------------ spotify --------------------=\n";
    #print "site: $site\n";
    #$html=`/usr/local/zeddweb/scripts/cfscrape_fetch.py $site`;
    #print "html: $html\n";
    #exit;

    $table = zUtil::getNthItemNew( 1, $html, "<table class=\"sortable\" id=\"spotifydaily\"", "</table>" );
    #print "table: --$table--\n";
    $count = 1;
    $rank = 1;
    while( $count < 25 )
    {
        $row = zUtil::getNthItemNew( $count, $table, "<tr>", "</tr>" );
        #print "row: $row\n\n";

        if( $row =~ /<tr>.*?
                    <td.class="np">(.*?)<\/td>.*?      # rank
                    <td.class="np">(.*?)<\/td>.*?      # previous rank
                    <td.class="text\ mp"><div>(.*?)<\/div><\/td>   # artist
                    /six ) {
            print( "rank: $1\n" );
            $rank = $1;
            $artist_row = $3;
            if( $artist_row =~ /<a href=\"(.*?)\">(.*?)<\/a>.*?<a href=\"(.*?)\">(.*?)<\/a>/si ) {
                print( "   href: $1\n" );
                print( "   artist: $2\n" );
                print( "   song ref: $3\n" );
                print( "   song: $4\n" );
                push @rValue,
                {
                    'rank' => $rank,
                    'artist' => $2,
                    'song' => $4
                };
            }
        }

        # $len = length($artist);
        # if( $len > 20 ) {
        #     $artist = substr($artist,0,20);
        # }

        $rank++;
        $count++;
    }

    #exit 1;

    return @rValue;
}

return 1;
