Browse Source

Added WorkingIcon (yell0), implemented EXIF stripping and rotation of muh pics, cleaned up plist and added envvar bs (PYTHONPATH etc) =]]

Wazakindjes 3 years ago
parent
commit
ed7a394aca
5 changed files with 81 additions and 17 deletions
  1. 6 3
      README.md
  2. 17 8
      com.jemoeder.lief.hurr.droppert.plist
  3. 3 0
      hurr.conf.example
  4. 55 6
      hurr.py
  5. BIN
      icinz/WorkingIcon.png

+ 6 - 3
README.md

@@ -3,12 +3,13 @@ This shit is a premium self-hosted image uploader thingy based on SFTP, written
 
 It connects to yo server over SSH and dumps the scrot, then copies a URL to ur clipb0ardins. =] You can monitor up to 3 directories (fully configurable), which you could use for the default scrot location (normally `~/Desktop`), some remote/networked dir and Dropbox/Camera Uploads or some shit. It werks by checking file differences in those dirs and uploads everything that matches the regex in the config.
 
-Furthermore, it supports archiving your pics so the main directory doesn't get cluttered af.
+Furthermore, it supports archiving your pics so the main directory doesn't get cluttered af as well as strippin' of EXIF tags (and rotating pics w/ EXIF orientation tags y0). ;]
 
 # Dependencies
 Be sure to install the following libs (either `pip install` or `easy_install` should werks):
 * gntp -- Growl notifier shit
 * paramiko -- SSH/SFTP bs
+* PIL/Pillow -- Python Image Library to rotate images w/ EXIF orientation tags ;]
 * pyperclip -- clipboard hecks lol
 
 Also, it requires the following:
@@ -19,7 +20,9 @@ Also, it requires the following:
 # Installation
 Copy `hurr.conf.example` to `hurr.conf` and fire up een editor. All the options are explained in there so git to reading fam.
 
-After that change the contents of the `com.jemoeder.lief.hurr.droppert.plist` file, namely the line that says `<string>/Users/[user]/[dir]/hurr.py</string>`. Then just copy it to `~/Library/LaunchAgents` and run `./load`. This makes sure it gets restarted after you reboot or logout and in again. Also it has a keepalive flag so if it died it'll be restarted. ;3
+After that change the contents of the `com.jemoeder.lief.hurr.droppert.plist` file, namely the line that says `<string>/Users/[user]/[dir]/hurr.py</string>`. Then just copy it to `~/Library/LaunchAgents` and run `./load`. This makes sure it gets restarted after you reboot or log out and in again. Also it has a keepalive flag so if it died it'll be restarted. ;3
+
+Depending on your setup, you may also need the `EnvironmentVariables` key in the plist file (in my case `launchctl` wouldn't import `PIL` lmao). Just remove the `<!-- -->` shit and ur gucci mane. Don't forget to `./reload` if you already l0aded em before doing dis.
 
 # Hurrrr pls halp it's br0ke
-Simply `./unload` that shit and do `./hurr.py` in a terminal, Pythinz will most likely shit out some errors that will give you an idea of wats goin on. =]
+Simply `./unload` that shit and do `./hurr.py` in a terminal, Pythinz will most likely shit out some errors that will give you an idea of wats goin on. =]

+ 17 - 8
com.jemoeder.lief.hurr.droppert.plist

@@ -1,12 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
 <plist version="1.0">
-  <dict>
-      <key>Label</key>
-      <string>com.jemoeder.lief.hurr.droppert.plist</string>
-      <key>Program</key>
-      <string>/Users/[user]/[dir]/hurr.py</string>
-      <key>KeepAlive</key>
-      <true/>
-    </dict>
+	<dict>
+		<key>Label</key>
+		<string>com.jemoeder.lief.hurr.droppert.plist</string>
+
+		<key>Program</key>
+		<string>/Users/[user]/[dir]/hurr.py</string>
+
+		<key>KeepAlive</key>
+		<true/>
+
+		<!-- YOU MAY NOT NEED THIS LOL
+		<key>EnvironmentVariables</key>
+		<dict>
+			<key>PYTHONPATH</key>
+			<string>/usr/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/dist-packages</string>
+		</dict>-->
+	</dict>
 </plist>

+ 3 - 0
hurr.conf.example

@@ -24,6 +24,9 @@ scrotdir = ~/Desktop
 # Use this pattern (yay regex), it's case omsensativ by default
 scrotpattern = Screen ?Shot(?: \d+-\d+-\d+ at \d+\.\d+\.\d+ )?.*\.(png|jpe?g|gif)
 
+# Strip EXIF tags (also rotates that shit if necessary)
+fuckexif = 1
+
 
 ### Auth lol
 [auth]

+ 55 - 6
hurr.py

@@ -12,6 +12,7 @@ import sys
 import threading
 import time
 import urllib2
