Skip to content

Commit

Permalink
Add a --download option to mythutil.
Browse files Browse the repository at this point in the history
"--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 2b8a573
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mythtv/programs/mythutil/commandlineparser.cpp
Expand Up @@ -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")

Expand Down
35 changes: 35 additions & 0 deletions mythtv/programs/mythutil/fileutils.cpp
Expand Up @@ -2,6 +2,7 @@
#include "exitcodes.h"
#include "mythlogging.h"
#include "ringbuffer.h"
#include "mythdownloadmanager.h"

// local headers
#include "fileutils.h"
Expand Down Expand Up @@ -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.