def __delattr__(self, attr):
     if attr == "track_number":
         MetaData.__setattr__(self, "__track_number__", 0)
     elif attr in self.FIELD_LENGTHS:
         MetaData.__setattr__(self, self.ID3v1_FIELDS[attr], u"")
     elif attr in self.FIELDS:
         # field not supported by ID3v1Comment, so ignore it
         pass
     else:
         MetaData.__delattr__(self, attr)
Пример #2
0
 def __delattr__(self, attr):
     if (attr == "track_number"):
         MetaData.__setattr__(self, "__track_number__", chr(0))
     elif (attr in self.FIELD_LENGTHS):
         MetaData.__setattr__(self, self.ID3v1_FIELDS[attr],
                              chr(0) * self.FIELD_LENGTHS[attr])
     elif (attr in self.FIELDS):
         # field not supported by ID3v1Comment, so ignore it
         pass
     else:
         MetaData.__delattr__(self, attr)
Пример #3
0
 def __delattr__(self, attr):
     if attr == "track_number":
         MetaData.__setattr__(self, "__track_number__", 0)
     elif attr in self.FIELD_LENGTHS:
         MetaData.__setattr__(self,
                              self.ID3v1_FIELDS[attr],
                              u"")
     elif attr in self.FIELDS:
         # field not supported by ID3v1Comment, so ignore it
         pass
     else:
         MetaData.__delattr__(self, attr)
Пример #4
0
 def __delattr__(self, attr):
     if (attr == "track_number"):
         MetaData.__setattr__(self, "__track_number__", chr(0))
     elif (attr in self.FIELD_LENGTHS):
         MetaData.__setattr__(self,
                              self.ID3v1_FIELDS[attr],
                              chr(0) * self.FIELD_LENGTHS[attr])
     elif (attr in self.FIELDS):
         # field not supported by ID3v1Comment, so ignore it
         pass
     else:
         MetaData.__delattr__(self, attr)
Пример #5
0
    def __delattr__(self, attr):
        import re

        def zero_number(unicode_value):
            return re.sub(r'\d+', u"0", unicode_value, 1)

        if attr in self.ATTRIBUTE_MAP:
            key = self.ATTRIBUTE_MAP[attr]

            if attr in {'track_number', 'album_number'}:
                try:
                    tag = self[key]
                    if tag.total() is None:
                        # if no slashed _total field, delete entire tag
                        del(self[key])
                    else:
                        # otherwise replace initial portion with 0
                        self[key] = self.ITEM.string(
                            key, zero_number(tag.__unicode__()))
                except KeyError:
                    # no tag to delete
                    pass
            elif attr in {'track_total', 'album_total'}:
                try:
                    tag = self[key]
                    if tag.total() is not None:
                        if tag.number() is not None:
                            self[key] = self.ITEM.string(
                                key,
                                tag.__unicode__().split(u"/", 1)[0].rstrip())
                        else:
                            del(self[key])
                    else:
                        # no total portion, so nothing to do
                        pass
                except KeyError:
                    # no tag to delete portion of
                    pass
            else:
                try:
                    del(self[key])
                except KeyError:
                    pass
        elif attr in MetaData.FIELDS:
            pass
        else:
            MetaData.__delattr__(self, attr)
Пример #6
0
    def __delattr__(self, attr):
        import re

        def zero_number(unicode_value):
            return re.sub(r'\d+', u"0", unicode_value, 1)

        if attr in self.ATTRIBUTE_MAP:
            key = self.ATTRIBUTE_MAP[attr]

            if attr in {'track_number', 'album_number'}:
                try:
                    tag = self[key]
                    if tag.total() is None:
                        # if no slashed _total field, delete entire tag
                        del(self[key])
                    else:
                        # otherwise replace initial portion with 0
                        self[key] = self.ITEM.string(
                            key, zero_number(tag.__unicode__()))
                except KeyError:
                    # no tag to delete
                    pass
            elif attr in {'track_total', 'album_total'}:
                try:
                    tag = self[key]
                    if tag.total() is not None:
                        if tag.number() is not None:
                            self[key] = self.ITEM.string(
                                key,
                                tag.__unicode__().split(u"/", 1)[0].rstrip())
                        else:
                            del(self[key])
                    else:
                        # no total portion, so nothing to do
                        pass
                except KeyError:
                    # no tag to delete portion of
                    pass
            else:
                try:
                    del(self[key])
                except KeyError:
                    pass
        elif attr in MetaData.FIELDS:
            pass
        else:
            MetaData.__delattr__(self, attr)
