當前位置: 首頁>>代碼示例>>Python>>正文


Python Httpy.get_meta方法代碼示例

本文整理匯總了Python中Httpy.Httpy.get_meta方法的典型用法代碼示例。如果您正苦於以下問題:Python Httpy.get_meta方法的具體用法?Python Httpy.get_meta怎麽用?Python Httpy.get_meta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Httpy.Httpy的用法示例。


在下文中一共展示了Httpy.get_meta方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: VideoBase

# 需要導入模塊: from Httpy import Httpy [as 別名]
# 或者: from Httpy.Httpy import get_meta [as 別名]
class VideoBase(object):

	def __init__(self, url):
		if not self.can_rip(url):
			# Don't instantiate if we can't rip it
			raise Exception('ripper (%s) cannot rip URL (%s)' % (self.__class__.__name__, url))
		self.url = url
		self.httpy = Httpy()

	@staticmethod
	def get_host():
		'''
			Returns the 'name' of this video ripper's host
		'''
		raise Exception('get_host() not overridden by inheriting class')

	@staticmethod
	def can_rip(url):
		'''
			Returns:
				True if this ripper can rip the given URL, False otherwise
		'''
		raise Exception('can_rip() not overridden by inheriting class')

	@staticmethod
	def get_sample_url():
		'''
			Returns a test URL to be used by test()
		'''
		raise Exception('get_sample_url() not overridden by inheriting class')

	def rip_video(self):
		'''
			Gets info about the video at self.url
			Returns:
				dict containing keys:
					['url']    video url
					['size']   filesize of video
					['type']   type of video (mp4/flv)
					['poster'] image showing preview of album (optional)
		'''
		raise Exception('rip-video() not overridden by inheriting class')

	def get_video_info(self, url):
		'''
			Asserts URL is valid and points to video
			Returns dict containing url, size, and type
		'''
		meta = self.httpy.get_meta(url)
		filesize = int(meta.get('Content-Length', '0'))
		filetype = meta.get('Content-Type', 'unknown')
		if not filetype.startswith('video/'):
			raise Exception('content-type (%s) not "video/" at %s' % (filetype, vid))
		else:
			filetype = filetype.replace('video/', '').replace('x-', '')
		return {
			'url' : url,
			'size' : filesize,
			'type' : filetype,
			'host' : self.get_host(),
			'source' : self.url
		}

	@staticmethod
	def iter_rippers():
		'''
			Iterator over all video rippers in this directory
		'''
		from os import getcwd, listdir, path
		if not getcwd().endswith('py'):
			prefix = 'py.'
		for mod in listdir(path.dirname(path.realpath(__file__))):
			if not mod.startswith('Video') or not mod.endswith('.py') or mod.startswith('VideoBase'):
				continue
			mod = mod[:-3]
			try:
				ripper = __import__('%s%s' % (prefix, mod), fromlist=[mod]).__dict__[mod]
			except:
				# Don't use a prefix
				ripper = __import__(mod, fromlist=[mod]).__dict__[mod]
			yield ripper

	@staticmethod
	def get_ripper(url):
		'''
			Searches through all video rippers in this directory for a compatible ripper.
			Args:
				url: URL of video to rip
			Returns:
				Uninstantiated class for the ripper that is compatible with the url.
			Raises:
				Exception if no ripper can be found, or other errors occurred
		'''
		for ripper in VideoBase.iter_rippers():
			if 'can_rip' in ripper.__dict__ and ripper.can_rip(url):
				return ripper
		raise Exception('no compatible ripper found')

	@staticmethod
	def test_ripper(ripper):
#.........這裏部分代碼省略.........
開發者ID:jadedgnome,項目名稱:rip3,代碼行數:103,代碼來源:VideoBase.py


注:本文中的Httpy.Httpy.get_meta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。