Esempio n. 1
0
    def search_by_keyword(self, query, page=1):
        client = VimeoClient(settings.VIMEO_CONSUMER_KEY,
                             settings.VIMEO_CONSUMER_SECRET)

        videos = client.vimeo_videos_search(query=query)

        data = {'results': []}

        data['index'] = {
            'total_results': len(videos),
            'items_per_page': self.NB_RESULTS_PER_PAGE
        }

        for video in videos.getchildren():
            current_result = {
                'id': video.get('id'),
                'name': video.get('title'),
                'permalink_url': 'http://vimeo.com/%s' % video.get('id'),
                'description': '',
                'embed_url': 'http://player.vimeo.com/video/%s' % video.get('id'),
                'embed_type': '',
                'duration': '',
                'user_name': '',
                'user_url': ''
            }
            response = client.vimeo_videos_getThumbnailUrls(video_id=video.get('id'))
            thumbnails = response.getchildren()
            information = client.vimeo_videos_getInfo(video_id=video.get('id'))

            if len(information):
                current_result.update({
                    'description': information.find('description').text,
                    'duration': information.find('duration').text,
                    'user_name': information.find('owner').get('display_name'),
                    'user_url': information.find('owner').get('profileurl')
                })

            if len(thumbnails) > 1:
                current_result['image_url'] = thumbnails[1].text

            data['results'].append(current_result)
        return data