Пример #7
0
    def __delattr__(self, attr):
        #FIXME
        # deletes all matching keys for the given attribute
        # in our list of comment strings

        import re

        if attr in self.ATTRIBUTE_MAP:
            key = self.ATTRIBUTE_MAP[attr]

            if attr in {'track_number', 'album_number'}:
                try:
                    current_values = self[key]

                    # save the _total side of any slashed fields for later
                    slashed_totals = [
                        int(match.group(0)) for match in [
                            re.search(r'\d+',
                                      value.split(u"/", 1)[1])
                            for value in current_values if u"/" in value
                        ] if match is not None
                    ]

                    # remove the TRACKNUMBER/DISCNUMBER field itself
                    self[key] = []

                    # if there are any slashed totals
                    # and there isn't a TRACKTOTAL/DISCTOTAL field already,
                    # add a new one
                    total_key = {
                        'track_number': u"TRACKTOTAL",
                        'album_number': u"DISCTOTAL"
                    }[attr]

                    if (len(slashed_totals) > 0) and (total_key not in self):
                        self[total_key] = [u"{:d}".format(slashed_totals[0])]
                except KeyError:
                    # no TRACKNUMBER/DISCNUMBER field to remove
                    pass
            elif attr in {'track_total', 'album_total'}:

                def slash_filter(unicode_string):
                    if u"/" not in unicode_string:
                        return unicode_string
                    else:
                        return unicode_string.split(u"/", 1)[0].rstrip()

                slashed_key = {
                    "track_total": u"TRACKNUMBER",
                    "album_total": u"DISCNUMBER"
                }[attr]

                # remove TRACKTOTAL/DISCTOTAL fields
                self[key] = []

                # preserve the non-slashed side of
                # TRACKNUMBER/DISCNUMBER fields
                try:
                    self[slashed_key] = [
                        slash_filter(s) for s in self[slashed_key]
                    ]
                except KeyError:
                    # no TRACKNUMBER/DISCNUMBER fields
                    pass
            else:
                # unlike __setattr_, which tries to preserve multiple instances
                # of fields, __delattr__ wipes them all
                # so that orphaned fields don't show up after deletion
                self[key] = []
        elif attr in self.FIELDS:
            # attribute is part of MetaData
            # but not supported by VorbisComment
            pass
        else:
            MetaData.__delattr__(self, attr)
    def __delattr__(self, attr):
        #FIXME
        # deletes all matching keys for the given attribute
        # in our list of comment strings

        import re

        if attr in self.ATTRIBUTE_MAP:
            key = self.ATTRIBUTE_MAP[attr]

            if attr in {'track_number', 'album_number'}:
                try:
                    current_values = self[key]

                    # save the _total side of any slashed fields for later
                    slashed_totals = [int(match.group(0)) for match in
                                      [re.search(r'\d+',
                                                 value.split(u"/", 1)[1])
                                       for value in current_values if
                                       u"/" in value]
                                      if match is not None]

                    # remove the TRACKNUMBER/DISCNUMBER field itself
                    self[key] = []

                    # if there are any slashed totals
                    # and there isn't a TRACKTOTAL/DISCTOTAL field already,
                    # add a new one
                    total_key = {'track_number': u"TRACKTOTAL",
                                 'album_number': u"DISCTOTAL"}[attr]

                    if (len(slashed_totals) > 0) and (total_key not in self):
                        self[total_key] = [u"{:d}".format(slashed_totals[0])]
                except KeyError:
                    # no TRACKNUMBER/DISCNUMBER field to remove
                    pass
            elif attr in {'track_total', 'album_total'}:
                def slash_filter(unicode_string):
                    if u"/" not in unicode_string:
                        return unicode_string
                    else:
                        return unicode_string.split(u"/", 1)[0].rstrip()

                slashed_key = {"track_total": u"TRACKNUMBER",
                               "album_total": u"DISCNUMBER"}[attr]

                # remove TRACKTOTAL/DISCTOTAL fields
                self[key] = []

                # preserve the non-slashed side of
                # TRACKNUMBER/DISCNUMBER fields
                try:
                    self[slashed_key] = [slash_filter(s) for s in
                                         self[slashed_key]]
                except KeyError:
                    # no TRACKNUMBER/DISCNUMBER fields
                    pass
            else:
                # unlike __setattr_, which tries to preserve multiple instances
                # of fields, __delattr__ wipes them all
                # so that orphaned fields don't show up after deletion
                self[key] = []
        elif attr in self.FIELDS:
            # attribute is part of MetaData
            # but not supported by VorbisComment
            pass
        else:
            MetaData.__delattr__(self, attr)
