本文整理汇总了Python中mutagen.flac.FLAC.lower方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.lower方法的具体用法?Python FLAC.lower怎么用?Python FLAC.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.lower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getNewFolderName
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import lower [as 别名]
def getNewFolderName(dr):
"""Takes a directory, performs mutagen voodoo on each file that has a
music extension, and returns a suggested folder name.
ARGS:
dr: A string with the directory to be renamed.
RETURNS:
suggested_name: A string with the suggested rename.
"""
os.chdir(dr)
files = validExtensions(os.listdir(dr))
if files == []: return "<no suggestion>"
broken = []
albums = {}
years = {}
qualities = {}
rename_props = {'al':albums,'yr':years,'ql':qualities}
rename_keys = ['al','yr','ql']
for item in files:
try:
name_copy = str(item)
except UnicodeEncodeError, e:
print "broke on item ", item
print "Attempting unicode magic"
name_copy = str(item.encode('utf8','replace'))
path = dr + '\\' + item
if item.lower().endswith('.mp3'): #handles mp3s
try:
item = MP3(item)
#album
try:
album = item.tags.getall('TALB')
except AttributeError:
print name_copy," has weird fuckin album tags"
album = []
broken.append(os.path.join(dr,name_copy))
if album != []:
album = str(album[0].text[0])
else:
album = u
#year
try:
year = item.tags.getall('TDRC')
except AttributeError:
print name_copy," has weird fuckin date tags"
year = []
broken.append(os.path.join(dr,name_copy))
if year != []:
year = str(year[0].text[0])
if len(year) != 4:
yl = re.findall(r,year)
if yl != []: year = yl[0]
else: year = u
else:
year = u
#quality
if isVBR(item):
VBR_quality = getVBRQuality(name_copy)
if VBR_quality != -1: q = 'V' + str(VBR_quality)
else: q = u
else:
q = item.info.bitrate / 1000
except HeaderNotFoundError:
print "No header found on ", item, ", skipping..."
broken.append(os.path.join(dr,item))
elif item.lower().endswith('.flac'): #handles flacs
try:
item = FLAC(item)
q = 'FLAC'
try:
year = item['date'][0]
if len(year) != 4:
yl = re.findall(r,year)
if yl != []: year = yl[0]
else: year = u
except KeyError:
year = u
try:
album = item['album'][0]
except KeyError:
album = u
except FLACNoHeaderError:
print "No header found on ", item, ", skipping..."
broken.append(os.path.join(dr,item))
elif item.lower().endswith('.m4a') or item.lower().endswith('m4p'):
try:
if item.lower().endswith('.m4a'): q = 'M4A'
else: q = 'M4P'
item = M4A(item)
try:
year = item.tags['\xa9day']
if len(year) != 4:
yl = re.findall(r,year)
if yl != []: year = yl[0]
else: year = u
except KeyError:
year = u
#.........这里部分代码省略.........