示例#1
0
文件: p.pymp3cut.py 项目: gree2/hobby
def guess_mimetype():
	from eyed3.utils import guessMimetype

	mtype = guessMimetype('EarthAfireP1.mp3')
	print mtype
	mtype = guessMimetype(mp3_file)
	print mtype

# guess_mimetype()
示例#2
0
def guess_mimetype():
    from eyed3.utils import guessMimetype

    mtype = guessMimetype('EarthAfireP1.mp3')
    print mtype
    mtype = guessMimetype(mp3_file)
    print mtype


# guess_mimetype()
示例#3
0
    def handleFile(self, f):
        super(StatisticsPlugin, self).handleFile(f)

        # mimetype stats
        mt = guessMimetype(f)
        if mt in self.mts:
            self.mts[mt] += 1
        else:
            self.mts[mt] = 1

        if self.audio_file and self.audio_file.tag:
            self.count += 1
            if os.path.basename(f).startswith('.'):
                self.hidden_file_count += 1

            # ID3 versions
            id3_version = self.audio_file.tag.version
            self.versions[id3_version] += 1
            sys.stdout.write('.')
            sys.stdout.flush()

            # mp3 bit rates
            vbr, br =  self.audio_file.info.bit_rate
            if vbr:
                self.bitrates["vbr"] += 1
            else:
                self.bitrates["cbr"] += 1
            for key in self.bitrate_keys:
                key_op, key_br = key
                if key_op(br, key_br):
                    self.bitrates[key] += 1
                    break
示例#4
0
文件: classic.py 项目: vicgc/Uforia
        def ImageArg(s):
            '''PATH:TYPE[:DESCRIPTION]
            Returns (path, type_id, mime_type, description)'''
            args = _splitArgs(s)
            if len(args) < 2:
                raise ValueError("too few parts")

            path, type_str = args[:2]
            desc = args[2] if len(args) > 2 else u""
            mt = None
            try:
                type_id = id3.frames.ImageFrame.stringToPicType(type_str)
            except:
                raise ValueError("invalid pic type")

            if not path:
                raise ValueError("path required")
            elif True in [
                    path.startswith(prefix) for prefix in [
                        "http://",
                        "https://",
                    ]
            ]:
                mt = ImageFrame.URL_MIME_TYPE
            else:
                if not os.path.isfile(path):
                    raise ValueError("file does not exist")
                mt = utils.guessMimetype(path)
                if mt is None:
                    raise ValueError("Cannot determine mime-type")

            return (path, type_id, mt, desc)
示例#5
0
        def ImageArg(s):
            '''PATH:TYPE[:DESCRIPTION]
            Returns (path, type_id, mime_type, description)'''
            args = _splitArgs(s)
            if len(args) < 2:
                raise ValueError("too few parts")

            path, type_str = args[:2]
            desc = unicode(args[2], LOCAL_ENCODING) if len(args) > 2 else u""
            mt = None
            try:
                type_id = id3.frames.ImageFrame.stringToPicType(type_str)
            except:
                raise ValueError("invalid pic type")

            if not path:
                raise ValueError("path required")
            elif True in [path.startswith(prefix)
                          for prefix in ["http://", "https://"]]:
                mt = ImageFrame.URL_MIME_TYPE
            else:
                if not os.path.isfile(path):
                    raise ValueError("file does not exist")
                mt = utils.guessMimetype(path)
                if mt is None:
                    raise ValueError("Cannot determine mime-type")

            return (path, type_id, mt, desc)
示例#6
0
 def _compute(self, file, audio_file):
     if audio_file:
         self["audio"] += 1
     if os.path.basename(file).startswith('.'):
         self["hidden"] += 1
     mt = guessMimetype(file)
     if mt and mt.startswith("audio/") and not audio_file:
         self["unsupported (other)"] += 1
示例#7
0
    def test(self, path, audio_file):
        mt = guessMimetype(path)
        if mt and mt.startswith("image/"):
            name, ext = os.path.splitext(os.path.basename(path))
            if name not in VALID_ARTWORK_NAMES:
                return [(-10, "Artwork file not in %s" % str(VALID_ARTWORK_NAMES))]

        return None
示例#8
0
 def _compute(self, file, audio_file):
     if audio_file:
         self["audio"] += 1
     if os.path.basename(file).startswith('.'):
         self["hidden"] += 1
     mt = guessMimetype(file)
     if mt and mt.startswith("audio/") and not audio_file:
         self["unsupported (other)"] += 1
示例#9
0
    def fromFile(path, type_):
        mime_type = guessMimetype(path)
        if not Image._validMimeType(mime_type):
            return None
        md5hash = md5()

        img = open(path, "rb")
        data = img.read()
        img.close()

        md5hash.update(data)

        return Image(type=type_,
                     mime_type=guessMimetype(path),
                     md5=md5hash.hexdigest(),
                     size=len(data),
                     data=data)
示例#10
0
文件: orm.py 项目: nicfit/mishmash
    def fromFile(path, type_):
        mime_type = guessMimetype(path)
        if not Image._validMimeType(mime_type):
            return None
        md5hash = md5()

        img = open(path, "rb")
        data = img.read()
        img.close()

        md5hash.update(data)

        return Image(type=type_,
                     mime_type=guessMimetype(path),
                     md5=md5hash.hexdigest(),
                     size=len(data),
                     data=data)
示例#11
0
    def test(self, path, audio_file):
        mt = guessMimetype(path)
        if mt and mt.startswith("image/"):
            name, ext = os.path.splitext(os.path.basename(path))
            if name not in VALID_ARTWORK_NAMES:
                return [(-10,
                         "Artwork file not in %s" % str(VALID_ARTWORK_NAMES))]

        return None
