NSLU2-Linux
view · edit · print · history

The following is a script that I use to quickly transfer music from a Linux PC to the Topfield 5000 PVR. It uses Puppy to 'copy' a specified directory, and all of its mp3 files, to the Topfield.

Warnings: I Am Not A Programmer. This script does very little error checking.

 #!/bin/bash
 # specify a source directory and this script will:
 #       create a directory of the same name on the Topfield (in the Topfield's \MP3 directory)
 #       copy all of the MP3s from the source directory to the new directory on the Topfield 
 #
 # e.g. usage: send_mp3s_to_toppy.sh /home/rik/music/various_artists/trainspotting
 #
 # WARNING: use at your own risk. IANAP!
 #


 if [ $# != 1 ]; then
        echo "ERROR: Please specify the directory to send to the Topfield" 1>&2
        echo "Usage: send_mp3s_to_toppy directory" 1>&2
        exit 1
 fi

 if [ ! -d "$1" ]; then
        echo "ERROR: $1 does not seem to be a directory" 1>&2
        echo "Usage: send_mp3s_to_toppy directory" 1>&2
        exit 1
 else
        dir="$1"
 fi


 echo "------------- Copying $dir to the Topfield..."

 the_dir=`basename "$dir"`
 puppy -c turbo 1

 echo "making a directory called \\Mp3\\"$the_dir" (on the Topfield)"
 puppy -c mkdir \\MP3\\"$the_dir"

 for file in "$dir"/*.mp3; do
        this_file=`basename "$file"`
        echo
        echo "------------- PROCESSING $this_file";
        puppy -c put "$file" \\MP3\\"$the_dir"\\"$this_file";
        echo "------------- FINISHED $this_file";
        echo
 done

 puppy -c turbo 0

Here is another mp3 copy script:

 #!/bin/sh

 # cpmp3tf.sh - should be runnable using any old path

 # This script copies *.mp3 files to a Topfield 5000 PVRt
 # It creates all directories as needed on the PVR
 # Set Dirmp3Src to your mp3 source directory
 # Script assumes a "..\artist\album\song" layout
 # Empty directories are still created at the PVR
 # files in upper level directories, ie not in an album directory, are ignored
 # Only files with an mp3 extension are copied

 # 25 GB of data takes about 12 hours to copy over to the Topfield!

 # Some other limitations:

 # 1) The Toppy application only all allows 128 directory and/or files per directory
 # Programs accessing the Toppy via the USB interface will allow more to be created
 # but the actual Toppy application will have a heart attack. To overcome this, you
 # can put groups of artists under additional directories, all containing a maximum
 # of 128 folders in each; e.g. under MP3  "MP3/Artists A to M" and "MP3/Artists N to Z"
 # An exception here is the directory "Various artists" - it may exceed the 128 maximum
 # and this isn't checked for. Currently the script will not execute if more 128 artists
 # are found. You could comment this code out, then copy all the mp3s over and then
 # sort it all out later using ftpd-topfield - probably the preferred method. You could 
 # use ftpd-topfield to do all the copying but this script perhaps has the advantage 
 # that it will keep going even if say some USB error occurs.

 # 2) mp3 files that have accented characters in their filename may cause problems on 
 # that file e.g. Clannard's Celtic Collection.

 # 3) Currently puppy doesn't return an appropriate error return status for this script
 # so the on Error exits don't work - not really a big problem

 # 4) because puppy cannot indicate if a directory already exists, this script should
 # be run only once. A second run will result in heaps of error msgs being shown as
 # puppy tries to create pre existing directories.

 # Possible improvements:
 # 1) It would be useful to change this code so that any error msgs from puppy were
 # sent to a text file.

 # 2) Artists with "The" in their name all get sorted together. It may be a good idea
 # to mod this script to remove these prefixes from the file name except for the artist
 # "The The"!

 # After copying all the MP3s to the PVR, you should restart the PVR. It looks 
 # like the directory layout may be loaded at start up by the Toppy app and
 # therefore needs to be refreshed.

 # If altering this script; beware of spaces in directory/filenames
 # some code could be replaced with ls -d but its results are bit
 # weird if used on the working directory so was avoided

 #---------------------------------------------------

 # start copying MP3 files from here - typically this is a Linux/Windows remote share
 # Typically P4 (this is a Pentium 4 in my case) would be mapped to say C:/Music on the share
 Dirmp3Src=/root/P4

 # destination directory on the Topfield PVR - it's created and should
 # always be MP3 to suit jukebox TAPs
 Dirmp3Dest=MP3

 # we'll keep count of how many MP3 files are copied
 mp3count=0

 # also the start and stop time
 StartTime=`date`
 StopTime=

 #---------------------------------------------------

 # got a valid mp3 source directory?
 if [ -d "$Dirmp3Src" ]
 then
  echo    "Source directory is      :  $Dirmp3Src"
  echo -e "Destination directory is :  \\$Dirmp3Dest"
  echo ""
 else
  echo "ERROR detected by $0: mp3 source directory $Dirmp3Src does not exist"
  exit 1
 fi

 #---------------------------------------------------

 # count the number of artists
 artistCount=0

 echo "Counting number of Artist directories - please wait ..."

 for file in $Dirmp3Src/*
 do
  if ! [ -d "$file" ]; then continue; fi

  artistCount=`expr $artistCount + 1`
 done

 # do the artist count
  if [ $artistCount -gt 128 ]
  then
  echo "ERROR detected by $0: Too many Artist directories - must be <= 128 but found $artistCount"
  exit 1
  fi

 #---------------------------------------------------

  echo "Creating Topfield 5000PVRt directory:  \\$Dirmp3Dest"
  puppy -t -c mkdir \\"$Dirmp3Dest"
  if [ $? -ne 0 ]; then echo "ERROR detected by $0: " \
    "Topfield PVR not turned on OR busy OR could not make directory"; exit 1; fi

 #---------------------------------------------------

 # loop through all the artists and create the corresponding destination directory
 for file in $Dirmp3Src/*
 do
  if ! [ -d "$file" ]; then continue; fi

  DirArtist=`basename "$file"`
  echo "Creating Topfield PVR directory:  \\..\\$DirArtist"
  puppy -t -c mkdir "\\$Dirmp3Dest\\$DirArtist"
  if [ $? -ne 0 ]; then echo "ERROR detected by $0: could not make directory"; exit 1; fi


  # loop through all the albums and create the corresponding destination directory
  for file in "$Dirmp3Src/$DirArtist"/*
  do
    if ! [ -d "$file" ]; then continue; fi

    DirAlbum=`basename "$file"`
    echo -e "\tCreating Topfield PVR directory:  \\..\\..\\$DirAlbum"
    puppy -t -c mkdir "\\$Dirmp3Dest\\$DirArtist\\$DirAlbum"
    if [ $? -ne 0 ]; then echo "ERROR detected by $0: could not make directory"; exit 1; fi


    # copy the mp3s to the PVR
    for mp3File in "$Dirmp3Src/$DirArtist/$DirAlbum/"*.mp3
    do
      mp3File=`basename "$mp3File"`
      echo -e "\t\tCopying track:  $mp3File"
      puppy -t -q -c put "$Dirmp3Src/$DirArtist/$DirAlbum/$mp3File" \
        "$Dirmp3Dest\\$DirArtist\\$DirAlbum\\$mp3File"
      if [ $? -ne 0 ]; then echo "ERROR detected by $0: could not copy mp3 file"; exit 1; fi

      mp3count=`expr $mp3count + 1`
    done
  done
 done

 StopTime=`date`

 #---------------------------------------------------

 echo ""
 echo "Done!"
 echo "Start time       : $StartTime"
 echo "Stop time        : $StopTime"
 echo "MP3 files copied : $mp3count"
 echo ""
 exit 0

 #---------------------------------------------------
view · edit · print · history · Last edited by epg.
Based on work by tman and JP.
Originally by epg.
Page last modified on October 01, 2005, at 11:28 AM