Blue Cog Blog Rotating Header Image

April, 2009:

How I Split Podcast Files

Update 2011-01-18: The Sansa m250 player finally died, and I now have a newer mp3 player that fast-forwards nicely, so I no longer do this goofy podcast splitting stuff.

Note: This is a “How-I” (works for me) not a “How-to” (do as I say) post.

I do goofy stuff sometimes. For example, I use Linux to download a couple podcasts targeted to Microsoft Windows developers. Specifically, I use µTorrent (that’s the “Micro” symbol so the name is pronounced “MicroTorrent”), a Windows BitTorrent client, running in Wine on Ubuntu to download the .NetRocks and Hanselminutes podcasts. I’ve had no problems running µTorrent in Wine. I got started doing this because my mp3 player was awkward to work with in Windows XP.

When I connected my Sansa m250 mp3 player to a Windows XP box, the driver software XP loaded wanted me to interact with the mp3 player as a media device. It has been a while, and I can’t recall exactly what it did, but I do recall it wanted me to use a media library application (one that would probably try to enforce DRM restrictions) and did not give me direct access to the file system on the player. There is probably a way around that, but I didn’t find it quickly at the time. What I did find was that when I connected the mp3 player to my old PC running Ubuntu it detected it and mounted it as a file system device that I could happily copy mp3 files to as I pleased. Good enough for me.

At first I was using the Azureus BitTorrent client, which is a Java app and runs on Ubuntu, to download the podcasts (and an occasional distro to play with). That application seemed to get more bloated with each release. It started displaying a bunch of flashy stuff and promoting things that you probably shouldn’t be downloading (but it’s okay if you don’t believe in copyright). I read about µTorrent and tried it on a Windows XP PC. It’s a lightweight program that does BitTorrent well without promoting piracy (personally, I do think copyright, with limits, is a good thing). While this worked well for downloading, I didn’t like the extra step of copying files from the PC running Windows to the other running Ubuntu to load them onto my mp3 player. After reading a timely article about Wine (the source of the article escapes me now), I decided to try running µTorrent using Wine. I don’t recall having any problems setting it up, it just worked. I did have to fiddle with my router to set up port forwarding but that’s not related to Wine or Ubuntu, just something you may have to do for BitTorrent to work.

This method of downloading the podcasts works well, but that’s not the end of the story. Occasionally I would be part way through a podcast and, for some reason (maybe I was trying to rewind a little bit within the file but my finger slipped and it went back to the beginning of the file), I would have to fast-forward to where I left off. Hour-long podcasts in a single mp3 file are not easy to fast forward with the Sansa player I have. It doesn’t forward faster the longer you hold the button like some devices do, it just goes at the same (painfully slow for a large file) pace. It seemed like splitting the mp3 files into sections would make that sort of thing easier. Bet there’s an app for that.

A search of the Ubuntu application repository turned up mp3splt. It has a GUI but I only wanted the command line executable which is available in the repository and can be installed from the command line (note that there’s no “i” in mp3splt):

sudo apt-get install mp3splt

After a couple trips to the man page to sort out which command line arguments to use, I had it splitting big mp3 files into sections in smaller mp3 files. That worked for splitting the files but I found that the player didn’t put those files in order when playing back. That’s not acceptable. I probably could just make a playlist file and use that to get the sections to play in order. I wondered if setting the ID3 tags in a way that numbered the tracks would make the player play them in order. Turns out it would. A search for “ID3” in the Ubuntu repository led to id3tool, a simple utility for editing the ID3 tags in mp3 files. I installed it too:

sudo apt-get install id3tool

I wrote a shell script named podsplit.sh to put this splitting apart all together. I use a specific directory to hold the mp3 files I want to split (but I’ll call it a “folder” since that’s the GUI metaphor, and I use the GNOME GUI to move the files around). I manually copy the downloaded mp3 files into the 2Split folder and then open a terminal and run the script. The script creates a sub-folder for each mp3 file that is split. When the script is finished I copy the sub-folders containing the resulting smaller mp3 files to the Sansa mp3 player.

Here’s the shell script:

#!/bin/bash

#------------------------------------------------------------
# podsplit.sh
#
# by Bill Melvin (bogusoft.com)
#
# BASH script for splitting mp3 podcasts into smaller pieces.
# I want to do this because it takes "forever" to fast-
# forward or rewind in a huge mp3 on my Sansa player.
#
# This script requires mp3splt and id3tool.
#
# This script, being a personal-use one-off utility, also 
# assumes some things:
# 1. mp3 files to be split are placed in ~/2Split
# 2. The file names are in the format showname_0001.mp3
#    or showname_0001_morestuff.mp3 where 0001 is the 
#    episode number.
# 
# I'm no nix wiz and I don't write many shell scripts so 
# this script also echoes a bunch of stuff so I can see 
# what's going on. 
#
#------------------------------------------------------------
# [2009-01-18] First version. 
#
# [2009-01-24] Use abbreviated show name for Artist.
#
# [2009-02-12] Changed split time from 3.0 to 5.0.   
#
# [2009-02-16] Use track number instead of end-time in track 
# title.
#
# [2009-02-19] Redirect some output to log file.
#------------------------------------------------------------

