本文整理汇总了Python中audiotools.MetaData类的典型用法代码示例。如果您正苦于以下问题:Python MetaData类的具体用法?Python MetaData怎么用?Python MetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setitem__
def __setitem__(self, key, values):
from audiotools import PY3
assert(isinstance(key, str if PY3 else unicode))
for v in values:
assert(isinstance(v, str if PY3 else unicode))
new_values = values[:]
new_comment_strings = []
matching_keys = self.ALIASES.get(key.upper(), frozenset([key.upper()]))
for comment in self.comment_strings:
if u"=" in comment:
(c_key, c_value) = comment.split(u"=", 1)
if c_key.upper() in matching_keys:
try:
# replace current value with newly set value
new_comment_strings.append(
u"{}={}".format(c_key, new_values.pop(0)))
except IndexError:
# no more newly set values, so remove current value
continue
else:
# passthrough unmatching values
new_comment_strings.append(comment)
else:
# passthrough values with no "=" sign
new_comment_strings.append(comment)
# append any leftover values
for new_value in new_values:
new_comment_strings.append(u"{}={}".format(key.upper(), new_value))
MetaData.__setattr__(self, "comment_strings", new_comment_strings)
示例2: __init__
def __init__(self, track_name, artist_name, album_name,
year, comment, track_number, genre):
#pre-emptively cut down overlong fields
MetaData.__init__(self,
track_name=track_name[0:30],
artist_name=artist_name[0:30],
album_name=album_name[0:30],
year=year[0:4],
comment=comment[0:28],
track_number=track_number)
self.__dict__['genre'] = genre
示例3: __init__
def __init__(self, comment_strings, vendor_string):
"""comment_strings is a list of unicode strings
vendor_string is a unicode string"""
from audiotools import PY3
# some debug type checking
for s in comment_strings:
assert(isinstance(s, str if PY3 else unicode))
assert(isinstance(vendor_string, str if PY3 else unicode))
MetaData.__setattr__(self, "comment_strings", comment_strings)
MetaData.__setattr__(self, "vendor_string", vendor_string)
示例4: __init__
def __init__(self, track_name, artist_name, album_name, year, comment, track_number, genre):
"""all fields except track_number are binary strings"""
# pre-emptively cut down overlong fields
MetaData.__init__(
self,
track_name=track_name[0:30],
artist_name=artist_name[0:30],
album_name=album_name[0:30],
year=year[0:4],
comment=comment[0:28],
track_number=track_number,
)
self.__dict__["genre"] = genre
示例5: intersection
def intersection(self, metadata):
"""given a MetaData-compatible object,
returns a new MetaData object which contains
all the matching fields and images of this object and 'metadata'
"""
def comment_present(comment):
if u"=" in comment:
key, value = comment.split(u"=", 1)
try:
for other_value in metadata[key]:
if value == other_value:
return True
else:
return False
except KeyError:
return False
else:
for other_comment in metadata.comment_strings:
if comment == other_comment:
return True
else:
return False
if isinstance(metadata, VorbisComment):
return self.__class__([comment
for comment in self.comment_strings
if comment_present(comment)],
self.vendor_string)
else:
return MetaData.intersection(self, metadata)
示例6: __delattr__
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: metadata_audiotools
def metadata_audiotools(self, path, media):
from audiotools import MetaData
import audiotools
meta = MetaData()
# release-level metadata
if media.release and media.release.main_image:
if meta.supports_images() and os.path.exists(media.release.main_image.path):
opt = dict(size=(200, 200), crop=True, bw=False, quality=80)
image = get_thumbnailer(media.release.main_image).get_thumbnail(opt)
meta.add_image(get_raw_image(image.path, 0))
audiotools.open(path).update_metadata(meta)
return
示例8: __delitem__
def __delitem__(self, key):
from audiotools import PY3
assert(isinstance(key, str if PY3 else unicode))
new_comment_strings = []
matching_keys = self.ALIASES.get(key.upper(), frozenset([key.upper()]))
for comment in self.comment_strings:
if u"=" in comment:
(c_key, c_value) = comment.split(u"=", 1)
if c_key.upper() not in matching_keys:
# passthrough unmatching values
new_comment_strings.append(comment)
else:
# passthrough values with no "=" sign
new_comment_strings.append(comment)
MetaData.__setattr__(self, "comment_strings", new_comment_strings)
示例9: __setattr__
def __setattr__(self, attr, value):
def swap_number(unicode_value, new_number):
import re
return re.sub(r'\d+', u"%d" % (new_number), unicode_value, 1)
def swap_slashed_number(unicode_value, new_number):
if u"/" in unicode_value:
(first, second) = unicode_value.split(u"/", 1)
return u"/".join([first, swap_number(second, new_number)])
else:
return u"/".join([unicode_value, u"%d" % (new_number)])
if attr in self.ATTRIBUTE_MAP:
key = self.ATTRIBUTE_MAP[attr]
if value is not None:
if attr in {'track_number', 'album_number'}:
try:
current_value = self[key].__unicode__()
self[key] = self.ITEM.string(
key, swap_number(current_value, value))
except KeyError:
self[key] = self.ITEM.string(
key, __number_pair__(value, None))
elif attr in {'track_total', 'album_total'}:
try:
current_value = self[key].__unicode__()
self[key] = self.ITEM.string(
key, swap_slashed_number(current_value, value))
except KeyError:
self[key] = self.ITEM.string(
key, __number_pair__(None, value))
elif attr == 'compilation':
self[key] = self.ITEM.string(key,
u"%d" % (1 if value else 0))
else:
self[key] = self.ITEM.string(key, value)
else:
delattr(self, attr)
else:
MetaData.__setattr__(self, attr, value)
示例10: __init__
def __init__(self, tags, contains_header=True, contains_footer=True):
"""constructs an ApeTag from a list of ApeTagItem objects"""
for tag in tags:
assert(isinstance(tag, ApeTagItem))
MetaData.__setattr__(self, "tags", list(tags))
MetaData.__setattr__(self, "contains_header", contains_header)
MetaData.__setattr__(self, "contains_footer", contains_footer)
示例11: __init__
def __init__(self, tags, contains_header=True, contains_footer=True):
"""constructs an ApeTag from a list of ApeTagItem objects"""
for tag in tags:
if (not isinstance(tag, ApeTagItem)):
raise ValueError("%s is not ApeTag" % (repr(tag)))
MetaData.__setattr__(self, "tags", list(tags))
MetaData.__setattr__(self, "contains_header", contains_header)
MetaData.__setattr__(self, "contains_footer", contains_footer)
示例12: __getattr__
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)
示例13: intersection
def intersection(self, metadata):
"""given a MetaData-compatible object,
returns a new MetaData object which contains
all the matching fields and images of this object and 'metadata'
"""
if type(metadata) is ID3v1Comment:
return ID3v1Comment(
genre=(self.__genre__ if
self.__genre__ == metadata.__genre__ else 0),
**{arg: getattr(self, field)
for arg, field in ID3v1Comment.ID3v1_FIELDS.items()
if getattr(self, field) == getattr(metadata, field)})
else:
return MetaData.intersection(self, metadata)
示例14: __getattr__
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)
示例15: __unicode__
def __unicode__(self):
if ('Cuesheet' not in self.keys()):
return ApeTag.__unicode__(self)
else:
import cue
try:
return u"%s%sCuesheet:\n%s" % \
(MetaData.__unicode__(self),
os.linesep * 2,
sheet_to_unicode(
cue.parse(
cue.tokens(unicode(self['Cuesheet']).encode(
'ascii', 'replace'))),
self.frame_count))
except cue.CueException:
return ApeTag.__unicode__(self)