Category Archives: Scripting

SmugMug Upload

A while back I created a set of scripts to upload files to SmugMug using php. I have recently rewritten that uploader and made it available on BitBucket. It should work almost exactly the same but it is generally better organized.

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.

#!/usr/bin/php
< ?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';
		break;
	case 'title':
		$pattern = '~"title".*?"(.*?)".*~s';
		break;
	case 'artist':
		$pattern = '~"artist".*?"(.*?)".*~s';
		break;
	default:
		exit;
}

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

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

SmugMug Uploader Updated

I have updated the SmugMug uploaders I released previously to include the latest version of phpSmug as well as making the uploader only look at image files. In the not too distant future, I hope to add video files.

Download the 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

#!/usr/bin/php

< ?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";
}