本文整理汇总了Python中weboob.capabilities.video.BaseVideo.url方法的典型用法代码示例。如果您正苦于以下问题:Python BaseVideo.url方法的具体用法?Python BaseVideo.url怎么用?Python BaseVideo.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weboob.capabilities.video.BaseVideo
的用法示例。
在下文中一共展示了BaseVideo.url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: video_info
# 需要导入模块: from weboob.capabilities.video import BaseVideo [as 别名]
# 或者: from weboob.capabilities.video.BaseVideo import url [as 别名]
def video_info(url):
"""Fetch info about a video using youtube-dl
:param url: URL of the web page containing the video
:rtype: :class:`weboob.capabilities.video.Video`
"""
if not MediaPlayer._find_in_path(os.environ['PATH'], 'youtube-dl'):
raise Exception('Please install youtube-dl')
try:
j = json.loads(subprocess.check_output(['youtube-dl', '-f', 'best', '-J', url]))
except subprocess.CalledProcessError:
return
v = BaseVideo(id=url)
v.title = j.get('title') or NotAvailable
v.ext = j.get('ext') or NotAvailable
v.description = j.get('description') or NotAvailable
v.url = j['url']
v.duration = j.get('duration') or NotAvailable
v.author = j.get('uploader') or NotAvailable
v.rating = j.get('average_rating') or NotAvailable
if j.get('thumbnail'):
v.thumbnail = Thumbnail(j['thumbnail'])
d = j.get('upload_date', j.get('release_date'))
if d:
v.date = parse_date(d)
return v
示例2: create_video_from_json
# 需要导入模块: from weboob.capabilities.video import BaseVideo [as 别名]
# 或者: from weboob.capabilities.video.BaseVideo import url [as 别名]
def create_video_from_json(self, _video):
video = BaseVideo()
video.id = u'%s' % _video['id']
video.backend = u'%s' % _video['id'].split('@')[-1]
if 'url' in _video.keys():
video.url = u'%s' % _video['url']
if 'thumbnail' in _video.keys() and _video['thumbnail'] and 'url' in _video['thumbnail'].keys():
video.thumbnail = BaseImage()
video.thumbnail.url = u'%s' % _video['thumbnail']['url']
else:
video.thumbnail.url = u''
video.title = u'%s' % _video['title']
if _video['date']:
_date = re.search('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*', _video['date'])
try:
datetime.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')
except TypeError:
datetime(*(time.strptime(_date.group(1), '%Y-%m-%d %H:%M:%S')[0:6]))
video.description = u'%s' % _video['description']
video.author = u'%s' % _video['author']
if _video['duration']:
_duration = _video['duration'].split(':')
video.duration = timedelta(hours=int(_duration[0]), minutes=int(_duration[1]), seconds=int(_duration[2]))
return video
示例3: parse_video
# 需要导入模块: from weboob.capabilities.video import BaseVideo [as 别名]
# 或者: from weboob.capabilities.video.BaseVideo import url [as 别名]
def parse_video(self, _video, category):
video = BaseVideo(u'%s#%s' % (_video['code'], category))
video.title = unicode(_video['title'])
video._video_code = unicode(_video['code'])
video.ext = u'mp4'
if 'runtime' in _video:
video.duration = timedelta(seconds=int(_video['runtime']))
if 'description' in _video:
video.description = unicode(_video['description'])
renditions = sorted(_video['rendition'], key=lambda x: 'bandwidth' in x and x['bandwidth']['code'], reverse=True)
video.url = unicode(max(renditions, key=lambda x: 'bandwidth' in x)['href'])
return video
示例4: parse_video
# 需要导入模块: from weboob.capabilities.video import BaseVideo [as 别名]
# 或者: from weboob.capabilities.video.BaseVideo import url [as 别名]
def parse_video(self, _video, category):
video = BaseVideo(u"%s#%s" % (_video["code"], category))
video.title = unicode(_video["title"])
video._video_code = unicode(_video["code"])
video.ext = u"mp4"
if "runtime" in _video:
video.duration = timedelta(seconds=int(_video["runtime"]))
if "description" in _video:
video.description = unicode(_video["description"])
renditions = sorted(
_video["rendition"], key=lambda x: "bandwidth" in x and x["bandwidth"]["code"], reverse=True
)
video.url = unicode(max(renditions, key=lambda x: "bandwidth" in x)["href"])
return video