spotifyprovider.py 文件源码

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

项目:xmusic-crawler 作者: rockers7414 项目源码 文件源码
def __search(self, keyword, search_type):
        offset = 0
        result_key = search_type + "s"
        result = []

        while True:
            self.logger.info("search " + keyword + ", offset = " + str(offset))
            params = {
                "q": keyword,
                "type": search_type,
                "offset": offset,
                "limit": 50
            }

            buf = BytesIO()

            client = pycurl.Curl()
            client.setopt(pycurl.URL, self.service_host +
                          "/v1/search" + "?" + urlencode(params))
            client.setopt(pycurl.WRITEFUNCTION, buf.write)
            client.perform()
            client.close()

            body = json.loads(buf.getvalue().decode("utf-8"))
            buf.close()

            if body[result_key]["total"] > 0:
                for data in body[result_key]["items"]:
                    result.append(data)

            if body[result_key]["total"] > \
                    body[result_key]["limit"] * (offset + 1):
                offset = offset + 1
            else:
                break

        self.logger.info("Done")
        return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号