Skip to content

Commit a24d960

Browse files
author
hoang.tran12
committed
update zing
1 parent 5427bd8 commit a24d960

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

scripts/zingmp3_downloadMusic.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getCurrentTab } from "./helpers/utils.js";
2+
13
export default {
24
icon: "https://zjs.zmdcdn.me/zmp3-desktop/releases/v1.7.64/static/media/icon_zing_mp3_60.f6b51045.svg",
35
name: {
@@ -227,16 +229,40 @@ export default {
227229
};
228230

229231
(async function () {
230-
// window.open(await ZingMp3.search('game thủ liên minh'));
232+
// window.open(await ZingMp3.search("game thủ liên minh"));
231233
// window.open(await ZingMp3.getLastPlaying());
232234
// window.open(await ZingMp3.getHome());
233235
// window.open(await ZingMp3.getChartHome());
234-
// window.open(await ZingMp3.getInfoMusic('ZWFE8OUO'))
236+
// window.open(await ZingMp3.getInfoMusic("ZWFE8OUO"));
237+
// window.open(await ZingMp3.getStreaming("Z6WZD78I"));
235238

236-
let url = prompt("Nhap link bai hat: ", location.href);
239+
const tab = await getCurrentTab();
240+
let url = prompt("Nhap link bai hat: ", tab.url);
237241
if (url) {
238242
let songid = ZingMp3.getSongIdFromURL(url);
239-
if (songid) window.open(await ZingMp3.getStreaming(songid));
243+
if (songid) {
244+
try {
245+
const streamUrl = await ZingMp3.getStreaming(songid);
246+
const res = await fetch(streamUrl);
247+
const json = await res.json();
248+
console.log(json);
249+
if (json.err) throw new Error(json.msg);
250+
if (!json.data) throw new Error("No Data");
251+
252+
let options = Object.keys(json.data);
253+
let choice = prompt(
254+
"Chọn chất lượng nhạc: \n" + options.join("\n"),
255+
options[options.length - 1]
256+
);
257+
258+
if (choice !== null) {
259+
let url = json.data[choice];
260+
window.open(url);
261+
}
262+
} catch (error) {
263+
alert("ERROR: " + error);
264+
}
265+
}
240266
}
241267
})();
242268
},

0 commit comments

Comments
 (0)