diff --git a/README.md b/README.md index 137620e..00e0d7d 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,15 @@ 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. + +### 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 b8185e8..bff83c4 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'])) @@ -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 dc27928..c34d93c 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] @@ -418,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)