本文整理汇总了Python中audiotools.MetaData.__getattribute__方法的典型用法代码示例。如果您正苦于以下问题:Python MetaData.__getattribute__方法的具体用法?Python MetaData.__getattribute__怎么用?Python MetaData.__getattribute__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类audiotools.MetaData
的用法示例。
在下文中一共展示了MetaData.__getattribute__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __getattribute__ [as 别名]
def __getattr__(self, attr):
if attr in self.ATTRIBUTE_MAP:
try:
if attr in {'track_number', 'album_number'}:
return self[self.ATTRIBUTE_MAP[attr]].number()
elif attr in {'track_total', 'album_total'}:
return self[self.ATTRIBUTE_MAP[attr]].total()
else:
return self[self.ATTRIBUTE_MAP[attr]].__unicode__()
except KeyError:
return None
elif attr in MetaData.FIELDS:
return None
else:
return MetaData.__getattribute__(self, attr)
示例2: __getattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __getattribute__ [as 别名]
def __getattr__(self, attr):
if attr == "track_number":
number = self.__track_number__
if number > 0:
return number
else:
return None
elif attr in self.ID3v1_FIELDS:
value = getattr(self, self.ID3v1_FIELDS[attr])
if len(value) > 0:
return value
else:
return None
elif attr in self.FIELDS:
return None
else:
return MetaData.__getattribute__(self, attr)
示例3: __getattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __getattribute__ [as 别名]
def __getattr__(self, attr):
if (attr == "track_number"):
number = ord(self.__track_number__)
if (number > 0):
return number
else:
return None
elif (attr in self.ID3v1_FIELDS):
value = getattr(
self,
self.ID3v1_FIELDS[attr]).rstrip(chr(0)).decode('ascii',
'replace')
if (len(value) > 0):
return value
else:
return None
elif (attr in self.FIELDS):
return None
else:
return MetaData.__getattribute__(self, attr)
示例4: __getattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __getattribute__ [as 别名]
def __getattr__(self, attr):
# returns the first matching key for the given attribute
# in our list of comment strings
if attr in self.ATTRIBUTE_MAP:
key = self.ATTRIBUTE_MAP[attr]
if attr in {'track_number', 'album_number'}:
try:
# get the TRACKNUMBER/DISCNUMBER values
# return the first value that contains an integer
for value in self[key]:
integer = re.search(r'\d+', value)
if integer is not None:
return int(integer.group(0))
else:
# otherwise, return None
return None
except KeyError:
# if no TRACKNUMBER/DISCNUMBER, return None
return None
elif attr in {'track_total', 'album_total'}:
try:
# get the TRACKTOTAL/DISCTOTAL values
# return the first value that contains an integer
for value in self[key]:
integer = re.search(r'\d+', value)
if integer is not None:
return int(integer.group(0))
except KeyError:
pass
# if no TRACKTOTAL/DISCTOTAL,
# or none of them contain an integer,
# look for slashed TRACKNUMBER/DISCNUMBER values
try:
for value in self[{"track_total": u"TRACKNUMBER",
"album_total": u"DISCNUMBER"}[attr]]:
if u"/" in value:
integer = re.search(r'\d+',
value.split(u"/", 1)[1])
if integer is not None:
return int(integer.group(0))
else:
return None
except KeyError:
# no slashed TRACKNUMBER/DISCNUMBER values either
# so return None
return None
elif attr == "compilation":
try:
# if present, return True if the first value is "1"
return self[key][0] == u"1"
except KeyError:
# if not present, return None
return None
else:
# attribute is supported by VorbisComment
try:
# if present, return the first value
return self[key][0]
except KeyError:
# if not present, return None
return None
elif attr in self.FIELDS:
# attribute is supported by MetaData
# but not supported by VorbisComment
return None
else:
# attribute is not MetaData-specific
return MetaData.__getattribute__(self, attr)
示例5: __getattr__
# 需要导入模块: from audiotools import MetaData [as 别名]
# 或者: from audiotools.MetaData import __getattribute__ [as 别名]
def __getattr__(self, attr):
import re
if (attr == 'track_number'):
try:
track_text = unicode(self["Track"])
track = re.search(r'\d+', track_text)
if (track is not None):
track_number = int(track.group(0))
if ((track_number == 0) and
(re.search(r'/.*?(\d+)',
track_text) is not None)):
# if track_total is nonzero and track_number is 0
# track_number is a placeholder
# so treat track_number as None
return None
else:
return track_number
else:
# "Track" isn't an integer
return None
except KeyError:
# no "Track" in list of items
return None
elif (attr == 'track_total'):
try:
track = re.search(r'/.*?(\d+)', unicode(self["Track"]))
if (track is not None):
return int(track.group(1))
else:
# no slashed integer field in "Track"
return None
except KeyError:
# no "Track" in list of items
return None
elif (attr == 'album_number'):
try:
media_text = unicode(self["Media"])
media = re.search(r'\d+', media_text)
if (media is not None):
album_number = int(media.group(0))
if ((album_number == 0) and
(re.search(r'/.*?(\d+)',
media_text) is not None)):
# if album_total is nonzero and album_number is 0
# album_number is a placeholder
# so treat album_number as None
return None
else:
return album_number
else:
# "Media" isn't an integer
return None
except KeyError:
# no "Media" in list of items
return None
elif (attr == 'album_total'):
try:
media = re.search(r'/.*?(\d+)', unicode(self["Media"]))
if (media is not None):
return int(media.group(1))
else:
# no slashed integer field in "Media"
return None
except KeyError:
# no "Media" in list of items
return None
elif (attr in self.ATTRIBUTE_MAP):
try:
return unicode(self[self.ATTRIBUTE_MAP[attr]])
except KeyError:
return None
elif (attr in MetaData.FIELDS):
return None
else:
return MetaData.__getattribute__(self, attr)