How I Manage My Podcast MP3s

For years now, I’ve been using whatever cheapo MP3 player I can find as my podcast player. Currently that’s a 4 Gb Insignia Sport that I got on clearance for around $50. Given my directory that holds all of my downloaded MP3s, I still need to get them from my MacBook on my player.

Over the last year, I’ve tweaked these scripts until I really have them in a state that I like. I invoke a single bash shell that does everything else. The bash shell is the one that contains all the directory names that are specific to my system. If you take my scripts and modify the bash scripts, these things should be usable by about anyone.

There is a bit of unix specificity in the copy script, in that I call the df function to determine how much space remains on the device. I’m not sure the way one would do that in Windows ruby script.

First, the outer script that I have called “sync_insignia.sh”:

#!/bin/sh

mkdir -p /Volumes/Insignia_SP/JuiceFiles
~/copy_mp3s.rb '/Users/dave/Downloads/JuiceFiles/*/*.{mp3,ogg}' '/Volumes/Insignia_SP/JuiceFiles/'
ls -rt /Volumes/Insignia_SP/JuiceFiles/*/*.{mp3,ogg} | ~/create_m3u.rb > /Volumes/Insignia_SP/podcast.m3u

Next, the copy_mp3s.rb script that does the bulk of this work. Note that the first parameter to it is a glob specification that gets the files you want to move.

#!/usr/bin/ruby

file_pattern = ARGV[0]
destination = ARGV[1]
files = Dir.glob(file_pattern)
files.sort! {|a,b| File.mtime(a) <=> File.mtime(b)}

files.each { |path|
#print "Path is #{path} \n\n"
directory = path.match('\/([^\/]+)\/[^\/]+$')[1]

system('mkdir','-p', destination + '/' + directory)

remaining=`df '#{destination}'`.split(' ')[10].to_i * 512
stat = File::Stat.new(path)
if (stat.size > remaining)
print "File #{path} is #{stat.size} bytes and only #{remaining} bytes are available. Exiting\n\n"
exit
else
print "File #{path} is #{stat.size} bytes and #{remaining} bytes are available. Copying\n\n"
end

system('cp','-p', path, destination + '/' + directory) }

Finally, the script that creates the m3u file, which my player uses to put the files in the order I want to hear them.

print "#EXTM3U\r\n"

while ((line= gets) != nil)
line.chomp!
line.gsub!('/', '\\')
print "#EXTINF: 1,#{line}\r\n#{line}\r\n"

end

This may not be perfect, but it works for me. I listen to the shows in oldest to newest order, and now these scripts copy them in that order as well. When I was occasionally getting problem when the scripts filled up every available byte, I added in a check so that the first file it encounters that is bigger than the remaining space will exit the script. At this point, it really works for me well.

One Reply to “How I Manage My Podcast MP3s”

  1. Nice, Dave! I always like seeing how others manage this stuff. When I moved my primary box box to all Windows about a year ago (I run VMs on it for Linux dev work), I broke my process that was similar, except using Python as the driver instead of Ruby. It’s fixable, but I’ve just been lazy and hadn’t gotten around to doing it, so I’m semi-manual at this point. But this is nice reminder that I should revisit that.

Comments are closed.