From 568aa02e1949f7da2fe3c6c5072d74004b3d281b Mon Sep 17 00:00:00 2001 From: Thibaut Meyer Date: Sun, 21 Oct 2018 16:06:38 +0200 Subject: [PATCH 1/2] Added functionality for album description --- README.md | 4 ++++ lycheesync/lycheedao.py | 4 ++-- lycheesync/lycheesyncer.py | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 137620e..8aec23e 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,10 @@ The resulting lychee structure will be: |_a3p1.jpg ``` +### Album description + +If a `desc.txt` file is present at the root of an album directory, its content will be the description of the album. + ### Counters diff --git a/lycheesync/lycheedao.py b/lycheesync/lycheedao.py index b8185e8..a675ffc 100644 --- a/lycheesync/lycheedao.py +++ b/lycheesync/lycheedao.py @@ -344,8 +344,8 @@ def createAlbum(self, album): cur = self.db.cursor() # logger.debug("try to createAlbum: %s", query) # duplicate of previous query to use driver quote protection features - cur.execute("insert into lychee_albums (id, title, sysstamp, public, password) values (%s,%s,%s,%s,NULL)", (album[ - 'id'], album['name'], datetime.datetime.now().strftime('%s'), str(self.conf["publicAlbum"]))) + cur.execute("insert into lychee_albums (id, title, description, sysstamp, public, password) values (%s,%s,%s,%s,%s,NULL)", (album[ + 'id'], album['name'], album['description'], datetime.datetime.now().strftime('%s'), str(self.conf["publicAlbum"]))) self.db.commit() cur.execute("select id from lychee_albums where title=%s", (album['name'])) diff --git a/lycheesync/lycheesyncer.py b/lycheesync/lycheesyncer.py index dc27928..3d9cff0 100644 --- a/lycheesync/lycheesyncer.py +++ b/lycheesync/lycheesyncer.py @@ -353,6 +353,7 @@ def sync(self): # Init album data album['id'] = None album['name'] = None + album['description'] = None album['path'] = None album['relpath'] = None # path relative to srcdir album['photos'] = [] # path relative to srcdir @@ -381,6 +382,12 @@ def sync(self): album['relpath'] = os.path.relpath(album['path'], self.conf['srcdir']) album['name'] = self.getAlbumNameFromPath(album) + # check for desc.txt file existence + if (os.path.exists(album['path']+"/desc.txt")): + fp = open(album['path']+"/desc.txt", "r") + album['description'] = fp.read() + fp.close() + if len(album['name']) > album_name_max_width: logger.warn("album name too long, will be truncated " + album['name']) album['name'] = album['name'][0:album_name_max_width] From e0a191259c80c5f78aeee19d9a464ea4d9d39d90 Mon Sep 17 00:00:00 2001 From: Thibaut Meyer Date: Sun, 28 Oct 2018 21:18:18 +0100 Subject: [PATCH 2/2] Added functionality for picture tags --- README.md | 5 +++++ lycheesync/lycheedao.py | 6 +++--- lycheesync/lycheemodel.py | 5 +++-- lycheesync/lycheesyncer.py | 8 +++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8aec23e..00e0d7d 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,11 @@ The resulting lychee structure will be: If a `desc.txt` file is present at the root of an album directory, its content will be the description of the album. +### Photo tags + +If a `.txt` file that has the same name as the picture is present in its folder, its content is going to be interpreted as tags for the pictures. The expected format is as following : +`tag1, tag2, tag3` + ### Counters diff --git a/lycheesync/lycheedao.py b/lycheesync/lycheedao.py index a675ffc..bff83c4 100644 --- a/lycheesync/lycheedao.py +++ b/lycheesync/lycheedao.py @@ -490,7 +490,7 @@ def addFileToAlbum(self, photo): "(id, url, " + "public, type, " + "width, height, " + - "size, star, " + + "size, star, tags, " + "thumbUrl, album, " + "iso, aperture, make, " + "model, shutter, focal, " + @@ -500,7 +500,7 @@ def addFileToAlbum(self, photo): "({}, '{}', " + "{}, '{}', " + "{}, {}, " + - "'{}', {}, " + + "'{}', {}, '{}', " + "'{}', '{}', " + "'{}', '{}', '{}', " + "'{}', '{}', '{}', " + @@ -509,7 +509,7 @@ def addFileToAlbum(self, photo): ).format(photo.id, photo.url, self.conf["publicAlbum"], photo.type, photo.width, photo.height, - photo.size, photo.star, + photo.size, photo.star, photo.tags, photo.thumbUrl, photo.albumid, photo.exif.iso, photo.exif.aperture, photo.exif.make, photo.exif.model, photo.exif.exposure, photo.exif.focal, diff --git a/lycheesync/lycheemodel.py b/lycheesync/lycheemodel.py index d3836a8..824fa27 100644 --- a/lycheesync/lycheemodel.py +++ b/lycheesync/lycheemodel.py @@ -78,6 +78,7 @@ class LycheePhoto: height = 0 size = "" star = 0 # no star by default + tags = "" thumbUrl = "" srcfullpath = "" destfullpath = "" @@ -129,7 +130,7 @@ def __generateHash(self): sha1.update(f.read()) self.checksum = sha1.hexdigest() - def __init__(self, id, conf, photoname, album): + def __init__(self, id, conf, photoname, album, tags): # Parameters storage self.conf = conf self.id = id @@ -137,6 +138,7 @@ def __init__(self, id, conf, photoname, album): self.originalpath = album['path'] self.albumid = album['id'] self.albumname = album['name'] + self.tags = tags # if star in file name, photo is starred if ('star' in self.originalname) or ('cover' in self.originalname): @@ -240,7 +242,6 @@ def __init__(self, id, conf, photoname, album): logger.exception("focal not readable for %s", self.srcfullpath) if decode == "ISOSpeedRatings": - try: if isinstance(value, tuple): self.exif.iso = list(value)[0] diff --git a/lycheesync/lycheesyncer.py b/lycheesync/lycheesyncer.py index 3d9cff0..c34d93c 100644 --- a/lycheesync/lycheesyncer.py +++ b/lycheesync/lycheesyncer.py @@ -425,9 +425,15 @@ def sync(self): logger.info("**** Adding %s to lychee album: %s", os.path.join(root, f), album['name']) + # check if tags are stored for a given photo + tags = "" + if os.path.isfile(os.path.join(root, os.path.splitext(f)[0] + ".txt")): + fp = open(os.path.join(root, os.path.splitext(f)[0] + ".txt"), "r") + tags = fp.read() + fp.close() # corruption detected here by launching exception pid = self.dao.getUniqPhotoId() - photo = LycheePhoto(pid, self.conf, f, album) + photo = LycheePhoto(pid, self.conf, f, album, tags) if not(self.dao.photoExists(photo)): res = self.copyFileToLychee(photo) self.adjustRotation(photo)