Skip to content

Commit 36bf9be

Browse files
committed
fix: handle :ext token issue, close #73 #70
1 parent a6bc06e commit 36bf9be

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/adapter/base.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { songUrl } from '$api'
22
import { Song, SongPlayUrlInfo } from '$define'
33
import { getId } from '$util'
44
import { invariant } from 'es-toolkit'
5-
import { get, trimStart } from 'es-toolkit/compat'
5+
import { get } from 'es-toolkit/compat'
66
import { extname } from 'path'
77

88
const NOT_IMPLEMENTED = 'not NOT_IMPLEMENTED'
@@ -53,6 +53,13 @@ export class BaseAdapter {
5353
return songDatas.map(function (songData, index) {
5454
const url = songData.playUrlInfo?.url
5555

56+
let ext: string | undefined
57+
if (url) {
58+
const pathname = new URL(url).pathname
59+
ext = extname(pathname)
60+
if (ext.startsWith('.')) ext = ext.slice(1)
61+
}
62+
5663
return {
5764
// 歌手
5865
singer:
@@ -73,7 +80,7 @@ export class BaseAdapter {
7380
isFreeTrial: songData.playUrlInfo ? Boolean(songData.playUrlInfo.freeTrialInfo) : undefined,
7481

7582
// extension
76-
ext: url && trimStart(extname(url), '.'),
83+
ext,
7784

7885
// index, first as 01
7986
index: String(index + 1).padStart(len, '0'),

src/adapter/playlist.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import { Playlist } from '$define'
33
import { BaseAdapter } from './base'
44

55
export class PlaylistAdapter extends BaseAdapter {
6-
#playlist: Playlist
6+
private playlist: Playlist
77
private async fetchPlaylist() {
8-
if (this.#playlist) return
9-
this.#playlist = await playlistDetail(this.id)
8+
if (this.playlist) return
9+
this.playlist = await playlistDetail(this.id)
1010
}
1111

1212
async getTitle() {
1313
await this.fetchPlaylist()
14-
return this.#playlist.name
14+
return this.playlist.name
1515
}
1616

1717
async getCover() {
1818
await this.fetchPlaylist()
19-
return this.#playlist.coverImgUrl
19+
return this.playlist.coverImgUrl
2020
}
2121

2222
async getSongDatas() {
2323
await this.fetchPlaylist()
24-
const trackIds = this.#playlist.trackIds.map((x) => x.id)
24+
const trackIds = this.playlist.trackIds.map((x) => x.id)
2525
const songDatas = await songDetail(trackIds)
2626
return songDatas
2727
}

0 commit comments

Comments
 (0)