本帖最后由 彳、亍 于 2021-6-11 20:31 编辑
这个api请求不了电台,只能用id作文件名了,,
-----搜了下好像没有python版,我来做一个
功能:把缓存转换为音乐文件,重命名
使用方法:
配置输入输出目录
需要xxx.uc和xxx.info两个文件
测试图
代码
[Python] 纯文本查看 复制代码 import requests
import os
import json
import re
INPUTPATH = 'D:\\xj\\test\\'
OUTPUTPATH = 'D:\\xj\\test\\'
flag = 1 # 歌手在歌名前面? 是1 否0
list = os.listdir(INPUTPATH)
for fname in list:
if fname.split('.')[-1] != 'uc':
continue
id = fname.split('-')[0]
resp = requests.get(url='https://api.imjad.cn/cloudmusic/', params={'id': id, 'type': 'detail'})
dat = json.loads(resp.text)
with open(INPUTPATH + fname, 'rb') as fi:
b = fi.read()
nm = dat['songs'][0]['name']
artist = dat['songs'][0]['ar'][0]['name']
with open(INPUTPATH + re.sub(r'(\.uc)', '.info', fname)) as fi:
type = json.loads(fi.read())['format']
if nm is None and artist is None:
optfname = id
else:
optfname = artist + ' - ' + nm if flag == 1 else nm + ' - ' + artist
print(optfname)
with open(OUTPUTPATH + optfname + '.' + type, 'wb') as fo:
for i in b:
fo.write((i ^ 0xa3).to_bytes(length=1, byteorder='little')) |