Пример #9
0
    def __delattr__(self, attr):
        import re

        if (attr == 'track_number'):
            try:
                # if "Track" field contains a slashed total
                if (re.search(r'\d+.*?/.*?\d+',
                              self['Track'].data) is not None):
                    # replace unslashed portion with 0
                    self['Track'].data = re.sub(r'\d+',
                                                str(int(0)),
                                                self['Track'].data,
                                                1)
                else:
                    # otherwise, remove "Track" field
                    del(self['Track'])
            except KeyError:
                pass
        elif (attr == 'track_total'):
            try:
                track_number = re.search(r'\d+',
                                         self["Track"].data.split("/")[0])
                # if track number is nonzero
                if (((track_number is not None) and
                     (int(track_number.group(0)) != 0))):
                    # if "Track" field contains a slashed total
                    # remove slashed total from "Track" field
                    self['Track'].data = re.sub(r'\s*/.*',
                                                "",
                                                self['Track'].data)
                else:
                    # if "Track" field contains a slashed total
                    if (re.search(r'/\D*?\d+',
                                  self['Track'].data) is not None):
                        # remove "Track" field entirely
                        del(self['Track'])
            except KeyError:
                pass
        elif (attr == 'album_number'):
            try:
                # if "Media" field contains a slashed total
                if (re.search(r'\d+.*?/.*?\d+',
                              self['Media'].data) is not None):
                    # replace unslashed portion with 0
                    self['Media'].data = re.sub(r'\d+',
                                                str(int(0)),
                                                self['Media'].data,
                                                1)
                else:
                    # otherwise, remove "Media" field
                    del(self['Media'])
            except KeyError:
                pass
        elif (attr == 'album_total'):
            try:
                album_number = re.search(r'\d+',
                                         self["Media"].data.split("/")[0])
                # if album number is nonzero
                if (((album_number is not None) and
                     (int(album_number.group(0)) != 0))):
                    # if "Media" field contains a slashed total
                    # remove slashed total from "Media" field
                    self['Media'].data = re.sub(r'\s*/.*',
                                                "",
                                                self['Media'].data)
                else:
                    # if "Media" field contains a slashed total
                    if (re.search(r'/\D*?\d+',
                                  self['Media'].data) is not None):
                        # remove "Media" field entirely
                        del(self['Media'])
            except KeyError:
                pass
        elif (attr in self.ATTRIBUTE_MAP):
            try:
                del(self[self.ATTRIBUTE_MAP[attr]])
            except KeyError:
                pass
        elif (attr in MetaData.FIELDS):
            pass
        else:
            MetaData.__delattr__(self, attr)
