Example #1
0
    def merge(self):

        remote = self.album.item(self.filename)
        if remote is None \
            or self.filename != remote.filename \
            or self.filetype != remote.filetype:

            # print(self.filetype + ' ' + self.fullpath + ' not found or cannot be merged with ' + str(remote))
            return False

        if self.modified is not None and self.modified / 1000 > remote.modified / 1000:
            print(self.filetype + ' ' + self.fullpath + ' timestamp differs, replacing existing ' + str(remote) + ' with ' + str(self))
            return False

        if self.filesize is not None and self.filesize != remote.filesize:
            print(self.filetype + ' ' + self.fullpath + ' filesize differs, replacing existing ' + str(remote) + ' with ' + str(self))
            return False

        changes = {}
        if self.title and self.title != remote.title:
            changes['title'] = self.title
        if self.description and self.description != remote.description:
            changes['description'] = self.description
        if self.rating is not None and self.rating != remote.rating:
            changes['rating'] = self.rating
        if not PhotoStationUtils.check_coordinates(self.latitude, remote.latitude):
            changes['gps_lat'] = self.latitude
        if not PhotoStationUtils.check_coordinates(self.longitude, remote.longitude):
            changes['gps_lng'] = self.longitude

        if len(changes) > 0:
            print(self.filetype + ' ' + self.fullpath +  ' has metadata changes ' + str(changes) + ', updating existing ' + str(remote))
            self.update(changes)

        return True
Example #2
0
 def delete(self):
     PhotoStationService.session.query('SYNO.PhotoStation.Photo', {
         'id': PhotoStationUtils.photo_id(self.filetype, self.album.path, self.filename),
         'method': 'delete',
         'ps_username': PhotoStationService.session.username
         })
     self.album.remove_item(self.filename)
Example #3
0
 def delete(self):
     PhotoStationService.session.query('SYNO.PhotoStation.Album', {
         'id': PhotoStationUtils.album_id(self.path),
         'method': 'delete',
         'ps_username': PhotoStationService.session.username
         })
     self.parent.remove_item(self.name)
Example #4
0
    def items(self):
        if not self._items:
            items = PhotoStationService.session.query(
                'SYNO.PhotoStation.Album', {
                    'method':
                    'list',
                    'id':
                    PhotoStationUtils.album_id(self.path),
                    'type':
                    'album,photo,video',
                    'offset':
                    0,
                    'limit':
                    -1,
                    'recursive':
                    'false',
                    'additional':
                    'album_permission,photo_exif,video_codec,video_quality,thumb_size,file_location'
                })

            self._items = {}
            for item in items['items']:
                if item['type'] == 'album':
                    album = PhotoStationAlbum.from_photostation(self, item)

                    self.add_item(album.name, album)
                else:
                    photo = PhotoStationPhoto.from_photostation(self, item)
                    self.add_item(photo.filename, photo)

        return self._items
Example #5
0
 def update(self, changes):
     data = {
         'id': PhotoStationUtils.photo_id(self.filetype, self.album.path, self.filename),
         'method': 'edit',
         'ps_username': PhotoStationService.session.username
         }
     data.update(changes)
     PhotoStationService.session.query('SYNO.PhotoStation.Photo', data)
Example #6
0
 def create(self, name):
     PhotoStationService.session.query('SYNO.PhotoStation.Album', {
         'name': name,
         'title': '',
         'description': '',
         'id': PhotoStationUtils.album_id(self.path),
         'method': 'create',
         'ps_username': PhotoStationService.session.username
         })
     album = PhotoStationAlbum(self, name)
     self.add_item(name, album)
     return album
Example #7
0
    def from_photostation(cls, album, psphoto):
        info = psphoto['info']

        created = PhotoStationUtils.ymdhms_to_timestamp_utc(info['takendate']) * 1000
        modified = PhotoStationUtils.ymdhms_to_timestamp_utc(info['createdate']) * 1000
        filesize = int(info['size'])

        if info.get('gps') is not None:
            latitude = info['gps']['lat']
            longitude = info['gps']['lng']
        else:
            latitude = longitude = None

        return cls(album, 
            filename = PhotoStationUtils.photo_name(psphoto['id']),
            filetype = psphoto['type'],
            created = created,
            modified = modified,
            filesize = filesize,
            title = info['title'].encode('utf-8'),
            description = info['description'].encode('utf-8'),
            rating = info['rating'],
            latitude = latitude,
            longitude = longitude)
Example #8
0
    def from_photostation(cls, album, psphoto):
        info = psphoto['info']

        created = int(
            time.mktime(time.strptime(info['takendate'],
                                      '%Y-%m-%d %H:%M:%S'))) * 1000
        modified = int(
            time.mktime(time.strptime(info['createdate'],
                                      '%Y-%m-%d %H:%M:%S'))) * 1000
        filesize = int(info['size'])

        if info.get('gps') is not None:
            latitude = info['gps']['lat']
            longitude = info['gps']['lng']
        else:
            latitude = longitude = None

        photoid = psphoto.get('id')
        thumbnail_sig = ''
        thumbnail_size = {}
        try:
            thumbnail_status = psphoto.get('thumbnail_status')
            thumbnail_status = thumbnail_status.split(',')
            thumb_size = psphoto.get('additional').get('thumb_size')
            thumbnail_sig = thumb_size.get('sig')
            for x in thumbnail_status:
                thumbnail_size[x] = thumb_size.get(x)
        except:
            pass

        return cls(album=album,
                   photoid=photoid,
                   filename=PhotoStationUtils.photo_name(psphoto['id']),
                   filetype=psphoto['type'],
                   created=created,
                   modified=modified,
                   filesize=filesize,
                   title=info['title'].encode('utf-8'),
                   description=info['description'].encode('utf-8'),
                   rating=info['rating'],
                   latitude=latitude,
                   longitude=longitude,
                   thumbnail_sig=thumbnail_sig,
                   thumbnail_sizes=thumbnail_size)
Example #9
0
    def find_items(self, tags, recursive=True):

        items_raw = PhotoStationService.session.query('SYNO.PhotoStation.Album', {
            'method': 'list',
            'id': PhotoStationUtils.album_id(self.path),
            'type': 'album,photo,video',
            'offset': 0, 
            'limit': -1,
            'recursive': recursive,
            'desc_tag' : ','.join(x.id for x in tags)
            })

        items = {}
        for item in items_raw['items']:
            if item['type'] == 'album':
                album = PhotoStationAlbum.from_photostation(self, item)
                items[album.name] = album
            else:
                photo = PhotoStationPhoto.from_photostation(self, item)
                items[photo.filename] = photo

        return items
Example #10
0
    def from_photostation(cls, parent, psalbum):
        album_path = PhotoStationUtils.album_path(psalbum['id'])
        name = album_path.replace(parent.path + '/', '')

        return cls(parent, name)
Example #11
0
 def id(self):
     return PhotoStationUtils.photo_id(self.filetype, self.album.path, self.filename)