Example #1
0
    def link(self, filename):
        """Links the audio, filename
        returns self if successful, None otherwise."""
        
        
        self.images = None
        tags, audio = self.load(filename, ASF)
        if audio is None:
            return

        for name, values in audio.tags.iteritems():
            try:
                self.__tags[self.__translate[name]] = map(unicode, values)
            except KeyError:
                if isinstance(values[0], ASFUnicodeAttribute):
                    if not '/' in name and name not in self.__tags:
                        self.__tags[name] = map(unicode, values)

        if 'WM/Picture' in audio:
            self.images = map(bin_to_pic, audio['WM/Picture'])

        self.__tags.update(info_to_dict(audio.info))
        self.__tags.update(tags)
        self.__tags['__filetype'] = u'ASF'
        self.filetype = u'ASF'
        self.__tags['__tag_read'] = u'ASF'
        self.set_attrs(ATTRIBUTES)
        self.mut_obj = audio
        self.update_tag_list()
        return self
Example #2
0
        def link(self, filename):
            """Links the audio, filename
            returns self if successful, None otherwise."""
            self.__images = []
            tags, audio = self.load(filename, base)
            if audio is None:
                return

            for key in audio:
                if key == COVER_KEY:
                    self.images = map(base64_to_image, audio[key])
                else:
                    self.__tags[key.lower()] = audio.tags[key]

            if base == FLAC:
                self.images = filter(None, map(bin_to_image, audio.pictures))
            elif not self.images:
                self.images = []

            self.__tags.update(info_to_dict(audio.info))
            self.__tags.update(tags)
            self.set_attrs(ATTRIBUTES)
            self.mut_obj = audio
            self._originaltags = self.__tags.keys()
            self.update_tag_list()
            return self
Example #3
0
        def link(self, filename):
            """Links the audio, filename
            returns self if successful, None otherwise."""
            no_header = DefaultHeaderError if header_error is None \
                else header_error

            self.__images = []
            try:
                tags, audio = self.load(filename, mutagen_file)
            except no_header: #Try loading just APEv2
                tags, audio = self.load(filename, APEv2File)
            except APENoHeaderError:
                audio = mutagen_file()
                tags, audio = self.load(filename, None)
                audio.filename = tags['__filepath']

            if audio is None:
                return

            images = []
            for key in audio:
                try:
                    if key.lower() in COVER_KEYS:
                        img_type = COVER_KEYS.get(key.lower(), 3)
                        images.append(
                            bin_to_pic(audio[key].value, img_type))
                    else:
                        self.__tags[key.lower()] = audio.tags[key][:]
                except TypeError:
                    pass

            self.images = images
            self.__tags.update(info_to_dict(audio.info))
            self.__tags.update(tags)
            self.__tags['__tag_read'] = u'APEv2'
            self.set_attrs(attrib_fields)
            self.filetype = filetype
            self.__tags['__filetype'] = filetype
            self.update_tag_list()
            self.mut_obj = audio
            return self
Example #4
0
        def link(self, filename):
            """Links the audio, filename
            returns self if successful, None otherwise."""
            no_header = DefaultHeaderError if header_error is None \
                else header_error

            self.__images = []
            try:
                tags, audio = self.load(filename, mutagen_file)
            except no_header:  #Try loading just APEv2
                tags, audio = self.load(filename, APEv2File)
            except APENoHeaderError:
                audio = mutagen_file()
                tags, audio = self.load(filename, None)
                audio.filename = tags['__filepath']

            if audio is None:
                return

            images = []
            for key in audio:
                try:
                    if key.lower() in COVER_KEYS:
                        img_type = COVER_KEYS.get(key.lower(), 3)
                        images.append(bin_to_pic(audio[key].value, img_type))
                    else:
                        self.__tags[key.lower()] = audio.tags[key][:]
                except TypeError:
                    pass

            self.images = images
            self.__tags.update(info_to_dict(audio.info))
            self.__tags.update(tags)
            self.__tags['__tag_read'] = u'APEv2'
            self.set_attrs(attrib_fields)
            self.filetype = filetype
            self.__tags['__filetype'] = filetype
            self.update_tag_list()
            self.mut_obj = audio
            return self
Example #5
0
        def link(self, filename):
            """Links the audio, filename
            returns self if successful, None otherwise."""
            self.__images = []
            tags, audio = self.load(filename, id3_filetype)
            if audio is None:
                return

            if audio.tags:  #Not empty
                audio.tags.update_to_v24()
                self.__tags.update(handle(audio))

                #Get the image data.
                apics = audio.tags.getall("APIC")
                if apics:
                    self.images = map(bin_to_pic, apics)
                else:
                    self.images = []

            self.__tags.update(tags)
            self.__tags.update(info_to_dict(audio.info))

            if self.ext.lower() == 'mp3':
                self.__tags['__filetype'] = u'MP3'
            else:
                self.__tags['__filetype'] = u'ID3'

            self.set_attrs(ATTRIBUTES, self.__tags)

            try:
                self.__tags[
                    '__tag_read'] = u'ID3v%s.%s' % audio.tags.version[:2]
            except AttributeError:
                self.__tags['__tag_read'] = u''
            self.mut_obj = audio
            self._originaltags = audio.keys()
            self.update_tag_list()
            return self
