local tArgs = { ... }

local function printUsage()
	print( "Usages:")
	print( "dj play" )
	print( "dj play <side>" )
	print( "dj stop" )
end

if #tArgs > 2 then
	printUsage()
	return
end

local sCommand = tArgs[1]
if sCommand == "stop" then
	-- Stop audio
	disk.stopAudio()

elseif sCommand == "play" or sCommand == nil then
	-- Play audio
	local sSide = tArgs[2]
	if sSide == nil then
		-- No disc specified, pick one at random
		local tSides = {}
		for n,sSide in ipairs( redstone.getSides() ) do
			if disk.isPresent( sSide ) and disk.hasAudio( sSide ) then
				table.insert( tSides, sSide )
			end
		end
		if #tSides == 0 then
			print( "No Music Discs in attached disk drives" )
			return
		end
		sSide = tSides[ math.random(1,#tSides) ]
	end

	-- Play the disc
	if disk.isPresent( sSide ) and disk.hasAudio( sSide ) then
		print( "Playing "..disk.getAudioTitle( sSide ) )
		disk.playAudio( sSide )
	else
		print( "No Music Disc in "..sSide.." disk drive" )
		return
	end
	
else
	printUsage()
	
end
