From 2b8a5738caf414cd43c011f85a4919fb1323d623 Mon Sep 17 00:00:00 2001 From: Chris Pinkham Date: Sat, 15 Jun 2013 01:42:08 -0700 Subject: [PATCH] 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. --- .../programs/mythutil/commandlineparser.cpp | 6 +++- mythtv/programs/mythutil/fileutils.cpp | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mythtv/programs/mythutil/commandlineparser.cpp b/mythtv/programs/mythutil/commandlineparser.cpp index 0c7cc0c0962..13d71cc8ed2 100644 --- a/mythtv/programs/mythutil/commandlineparser.cpp +++ b/mythtv/programs/mythutil/commandlineparser.cpp @@ -13,7 +13,11 @@ void MythUtilCommandLineParser::LoadArguments(void) CommandLineArg::AllowOneOf( QList() // 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") diff --git a/mythtv/programs/mythutil/fileutils.cpp b/mythtv/programs/mythutil/fileutils.cpp index cba79d7b2b4..ef2caae1baa 100644 --- a/mythtv/programs/mythutil/fileutils.cpp +++ b/mythtv/programs/mythutil/fileutils.cpp @@ -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: */