Pull info from Pithos for Conky

I switched from pianobar to Pithos as pianobar didn’t work as well with conky as I would have liked. The script below lets me get information from Pithos that I can use in pianobar.

< ?php

$song=`dbus-send --print-reply --dest=net.kevinmehall.Pithos /net/kevinmehall/Pithos net.kevinmehall.Pithos.GetCurrentSong`;

$matches = array();

switch($argv[1]) {
	case 'album':
		$pattern = '~"album".*?"(.*?)".*~s';
	case 'title':
		$pattern = '~"title".*?"(.*?)".*~s';
	case 'artist':
		$pattern = '~"artist".*?"(.*?)".*~s';

preg_match($pattern, $song, $matches);

if($matches) {
	echo $matches[1];

PHP Uploader for SmugMug

EDIT (9/28/2009): I pulled the sourcecode out of the post as it was far too long. I have also updated the download package with a couple of important fixes.

I just recently started playing with SmugMug and am really liking it so far. One of my complaints so far is the upload process. Let me be clear here…they have many upload options and odds are good that those options work for the majority of people. But I’m not one of them. Basically I want to be able to keep my online galleries in sync with the photos on my computer and I didn’t see an easy way to do this with the available options. Fortunately, SmugMug provides a solid API and many people have written tools that make use of it. I looked through what people have already written and unsurprisingly didn’t find one that did exactly what I wanted. I did find phpSmug which is a PHP class that makes using the api extremely simple.

Over the course of two days, I have written 2 separate (but related) uploaders that handle the things I need them to. Both require an API key and a valid SmugMug account. These aren’t necessarily the prettiest code I have ever written, but I think they work pretty well.

Download full (UPDATED) package


This one is a fairly simple uploader. You give it the name of an album and a list of pictures to upload and it will upload any files that don’t already exist, replace files that do exist and update the metadata for those files.


This is the one that will keep a filesystem in sync with SmugMug. Point it at a folder and it will create categories, albums and handle the uploading (in the same way as upload.php).


This is a quick way to delete categories. Mostly I made it for while I was testing, but as there doesn’t seem to be a way to delete categories through the SmugMug UI this may be useful to someone.

Standard disclaimers apply to all of this. If it somehow causes the world to end or any other undesired effect, I take no responsibility. That said, it works pretty well for me. If you find any problems, let me know and I will update what I have posted.

Download full package

PHP Script for Deleting Orphaned Images

The title for this sucks. But that is because it isn’t easy to concisely describe (in a title fashion) what the script does. Imagine you have a lot of pictures from a photo shoot in both tif and jpg formats. You pick out the jpgs you want to keep and delete the rest. You still have all the tifs and want to delete the ones without a corresponding jpg. This script will do that. It takes three arguments: directory to delete from, directory to base that on, and an optional backup directory to move instead of deleting.

If you want it to handle different extensions, edit the code where it says jpg and tif


< ?php $deleteFromDir = rtrim($argv[1], '/'); $basedOnDir = rtrim($argv[2], '/'); $backupDir = rtrim($argv[3], '/'); if(!empty($backupDir) && !file_exists($backupDir)){ if(!mkdir($backupDir)){ dir("Unable to create backup directory. Quitting\n"); } } $dh = opendir($deleteFromDir); if($dh){ while(false !== ($file = readdir($dh))){ if($file[0] != '.' && !empty($file)){ $info = pathinfo($deleteFromDir . '/' . $file); if($info['extension'] == 'tif' && !file_exists($basedOnDir . '/'. $info['filename'] . '.jpg')){ echo $file . "\n"; if(!empty($backupDir)){ rename($deleteFromDir . '/' . $file, $backupDir . '/' . $file); }else{ unlink($deleteFromDir . '/' . $file); } } } } }else{ echo "Unable to open $dir\n"; } [/sourcecode]