本文整理汇总了Python中audiotools.MetaData.__delattr__方法的典型用法代码示例。如果您正苦于以下问题:Python MetaData.__delattr__方法的具体用法?Python MetaData.__delattr__怎么用?Python MetaData.__delattr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audiotools.MetaData
的用法示例。
在下文中一共展示了MetaData.__delattr__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __delattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __delattr__ [as 别名]
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)
示例2: __delattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __delattr__ [as 别名]
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)
示例3: __delattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __delattr__ [as 别名]
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)
示例4: __delattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __delattr__ [as 别名]
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)
示例5: __delattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __delattr__ [as 别名]
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)