Browse Source

Allow passing of een URL (so encoded/without spaces nikka) as "quick" CLI arg ;3

Wazakindjes 4 years ago
parent
commit
b01cc32603
1 changed files with 18 additions and 2 deletions
  1. 18 2
      hurr.py

+ 18 - 2
hurr.py

@@ -11,6 +11,7 @@ import string
 import sys
 import threading
 import time
+import urllib2
 
 OLDFILES = OLDFILES_ALT = OLDFILES_DB = []
 SKIPPEM = SKIPPEM_ALT = SKIPPEM_DB = False
@@ -161,6 +162,9 @@ def main(path):
 		growlnotif(0)
 		if upload(path, remotefile) == 0:
 			growlnotif(1)
+		if path.startswith("/tmp/"):
+			print "Cleaning up tmpfile: %s" % path
+			os.remove(path);
 		sys.exit(0)
 
 	while True:
@@ -282,12 +286,24 @@ if __name__ == "__main__":
 	print "Checking for daemon mode"
 	if len(sys.argv) > 1:
 		print "Seems to be a quick file upload, checking existence of %s" % sys.argv[1]
-		if os.path.isfile(sys.argv[1]) == False:
+		temppath = ' '.join(sys.argv[1:])
+		if temppath.startswith("https://") or temppath.startswith("http://"):
+			print "Seems to be a URL too, checkin em sanity lol"
+			try:
+				checkem = urllib2.urlopen(temppath)
+				temppath = "/tmp/%d%s" % (int(time.time()), os.path.splitext(temppath)[1])
+				with open(temppath, "wb") as tmpf:
+					tmpf.write(checkem.read())
+			except Exception as muherr:
+				print "Unable to download from URL fam: %s" % (str(muherr))
+				sys.exit(1)
+
+		elif os.path.isfile(temppath) == False:
 			print "File doesn't exist lol"
 			sys.exit(1)
 
 		print "Calling main function"
-		main(sys.argv[1])
+		main(temppath)
 	else:
 		print "Setting up threads"
 		run_event = threading.Event()