利用Cloudflare Workers反代Spotify这一篇文章中,我们已经大概知道了该如何用CF反代Spotify,但其中,有一个关于Cookie的设置问题没有讲清楚,今天又试了一下,总结出了有些东西,所以来补个档。为什么不在原文直接插呢,因为太乱了懒得改了,而且还能水篇文章

首先,你需要知道,Spotify的某些Cookie是无法在镜像站成功登录的,所以你必须按照我试出来的方法获取并设置Cookie,至于为什么,我也不知道()

如果你获取到的Cookie长下面这样,是无法登录的:

sp_t=977ecfbe-XXXX-4d9d-XXXX-a99c5XXXX588; _gcl_au=1.1.199XXXX942.1691758057; sp_adid=885XXXXX-33bb-4f0b-aa04-aae7d316850c; OptanonAlertBoxClosed=2023-08-11T12:47:55.548Z; _yjsu_yjad=XXXXX59866.e93XXXXX-d82b-44a3-XXXX-d189c35adac1; _cs_c=0; _scid=42a39544-XXXX-XXXX-ad25-ce02b46cc793; _sctr=1%7C1692979XXXXXX; sp_gaid=0088fc9eXXXXXda6; _pin_unauth=dWlkPVl6WXXXXXXXzWkRRMw; sp_last_utm=%7B%22utm_campaign%22%3A%22your_account%22%2C%22utm_medium%22%3A%22menu%22%2C%22utm_source%22%3A%22spotify%22%7D; _cs_id=cc5aXXXX-a51c-ab3b-b276-167cb4aa3dc4.1XXXXX9866.2.1693140054.1693139261.1.1727223866730; _scid_r=42a39544-29c1-4342-ad25-ce02b46cc793; _ga_S35RN5WNT2=GS1.1.1XXXX0.2.1.1693140059.0.0.0; sp_pfhp=2cXXXXX8-8a92-XXXX-a1c0-8b43b3090b49; _gid=GA1.2.8070XXXXX.1XXXXX9960; sp_key=9d951571-6128-4276-XXXX-4651837bd536; OptanonConsent=isIABGlobal=false&datestamp=Thu+Oct+12+2023+13%3A57%3A38+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.26.0&hosts=&landingPath=NotLandingPage&groups=s00%3A1%2Cf00%3A1%2Cm00%3A1%2Ct00%3A1%2Ci00%3A1%2Cf11%3A1&geolocation=JP%3B13&AwaitingReconsent=false; sss=1; _ga=GA1.2.234901318.1XXXX58061; _gat_UA-57XXXXX-31=1; _ga_ZWG1NSHWD8=GS1.1.1697XXX960.5.1.1XXXX0328.0.0.0

可以的是长这样的:

sp_m=jp; sp_t=977eXXXX-a9f7-XXXX-97bf-a99c5f36e588; _gcl_au=1.1.1XXXX69942.1691758057; sp_adid=8XXXX32-33bb-4f0b-aa04-aae7XXc; OptanonAlertBoxClosed=2023-08-11T12:47:55.548Z; _yjsu_yjad=1693059866.e93100cb-d82XXX3-82e9-d189c35adac1; _cs_c=0; _scid=42a39XXX-29c1-4342-ad25-ce02b46XXXX3; _sctr=1%7C169XXXXX00000; sp_gaid=0088fXX3f8772283deXXXXfd2beb156b7da6; _pin_unauth=dWlUzWmpBdEXXXXXRMw; sp_last_utm=%7B%22utm_campaign%22%3A%22your_account%22%2C%22utm_medium%22%3A%22menu%22%2C%22utm_source%22%3A%22spotify%22%7D; _cs_id=cc5acXXXXX-b276-167cb4aa3dc4.1XXXXXX0054.1693139261.1.1727223866730; _scid_r=42a3954XXXXXXXX-ce02b46cc793; _ga_S35RN5WNT2=GS1XXXXXX260.2.1.1693140059.0.0.0; sp_landing=https%3A%2F%2Fwww.spotify.com%2Fjp%2F; sp_pfhp=2c2ccb58XXXX1c0-8b43b3090b49; _gid=GA1.2.80702013XXX9960; sp_dc=AQBr_Y208eFUREG5KV7zl-NnYjXXXXkEWCsed-fw9t5mZtT29aXXXXh3M; sp_key=9d951571-6128-4276-ae11-46XXXXX536; OptanonConsent=isIABGlobal=false&datestamp=Thu+Oct+12+2023+13%3A57%3A38+GMT%2B0800+(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)&version=6.26.0&hosts=&landingPath=NotLandingPage&groups=s00%3A1%2Cf00%3A1%2Cm00%3A1%2Ct00%3A1%2Ci00%3A1%2Cf11%3A1&geolocation=JP%3B13&AwaitingReconsent=false; sss=1; _ga=GA1.2.234901318.16XXX58061; _gat_UA-XXXXX31=1; _ga_ZWG1NSHWD8=GS1.1XXXXX60.5.1.1697090328.0.0.0

总之,不出意外,正确的Cookie开头必须是`sp_m`。

接下来来讲我的思路,首先,随便找一首歌右键选择嵌入代码,将src复制粘贴打开:

F12打开开发者工具,刷新网页,找到带monitoring的请求:

复制Cookie至CF脚本内即可:

不出意外,应该是成功了。

对于Cookie有效期,我也不清楚,但过一段时间就会掉,记得上去换。