Exemple #1
0
 def _load_metadata(self):
     """Try to load metadata from the actual file"""
     try:
         width, height, author, soft, date_taken = _return_tuple(0, 5)
         info = kaa.metadata.parse(self.__str__())
         if info is not None:
             if info.width is not None:
                 width = info.width
             if info.height is not None:
                 height = info.height
             if info.author is not None:
                 author = info.author
             elif info.artist is not None:
                 author = info.author
             if info.software is not None:
                 soft = info.software
             if info.timestamp is not None:
                 date_taken = datetime.datetime.fromtimestamp\
                                 (info.timestamp).strftime\
                                 ("%Y/%m/%d %H:%M:%S")
     except Exception, exc:
         if SETTINGS.metadataerror is True:
             MANAGER.append_event("Error loading image metadata",
                                  self.__str__(), exc, 3)
         print "Error occurred loading image metadata: " + self.__str__()
         print exc
Exemple #2
0
 def __init__(self, parent, name, relpath, mimetype, atime, mtime, size,
              strsize):
     super(Photo, self).__init__(parent, name, relpath, mimetype, atime,
                                 mtime, size=size, strsize=strsize)
     try:
         self._icon = \
         gtk.gdk.pixbuf_new_from_file_at_size(self._parent + SEPARATOR +
                                              self._name,
                                              SETTINGS.thumblistsize,
                                              SETTINGS.thumblistsize)
         self._thumb = \
         gtk.gdk.pixbuf_new_from_file_at_size(self._parent + SEPARATOR + \
                                              self._name,
                                              SETTINGS.thumbpanesize,
                                              SETTINGS.thumbpanesize)
         self._hasthumb = True
     except Exception as exc:
         if SETTINGS.thumberror is True:
             MANAGER.append_event("Error loading thumbnail",
                                  self.__str__(), exc, 5)
         self.parse_icon()
     #Try loading image metadata
     self._res, self._date_taken, self._author, self._soft, \
         self._date_taken = _return_tuple(NO_INFO, 5)
     if NO_KAA is not True:
         self._load_metadata()
Exemple #3
0
    def _append(self, object, datum):
        data = datum['data']
        piter = datum['piter']
        MANAGER.append_event(piter, '', '', 1)
        iter = self._tsdirtree.append(piter, data)
        path = self._tsdirtree.get_path(iter)

        self._pconn.send(path)
Exemple #4
0
 def _get_audio_metadata(self, audio):
     """Try to load metadata from the actual file"""
     audio.bitrate, audio.codec, audio.length, \
     audio.samplerate = _return_tuple(NO_INFO, 4)
     length, samplerate, bitrate, codec = _return_tuple(0, 4)
     try:
         info = kaa.metadata.parse(audio.__str__())
         if info is not None:
             if hasattr(info, "length") and info.length is not None:
                 length = str(int(info.length / 60)) + ":" + \
                             str(int(info.length % 60)).zfill(2)
             elif hasattr(info, "audio"):
                 if (info.audio[0]) is not None and \
                 hasattr(info.audio[0], "length") and \
                 info.audio[0].length is not None:
                     length = str(int(info.audio[0].length / 60)) + ":" + \
                                 str(int(info.audio[0].length % 60))\
                                 .zfill(2)
             if hasattr(info, "bitrate") and info.bitrate is not None:
                 bitrate = str(info.bitrate) + " Kbps"
             elif hasattr(info, "audio"):
                 if (info.audio[0]) is not None and \
                 hasattr(info.audio[0], "bitrate") and \
                 info.audio[0].bitrate is not None:
                     bitrate = str(info.audio[0].bitrate) + " Kbps"
             if hasattr(info, "samplerate")\
             and info.samplerate is not None:
                 samplerate = str(info.samplerate / 1000) + " KHz"
             elif hasattr(info, "audio"):
                 if (info.audio[0]) is not None and \
                 hasattr(info.audio[0], "samplerate") and \
                 info.audio[0].samplerate is not None:
                     samplerate = str(info.audio[0].samplerate
                                      / 1000) + " KHz"
             if hasattr(info, "codec") and info.codec is not None:
                 codec = info.codec
             elif hasattr(info, "audio"):
                 if (info.audio[0]) is not None and \
                 hasattr(info.audio[0], "codec") and \
                 info.audio[0].codec is not None:
                     codec = info.audio[0].codec
     except Exception as exc:
         if SETTINGS.metadataerror is True:
             MANAGER.append_event("Error loading audio metadata",
                                  self.__str__(), exc, 3)
         print "Error loading audio metadata: " + audio.__str__()
         print exc
     if length != 0:
         audio.length = length
     if samplerate != 0:
         audio.samplerate = samplerate
     if bitrate != 0:
         audio.bitrate = bitrate
     if codec != 0:
         audio.codec = codec
