#!/usr/bin/perl

##################################################
#
# GiantDisc mp3 Jukebox
# 
# © 2000, Rolf Brugger
#
##################################################


# gdinfo: Prints requested informations. This command is usually called
#         from remote hosts (command rsh)


use lib '/home/music/bin';
use gdgentools;

if    ($#ARGV == 1  && $ARGV[0] eq "-d"){
  print gdparams::gdbase()."/".gdgentools::get_ripdirectory($ARGV[1])."\n";
}

elsif ($#ARGV == 1  && $ARGV[0] eq "-s"){
  my @flist = glob $ARGV[1];
  if (scalar(@flist)>0){
    my @fstat = stat ($flist[0]);
    print $fstat[7];
  }
  else{ 
    print "0";
  }
}

elsif ($#ARGV == 1  && $ARGV[0] eq "-m"){
  my @flist = glob $ARGV[1];
  if (scalar(@flist)>0){
    my @fstat = stat ($flist[0]);
    print $fstat[9];
  }
  else{ 
    print "0";
  }
}

elsif ($#ARGV == 0  && $ARGV[0] eq "-l"){
  # currently lists mp3, ogg AND flac files
  my @flist = glob "~music/[0-9][0-9]/tr*.mp3 "
                  ."~music/[0-9][0-9]/tr*.ogg "
                  ."~music/[0-9][0-9]/tr*.flac";
  my $i=0;
  while ($i < scalar(@flist)){
    my @fstat = stat ($flist[$i]);
    if ($flist[$i] =~ /.*music\/[0-9][0-9]\/(tr.x[0-9a-f\-]*.[mof][pgl][3ga][c]?)/){
      print $fstat[9]." ".$fstat[7]." ".$1."\n";
    }
    $i++;
  }
}

elsif ($#ARGV == 0  && $ARGV[0] eq "-i"){
  # currently lists jpg
  my @flist = glob "~music/[0-9][0-9]/*.jpg 0";
  my $i=0;
  while ($i < scalar(@flist)){
    my @fstat = stat ($flist[$i]);
    if ($flist[$i] =~ /.*music\/[0-9][0-9]\/(img..[0-9a-f\-]*.jpg?)/){
      print $fstat[9]." ".$fstat[7]." ".$1."\n";
    }
    $i++;
  }
}
else{
print <<EndOfTxt;

 gdinfo: Prints requested informations. This command is usually called
         from remotely (command rsh)
 Options:
   -d n        GiantDisc, get music directory.
               Returns the first music directory with n Mbytes free space.
   -s file     Size of file in bytes
   -m file     Modification date of file (seconds since epoch)
   -l          prints a list with all .mp3 and .ogg files in the
               music directories 00, 01, ... Also prints filesizes
               and modification dates
   -i          prints a list of all .jpg files in the
               music directories 00, 01, ... Also prints filesizes
               and modification dates. 
   
EndOfTxt
}

#
