Skip to content

Commit

Permalink
QQ music audition
Browse files Browse the repository at this point in the history
  • Loading branch information
HeHang0 committed Nov 9, 2023
1 parent c7804c2 commit 6fbee13
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 300 deletions.
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"private": false,
"scripts": {
"start": "vite",
"start": "vite --host",
"build": "run-p type-check build-only",
"build:zip": "cross-env BUILD_ZIP=1 run-p type-check build-only",
"preview": "vite preview",
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/player/Lyric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ onUnmounted(() => {
});
</script>
<template>
<div class="music-lyric" :class="pure ? 'music-lyric-pure' : ''">
<div class="music-lyric" :class="props.pure ? 'music-lyric-pure' : ''">
<div class="music-lyric-header">
<div class="music-lyric-name text-overflow-1" :title="play.music.name">
{{ play.music.name }}
</div>
<div
class="music-lyric-desc"
v-show="play.music.album || play.music.singer"
:style="pure ? 'justify-content: center' : ''">
:style="props.pure ? 'justify-content: center' : ''">
<div v-if="play.music.album" class="text-overflow-1">
<span>专辑:</span
><span
Expand Down
15 changes: 12 additions & 3 deletions web/src/stores/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const usePlayStore = defineStore('play', {
this.music.type = music?.type || 'local';
this.music.url = music?.url || '';
this.music.lyricUrl = music?.lyricUrl || '';
this.music.audition = music?.audition || false;
!noSave && storage.setValue(StorageKey.CurrentMusic, this.music);
},
setSortType(type: SortType) {
Expand Down Expand Up @@ -247,7 +248,7 @@ export const usePlayStore = defineStore('play', {
this.setCurrentMusic(this.musicList[0]);
}
},
async play(music?: Music, musicList?: Music[], auto?: boolean) {
async play(music?: Music, musicList?: Music[]) {
if (this.preparePlay) {
return;
}
Expand Down Expand Up @@ -283,6 +284,7 @@ export const usePlayStore = defineStore('play', {
this.setCurrentMusic(music);
}
await api.musicDetail(music);
this.music.audition = music.audition;
if (!music.url) {
console.log('fail', music);
ElMessage(messageOption('当前音乐无法播放'));
Expand Down Expand Up @@ -354,7 +356,7 @@ export const usePlayStore = defineStore('play', {
}
if (currentIndex < 0 || currentIndex >= this.musicList.length)
currentIndex = 0;
this.play(this.musicList[currentIndex], undefined, auto);
this.play(this.musicList[currentIndex]);
},
async last() {
this.nextPlay = null;
Expand Down Expand Up @@ -433,6 +435,9 @@ export const usePlayStore = defineStore('play', {
this.playStatus.currentTime = data.currentTime || '00:00';
}
if (data.totalTime && this.playStatus.totalTime != data.totalTime) {
if (this.music.audition && this.music.duration) {
data.totalTime = this.music.duration;
}
this.playStatus.totalTime = data.totalTime;
if (!this.music.duration) {
this.music.duration = data.totalTime;
Expand All @@ -457,7 +462,11 @@ export const usePlayStore = defineStore('play', {
!this.playStatus.disableUpdateProgress &&
this.playStatus.progress != data.progress
) {
localStorage.setItem(StorageKey.Progress, data.progress as any);
if (this.music.audition && this.music.length) {
data.progress = (60000 * data.progress) / this.music.length;
} else {
localStorage.setItem(StorageKey.Progress, data.progress as any);
}
this.playStatus.progress = data.progress || 0;
if (
data.progress &&
Expand Down
12 changes: 2 additions & 10 deletions web/src/utils/api/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { httpProxy } from '../http';
import {
duration2Millisecond,
highlightKeys,
millisecond2Duration,
parseCookie
} from '../utils';
Expand Down Expand Up @@ -93,21 +94,12 @@ export async function search(
const ret = await res.json();
const list: Music[] = [];
const total: number = ret.result.songCount;
var keys = keywords.split(/[\s]+/);
ret.result.songs.map((m: any) => {
var highlightName = m.name;
type == 1 &&
keys.map(n => {
highlightName = highlightName.replace(
n,
`<span class="c_tx_highlight">${n}</span>`
);
});
const album = m.al || m.album || {};
list.push({
id: m.id,
name: m.name,
highlightName: highlightName,
highlightName: highlightKeys(m.name, keywords),
image: (album.picUrl || '') + '?param=100y100',
singer: parseSinger(m.ar || m.artists),
album: album.name || '',
Expand Down
4 changes: 3 additions & 1 deletion web/src/utils/api/migu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
duration2Millisecond,
durationTrim,
formatCookies,
highlightKeys,
parseCookie,
second2Duration
} from '../utils';
Expand Down Expand Up @@ -43,7 +44,7 @@ export function setPlayQuality(quality: MusicQuality) {
export async function search(keywords: string, offset: number) {
var url = `https://m.music.migu.cn/migumusic/h5/search/all?text=${encodeURIComponent(
keywords
).replace(/%20/g, '+')}&pageNo=${offset + 1}&pageSize=30`;
).replace(/%20/g, '+')}&pageNo=${Math.round(offset / 30) + 1}&pageSize=30`;
var res = await httpProxy({
url: url,
method: 'GET',
Expand All @@ -62,6 +63,7 @@ export async function search(keywords: string, offset: number) {
list.push({
id: m.copyrightId,
name: m.name,
highlightName: highlightKeys(m.name, keywords),
image: padProtocol(m.mediumPic),
singer: Array.isArray(m.singers)
? m.singers.map((n: any) => n.name).join(' / ')
Expand Down
Loading

0 comments on commit 6fbee13

Please sign in to comment.