Exemple #5
0
 def parse_icon(self):
     """Method used when reading from binary file."""
     try:
         self._icon = gtk.icon_theme_get_default().\
             load_icon(ICONS[MIMES[self._mimetype]], SETTINGS.iconlistsize,
                     gtk.ICON_LOOKUP_FORCE_SVG)
     except Exception as exc:
         if SETTINGS.missingicon is True:
             MANAGER.append_event("Error loading icon for mimetype: " +
                                  self._mimetype, self.__str__(), exc, 4)
     if self._icon == None:
         self._icon = gtk.icon_theme_get_default().\
         load_icon(ICONS["file"], SETTINGS.iconlistsize,
                   gtk.ICON_LOOKUP_FORCE_SVG)
Exemple #6
0
 def btnsave_clicked_cb(self, widget):
     """Shows the "Save" dialog."""
     savedialog = \
     gtk.FileChooserDialog(title="Point me a destination...",
                           parent = self._window,
                           action = gtk.FILE_CHOOSER_ACTION_SAVE,
                           buttons = (gtk.STOCK_CANCEL,
                                      gtk.RESPONSE_CANCEL,
                                      gtk.STOCK_OK, gtk.RESPONSE_OK))
     plainfilter = gtk.FileFilter()
     plainfilter.add_mime_type("text/plain")
     plainfilter.set_name("Plain text")
     savedialog.add_filter(plainfilter)
     savedialog.set_do_overwrite_confirmation(True)
     response = savedialog.run()
     if response == gtk.RESPONSE_OK:
         MANAGER.save_to_disk(savedialog.get_filename())
     savedialog.destroy()
Exemple #7
0
 def _load_metadata(self):
     """Try to load metadata from the actual file"""
     length, videocodec, videobitrate, videores, \
     videofps, videoar, audiobitrate, audiosamplerate, \
     audiocodec, audiochannels, sublangs = _return_tuple(0, 11)
     try:
         info = kaa.metadata.parse(self.__str__())
         if info is not None:
             if hasattr(info, "length") and info.length is not None:
                 hourlength, minlength, seclength = _return_tuple(0, 3)
                 if info.length >= 60:
                     minlength = int(info.length / 60)
                     seclength = int(info.length % 60)
                     while minlength >= 60:
                         hourlength += int(minlength / 60)
                         minlength = int(minlength % 60)
                 length = str(hourlength) + ":" + str(minlength).zfill(2)\
                             + ":" + str(seclength).zfill(2)
             
             #Loading video attributes
             if hasattr(info, "video") and info.video[0] is not None:
                 video = info.video[0]
                 if hasattr(video, "codec") and video.codec is not None:
                     videocodec = str(video.codec)
                 if hasattr(video, "bitrate")\
                 and video.bitrate is not None:
                     videobitrate = str(video.bitrate) + " Kbps"
                 if hasattr(video, "aspect")\
                 and video.aspect is not None:
                     videoar = str(round(video.aspect, 2))
                 if hasattr(video, "width") and video.width is not None\
                 and hasattr(video, "height") and video.height is not None:
                     videores = str(video.width) + "x" + str(video.height)
                     if videoar == 0:
                         videoar = str(round(float(video.width)
                                             /video.height,2))
                 if hasattr(video, "fps") and video.fps is not None:
                     videofps = str(round(video.fps, 3))
             
             #Loading audio attributes
             if hasattr(info, "audio") and info.audio[0] is not None:
                 audio = info.audio[0]
                 if hasattr(audio, "codec") and audio.codec is not None:
                     audiocodec = str(audio.codec)
                 if hasattr(audio, "samplerate")\
                 and audio.samplerate is not None:
                     audiosamplerate = str(audio.samplerate / 1000) + " KHz"
                 if hasattr(audio, "bitrate")\
                 and audio.bitrate is not None:
                     audiobitrate = str(audio.bitrate)
                 if hasattr(audio, "channels")\
                 and audio.channels is not None:
                     audiochannels = str(audio.channels)
             
             #Loading subtitle attributes
             if hasattr(info, "subtitles") and len(info.subtitles) > 0:
                 sublangs = ""
                 sublangs += info.subtitles[0].language
                 if len(info.subtitles) > 1:
                     for sub in info.subtitles[1:]:
                         sublangs += ", " + sub.language
     except Exception as exc:
         if SETTINGS.metadataerror is True:
             MANAGER.append_event("Error loading video metadata", 
                                  self.__str__(), exc, 3)
         print "Error loading video metadata: " + self.__str__()
         print exc
     
     #Assigning to class variables
     if length != 0:
         self._length = length
     if videocodec != 0:
         self._videocodec = videocodec
     if videobitrate != 0:
         self._videobitrate = videobitrate
     if videores != 0:
         self._videores = videores
     if videofps != 0:
         self._videofps = videofps
     if videoar != 0:
         self._videoar = videoar
     if audiobitrate != 0:
         self._audiobitrate = audiobitrate
     if audiosamplerate != 0:
         self._audiosamplerate = audiosamplerate
     if audiocodec != 0:
         self._audiocodec = audiocodec
     if audiochannels != 0:
         self._audiochannels = audiochannels
     if sublangs != 0:
         self._sublangs = sublangs
