connection.py 文件源码

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

项目:movie-network 作者: farbodf 项目源码 文件源码
def get_youtube_vid_id(self, query, max_results=10):
        """
        Makes a request to youtube API with a search query and returns the
        corresponding video's id.
        :param query: search query of type string to be used for
                      searching youtube.
        :param max_results: The maximum results returned by searching youtube
        :returns: The movie id of the first video came up in the youtube search
        """
        youtube = build(Connection.YOUTUBE_API_SERVICE_NAME,
                        Connection.YOUTUBE_API_VERSION,
                        developerKey=self.keys['google'])

        search_response = youtube.search().list(
            q=query,
            part="id,snippet",
            maxResults=max_results
        ).execute()

        for search_result in search_response.get("items", []):
            if search_result["id"]["kind"] == "youtube#video":
                return search_result["id"]["videoId"]
        else:
            return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号