示例#12
0
    def test(self, path, audio_file):
        mt = guessMimetype(path)

        for name in os.path.split(path):
            if name.startswith('.'):
                return [(-100, "Hidden file type")]

        if mt not in VALID_MIME_TYPES:
            return [(-100, "Unsupported file type: %s" % mt)]
        return None
示例#13
0
    def test(self, path, audio_file):
        mt = guessMimetype(path)

        for name in os.path.split(path):
            if name.startswith('.'):
                return [(-100, "Hidden file type")]

        if mt not in VALID_MIME_TYPES:
            return [(-100, "Unsupported file type: %s" % mt)]
        return None
示例#14
0
    def _compute(self, file, audio_file):
        mt = guessMimetype(file)

        if audio_file:
            self[self.SUPPORTED_AUDIO] += 1
        elif mt and mt.startswith("audio/"):
            self[self.UNSUPPORTED_AUDIO] += 1
        elif os.path.basename(file).startswith('.'):
            self[self.HIDDEN_FILES] += 1
        else:
            self[self.OTHER_FILES] += 1
示例#15
0
    def _compute(self, file, audio_file):
        mt = guessMimetype(file)

        if audio_file:
            self[self.SUPPORTED_AUDIO] += 1
        elif mt and mt.startswith("audio/"):
            self[self.UNSUPPORTED_AUDIO] += 1
        elif os.path.basename(file).startswith("."):
            self[self.HIDDEN_FILES] += 1
        else:
            self[self.OTHER_FILES] += 1
示例#16
0
    def handleFile(self, f, *args, **kwargs):
        '''Loads ``f`` and sets ``self.audio_file`` to an instance of
        :class:`eyed3.core.AudioFile` or ``None`` if an error occurred.

        The ``*args`` and ``**kwargs`` are passed to :func:`eyed3.core.load`.
        '''
        self.audio_file = None

        mtype = utils.guessMimetype(f)
        if mtype is None or not (mtype.startswith("audio/") or
                                 mtype.startswith("application/")):
            return

        self._num_loaded += 1
        try:
            self.audio_file = core.load(f, *args, **kwargs)
        except NotImplementedError as ex:
            # Frame decryption, for instance...
            printError(ex)
        else:
            if not self.audio_file:
                printError("Unsupported file type: %s" % f)
示例#17
0
    def handleFile(self, f, *args, **kwargs):
        """Loads ``f`` and sets ``self.audio_file`` to an instance of
        :class:`eyed3.core.AudioFile` or ``None`` if an error occurred or the
        file is not a recognized type.

        The ``*args`` and ``**kwargs`` are passed to :func:`eyed3.core.load`.
        """

        try:
            self.audio_file = core.load(f, *args, **kwargs)
        except NotImplementedError as ex:
            # Frame decryption, for instance...
            printError(str(ex))
            return

        if self.audio_file:
            self._num_loaded += 1
            if self._file_cache is not None:
                self._file_cache.append(self.audio_file)
        elif self._dir_images is not None:
            mt = guessMimetype(f)
            if mt and mt.startswith("image/"):
                self._dir_images.append(f)
示例#18
0
    def handleFile(self, f, *args, **kwargs):
        '''Loads ``f`` and sets ``self.audio_file`` to an instance of
        :class:`eyed3.core.AudioFile` or ``None`` if an error occurred or the
        file is not a recognized type.

        The ``*args`` and ``**kwargs`` are passed to :func:`eyed3.core.load`.
        '''
        self.audio_file = None

        try:
            self.audio_file = core.load(f, *args, **kwargs)
        except NotImplementedError as ex:
            # Frame decryption, for instance...
            printError(str(ex))
            return

        if self.audio_file:
            self._num_loaded += 1
            if self._file_cache is not None:
                self._file_cache.append(self.audio_file)
        elif self._dir_images is not None:
            mt = guessMimetype(f)
            if mt and mt.startswith("image/"):
                self._dir_images.append(f)
示例#19
0
def testSampleMimeTypesUtils():
    for ext, valid_types in mime_test_params:
        guessed = utils.guessMimetype(os.path.join(DATA_D, f"sample.%s" % ext))
        assert guessed in valid_types
示例#20
0
 def mime_type(self):
     if self._mime_type:
         return self._mime_type
     self._mime_type = guessMimetype(self.file_path)
     return self._mime_type
def testSampleMimeTypes(ext, valid_types):
    guessed = guessMimetype(os.path.join(DATA_D, "sample.%s" % ext))
    if guessed:
        assert guessed in valid_types
示例#22
0
 def _compute(self, file, audio_file):
     mt = guessMimetype(file)
     self[mt] += 1
示例#23
0
def testId3MimeTypes():
    for ext in ("id3", "tag"):
        mt = guessMimetype("example.%s" % ext)
        assert_equal(mt, "application/x-id3")
 def handleFile(self, f):
     print("%s\t[ %s ]" % (f, guessMimetype(f)))
示例#25
0
 def _compute(self, file, audio_file):
     mt = guessMimetype(file)
     self[mt] += 1
示例#26
0
 def handleFile(self, f):
     print("%s\t[ %s ]" % (f, guessMimetype(f)))
示例#27
0
文件: art.py 项目: COMU/gramafon
 def mime_type(self):
     if self._mime_type:
         return self._mime_type
     self._mime_type = guessMimetype(self.file_path)
     return self._mime_type
示例#28
0
文件: test_utils.py 项目: zhu/eyeD3
def testSampleMimeTypes(ext, valid_types):
    guessed = guessMimetype(os.path.join(DATA_D, "sample.%s" % ext))
    if guessed:
        assert guessed in valid_types