Skip to content

Commit

Permalink
feat: 优化脚本获取
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Jan 7, 2024
1 parent c51162d commit 12f9e90
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions common/lx_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,46 @@

logger = log('lx_script')

jsd_mirror_list = [
'https://cdn.jsdelivr.net',
'https://gcore.jsdelivr.net',
'https://fastly.jsdelivr.net',
'https://jsd.cdn.zzko.cn',
'https://jsdelivr.b-cdn.net',
]
githun_raw_mirror_list = [
'https://raw.githubusercontent.com',
'https://mirror.ghproxy.com/https://raw.githubusercontent.com',
'https://ghraw.gkcoll.xyz',
'https://raw.fgit.mxtrans.net',
'https://github.moeyy.xyz/https://raw.githubusercontent.com',
'https://raw.fgit.cf',
]

async def get_response(retry = 0):
if (retry > 10):
if (retry > 21):
logger.warning('请求源脚本内容失败')
return
baseurl = 'https://raw.githubusercontent.com/lxmusics/lx-music-api-server/main/lx-music-source-example.js'
baseurl = '/lxmusics/lx-music-api-server/main/lx-music-source-example.js'
jsdbaseurl = '/gh/lxmusics/lx-music-api-server@main/lx-music-source-example.js'
try:
if (iscn and (retry % 2) == 0):
req = await Httpx.AsyncRequest('https://mirror.ghproxy.com/' + baseurl)
else:
req = await Httpx.AsyncRequest(baseurl)
i = retry
if (i > 10):
i = i - 11
if (i < 5):
req = await Httpx.AsyncRequest(jsd_mirror_list[retry] + jsdbaseurl)
elif (i < 11):
req = await Httpx.AsyncRequest(githun_raw_mirror_list[retry - 5] + baseurl)
if (not req.text.startswith('/*!')):
logger.info('疑似请求到了无效的内容,忽略')
raise Exception from None
except Exception as e:
if (isinstance(e, RuntimeError)):
if ('Session is closed' in str(e)):
logger.error('脚本更新失败,clientSession已被关闭')
return
return await get_response(retry + 1)
return req

async def get_script():
req = await get_response()
if (req.status == 200):
Expand Down

0 comments on commit 12f9e90

Please sign in to comment.