From fe073801f8e1e711e6bbe744f406b0fd0a0ce69e Mon Sep 17 00:00:00 2001 From: Relakkes Date: Thu, 4 Jan 2024 00:11:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=8F=E7=BA=A2=E4=B9=A6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=9B=BE=E7=89=87=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media_platform/xhs/help.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/media_platform/xhs/help.py b/media_platform/xhs/help.py index c1e191f..67fc7d3 100644 --- a/media_platform/xhs/help.py +++ b/media_platform/xhs/help.py @@ -257,6 +257,30 @@ def get_search_id(): return base36encode((e + t)) +img_cdns = [ + "https://sns-img-qc.xhscdn.com", + "https://sns-img-hw.xhscdn.com", + "https://sns-img-bd.xhscdn.com", + "https://sns-img-qn.xhscdn.com", +] + +def get_img_url_by_trace_id(trace_id: str, format_type: str = "png"): + return f"{random.choice(img_cdns)}/{trace_id}?imageView2/format/{format_type}" + + +def get_img_urls_by_trace_id(trace_id: str, format_type: str = "png"): + return [f"{cdn}/{trace_id}?imageView2/format/{format_type}" for cdn in img_cdns] + + +def get_trace_id(img_url: str): + return img_url.split("/")[-1] + + if __name__ == '__main__': - a = get_b3_trace_id() - print(a) + _img_url = "https://sns-img-bd.xhscdn.com/7a3abfaf-90c1-a828-5de7-022c80b92aa3" + # 获取一个图片地址在多个cdn下的url地址 + # final_img_urls = get_img_urls_by_trace_id(get_trace_id(_img_url)) + final_img_url = get_img_url_by_trace_id(get_trace_id(_img_url)) + print(final_img_url) + +