split_home=~/2Split
logfn="${split_home}/podsplit-log.txt"

ChangeID3() {
  filepath=$1
  filename=$2

  # Get track number from ID3.
  temp=`id3tool "$filepath" | grep Track: | cut -c9-`
  
  # Zero-pad to length of 3 characters.
  track=`printf "%03d" $temp`
    
  # Extract the name of the show and the episode number from 
  # the file name. This only works if the file naming follows 
  # the convention showname_0001_morestuff.mp3 where 0001 
  # is the episode number. The file name is split into fields 
  # delimited by the underscore character.
  show=`echo $filename | cut -d'_' -f1`
  episode=`echo $filename | cut -d'_' -f2`
  abbr="${show:0:6}"
  album="${abbr}_${episode}"
  title="${abbr}_${episode}_${track}"

  echo "ChangeID3"
  echo "filepath = $filepath" >> $logfn
  echo "filename = $filename" >> $logfn
  echo "show = $show" >> $logfn
  echo "abbr = $abbr" >> $logfn
  echo "episode = $episode" >> $logfn
  echo "album = $album" >> $logfn
  echo "title = $title" >> $logfn
  echo "track = $track" >> $logfn
  echo "BEFORE" >> $logfn
  id3tool "$filepath" >> $logfn
  
  id3tool --set-album="$album" --set-artist="$abbr" --set-title="$title" "$1"
  
  echo "AFTER" >> $logfn
  id3tool "$filepath" >> $logfn
}

