本文整理汇总了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):
#.........这里部分代码省略.........