/***************************************************************************
 *   Copyright (C) 2008 by Andreas Silberstorff   *
 *   taki@Rivendell   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "recordcommand.h"
#include "settings.h"
#include <KDE/KLocale>
#include <KStandardDirs>
#include <KDebug>
#include <QDir>

namespace MPlayerScriptDevice {

/**
 * A Command using MPlayer shellscripts
 *
 * @short MPlayerCommand
 * @author Andreas Silberstorff <ml@andreas-silberstorff.de>
 * @version 1.0.91
 */

RecordCommand::RecordCommand()
{
	kDebug() << "creating RecordCommand";
	_program = Settings::mencoder();
	_type = "dvb";
	_ovc = "copy";
	_oac = "copy";
	_of = "mpeg";
	_suffix = "mpg";
}

RecordCommand::~RecordCommand()
{
}

QString RecordCommand::script()
{
	kDebug() << "script()";
	QString dirName = _collectionpath + QDir::separator() + _titel;

	QString cmd = _program;
	cmd += " \"" + _type + "://"+ _channel + "\"";
	cmd += " -ovc " + _ovc;
	cmd += " -oac " + _oac;
	cmd += " -endpos " + _duration.toString("hh:mm:ss");
	cmd += " -of " + _of;
	cmd += " -o \"" + dirName;
	cmd += QDir::separator() + _channel;
	cmd += "_`/bin/date +%a_%d.%b.%G_%H%M%S`." + _suffix;
	cmd += "\"";

	QDir* dir = new QDir(dirName);
	if (!dir->exists()) {
		dir->mkpath(dirName);
	}
	delete dir;
	return cmd;
}

QString RecordCommand::url()
{
	return KStandardDirs::locateLocal("tmp", "kalvatv_fifo." + _suffix);
}

}