Exemple #8
0
 def do_index_process(self, path, relpath, hroot = None):
     """The bulk of the indexing process.
     
     It is called recursively for every file and directory found, and
     appends it to the structure.
     """
     if self._stop is True:
         return None
     try:
         dirname = os.path.dirname(path)
         basename = os.path.basename(path)
         absname = dirname + SEPARATOR + basename
         relpath += SEPARATOR
         size = os.path.getsize(absname)
         size = round(size, 2)
         stat = os.stat(absname)
         atime = datetime.datetime.fromtimestamp(stat.st_atime).\
                 strftime("%Y/%m/%d %H:%M:%S")
         mtime = datetime.datetime.fromtimestamp(stat.st_mtime).\
                 strftime("%Y/%m/%d %H:%M:%S")
         root = self._factory.new_dir(dirname, basename, relpath, atime,
                                      mtime, hroot, size,
                                      self.parse_size(size), absname)
         ldir = os.listdir(path)
         ldir.sort(cmp = lambda x, y: cmp(x.lower(), y.lower()))
         if SETTINGS.gnuhidden is True:
             self.hidden_linux_filter(ldir)
         if SETTINGS.savebackup is True:
             self.save_backup_linux_filter(ldir)
         relpath += basename
         for entry in ldir:
             if self._stop is True:
                 return None
             try:
                 rpath = relpath + SEPARATOR
                 self.last = path + SEPARATOR + entry
                 if os.path.isfile(path + SEPARATOR + entry):
                     atime = datetime.datetime.fromtimestamp\
                             (os.path.getatime(path + SEPARATOR + entry)
                              ).strftime("%Y/%m/%d %H:%M:%S")
                     mtime = datetime.datetime.fromtimestamp\
                     (os.path.getmtime(path + SEPARATOR + entry)
                      ).strftime("%Y/%m/%d %H:%M:%S")
                     mimetype = mimetypes.guess_type(path + SEPARATOR
                                                     + entry, False)
                     size = os.path.getsize(root.__str__() + SEPARATOR
                                            + entry)
                     size = round(size, 2)
                     if (mimetype[0] is not None and MIMES[mimetype[0]]
                         == "image"):
                         _file = self._factory.\
                                 new_photo(root.parent + SEPARATOR +
                                           root.name, entry, rpath,
                                           mimetype, atime, mtime, root,
                                           size, self.parse_size(size),
                                           self.last)
                     elif (mimetype[0] is not None and MIMES[mimetype[0]]
                           == "audio" and not mimetype[0] in NOT_AUDIO):
                         _file = self._factory.\
                                 new_audio(root.parent + SEPARATOR +
                                           root.name, entry, rpath,
                                           mimetype, atime, mtime, root,
                                           size, self.parse_size(size),
                                           self.last)
                     elif (mimetype[0] is not None and MIMES[mimetype[0]]
                           == "video"):
                         _file = self._factory.\
                                 new_video(root.parent + SEPARATOR +
                                           root.name, entry, rpath,
                                           mimetype, atime, mtime, root,
                                           size, self.parse_size(size),
                                           self.last)
                     else:
                         _file = self._factory.\
                                 new_file(root.parent + SEPARATOR +
                                          root.name, entry, rpath,
                                          mimetype, atime, mtime, root,
                                          self.last, size,
                                          self.parse_size(size),)
                     #if root is not None:
                         #root.append_file(_file)
                     self._position += 1
                 else:
                     if self._stop is False:
                         _dir = self.do_index_process(path + SEPARATOR +
                                                      entry, relpath, root)
                         #root.append_dir(_dir)
                         self._position += 1
                     else:
                         return None
             except KeyError as error:
                 if SETTINGS.missingmime:
                     MANAGER.\
                     append_event("Error indexing file. Probably the " +
                                  "MIME is not found in the MIME list.",
                                  absname + SEPARATOR + entry, error, 1)
                     print "Error indexing file: " + absname + SEPARATOR + \
                             entry + ". Probably the MIME is not" + \
                             "found in the MIME list."
                     print error
             except Exception as exc:
                if SETTINGS.ioerror:
                    MANAGER.\
                    append_event("Error indexing file. I/O error.",
                                 absname + SEPARATOR + entry, exc, 2)
                    print "Error indexing file: " + absname + SEPARATOR + \
                            entry + ". I/O error."
                    print exc
         if root is not None:
             if (root.__str__() == self._path):
                 self.calculate_dir_size(root)
                 root.strsize = self.parse_size(root.size)
                 self._root = None
             return root
     except Exception as exc:
         if SETTINGS.ioerror:
             MANAGER.append_event("Error indexing directory. I/O error",
                                  absname, exc, 2)
         print "Error indexing directory: " + absname
         print exc
         return root