|
I've created a shell script that makes my life with the PSP a bit easier. It can select random songs from my mp3 library and copy them automatically to the PSP and even re-encode them on the fly so that I can fit more songs on my Memory Stick. It can also backup all data on the Memory Stick or selected data types, show information about the PSP and more.
Version 1.3 of pspcp was released on August 26, 2005. Information about the changes and a link to the new version is available inside the article.
Most of these things can be done easily by hand just by copying the songs you want to the PSP directory or copying the files you want to backup yourself. This script also needs a separate script/program to get the list of the randomized songs, I use a modified version of the otto audio jukebox 2.0, but since all that's needed is something that returns a list of filenames, one per line, you could use find or anything that can produce this output. In the instructions below I've added a few notes on how to do this without the use of otto.
Download
This is where you can download the latest version of this script. Please make sure you read the requirements and usage instructions below. Download the file and rename it "pspcp" (without the quotes) and place it somewhere in your PATH.
Changes
v1.3
This version adds several new command line options. It's now possible to see how much space is available on the PSP and how much space is used by the different media types. A possibility to list all songs on the PSP was added as well as some new options to list usage and version information about pspcp. Finally the LAME encoding quality settings were moved to the configuration options to be more easily edited.
Requirements
This is a list of requirements needed to be able to run this script. It is provided as-is, it works for me but YMMV.
- Sony PSP - Not strictly necessary, but it's more useful if you do have it.
- USB cable - To connect your PSP to your Linux computer. Should also work with a Wi-Fi connection.
- Bash - If you run linux or a *nix variant you should already have this.
- LAME - If you want to re-encode your MP3 files you will need LAME or a similar product that uses the same command line arguments as LAME. *)
- id3cp - This is used to keep the ID3 tags of re-encoded mp3 files, this is a part of the mp3lib package I believe. *)
- A program or script that returns a randomized list of mp3 files.
- mp3info - A script to return information about mp3 songs, found here: http://www.ibiblio.org/mp3info/ *)
*) Only necessary for some functionality.
Configuration of the sript
Before you use this script you should have a look at the configurable variables at the top of the file and change everything to match your setup. At the very least you will need to change the RANDOMSCRIPT that selects random mp3 files.
DEBUG
Set this option to 1 if you want debug information to be written to the screen.
TMPPATH
This is a path to a directory where temporary files are saved when re-encoding mp3 files. The script will try to create this directory if it doesn't exist.
PSPPATH
This is the absolute path to where your PSP is mounted. Can actually be any directory on your filesystem.
PSPMUSIC
If you want to save the mp3 files you copy to the PSP in a sub-directory of the music directory you can set the name here. Set it to nothing if you want the files to be in the root of the music directory.
MUSICPATH
This sets up the complete path to save files copied to the PSP. You should probable leave it as it is, but you could change "music" to "photos" if you want to use the script to copy JPEG images to your PSP. This path can be changed with the -t comman line argument.
BACKUPPATH
This is the complete path to where you want to backup files from your PSP when using the -b option. If the directory doesn't exist, the script will try to create it and if it fails, it will exit with an error without backing up any files or doing anything else.
LAME
This is the re-encoding script to use, standard LAME arguments for bitrate and stereo mode will be added to this. If lame isn't in your PATH you should enter the complete path to the lame command and if you use another re-encoding program you should make sure it works with the extra options.
RANDOMSCRIPT
This is a script that produces a list of paths to the files you want to copy to the PSP, there should be one file per line. The $COUNT variable contains the number of files that the script wants to use. You will need to change this. Here is an example that will use the first $COUNT files found in the directory ~/music:
RANDOMSCRIPT='find ~/music/ -name "*.[mM][pP]3" | head - -n $COUNT'
You might be able to use the rl command to randomize the list of files first. If you've installed that program, you could try the following:
RANDOMSCRIPT='find ~/music/ -name "*.[mM][pP]3" | rl -c $COUNT'
ID3CP
This is the path to the id3cp command. If you use something else, it should take the original mp3 file to copy the ID3 tag from as the first argument and the new mp3 file to copy the ID3 tag to as the second argument.
STATCMD
You probably don't need to change this. This is a line that checks if there is enough space left on the PSP before trying to copy files to it.
MP3INFO
If you want to use the new -m option to list information about the mp3 songs on the PSP you will need the mp3info script. If you are unable to get it, or want to use some other program, just change the MP3INFO configuration variable and make sure it's a valid shell command that returns information about an mp3 file (file path appended at the end of the string) in the following format:
Artist<tab>Album<tab>Track Number<tab>Track Title<tab>Bitrate<tab>Length
N.B.All "<tab>" should be replaced by an actual tab character, often written as "t" without the quotes.
LAMEQ1/LAMEQ2/LAMEQ3/LAMEQ4
These four configuration options define the four different encoding qualities used when re-encoding mp3 files using the -q command line option. These use the LAME command line options, see the LAME documentation for available options if you want to change these values. LAMEQ1 is the lowest quality setting (used by -q 1) and LAMEQ4 is the highest quality (used by -q 4).
Usage
This is a short description on how to use this script. Most of the functionality should be quite straight-forward.
Usage information from the program
pspcp v1.3 (08/26/05) - Copy and possibly re-encode mp3 files to Sony PSP.
(c) Olle Johansson 26 Aug 2005
Usage:
pspcp [-himdve] [-t <target directory>] [-r <number>] [-q <quality>] [<path>]
Pass name of mp3 to copy as argument or use the -r option to copy random
songs. If no reencoding quality is given, the mp3 is copied as-is.
-i Print information about your PSP.
-m Show information about all songs on your PSP.
-r X Random, choose X random mp3:s
-q X Quality of re-encoding, 1 is lowest and 4 is highest quality.
-t X Change target music directory (DEFAULT: /mnt/psp/PSP/MUSIC/)
-b X Backup data
X=g(ame)|m(usic)|p(hoto)|s(avedata)|v(ideo)|b(rowser)|a(ll)
-e Erase content of music directory on Sony PSP before adding new files.
-v Verbose, outputs information on what the script is doing.
-V Print version information.
-d Dummy mode, print commands instead of executing.
Copying a file to the PSP music directory
To copy one file to the music directory of your PSP, just run the script in the following way:
> pspcp "~/music/Led Zeppelin - Stairway to Heaven.mp3"
Remember to put quotes around the filename if it has spaces in it. You can only copy one file at a time this way and it won't work with directories either.
-d = Dummy mode
If you want to check out what the script would do for a given set of command line arguments you can add the option "-d", which will make the script run in Dummy mode. This means that nothing will actually be done, instead all commands will be output to the screen.
-v = Verbose mode
If you want to know what the script is doing you could use the option "-v" to make the script more verbose. It will then print information on what files it is about to copy and other commands it will run.
-r = Copy random files
The "-r" option takes an extra argument telling it how many files it should copy. The script will then use the configured program to generate a randomized list of that number of mp3 files and will copy them to the PSP music directory.
-q = Re-encode mp3 files
When the script copies mp3 files to the PSP it can re-encode them on the fly using LAME. The extra argument is a number which tells the script what quality it should be, where 1 is lowest quality and 4 is highest. Mp3 files that have a lower quality than the original will be re-encoded as well, but of course that won't make them sound better, the files will just be bigger.
This option might be useful if your mp3 files are very high quiality, as listening to music on the PSP through headphones probably won't need as high quality as when you listen on your Hi-Fi sound system at home. It might also be useful to fit more songs on your Memory Stick if it's not big enough.
-t = Change target directory
This option changes the default target directory where files are copied to. The is a complete path to where you want the files to be copied. This can be anywhere on your file system and you can change it to the PSP photo directory as well to copy photos instead of music.
-b = Backup PSP data
Before any other change is done, the script can make a backup of the data on the Memory Stick of your PSP. This will just copy the files of the given type, or all data, to the backup directory configured in the script.
The argument can be one of the following: g or game for files in the Game directory, p or photo for the files in the photo directory, s or savedata for your Game Save data, v or video for your video files, b or browser to save the system folder used by the browser in firmware 2.00. Anything else will backup everything on the Memory Stick of the PSP.
-e = Erase music files
If you want to clean out the music directory before you add new songs you can use this option. It will delete all files in the configured MUSICPATH, or the directory set with the -t option.
-m = Show song information
If you have the mp3info script installed this option will list all songs on the PSP. Information shown on each song is Artist, Album name, Track number, Song Title, Bitrate and Length, if available.
-i = PSP Information
Show size of Memory Stick in the PSP, available free space on it and a run-down of memory usage of directories.
-V = Version information
Print version information about pspcp.
-h = Usage information
Print usage information.
Things to do
I might update this script in the future to be able to do more things, if I ever get the time and feel that I really need the feature. If you have any ideas, please let me know. I also gladly accept patches to the script.
- Option to clean up file names
- Make sure quality of mp3 is higher than target quality before re-encoding.
- Select what type of data to copy to automatically insert in right dir.
- Possibly find type of data automatically.
- Make it possible to have more than one file to copy as arguments.
- Scale images to best size for viewing on PSP.
-
- Copy html files to Common directory and create index file with a list of links.
-
- Restore backed up information.
-
- Cache information about songs to make it quicker to show the list.
-
- Listing of movies, pictures and gamesaves on the memory stick.
-
- Separate Memory Usage information from info, or speed it up. Possibly cache info.
-
|