Permalink
Browse files

Add a --download option to mythutil.

"--download --infile URI --outfile FILENAME" will download the file
pointed to by 'URI' using MythDownloadManager and save it as 'FILENAME'.

URI is expected to use one of http://, ftp://, or myth:// protocols
since these are the only ones currently supported by MythDownloadManager.
  • Loading branch information...
cpinkham committed Jun 15, 2013
1 parent 0866fcb commit 2b8a5738caf414cd43c011f85a4919fb1323d623
Showing with 40 additions and 1 deletion.
  1. +5 −1 mythtv/programs/mythutil/commandlineparser.cpp
  2. +35 −0 mythtv/programs/mythutil/fileutils.cpp
@@ -13,7 +13,11 @@ void MythUtilCommandLineParser::LoadArguments(void)
CommandLineArg::AllowOneOf( QList<CommandLineArg*>()
// fileutils.cpp
<< add("--copyfile", "copyfile", false,
"Copy a MythTV Storage Group file", "")
"Copy a MythTV Storage Group file using RingBuffers", "")
->SetGroup("File")
->SetRequiredChild(QStringList("infile") << "outfile")
<< add("--download", "download", false,
"Download a file using MythDownloadManager", "")
->SetGroup("File")
->SetRequiredChild(QStringList("infile") << "outfile")
@@ -2,6 +2,7 @@
#include "exitcodes.h"
#include "mythlogging.h"
#include "ringbuffer.h"
#include "mythdownloadmanager.h"
// local headers
#include "fileutils.h"
@@ -108,9 +109,43 @@ static int CopyFile(const MythUtilCommandLineParser &cmdline)
return result;
}
static int DownloadFile(const MythUtilCommandLineParser &cmdline)
{
int result = GENERIC_EXIT_OK;
if (cmdline.toString("infile").isEmpty())
{
LOG(VB_GENERAL, LOG_ERR, "Missing --infile option");
return GENERIC_EXIT_INVALID_CMDLINE;
}
QString url = cmdline.toString("infile");
if (cmdline.toString("outfile").isEmpty())
{
LOG(VB_GENERAL, LOG_ERR, "Missing --outfile option");
return GENERIC_EXIT_INVALID_CMDLINE;
}
QString dest = cmdline.toString("outfile");
bool ok = GetMythDownloadManager()->download(url, dest);
if (!ok)
{
LOG(VB_GENERAL, LOG_INFO, "Error downloading file.");
result = GENERIC_EXIT_NOT_OK;
}
else
{
LOG(VB_GENERAL, LOG_INFO, "File downloaded.");
}
return result;
}
void registerFileUtils(UtilMap &utilMap)
{
utilMap["copyfile"] = &CopyFile;
utilMap["download"] = &DownloadFile;
}
/* vim: set expandtab tabstop=4 shiftwidth=4: */

0 comments on commit 2b8a573

Please sign in to comment.