Пример #10
0
    def __delattr__(self, attr):
        # deletes all matching keys for the given attribute
        # in our list of comment strings

        if ((attr == "track_number") or (attr == "album_number")):
            key = self.ATTRIBUTE_MAP[attr]
            try:
                # convert the slashed side of TRACKNUMBER/DISCNUMBER fields
                # to TRACKTOTAL/DISCKTOTAL fields
                slashed_field = re.compile(r'/\s*(.*)')

                orphaned_totals = [
                    match.group(1) for match in
                    [slashed_field.search(value) for value in self[key]]
                    if match is not None
                ]

                # remove any TRACKNUMBER/DISCNUMBER fields
                self[key] = []

                if (len(orphaned_totals) > 0):
                    total_key = {
                        "track_number": u"TRACKTOTAL",
                        "album_number": u"DISCTOTAL"
                    }[attr]
                    try:
                        # append new TRACKTOTAL/DISCTOTAL fields
                        self[total_key] = self[total_key] + orphaned_totals
                    except KeyError:
                        # no TRACKTOTAL/DISCTOTAL field, so add new ones
                        self[total_key] = orphaned_totals
            except KeyError:
                # no TRACKNUMBER/DISCNUMBER fields to remove
                pass
        elif ((attr == "track_total") or (attr == "album_total")):
            slashed_key = {
                "track_total": u"TRACKNUMBER",
                "album_total": u"DISCNUMBER"
            }[attr]
            slashed_field = re.compile(r'(.*?)\s*/.*')

            def slash_filter(s):
                match = slashed_field.match(s)
                if (match is not None):
                    return match.group(1)
                else:
                    return s

            # remove TRACKTOTAL/DISCTOTAL fields
            self[self.ATTRIBUTE_MAP[attr]] = []

            # preserve the non-slashed side of TRACKNUMBER/DISCNUMBER fields
            try:
                self[slashed_key] = [
                    slash_filter(s) for s in self[slashed_key]
                ]
            except KeyError:
                # no TRACKNUMBER/DISCNUMBER fields
                pass
        elif (attr in self.ATTRIBUTE_MAP):
            # unlike __setattr_, which tries to preserve multiple instances
            # of fields, __delattr__ wipes them all
            # so that orphaned fields don't show up after deletion
            self[self.ATTRIBUTE_MAP[attr]] = []
        elif (attr in self.FIELDS):
            # attribute is part of MetaData
            # but not supported by VorbisComment
            pass
        else:
            MetaData.__delattr__(self, attr)
Пример #11
0
    def __delattr__(self, attr):
        import re

        if (attr == 'track_number'):
            try:
                # if "Track" field contains a slashed total
                if (re.search(r'\d+.*?/.*?\d+', self['Track'].data)
                        is not None):
                    # replace unslashed portion with 0
                    self['Track'].data = re.sub(r'\d+', str(int(0)),
                                                self['Track'].data, 1)
                else:
                    # otherwise, remove "Track" field
                    del (self['Track'])
            except KeyError:
                pass
        elif (attr == 'track_total'):
            try:
                track_number = re.search(r'\d+',
                                         self["Track"].data.split("/")[0])
                # if track number is nonzero
                if (((track_number is not None)
                     and (int(track_number.group(0)) != 0))):
                    # if "Track" field contains a slashed total
                    # remove slashed total from "Track" field
                    self['Track'].data = re.sub(r'\s*/.*', "",
                                                self['Track'].data)
                else:
                    # if "Track" field contains a slashed total
                    if (re.search(r'/\D*?\d+', self['Track'].data)
                            is not None):
                        # remove "Track" field entirely
                        del (self['Track'])
            except KeyError:
                pass
        elif (attr == 'album_number'):
            try:
                # if "Media" field contains a slashed total
                if (re.search(r'\d+.*?/.*?\d+', self['Media'].data)
                        is not None):
                    # replace unslashed portion with 0
                    self['Media'].data = re.sub(r'\d+', str(int(0)),
                                                self['Media'].data, 1)
                else:
                    # otherwise, remove "Media" field
                    del (self['Media'])
            except KeyError:
                pass
        elif (attr == 'album_total'):
            try:
                album_number = re.search(r'\d+',
                                         self["Media"].data.split("/")[0])
                # if album number is nonzero
                if (((album_number is not None)
                     and (int(album_number.group(0)) != 0))):
                    # if "Media" field contains a slashed total
                    # remove slashed total from "Media" field
                    self['Media'].data = re.sub(r'\s*/.*', "",
                                                self['Media'].data)
                else:
                    # if "Media" field contains a slashed total
                    if (re.search(r'/\D*?\d+', self['Media'].data)
                            is not None):
                        # remove "Media" field entirely
                        del (self['Media'])
            except KeyError:
                pass
        elif (attr in self.ATTRIBUTE_MAP):
            try:
                del (self[self.ATTRIBUTE_MAP[attr]])
            except KeyError:
                pass
        elif (attr in MetaData.FIELDS):
            pass
        else:
            MetaData.__delattr__(self, attr)