示例#1
0
 def openFile(cls, path):
     fileExtension = os.path.splitext(path)[1][1:].strip().lower()
     if fileExtension not in Tagger.FILEFORMATS:
         raise TaggerError("File not supported!", path)
     try:
         if fileExtension == "mp3":
             file = MP3tag(path)
         elif fileExtension == "flac":
             file = FLACtag(path)
     except MutagenError as e:
         raise TaggerError("Cannot open file because " + str(e), path)
     return file
示例#2
0
 def retrieveSelectedImage(cls, hash, path):
     file = cls.openFile(path)
     try:
         for item in file.retrieveImages():
             if item.tag.HashKey == hash:
                 return item.tag.data
     except ModuleTaggerError as e:
         raise TaggerError(e.msg, e.src)
示例#3
0
    def addImage(cls, mode, src, desc, type, path):
        file = cls.openFile(path)
        if mode == "path":
            try:
                data = open(src, 'rb').read()
                format = imghdr.what("image", data)
                if not format or format not in cls.IMAGEFORMATS:
                    raise TaggerError("Unsupported image file format!", format)
                else:
                    file.addImage(desc, type, data, format)
            except IOError:
                raise TaggerError("Cannot open image file!", src)
            except ModuleTaggerError as e:
                raise TaggerError(e.msg, path)

        elif mode == "url":
            try:
                response = requests.get(src)
                data = response.content
                format = imghdr.what("image", data)
                if not format or format not in cls.IMAGEFORMATS:
                    raise TaggerError("Unsupported image file format!", format)
                else:
                    file.addImage(desc, type, data, format)
            except ModuleTaggerError as e:
                raise TaggerError(e.msg, path)
            except Exception as e:
                raise TaggerError("Cannot load image from url!", src)

        else:
            raise TaggerError("Wrong mode selected", "")
示例#4
0
    def retrieveCoverImage(cls, path):
        file = cls.openFile(path)
        data = None

        try:
            for item in file.retrieveImages():
                if item.type == "COVER_FRONT":
                    return item.tag.data
                else:
                    data = item.tag.data
        except ModuleTaggerError as e:
            raise TaggerError(e.msg, e.src)

        if data:
            return data
示例#5
0
 def putTag(cls, name, value, path):
     try:
         file = cls.openFile(path)
         file.putTag(name, value)
     except MutagenError:
         raise TaggerError("Tag in file cannot be changed!", path)
示例#6
0
 def deleteTag(cls, path):
     try:
         file = cls.openFile(path)
         file.deleteTag()
     except MutagenError:
         raise TaggerError("Whole tag cannot be deleted!", path)
示例#7
0
 def deleteAllImages(cls, path):
     try:
         file = cls.openFile(path)
         file.deleteAllImages()
     except MutagenError:
         raise TaggerError("Images deletion cannot be done!", path)
示例#8
0
 def deleteImage(cls, hash, path):
     try:
         file = cls.openFile(path)
         file.deleteImage(hash)
     except MutagenError:
         raise TaggerError("Image deletion cannot be done!", path)
示例#9
0
 def changeImageDesc(cls, desc, hash, path):
     try:
         file = cls.openFile(path)
         file.changeImageDesc(desc, hash)
     except MutagenError:
         raise TaggerError("Image description cannot be changed!", path)
示例#10
0
 def changeImageType(cls, type, hash, path):
     try:
         file = cls.openFile(path)
         file.changeImageType(type, hash)
     except MutagenError:
         raise TaggerError("Image type cannot be changed!", path)
示例#11
0
 def retrieveAllImagesDetails(cls, path):
     file = cls.openFile(path)
     try:
         return file.retrieveImages()
     except ModuleTaggerError as e:
         raise TaggerError(e.msg, e.src)