providers.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:tumanov_castleoaks 作者: Roamdev 项目源码 文件源码
def get_info(cls, video_key):
        req = request.Request('http://vimeo.com/api/v2/video/%s.xml' % video_key, method='GET')
        try:
            logger.debug('{0.method} {0.full_url}'.format(req))
            response = request.urlopen(req, timeout=3)
        except error.URLError:
            return None

        if response.status != 200:
            return None

        dom = minidom.parseString(response.read())
        title = dom.getElementsByTagName('title').item(0)
        description = dom.getElementsByTagName('description').item(0)
        description = description.firstChild.data
        description = re.sub(r'<br\s*/?>\s*', '\n', description)
        thumbnail_large = dom.getElementsByTagName('thumbnail_large').item(0)
        width = dom.getElementsByTagName('width').item(0)
        width = int(width.firstChild.data)
        height = dom.getElementsByTagName('height').item(0)
        height = int(height.firstChild.data)
        embed_width = min(640, width)
        embed_height = int(embed_width * height / width)
        code = '<iframe src="//player.vimeo.com/video/{}" ' \
               'width="{}" height="{}" frameborder="0" ' \
               'webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
        return {
            'title': title.firstChild.data,
            'description': strip_tags(description),
            'preview_url': thumbnail_large.firstChild.data.replace('webp', 'jpg'),
            'embed': code.format(video_key, embed_width, embed_height)
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号