Example #6
0
        def link(self, filename):
            """Links the audio, filename
            returns self if successful, None otherwise."""
            self.__images = []
            tags, audio = self.load(filename, id3_filetype)
            if audio is None:
                return

            if audio.tags: #Not empty
                audio.tags.update_to_v24()
                self.__tags.update(handle(audio))

                #Get the image data.
                apics = audio.tags.getall("APIC")
                if apics:
                    self.images = map(bin_to_pic, apics)
                else:
                    self.images = [];

            self.__tags.update(tags)
            self.__tags.update(info_to_dict(audio.info))

            if self.ext.lower() == 'mp3':
                self.__tags['__filetype'] = u'MP3'
            else:
                self.__tags['__filetype'] = u'ID3'

            self.set_attrs(ATTRIBUTES, self.__tags)

            try:
                self.__tags['__tag_read'] = u'ID3v%s.%s' % audio.tags.version[:2]
            except AttributeError:
                self.__tags['__tag_read'] = u''
            self.mut_obj = audio
            self._originaltags = audio.keys()
            self.update_tag_list()
            return self
Example #7
0
    def link(self, filename):
        """Links the audio, filename
        returns self if successful, None otherwise."""

        tags, audio = self.load(filename, MP4)
        self.images = []

        if audio is None:
            return

        revmap, mapping = self.revmapping, self.mapping
        self.revmapping, self.mapping = {}, {}

        self.__freeform = {} #Keys are tags as required by mutagen i.e. The '----'
                             #frames. Values are the tag as represented by puddletag.

        if audio.tags: #Not empty
            keys = audio.keys()
            try:
                self.images = map(bin_to_pic, audio['covr'])
                keys.remove('covr')
            except KeyError:
                self.images = []

            convert = lambda k, v: FUNCS[k][1](v)

            #I want 'trkn', to split into track and totaltracks, like Mp3tag.
            if 'trkn' in keys:
                tags['track'] = convert('track',
                    [z[0] for z in audio['trkn']])
                tags['totaltracks'] = convert('totaltracks',
                    [z[1] for z in audio['trkn']])
                keys.remove('trkn')

            #Same as above
            if 'disk' in keys:
                tags['disc'] = convert('disc', [z[0] for z in audio['disk']])
                tags['totaldiscs'] = convert('totaldiscs',
                    [z[1] for z in audio['disk']])
                keys.remove('disk')

            for key in keys:
                if key in TAGS:
                    tags[TAGS[key]] = convert(TAGS[key], audio[key])
                else:
                    field = key[key.find(':', key.find(':') +1) + 1:]
                    try:
                        field = field.decode('utf8')
                    except UnicodeDecodeError:
                        field = field.decode('latin1')

                    self.__freeform[field] = key
                    try:
                        tags[field] = [unicode(v, 'utf8') if not
                            isinstance(v, unicode) else v for v in audio[key]]
                    except UnicodeDecodeError:
                        self.__errors.add(field)

        for k,v in tags.items():
            if not v:
                del(tags[k])

        self.__tags.update(info_to_dict(audio.info))
        self.__tags.update(tags)
        self.revmapping, self.mapping = revmap, mapping
        self.__tags['__tag_read'] = u'MP4'
        self.filetype = 'MP4'
        self.__tags['__filetype'] = self.filetype
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()
        self.mut_obj = audio
Example #8
0
    def link(self, filename):
        """Links the audio, filename
        returns self if successful, None otherwise."""

        tags, audio = self.load(filename, MP4)
        self.images = []

        if audio is None:
            return

        revmap, mapping = self.revmapping, self.mapping
        self.revmapping, self.mapping = {}, {}

        self.__freeform = {
        }  #Keys are tags as required by mutagen i.e. The '----'
        #frames. Values are the tag as represented by puddletag.

        if audio.tags:  #Not empty
            keys = audio.keys()
            try:
                self.images = map(bin_to_pic, audio['covr'])
                keys.remove('covr')
            except KeyError:
                self.images = []

            convert = lambda k, v: FUNCS[k][1](v)

            #I want 'trkn', to split into track and totaltracks, like Mp3tag.
            if 'trkn' in keys:
                tags['track'] = convert('track', [z[0] for z in audio['trkn']])
                tags['totaltracks'] = convert('totaltracks',
                                              [z[1] for z in audio['trkn']])
                keys.remove('trkn')

            #Same as above
            if 'disk' in keys:
                tags['disc'] = convert('disc', [z[0] for z in audio['disk']])
                tags['totaldiscs'] = convert('totaldiscs',
                                             [z[1] for z in audio['disk']])
                keys.remove('disk')

            for key in keys:
                if key in TAGS:
                    tags[TAGS[key]] = convert(TAGS[key], audio[key])
                else:
                    field = key[key.find(':', key.find(':') + 1) + 1:]
                    try:
                        field = field.decode('utf8')
                    except UnicodeDecodeError:
                        field = field.decode('latin1')

                    self.__freeform[field] = key
                    try:
                        field_value = []
                        for v in audio[key]:
                            if isinstance(v, str):
                                field_value.append(unicode(v, 'utf8'))
                            elif isinstance(v, unicode):
                                field_value.append(v)
                            else:
                                field_value.append(unicode(v))
                    except UnicodeDecodeError:
                        self.__errors.add(field)

        for k, v in tags.items():
            if not v:
                del (tags[k])

        self.__tags.update(info_to_dict(audio.info))
        self.__tags.update(tags)
        self.revmapping, self.mapping = revmap, mapping
        self.__tags['__tag_read'] = u'MP4'
        self.filetype = 'MP4'
        self.__tags['__filetype'] = self.filetype
        self.set_attrs(ATTRIBUTES, self.__tags)
        self.update_tag_list()
        self.mut_obj = audio