Skip to content

Commit

Permalink
fix: 播放链接接口支持复杂的链接
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Sep 13, 2024
1 parent 48797dd commit f1625e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion xiaomusic/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,3 @@ def _send_play_event(self, name, sec):
event.set_event_param(name="sec", value=sec)
event_list = [event]
self.gtag.send(events=event_list)

9 changes: 5 additions & 4 deletions xiaomusic/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import secrets
import shutil
import tempfile
import urllib.parse
from contextlib import asynccontextmanager
from dataclasses import asdict
from typing import Annotated
Expand Down Expand Up @@ -145,7 +146,7 @@ def playingmusic(did: str = "", Verifcation=Depends(verification)):
is_playing = xiaomusic.isplaying(did)
cur_music = xiaomusic.playingmusic(did)
# 播放进度
offset,duration = xiaomusic.get_offset_duration(did)
offset, duration = xiaomusic.get_offset_duration(did)
return {
"ret": "OK",
"is_playing": is_playing,
Expand Down Expand Up @@ -293,9 +294,9 @@ def cleanup_temp_file(tmp_file_path):
async def playurl(did: str, url: str, Verifcation=Depends(verification)):
if not xiaomusic.did_exist(did):
return {"ret": "Did not exist"}

log.info(f"playurl did: {did} url: {url}")
return await xiaomusic.play_url(did=did, arg1=url)
decoded_url = urllib.parse.unquote(url)
log.info(f"playurl did: {did} url: {decoded_url}")
return await xiaomusic.play_url(did=did, arg1=decoded_url)


@app.post("/debug_play_by_music_url")
Expand Down
3 changes: 2 additions & 1 deletion xiaomusic/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ $(function(){

$("#playurl").on("click", () => {
var url = $("#music-url").val();
$.get(`/playurl?url=${url}&did=${did}`, function(data, status) {
const encoded_url = encodeURIComponent(url);
$.get(`/playurl?url=${encoded_url}&did=${did}`, function(data, status) {
console.log(data);
});
});
Expand Down

0 comments on commit f1625e7

Please sign in to comment.