Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add pronunciation lyric mode #2091

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/locale/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default {
pause: 'Pause',
mute: 'Mute',
nextUp: 'Next Up',
translationLyric: 'lyric (trans)',
PronunciationLyric: 'lyric (pronounce)',
},
modal: {
close: 'Close',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/lang/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export default {
pause: 'Durdur',
mute: 'Sesi kapat',
nextUp: 'Sıradaki',
translationLyric: 'şarkı sözleri (çeviri)',
PronunciationLyric: 'şarkı sözleri (çeviri)',
},
modal: {
close: 'Kapat',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export default {
pause: '暂停',
mute: '静音',
nextUp: '播放列表',
translationLyric: '歌词(译)',
PronunciationLyric: '歌词(音)',
},
modal: {
close: '关闭',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/lang/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export default {
pause: '暫停',
mute: '靜音',
nextUp: '播放清單',
translationLyric: '歌詞(譯)',
PronunciationLyric: '歌詞(音)',
},
modal: {
close: '關閉',
Expand Down
1 change: 1 addition & 0 deletions src/utils/lyrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export function lyricParser(lrc) {
return {
lyric: parseLyric(lrc?.lrc?.lyric || ''),
tlyric: parseLyric(lrc?.tlyric?.lyric || ''),
romalyric: parseLyric(lrc?.romalrc?.lyric || ''),
lyricuser: lrc.lyricUser,
transuser: lrc.transUser,
};
Expand Down
86 changes: 84 additions & 2 deletions src/views/lyrics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@
>
<svg-icon icon-class="shuffle" />
</button-icon>
<button-icon
v-show="
isShowLyricTypeSwitch &&
$store.state.settings.showLyricsTranslation &&
lyricType === 'translation'
"
:title="$t('player.translationLyric')"
@click.native="switchLyricType"
>
<span class="lyric-switch-icon">译</span>
</button-icon>
<button-icon
v-show="
isShowLyricTypeSwitch &&
$store.state.settings.showLyricsTranslation &&
lyricType === 'romaPronunciation'
"
:title="$t('player.PronunciationLyric')"
@click.native="switchLyricType"
>
<span class="lyric-switch-icon">音</span>
</button-icon>
</div>
</div>
</div>
Expand All @@ -215,7 +237,7 @@
>
<div id="line-1" class="line"></div>
<div
v-for="(line, index) in lyricWithTranslation"
v-for="(line, index) in lyricToShow"
:id="`line${index}`"
:key="index"
class="line"
Expand Down Expand Up @@ -277,6 +299,8 @@ export default {
lyricsInterval: null,
lyric: [],
tlyric: [],
romalyric: [],
lyricType: 'translation', // or 'romaPronunciation'
highlightLyricIndex: -1,
minimize: true,
background: '',
Expand All @@ -302,6 +326,14 @@ export default {
bgImageUrl() {
return this.player.currentTrack?.al?.picUrl + '?param=512y512';
},
isShowLyricTypeSwitch() {
return this.romalyric.length > 0 && this.tlyric.length > 0;
},
lyricToShow() {
return this.lyricType === 'translation'
? this.lyricWithTranslation
: this.lyricWithRomaPronunciation;
},
lyricWithTranslation() {
let ret = [];
// 空内容的去除
Expand Down Expand Up @@ -333,6 +365,37 @@ export default {
}
return ret;
},
lyricWithRomaPronunciation() {
let ret = [];
// 空内容的去除
const lyricFiltered = this.lyric.filter(({ content }) =>
Boolean(content)
);
// content统一转换数组形式
if (lyricFiltered.length) {
lyricFiltered.forEach(l => {
const { rawTime, time, content } = l;
const lyricItem = { time, content, contents: [content] };
const sameTimeRomaLyric = this.romalyric.find(
({ rawTime: tLyricRawTime }) => tLyricRawTime === rawTime
);
if (sameTimeRomaLyric) {
const { content: romaLyricContent } = sameTimeRomaLyric;
if (content) {
lyricItem.contents.push(romaLyricContent);
}
}
ret.push(lyricItem);
});
} else {
ret = lyricFiltered.map(({ time, content }) => ({
time,
content,
contents: [content],
}));
}
return ret;
},
lyricFontSize() {
return {
fontSize: `${this.$store.state.settings.lyricFontSize || 28}px`,
Expand Down Expand Up @@ -439,9 +502,10 @@ export default {
if (!data?.lrc?.lyric) {
this.lyric = [];
this.tlyric = [];
this.romalyric = [];
return false;
} else {
let { lyric, tlyric } = lyricParser(data);
let { lyric, tlyric, romalyric } = lyricParser(data);
lyric = lyric.filter(
l => !/^作(词|曲)\s*(:|:)\s*无$/.exec(l.content)
);
Expand All @@ -461,15 +525,27 @@ export default {
if (lyric.length === 1 && includeAM) {
this.lyric = [];
this.tlyric = [];
this.romalyric = [];
return false;
} else {
this.lyric = lyric;
this.tlyric = tlyric;
this.romalyric = romalyric;
if (tlyric.length * romalyric.length > 0) {
this.lyricType = 'translation';
} else {
this.lyricType =
lyric.length > 0 ? 'translation' : 'romaPronunciation';
}
return true;
}
}
});
},
switchLyricType() {
this.lyricType =
this.lyricType === 'translation' ? 'romaPronunciation' : 'translation';
},
formatTrackTime(value) {
return formatTrackTime(value);
},
Expand Down Expand Up @@ -758,6 +834,12 @@ export default {
width: 22px;
}
}
.lyric-switch-icon {
color: var(--color-text);
font-size: 14px;
line-height: 14px;
opacity: 0.88;
}
}
}
}
Expand Down