SplitMP3() {  
  echo "SplitMP3"
  name1=$1
  echo "name1 = $name1"
  
  # Get file name and extension without directory path.
  name2=${name1#$split_home/}
  echo "name2 = $name2"
  
  # Get just the file name without the extension.
  name3=${name2%.mp3}
  echo "name3 = $name3"

  outdir=$split_home/$name3.split
  echo "Create $outdir"
  mkdir "$outdir"

  mp3splt -a -t 5.0 -d "$outdir" -o @t_@n $1

  for MP3 in $outdir/*.mp3
  do
    ChangeID3 "$MP3" "$name3"
  done   
}

for FN in $split_home/*.mp3
do
  SplitMP3 "$FN"
done

echo "Done."

This is not a flexible script as my folder for splitting files is hard-coded and it assumes a file naming convention for the mp3 files being split. If you’re an experienced shell scripter I’m sure you can do better. I still consider myself a Linux “noob” (and offer proof as well), intermediate in some areas at best. I am posting this because someone else may be trying to solve a similar problem and this can serve as an example of what worked for one person, in one situation, to work around the limitations of one particular mp3 player. Someone less goofy would probably just buy an iPod and use iTunes to handle the podcast files.

The Handy Switch

I turned on the TV while eating lunch. CNN ran a little Earth Day segment. A question was asked about things you can do at the office to save energy. One of the items mentioned was that you can save about seven dollars worth of energy a month by turning off a printer. Besides reminding me that it’s Earth Day (which I would have already known were I truly GreenTM), it made me think about a simple device I have been using to stop some of the power leaks caused by devices that are plugged in all the time (many of which are on even when they’re “off”). So for my Earth Day submission I give you the GE Handy Switch.

HandySwitch01

There may be similar switches made by a company other than General Electric. It just happens that the ones I have found locally are the Handy Switch made by GE. They come in both three prong (grounded) and two prong versions. As you can see from the pictures, I like to draw a “0” and a “1” with a marker to make it easy to see at arm’s length which position is off or on.

HandySwitch02

If a device such as a printer can use about seven dollars (that number comes from the CNN story, I’ve not confirmed it in any way) worth of electricity a month then, at around five dollars each, these switches can quickly pay back their cost in energy savings. If you’re curious about how much electricity your devices are actually using you can get a meter such as the Kill A Watt to measure that.

HandySwitch04

I keep buying more of these over time because they seem to actually be handy. They are available at Wal-Mart and others stores, at least here in the US. I assume there are similar devices suited to the local electrical connector specifications available in other countries.

HandySwitch03

If we all do little things to save energy, like plug small electrical leaks, over time the savings will add up, in our individual electric bills and in the world’s energy use.

Foxit Reader Gets The Boot

I have used Foxit Reader for a while on several PCs for viewing PDF files. I really liked that it was a single fast and lightweight executable that did not require an installer. Lately I ran into some problems with it crashing on a PC running Windows Vista. Not sure whether the problem was due to it running on Vista or due to PDF files using newer features of the PDF format (I have not looked to see if there are new features of the PDF format), I decided to download the latest version of Foxit Reader.

I noticed some bad signs early on in the installation.

foxit reader 1

“Install Firefox plugin” looks like a reasonable option. Some people probably do want to view PDF files in the browser. I prefer to download them by default. I’ll just turn off that option.

foxit reader 2

When I clicked the check box to turn off the Firefox plugin the other options that I had turned off above became selected again. I tried it a couple times and it repeated. Seems like a bug to me. I turned off the Firefox plugin, and then turned off the other options above, and moved on to the next step…

foxit reader 3

Oh no. AdCrap! And some sneaky wording too. See how you might think you have to “accept the License Terms” not for the toolbar but for the whole app?

They also assume I want Ask.com to be my default search provider. Why didn’t I think of that? At least they didn’t assume I always want to go to their start page, but they did give me the option.

foxit reader 4

More scary red text. This is not looking good.

foxit reader 5

But wait, there’s more… double AdCrap! Already checked is “Create desktop, quick launch and start menu icon to eBay.” Since I am installing this software to read documents it only makes sense that I want to go to eBay often, and quickly!

Well, I went ahead and installed it – slowly – reading the whole dialog – you can’t just next, next, next anymore.

foxit reader 6

After I opened a document that the older Foxit Reader had crashed on, and it seemed to be working now, I thought I might keep the new version. Then the automatic update dialog popped. This was the last straw. Am I going to trust the folks who just tried to get me to install AdCrap on my computer to do automatic updates? No. I am not.

foxit reader 7

And, yes, I am sure I want to uninstall it.

Is Acrobat Reader looking better to me than it did before? Not really, but Foxit Reader now looks worse. Sad to say what was once a slick and unencumbered piece of software is now showing signs of desperation. If their business plan was to use the free PDF reader to gain name recognition and “mind share” to help them sell other products and services they should have stuck with that plan. Trying to squeeze some revenue out of free software by putting in AdCrap turns people off. At least that’s what it does to me.

COLARC Meeting – April 2009

Software Archeology was the topic of the presentation given by Michael Rozlog of Embarcadero Technologies at this month’s meeting of the Columbus Architecture Group. As a software developer, you sometimes inherit code that you had nothing to do with creating. This can happen for a variety of reasons but the end result is you have a big lump of code that you know little to nothing about. As Michael described it, that code is effectively locked until you take steps to discover how it works. Michael described following aspects of “unlocking” an unfamiliar codebase using software tools and showed some examples using JBuilder:

  • Visualization using a modeling tool that can map existing code.
  • Using a metrics tool to find design violations.
  • Using an auditing tool to find style violations.
  • Reviewing business logic (unit tests, acceptance tests – if you’re lucky enough to have inherited those too).
  • Using a profiling tool to find areas in the code with performance problems.
  • Creating documentation so future maintainers will not have to start from scratch.

From my experience, sometimes you don’t have modeling, auditing, or metrics tools available for a particular system. You just have to grab a shovel and start digging up bones. Make a copy of the code and do some throw-away refactoring (that code will never be checked back into source control). Try to break parts of the system and see if it breaks in the way you expect. Try to come up with some big picture tests that can be automated. Later, when you know more about the system and are ready to start fixing bugs and adding features, you can add unit tests around just the parts you are going to change. Though some environments just don’t support unit tests, but I digress (as usual).

I have a small company background and at this point I’ve never worked with a system approaching a million lines of code. I’m sure there are systems too large to explore manually that can only be discovered using a tool suite that’s up to the task. Nonetheless, I am reminded by Michael’s examples at this meeting, if you have the tools available you should use them, even for a small system, even for your own code that you think you know well. You’re bound to learn something, and make your code better in the process.

Also in my notes from the meeting:

Kivat graphs

Shotgun Surgery

Stupid iPhone apps can make a lot of money if they go viral.

…and from Microsoft, who provided the meeting space:

Are you certifiable?

IT Management Community Hub

iHome Portable Speaker

iHome picture

I picked up the iHome portable speaker for iPod (model iHM3B) at Wal-Mart for less than $20 a few months ago. I like it enough to mention it here in case someone else looking for a portable speaker for their mp3 player happens to stumble upon this blog. It is designed to work with an iPod but I don’t have an iPod (not that I don’t want one – I just don’t have one). Fortunately it has a 1/8 inch stereo jack so I can use it with my Sansa mp3 player (the Sansa was cheap and it works, but it’s not the subject here). The iHome takes four AAA batteries and comes with a set of alkaline batteries. I have been using rechargeable batteries and am pleased that it will play for hours on a charge even though rechargeable batteries tend to deliver less power than alkaline batteries. The iHome is also louder than I expected it to be. I can even listen to it while I’m in the shower (don’t take it in the shower – it’s not waterproof). Keep in mind I use it to listen to podcasts that are mostly talk, not much music. If you want jamming bass you’ll have to go bigger.

iHome picture

I suppose mine will mess up now that I’ve bragged about it. Well, at this point I feel I’ve got my money’s worth anyway. I’d buy another.