diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-11-08 14:08:34 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-11-08 14:08:34 +0100 |
commit | 64d1ded5bf1e86c896a4520626df1a7628203e16 (patch) | |
tree | e4a09731283a8147d5552f9ed1c5c78a8b43caaf | |
parent | f16d560268134222c4f9068b63df2d4b29af714c (diff) |
Handle URL arguments
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | fb.py | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -196,6 +196,26 @@ class CURLWrapper: return result["data"] + def dl_file(self, url, path): + # TODO: this is duplicated in __init__ (well mostly) + c = pycurl.Curl() + c.setopt(c.USERAGENT, self.config['useragent']) + c.setopt(c.HTTPHEADER, [ + "Expect:", + ]) + + if self.config["debug"]: + c.setopt(c.VERBOSE, 1) + + outfp = open(path, 'wb') + try: + c.setopt(c.URL, url) + c.setopt(c.WRITEDATA, outfp) + c.perform() + finally: + outfp.close() + c.close() + class ProgressBar: def __init__(self): @@ -519,6 +539,11 @@ class FBClient: def upload(self): if self.args.tar: + for arg in self.args.args: + if re.match('https?://', arg): + sys.stderr.write("Error: --tar does not support URLs as arguments") + return + tarPath = os.path.join(self.tempdir, 'upload.tar') tar = tarfile.open(tarPath, 'w') for file in self.args.args: @@ -541,9 +566,20 @@ class FBClient: self.upload_files([tempfile]) return else: - self.upload_files(self.args.args) + # TODO: detect paste URLs and add their IDs to a multipaste + files = [self.dl_file(arg) for arg in self.args.args] + self.upload_files(files) return + def dl_file(self, arg): + if re.match('https?://', arg): + outfile = os.path.basename(arg) + self.curlw.dl_file(arg, outfile) + return outfile + + return arg + + def extractId(self, arg): arg = arg.replace(self.config['pastebin'], '') match = re.match('^([^/]+)', arg) |