Example #1
0
def autorotate(path):
    if path.split('.')[-1].lower() not in ('jpg', 'jpeg'):
        return False

    output = check_output(['jhead', encode_path(path)], stderr=STDOUT).splitlines()
    rotated = False
    for line in output:
        if line.startswith('Orientation'):
            rotated = True
            break

    if not rotated: return False

    copy(path, path + '.original')
    print check_output(['jhead', '-autorot', encode_path(path)])

    return path + '.original'
Example #2
0
 def upload(self, path, album_id, length=None, md5=None, hidden=False, options={}):
     # path = encode_path(path)
     if length is None or md5 is None:
         contents = open(encode_path(path), "rb").read()
         length = len(contents)
         md5 = hashlib.md5(contents).hexdigest()
     # args = {'Content-Length': length,
     #         'Content-MD5': md5,
     #         'X-Smug-SessionID': self.session,
     #         'X-Smug-Version': API_VERSION,
     #         'X-Smug-ResponseType': 'JSON',
     #         'X-Smug-AlbumID': album_id,
     #         'X-Smug-FileName': os.path.basename(path) }
     filename = os.path.basename(path)
     if any(ord(ch) >= 128 for ch in filename):
         ascii = filename.encode("ascii", "ignore")
         name_portion = ".".join(ascii.split(".")[:-1])
         ext = ascii.split(".")[-1]
         filename = "-".join(["escaped", name_portion, md5[:10]]) + "." + ext
         logging.info("Filename is not ASCII: replacing with md5 %s ..", filename)
     args = {
         "Content-Length": length,
         "Content-MD5": md5,
         "X-Smug-SessionID": self.session,
         "X-Smug-Version": API_VERSION,
         "X-Smug-ResponseType": "JSON",
         "X-Smug-AlbumID": album_id,
         "X-Smug-FileName": filename,
         # 'Content-Type': 'multipart/form-data'
     }
     args.update(options)
     if hidden:
         args["X-Smug-Hidden"] = "true"
     ret = requests.post(UPLOAD_URL, headers=args, files={"file": (filename, open(encode_path(path), "rb"))})
     ret.encoding = "utf-8"
     print ret.text
     return ret.json()