Example #1
0
 def process_updated_file(self, filename, context):
     self.get_logger().error('Updated file: %s', filename)
     mime = get_mime_type(filename)
     _, ext = os.path.splitext(filename)
     if not self.is_hidden(filename):
         # Process song
         if mime in TAGGED_MIME_TYPES or ext in TAGGED_EXTENSIONS:
             song_info = get_song_info(filename, context, self.get_logger())
         elif mime in SUPPORTED_MIME_TYPES or ext in SUPPORTED_EXTENSIONS:
             song_info = extract_using_filename(filename, context, self.get_logger()).clean()
         else:
             song_info = None
         # If we got some information
         if song_info != None:
             s = Song.query.filter_by(file=filename).first()
             if s == None:
                 self.add_to_database(filename, song_info)
             else:
                 self.replace_in_database(filename, s, song_info)
Example #2
0
 def process_updated_file(self, filename, context):
     if not self.is_hidden(filename) and get_mime_type(filename).startswith("image/"):
         # Get modification time
         f = open(filename, "rb")
         tags = EXIF.process_file(f, stop_tag="DateTimeOriginal")
         if "EXIF DateTimeOriginal" in tags:
             date_as_string = tags["EXIF DateTimeOriginal"].values
             date = datetime.datetime.strptime(date_as_string, "%Y:%m:%d %H:%M:%S")
         else:
             date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
         f.close()
         # Update or write new
         photo = Photo.query.filter_by(file=filename).first()
         now = datetime.datetime.now()
         owner = get_file_owner(filename).get_username()
         shared = is_file_shared(filename)
         if photo != None:
             photo.date = date
             photo.lastModified = now
             photo.owner = owner
             photo.shared = shared
             db.session.commit()
         else:
             photo = Photo(filename, os.path.basename(filename), date, datetime.datetime.now(), owner, shared)
             db.session.add(photo)
             db.session.commit()
             # Add to album
             context_path = "/var/nublic/data/" + context[:-1]
             (parent, _basename) = os.path.split(filename)
             (p_parent, p_basename) = os.path.split(parent)
             (_p_p_parent, p_p_basename) = os.path.split(p_parent)
             if context_path == parent:
                 album = None
             elif context_path == p_parent:
                 album = p_basename
             else:
                 album = p_p_basename + "/" + p_basename
             if album != None:
                 ab = get_or_create_album(album)
                 relation = PhotoAlbum(ab.id, photo.id)
                 db.session.add(relation)
                 db.session.commit()