From 2b8918dd7cffc584077cf886ba7a70cbaa1ad6cd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 25 Aug 2014 22:37:46 +0200 Subject: [PATCH 1/6] Return proper date type. --- scanner/PhotoAlbum.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index aeb3087..fffe4ac 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -306,14 +306,19 @@ class Photo(object): return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes] @property def date(self): + correct_date = None; if not self.is_valid: - return datetime(1900, 1, 1) + correct_date = datetime(1900, 1, 1) if "dateTimeOriginal" in self._attributes: - return self._attributes["dateTimeOriginal"] + correct_date = self._attributes["dateTimeOriginal"] elif "dateTime" in self._attributes: - return self._attributes["dateTime"] + correct_date = self._attributes["dateTime"] else: - return self._attributes["dateTimeFile"] + correct_date = self._attributes["dateTimeFile"] + if isinstance(correct_date, unicode): + correct_date = datetime.strptime(correct_date, '%Y:%m:%d %H:%M:%S') + return correct_date + def __cmp__(self, other): date_compare = cmp(self.date, other.date) if date_compare == 0: From 7d2528280beff38779afae1503ab5ad3cf6a5cbf Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 19 Jan 2015 13:08:45 +0100 Subject: [PATCH 2/6] Python unicode is awful --- scanner/PhotoAlbum.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index fffe4ac..d6e14c4 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -145,9 +145,9 @@ class Photo(object): exif = {} for tag, value in info.items(): decoded = TAGS.get(tag, tag) - if isinstance(value, str): + if isinstance(value, str) or isinstance(value, unicode): value = value.strip().partition("\x00")[0] - if isinstance(decoded, str) and decoded.startswith("DateTime"): + if (isinstance(decoded, str) or isinstance(value, unicode)) and decoded.startswith("DateTime"): try: value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S') except KeyboardInterrupt: @@ -315,8 +315,6 @@ class Photo(object): correct_date = self._attributes["dateTime"] else: correct_date = self._attributes["dateTimeFile"] - if isinstance(correct_date, unicode): - correct_date = datetime.strptime(correct_date, '%Y:%m:%d %H:%M:%S') return correct_date def __cmp__(self, other): From 61aabc7ee2b798365a62e0f1803a4f730fb64124 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 25 Jan 2015 14:19:38 +0100 Subject: [PATCH 3/6] Copy and paste error --- scanner/PhotoAlbum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index d6e14c4..8e09554 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -147,7 +147,7 @@ class Photo(object): decoded = TAGS.get(tag, tag) if isinstance(value, str) or isinstance(value, unicode): value = value.strip().partition("\x00")[0] - if (isinstance(decoded, str) or isinstance(value, unicode)) and decoded.startswith("DateTime"): + if (isinstance(decoded, str) or isinstance(decoded, unicode)) and decoded.startswith("DateTime"): try: value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S') except KeyboardInterrupt: From 8956a6c9a5a08cbebd418da1019d625ae3ac1bb6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 27 Jan 2015 14:25:06 +0100 Subject: [PATCH 4/6] Don't prefix root for images --- web/js/010-libphotofloat.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/js/010-libphotofloat.js b/web/js/010-libphotofloat.js index 0a84014..f8a1107 100644 --- a/web/js/010-libphotofloat.js +++ b/web/js/010-libphotofloat.js @@ -137,12 +137,15 @@ return PhotoFloat.cachePath(album.parent.path + "/" + album.path); }; PhotoFloat.photoPath = function(album, photo, size, square) { - var suffix; + var suffix, hash; if (square) suffix = size.toString() + "s"; else suffix = size.toString(); - return "cache/" + PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg"); + hash = PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg"); + if (hash.indexOf("root-") === 0) + hash = hash.substring(5); + return "cache/" + hash; }; PhotoFloat.originalPhotoPath = function(album, photo) { return "albums/" + album.path + "/" + photo.name; From 148b88951d49ffdcd1a8e47e0b8b44a18f2f718a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 27 Jan 2015 14:39:44 +0100 Subject: [PATCH 5/6] Don't deal with invalid unicode --- scanner/TreeWalker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scanner/TreeWalker.py b/scanner/TreeWalker.py index 191b187..f52873b 100644 --- a/scanner/TreeWalker.py +++ b/scanner/TreeWalker.py @@ -49,7 +49,10 @@ class TreeWalker: except KeyboardInterrupt: raise except: - pass + next_level() + message("unicode error", entry.decode(sys.getfilesystemencoding(), "replace")) + back_level() + continue entry = os.path.join(path, entry) if os.path.isdir(entry): album.add_album(self.walk(entry)) From 54c68be7fd20b279aec540778b57e9a017571afa Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 27 Jan 2015 15:18:27 +0100 Subject: [PATCH 6/6] Don't crash when unable to unlink --- scanner/PhotoAlbum.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index 8e09554..437687e 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -262,11 +262,17 @@ class Photo(object): try: image.save(thumb_path, "JPEG", quality=88) except KeyboardInterrupt: - os.unlink(thumb_path) + try: + os.unlink(thumb_path) + except: + pass raise except: message("save failure", os.path.basename(thumb_path)) - os.unlink(thumb_path) + try: + os.unlink(thumb_path) + except: + pass def _thumbnails(self, image, thumb_path, original_path): mirror = image