Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

作者能不能增加一个播放功能 #120

Open
djapple opened this issue Aug 20, 2023 · 3 comments
Open

作者能不能增加一个播放功能 #120

djapple opened this issue Aug 20, 2023 · 3 comments

Comments

@djapple
Copy link

djapple commented Aug 20, 2023

能不能增加一个在线播放的功能
比如搜索出来的歌曲可以播放

@sit-back-andrelax-plz
Copy link

我是在本地魔改了下,由于跟秋城落叶大神可能思路不太一样,没敢pull代码,贴一下大概逻辑,仅供大家参考

SearchMusic.Vue

<el-link v-if="basicStore.config.platform=='kw'" :icon="Headset"  :href="`/ext/playUrl?mid=${scope.row.mid}&t=kw&q=mp3&r=1`" target="_blank"><span style="margin-left: 4px;">试听</span></el-link>
<el-link v-if="basicStore.config.platform=='qq'" :icon="Headset"  :href="`/ext/playUrl?m=${encodeURIComponent(JSON.stringify(scope.row))}&t=qq&q=mp3&r=1`" target="_blank"><span style="margin-left: 4px;">试听</span></el-link>

浏览器直接播放大概逻辑,获取地址的建议自己做一个API类避免跟git主干冲突(我是自建了一个flaskSystem.src.Api.ExtendApi)

# 音乐试听全家桶
@app.get("/ext/playUrl")
def extPlayurl():
    type = request.args.get('t') #音源类型kw qq
    mid  = request.args.get('mid') #音乐id
    q    = request.args.get('q') #质量
    mjson= request.args.get('m') #qq时的歌曲信息json串
    url  = ''
    if type=='kw': # 酷我
        if q == 'best':
            q = 'flac|mp3|aac'
        url = ext.getKwDownloadUrlByApp(mid, q)
    elif type=='qq': # QQ
        music = json.loads(mjson)
        if q == 'mp3':
            music['prefix'] = 'mp3'
        url = ext.getQQDownloadLink(music)
    if request.args.get('r') : # 浏览器立即试听
        hqUrl = f'/ext/playUrl?t={type}&mid={mid}&albumId={albumId}&q=best&m={mjson}'
        return redirect(f"/ext/common/playRealtime?url={quote(url)}&hq={quote(hqUrl)}", 302)
    else : # 跳转最高音质版本
        return redirect(url, 302)

# 实时试听音乐的承载页,避免某些url返回的header直接触发浏览器下载文件,要的就是随时能听到😏
@app.get('/ext/common/playRealtime')
def extPlayRealtime():
    template = '''
    <!DOCTYPE html>
    <html>
    <head>
    <title>音乐试听页</title>  
    <meta name="referrer" content="no-referrer">
    <style>
        * {margin:0; padding:0 }
        body{background: #000;   width: 100%; height: 100vh;
            display: flex; flex-direction: column; justify-content: center; } 
        audio{margin: 0 auto;display: block; width: 400px; height: 54px; }
        a{color:#fff; text-decoration: none; }
        p{text-align:center; padding: 10px; }
    </style>
    </head>
    <body>
        <audio controls autoplay src="{{url}}" defer></audio> 
        <p><a href="{{hq}}">最高音质↗</a></p>
    </body>
    </html>
    '''
    return render_template_string(template, url=request.args.get('url'), hq=request.args.get('hq'))

@QiuChenly
Copy link
Collaborator

👍

@incubus-ohy
Copy link

请问下后续会有计划做个播放功能吗

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants