A bash script to create RealPlayer playlists

Sep 04, '07 07:30:00AM

Contributed by: rustin

It seems to me that Realplayer 10 for Mac lacks any function for creating or managing a playlist. I have a folder full of .rmvb movies that I would like to play sequentially without having to open each time one movie ends. While I could just convert them to a more usable format (mpeg h.264?) and open them with a better player, instead I created a little bash script to make a playlist of all files in a directory (aka folder). I thought I would post my little script for those who are not clued on regular expressions or shell scripting.

I created a file in my home directory called makeram.sh and put in the following code:

#!/bin/bash
i=`pwd | sed s/'\ '/\%20/g`

for j in `ls | grep '\.rmvb$' | sed s/'\ '/\%20/g`;
  do
    echo file:\/\/localhost$i\/$j >> ./playlist.ram
  done
After saving the file, don't forget to make it executable with chmod +x ~/makeram.sh.

Basically, the script works by replacing any spaces with %20, and then constructs a single line of this format:

file://localhost/current_directory/filename.rmvb
It stores this single line in a file called playlist.ram. It does this for as many files exist that end in .rmvb in that directory. If you want to put other file types in the playlist, you can change .rmvb$ in the line that begins with for j in to reflect the extension of the file type you want to add. Then just run ~/makeram.sh again and it will append those files to the existing playlist.ram in that directory. For example, you could change it to .avi$ for avi files. Or you could do a regexp OR operation if you're so inclined.

Now I just navigate to the directory with the Real Media files in them and type ~/makeram.sh, and it creates a playlist.ram file for me in that directory. Opening the playlist.ram file with RealPlayer will play the files one after the other. You can skip forward or backward using Command-Right Arrow or Command-Left Arrow.

A more elegant solution would be to create a folder action or just some AppleScript to automatically create these files but, alas, I have no AppleScript clue. If someone could show me this in AppleScript, I'd love to see it.

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070903120755423