+from PIL import Image, ExifTags
 
 OLDFILES = OLDFILES_ALT = OLDFILES_DB = []
 SKIPPEM = SKIPPEM_ALT = SKIPPEM_DB = False
@@ -36,7 +37,8 @@ MUHCONF = {
 	'scrotdir_alt': '',
 	'scrotpattern_alt': '',
 	'scrotdir_db': '',
-	'scrotpattern_db': ''
+	'scrotpattern_db': '',
+	'fuckexif': None,
 }
 
 def getscrots():
@@ -87,7 +89,7 @@ def getscrots_db():
 		SKIPPEM_DB = True
 		return []
 
-def growlnotif(ID, errorid=None, errormsg=None):
+def growlnotif(ID, errorid=None, errormsg=None, desc=None):
 	global GROWL, MUHCONF
 	growlnaem = MUHCONF['growlname']
 	icondir = MUHCONF['icondir']
@@ -115,8 +117,55 @@ def growlnotif(ID, errorid=None, errormsg=None):
 			icon=open('%s/ErrorIcon.png' % icondir, 'rb').read()
 		)
 
+	elif ID == 3:
+		GROWL.notify(
+			noteType='Working',
+			title=growlnaem,
+			description=desc,
+			icon=open('%s/WorkingIcon.png' % icondir, 'rb').read()
+		)
+
 def upload(local, remote):
 	global AMOUNT, MUHCONF
+
+	if MUHCONF['fuckexif'] == True:
+		try:
+			image_exif = Image.open(local)
+			exif = dict(image_exif._getexif().items())
+			found_orient = False
+
+			growlnotif(3, desc="Stripping EXIF data")
+			for oi in ExifTags.TAGS.keys():
+				if ExifTags.TAGS[oi] == 'Orientation':
+					found_orient = True
+					break
+
+			if found_orient == True and exif[oi] != 1:
+				growlnotif(3, desc="Rotating image from EXIF orientation tag first tho lol")
+
+				orientation = exif[oi]
+				if orientation is 6:
+					image_exif = image_exif.rotate(-90, expand=True)
+				elif orientation is 8:
+					image_exif = image_exif.rotate(90, expand=True)
+				elif orientation is 3:
+					image_exif = image_exif.rotate(180, expand=True)
+				elif orientation is 2:
+					image_exif = image_exif.transpose(Image.FLIP_LEFT_RIGHT)
+				elif orientation is 5:
+					image_exif = image_exif.rotate(-90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
+				elif orientation is 7:
+					image_exif = image_exif.rotate(90, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
+				elif orientation is 4:
+					image_exif = image_exif.rotate(180, expand=True).transpose(Image.FLIP_LEFT_RIGHT)
+
+			image_exif.save(local, exif="")
+			image_exif.close()
+
+		except Exception as e:
+			pass
+
+	growlnotif(0)
 	try:
 		SSH.connect(MUHCONF['server'], username=MUHCONF['joeser'], key_filename="%s/%s" % (MUHCONF['sshdir'], MUHCONF['sshkey']));
 		sftp = SSH.open_sftp()
@@ -159,7 +208,6 @@ def main(path):
 
 	if path != None:
 		remotefile = ''.join([random.choice(string.ascii_letters + string.digits + '-_') for c in range(8)]) + os.path.splitext(path)[1]
-		growlnotif(0)
 		if upload(path, remotefile) == 0:
 			growlnotif(1)
 		if path.startswith("/tmp/"):
@@ -198,7 +246,6 @@ def runUpload(newfiles, basepath):
 		for file in newfiles:
 			path = '%s/%s' % (basepath, file)
 			remotefile = ''.join([random.choice(string.ascii_letters + string.digits + '-_') for c in range(8)]) + (os.path.splitext(file)[1])
-			growlnotif(0)
 			print "Uploading %s to %s" % (path, remotefile)
 			if upload(path, remotefile) == 0:
 				growlnotif(1)
@@ -228,6 +275,8 @@ if __name__ == "__main__":
 					cval = None
 					if copt in ["archivecount", "archivewait", "archivetime"]:
 						cval = Config.getint(csect, copt)
+					elif copt in ["fuckexif"]:
+						cval = Config.getboolean(csect, copt)
 					else:
 						cval = (Config.get(csect, copt)).strip();
 						if cval in MUHCONF.keys():
@@ -278,8 +327,8 @@ if __name__ == "__main__":
 	print "Setting up Growl"
 	GROWL = gntp.notifier.GrowlNotifier(
 		applicationName = MUHCONF['growlname'],
-		notifications = ['Uploading', 'Complete', 'Error'],
-		defaultNotifications = ['Uploading', 'Complete', 'Error']
+		notifications = ['Uploading', 'Complete', 'Error', 'Working'],
+		defaultNotifications = ['Uploading', 'Complete', 'Error', 'Working']
 	)
 	GROWL.register()
 

BIN
icinz/WorkingIcon.png