def search(self, cardinal, user, channel, msg):
        # Before we do anything, let's make sure we'll be able to query YouTube
        if self.api_key is None:
            cardinal.sendMsg(channel, "YouTube plugin is not configured correctly. Please set API key.")

        # Grab the search query
        try:
            search_query = msg.split(' ', 1)[1]
        except IndexError:
            cardinal.sendMsg(channel, "Syntax: .youtube <search query>")
            return

        params = {'q': search_query, 'part': 'snippet', 'maxResults': 1, 'type': 'video'}

        try:
            result = self._form_request("search", params)
        except Exception, e:
            cardinal.sendMsg(channel, "Unable to connect to YouTube.")
            self.logger.exception("Failed to connect to YouTube")
            return

        if 'error' in result:
            cardinal.sendMsg(channel, "An error occurred while attempting to search YouTube.")
            self.logger.error(
                "Error attempting to search YouTube: %s" % content['error']
            )
            return

        try:
            video_id = str(result['items'][0]['id']['videoId'].encode('utf-8'))

            params = {
                'id': video_id,
                'maxResults': 1,
                'part': 'snippet,statistics'
            }
        except IndexError:
            cardinal.sendMsg(channel, "No videos found matching that search.")
            return

        try:
            result = self._form_request("videos", params)
        except Exception, e:
            cardinal.sendMsg(channel, "Unable to connect to YouTube.")
            self.logger.exception("Failed to connect to YouTube")
            return

        try:
            message = self._parse_item(result['items'][0])
            cardinal.sendMsg(channel, message)
        except __HOLE__:
            cardinal.sendMsg(channel, "No videos found matching that search.")
        except Exception, e:
            self.logger.exception("Failed to parse info for %s'" % video_id)
            raise EventRejectedMessage
dataset/ETHPy150Open JohnMaguire/Cardinal/plugins/youtube/plugin.py/YouTubePlugin.search