当前位置: 首页>>代码示例>>Python>>正文


Python FLAC.lower方法代码示例

本文整理汇总了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
#.........这里部分代码省略.........
开发者ID:ejiblabahaba,项目名称:music_organizer,代码行数:103,代码来源:NamingTools.py


注:本文中的mutagen.flac.FLAC.lower方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。