本文整理汇总了Python中mimetypes.MimeTypes.guess_all_extensions方法的典型用法代码示例。如果您正苦于以下问题:Python MimeTypes.guess_all_extensions方法的具体用法?Python MimeTypes.guess_all_extensions怎么用?Python MimeTypes.guess_all_extensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mimetypes.MimeTypes
的用法示例。
在下文中一共展示了MimeTypes.guess_all_extensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_extension
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import guess_all_extensions [as 别名]
def get_extension(url):
from mimetypes import MimeTypes
mime_types = MimeTypes()
(type, encoding) = mime_types.guess_type(url)
extensions = mime_types.guess_all_extensions(type)
extension = extensions[-1]
return extension
示例2: _getExtension
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import guess_all_extensions [as 别名]
def _getExtension( episode ):
# get extension from url
urlExt = os.path.splitext( episode.url )[ 1 ]
# get extension from media type
mime = MimeTypes()
mimeExtList = mime.guess_all_extensions( episode.type )
# check if url extension matches any item in list
if urlExt in mimeExtList:
# yep, then url extension is good
return urlExt
# otherwise, use recommendation from MimeTypes, as default we use .mp3
mimeExt = mime.guess_extension( episode.type )
if mimeExt == None:
mimeExt = ".mp3"
return mimeExt