summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-11-08 14:08:34 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-11-08 14:08:34 +0100
commit64d1ded5bf1e86c896a4520626df1a7628203e16 (patch)
treee4a09731283a8147d5552f9ed1c5c78a8b43caaf
parentf16d560268134222c4f9068b63df2d4b29af714c (diff)
Handle URL arguments
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xfb.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/fb.py b/fb.py
index 6b1fd69..cc62f50 100755
--- a/fb.py
+++ b/fb.py
@@ -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)