Example #1
0
    def getFileInfoUnicode(self, name, pathname):

        try:
            if type(name) is str:
                name_f = u"%s" % name
                pathname_f = u"%s" % pathname
            else:
                name_f = name
                pathname_f = pathname

            try:
                size = os.path.getsize(pathname_f)
            except:
                size = os.path.getsize(pathname)

            try:
                info = metadata.detect(pathname_f)
            except:
                info = metadata.detect(pathname)

            if info:
                bitrateinfo = (int(info["bitrate"]), int(info["vbr"]))
                fileinfo = (name, size, bitrateinfo, int(info["time"]))
            else:
                fileinfo = (name, size, None, None)

            return fileinfo
        except Exception, errtuple:
            message = _("Scanning File Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': pathname}
            self.logMessage(message)
            displayTraceback(sys.exc_info()[2])
Example #2
0
	def getFilesList(self, mtimes, oldmtimes, oldlist, yieldcall = None, progress=None, rebuild=False):
		""" Get a list of files with their filelength and 
		(if mp3) bitrate and track length in seconds """
		list = {}
		count = 0
		for directory in mtimes:
			directory = os.path.expanduser(directory)
			virtualdir = self.real2virtual(directory)
			count +=1
			if progress:
				percent = float(count)/len(mtimes)
				if percent <= 1.0:
					gobject.idle_add(progress.set_fraction, percent)

			if self.hiddenCheck(directory):
				continue
			if not rebuild and directory in oldmtimes:
				if mtimes[directory] == oldmtimes[directory]:
					if os.path.exists(directory):
						try:
							list[virtualdir] = oldlist[virtualdir]
							continue
						except KeyError:
							log.addwarning("Inconsistent cache for '%s', rebuilding '%s'" % (virtualdir, directory))
					else:
						print "Dropping removed directory %s" % directory
						continue

			list[virtualdir] = []

			try:
				contents = os.listdir(directory)
			except OSError, errtuple:
				print str(errtuple)
				self.logMessage(str(errtuple))
				continue
			contents.sort()

			for filename in contents:

				if self.hiddenCheck(filename):
					continue	
				path = os.path.join(directory, filename)
				try:

					isfile = os.path.isfile(path)
				except OSError, errtuple:
					message = _("Scanning Error: %(error)s Path: %(path)s") % {'error':errtuple, 'path':path}
					print str(message)
					self.logMessage(message)
					displayTraceback(sys.exc_info()[2])
					continue
				else:
					if isfile:
						# It's a file, check if it is mp3 or ogg
						data = self.getFileInfo(filename, path)
						if data is not None:
							list[virtualdir].append(data)
				if yieldcall is not None:
					yieldcall()
Example #3
0
    def getFileInfo(self, name, pathname):

        try:
            size = os.path.getsize(pathname)
            info = metadata.detect(pathname)

            if info:

                # Sometimes the duration (time) or the bitrate of the file is unknown
                if info["time"] is None or info["bitrate"] is None:
                    fileinfo = (name, size, None, None)
                else:
                    bitrateinfo = (int(info["bitrate"]), int(info["vbr"]))
                    fileinfo = (name, size, bitrateinfo, int(info["time"]))
            else:
                fileinfo = (name, size, None, None)

            return fileinfo

        except Exception, errtuple:
            message = _("Scanning File Error: %(error)s Path: %(path)s") % {
                'error': errtuple,
                'path': pathname
            }
            self.logMessage(message)
            displayTraceback(sys.exc_info()[2])
Example #4
0
    def getFileInfoUnicode(self, name, pathname):

        try:
            if type(name) is str:
                name_f = u"%s" % name
                pathname_f = u"%s" % pathname
            else:
                name_f = name
                pathname_f = pathname

            try:
                size = os.path.getsize(pathname_f)
            except:
                size = os.path.getsize(pathname)

            try:
                info = metadata.detect(pathname_f)
            except:
                info = metadata.detect(pathname)

            if info:
                bitrateinfo = (int(info["bitrate"]), int(info["vbr"]))
                fileinfo = (name, size, bitrateinfo, int(info["time"]))
            else:
                fileinfo = (name, size, None, None)

            return fileinfo
        except Exception, errtuple:
            message = _("Scanning File Error: %(error)s Path: %(path)s") % {
                'error': errtuple,
                'path': pathname
            }
            self.logMessage(message)
            displayTraceback(sys.exc_info()[2])
Example #5
0
    def getDirsMtimesUnicode(self, dirs, yieldcall=None):

        list = {}

        for directory in dirs:

            directory = os.path.expanduser(directory.replace("//", "/"))

            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck({'dir': directory}):
                continue

            try:
                contents = dircache.listdir(u_directory)
                mtime = os.path.getmtime(u_directory)
            except OSError, errtuple:
                message = _("Scanning Directory Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': u_directory}
                print str(message)
                self.logMessage(message)
                displayTraceback(sys.exc_info()[2])
                continue

            contents.sort()

            list[str_directory] = mtime

            for filename in contents:

                path = os.path.join(directory, filename)

                # force Unicode for reading from disk in win32
                u_path = u"%s" % path
                s_path = str(path)

                try:
                    isdir = os.path.isdir(u_path)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': u_path}
                    print str(message)
                    self.logMessage(message)
                    continue

                try:
                    mtime = os.path.getmtime(u_path)
                except OSError, errtuple:
                    try:
                        mtime = os.path.getmtime(s_path)
                    except OSError, errtuple:
                        message = _("Scanning Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': u_path}
                        print str(message)
                        self.logMessage(message)
                        continue
Example #6
0
    def getDirsMtimes(self, dirs, yieldcall=None):

        list = {}

        for directory in dirs:

            directory = os.path.expanduser(directory.replace("//", "/"))

            if self.hiddenCheck({'dir': directory}):
                continue

            try:
                contents = dircache.listdir(directory)
                mtime = os.path.getmtime(directory)
            except OSError, errtuple:
                message = _(
                    "Scanning Directory Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': directory
                    }
                print str(message)
                self.logMessage(message)
                displayTraceback(sys.exc_info()[2])
                continue

            contents.sort()

            list[directory] = mtime

            for filename in contents:

                path = os.path.join(directory, filename)

                try:
                    isdir = os.path.isdir(path)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': path
                    }
                    print str(message)
                    self.logMessage(message)
                    continue

                try:
                    mtime = os.path.getmtime(path)
                except OSError, errtuple:
                    islink = False
                    try:
                        islink = os.path.islink(path)
                    except OSError, errtuple2:
                        print errtuple2
Example #7
0
    def getDirsMtimes(self, dirs, yieldcall=None):

        list = {}

        for directory in dirs:

            directory = os.path.expanduser(directory.replace("//", "/"))

            if self.hiddenCheck({'dir': directory}):
                continue

            try:
                contents = dircache.listdir(directory)
                mtime = os.path.getmtime(directory)
            except OSError, errtuple:
                message = _("Scanning Directory Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': directory}
                print str(message)
                self.logMessage(message)
                displayTraceback(sys.exc_info()[2])
                continue

            contents.sort()

            list[directory] = mtime

            for filename in contents:

                path = os.path.join(directory, filename)

                try:
                    isdir = os.path.isdir(path)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': path}
                    print str(message)
                    self.logMessage(message)
                    continue

                try:
                    mtime = os.path.getmtime(path)
                except OSError, errtuple:
                    islink = False
                    try:
                        islink = os.path.islink(path)
                    except OSError, errtuple2:
                        print errtuple2
Example #8
0
    def getFileInfo(self, name, pathname):

        try:
            size = os.path.getsize(pathname)
            info = metadata.detect(pathname)

            if info:

                # Sometimes the duration (time) or the bitrate of the file is unknown
                if info["time"] is None or info["bitrate"] is None:
                    fileinfo = (name, size, None, None)
                else:
                    bitrateinfo = (int(info["bitrate"]), int(info["vbr"]))
                    fileinfo = (name, size, bitrateinfo, int(info["time"]))
            else:
                fileinfo = (name, size, None, None)

            return fileinfo

        except Exception, errtuple:
            message = _("Scanning File Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': pathname}
            self.logMessage(message)
            displayTraceback(sys.exc_info()[2])
Example #9
0
    def getFilesListUnicode(self, mtimes, oldmtimes, oldlist, yieldcall=None, progress=None, rebuild=False):
        """ Get a list of files with their filelength, bitrate and track length in seconds """

        list = {}
        count = 0

        for directory in mtimes:

            directory = os.path.expanduser(directory)
            virtualdir = self.real2virtual(directory)
            count += 1

            if progress:
                percent = float(count)/len(mtimes)
                if percent <= 1.0:
                    gobject.idle_add(progress.set_fraction, percent)

            # force Unicode for reading from disk
            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck({'dir': directory}):
                continue

            if directory in oldmtimes and directory not in oldlist:
                # Partial information, happened with unicode paths that N+ couldn't handle properly
                del oldmtimes[directory]

            if not rebuild and directory in oldmtimes:
                if mtimes[directory] == oldmtimes[directory]:
                    if os.path.exists(directory):
                        try:
                            list[virtualdir] = oldlist[virtualdir]
                            continue
                        except KeyError:
                            log.addwarning(_("Inconsistent cache for '%(vdir)s', rebuilding '%(dir)s'") % {
                                'vdir': virtualdir,
                                'dir': directory
                            })
                    else:
                        log.adddebug(_("Dropping missing directory %(dir)s") % {'dir': directory})
                        continue

            list[virtualdir] = []

            try:
                contents = os.listdir(u_directory)
            except OSError, errtuple:
                print str(errtuple)
                self.logMessage(str(errtuple))
                continue

            contents.sort()

            for filename in contents:

                if self.hiddenCheck({'dir': directory, 'file': filename}):
                    continue

                path = os.path.join(directory, filename)
                s_path = str(path)
                ppath = unicode(path)

                s_filename = str(filename)
                try:
                    # try to force Unicode for reading from disk
                    isfile = os.path.isfile(ppath)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': path}
                    print str(message)
                    self.logMessage(message)
                    displayTraceback(sys.exc_info()[2])
                    continue
                else:
                    if isfile:
                        # Get the metadata of the file via mutagen
                        data = self.getFileInfoUnicode(s_filename, s_path)
                        if data is not None:
                            list[virtualdir].append(data)

                if yieldcall is not None:
                    yieldcall()
Example #10
0
    def getFilesListUnicode(self, mtimes, oldmtimes, oldlist, yieldcall=None, progress=None, rebuild=False):
        """ Get a list of files with their filelength and
        (if mp3) bitrate and track length in seconds """

        list = {}
        count = 0

        for directory in mtimes:
            directory = os.path.expanduser(directory)
            virtualdir = self.real2virtual(directory)
            count += 1

            if progress:
                percent = float(count)/len(mtimes)
                if percent <= 1.0:
                    gobject.idle_add(progress.set_fraction, percent)

            # force Unicode for reading from disk
            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck(directory):
                continue

            if not rebuild and directory in oldmtimes:
                if mtimes[directory] == oldmtimes[directory]:
                    list[virtualdir] = oldlist[virtualdir]
                    continue

            list[virtualdir] = []

            try:
                contents = os.listdir(u_directory)
            except OSError, errtuple:
                print str(errtuple)
                self.logMessage(str(errtuple))
                continue

            contents.sort()

            for filename in contents:

                if self.hiddenCheck(filename):
                    continue

                path = os.path.join(directory, filename)
                s_path = str(path)
                ppath = unicode(path)

                s_filename = str(filename)
                try:
                    # try to force Unicode for reading from disk
                    isfile = os.path.isfile(ppath)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {'error': errtuple, 'path': path}
                    print str(message)
                    self.logMessage(message)
                    displayTraceback(sys.exc_info()[2])
                    continue
                else:
                    if isfile:
                        # Get the metadata of the file via mutagen
                        data = self.getFileInfoUnicode(s_filename, s_path)
                        if data is not None:
                            list[virtualdir].append(data)

                if yieldcall is not None:
                    yieldcall()
Example #11
0
    def getFilesListUnicode(self,
                            mtimes,
                            oldmtimes,
                            oldlist,
                            yieldcall=None,
                            progress=None,
                            rebuild=False):
        """ Get a list of files with their filelength and
        (if mp3) bitrate and track length in seconds """

        list = {}
        count = 0

        for directory in mtimes:
            directory = os.path.expanduser(directory)
            virtualdir = self.real2virtual(directory)
            count += 1

            if progress:
                percent = float(count) / len(mtimes)
                if percent <= 1.0:
                    gobject.idle_add(progress.set_fraction, percent)

            # force Unicode for reading from disk
            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck(directory):
                continue

            if not rebuild and directory in oldmtimes:
                if mtimes[directory] == oldmtimes[directory]:
                    list[virtualdir] = oldlist[virtualdir]
                    continue

            list[virtualdir] = []

            try:
                contents = os.listdir(u_directory)
            except OSError, errtuple:
                print str(errtuple)
                self.logMessage(str(errtuple))
                continue

            contents.sort()

            for filename in contents:

                if self.hiddenCheck(filename):
                    continue

                path = os.path.join(directory, filename)
                s_path = str(path)
                ppath = unicode(path)

                s_filename = str(filename)
                try:
                    # try to force Unicode for reading from disk
                    isfile = os.path.isfile(ppath)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': path
                    }
                    print str(message)
                    self.logMessage(message)
                    displayTraceback(sys.exc_info()[2])
                    continue
                else:
                    if isfile:
                        # Get the metadata of the file via mutagen
                        data = self.getFileInfoUnicode(s_filename, s_path)
                        if data is not None:
                            list[virtualdir].append(data)

                if yieldcall is not None:
                    yieldcall()
Example #12
0
    def getFilesList(self,
                     mtimes,
                     oldmtimes,
                     oldlist,
                     yieldcall=None,
                     progress=None,
                     rebuild=False):
        """ Get a list of files with their filelength and
        (if mp3) bitrate and track length in seconds """

        list = {}
        count = 0

        for directory in mtimes:
            directory = os.path.expanduser(directory)
            virtualdir = self.real2virtual(directory)
            count += 1

            if progress:
                percent = float(count) / len(mtimes)
                if percent <= 1.0:
                    gobject.idle_add(progress.set_fraction, percent)

            if self.hiddenCheck(directory):
                continue

            if not rebuild and directory in oldmtimes:
                if mtimes[directory] == oldmtimes[directory]:
                    if os.path.exists(directory):
                        try:
                            list[virtualdir] = oldlist[virtualdir]
                            continue
                        except KeyError:
                            log.addwarning(
                                "Inconsistent cache for '%s', rebuilding '%s'"
                                % (virtualdir, directory))
                    else:
                        print "Dropping removed directory %s" % directory
                        continue

            list[virtualdir] = []

            try:
                contents = os.listdir(directory)
            except OSError, errtuple:
                print str(errtuple)
                self.logMessage(str(errtuple))
                continue
            contents.sort()

            for filename in contents:

                if self.hiddenCheck(filename):
                    continue

                path = os.path.join(directory, filename)
                try:
                    isfile = os.path.isfile(path)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': path
                    }
                    print str(message)
                    self.logMessage(message)
                    displayTraceback(sys.exc_info()[2])
                    continue
                else:
                    if isfile:
                        # Get the metadata of the file via mutagen
                        data = self.getFileInfo(filename, path)
                        if data is not None:
                            list[virtualdir].append(data)

                if yieldcall is not None:
                    yieldcall()
Example #13
0
    def getDirsMtimesUnicode(self, dirs, yieldcall=None):

        list = {}

        for directory in dirs:
            directory = os.path.expanduser(directory.replace("//", "/"))

            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck(u_directory):
                continue

            try:
                contents = dircache.listdir(u_directory)
                mtime = os.path.getmtime(u_directory)
                contents.sort()
            except OSError, errtuple:
                message = _(
                    "Scanning Directory Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': u_directory
                    }
                print str(message)
                self.logMessage(message)
                displayTraceback(sys.exc_info()[2])
                continue

            list[str_directory] = mtime

            for filename in contents:
                path = os.path.join(directory, filename)

                # force Unicode for reading from disk in win32
                u_path = u"%s" % path
                s_path = str(path)

                try:
                    isdir = os.path.isdir(u_path)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': u_path
                    }
                    print str(message)
                    self.logMessage(message)
                    continue

                try:
                    mtime = os.path.getmtime(u_path)
                except OSError, errtuple:
                    try:
                        mtime = os.path.getmtime(s_path)
                    except OSError, errtuple:
                        message = _(
                            "Scanning Error: %(error)s Path: %(path)s") % {
                                'error': errtuple,
                                'path': u_path
                            }
                        print str(message)
                        self.logMessage(message)
                        continue
Example #14
0
    def getFilesListUnicode(self,
                            mtimes,
                            oldmtimes,
                            oldlist,
                            yieldcall=None,
                            progress=None,
                            rebuild=False):
        """ Get a list of files with their filelength, bitrate and track length in seconds """

        list = {}
        count = 0

        for directory in mtimes:

            directory = os.path.expanduser(directory)
            virtualdir = self.real2virtual(directory)
            count += 1

            if progress:
                percent = float(count) / len(mtimes)
                if percent <= 1.0:
                    gobject.idle_add(progress.set_fraction, percent)

            # force Unicode for reading from disk
            u_directory = u"%s" % directory
            str_directory = str(directory)

            if self.hiddenCheck({'dir': directory}):
                continue

            if directory in oldmtimes and directory not in oldlist:
                # Partial information, happened with unicode paths that N+ couldn't handle properly
                del oldmtimes[directory]

            if not rebuild and directory in oldmtimes:
                if mtimes[directory] == oldmtimes[directory]:
                    if os.path.exists(directory):
                        try:
                            list[virtualdir] = oldlist[virtualdir]
                            continue
                        except KeyError:
                            log.addwarning(
                                _("Inconsistent cache for '%(vdir)s', rebuilding '%(dir)s'"
                                  ) % {
                                      'vdir': virtualdir,
                                      'dir': directory
                                  })
                    else:
                        log.adddebug(
                            _("Dropping missing directory %(dir)s") %
                            {'dir': directory})
                        continue

            list[virtualdir] = []

            try:
                contents = os.listdir(u_directory)
            except OSError, errtuple:
                print str(errtuple)
                self.logMessage(str(errtuple))
                continue

            contents.sort()

            for filename in contents:

                if self.hiddenCheck({'dir': directory, 'file': filename}):
                    continue

                path = os.path.join(directory, filename)
                s_path = str(path)
                ppath = unicode(path)

                s_filename = str(filename)
                try:
                    # try to force Unicode for reading from disk
                    isfile = os.path.isfile(ppath)
                except OSError, errtuple:
                    message = _("Scanning Error: %(error)s Path: %(path)s") % {
                        'error': errtuple,
                        'path': path
                    }
                    print str(message)
                    self.logMessage(message)
                    displayTraceback(sys.exc_info()[2])
                    continue
                else:
                    if isfile:
                        # Get the metadata of the file via mutagen
                        data = self.getFileInfoUnicode(s_filename, s_path)
                        if data is not None:
                            list[virtualdir].append(data)

                if yieldcall is not None:
                    yieldcall()