File size: 2,665 Bytes
00a912e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { AudioQuality, MusicSource, PlatformAuthStatus } from '@music-together/shared'

export interface AudioQualityOption {
  value: AudioQuality
  label: string
  platform?: MusicSource
  description?: string
}

const BASE_OPTIONS: AudioQualityOption[] = [
  { value: 128, label: '标准 128kbps' },
  { value: 192, label: '较高 192kbps' },
  { value: 320, label: '高品质 320kbps' },
]

const PLATFORM_OPTIONS: Record<MusicSource, AudioQualityOption[]> = {
  netease: [
    { value: 999, label: '无损 SQ', platform: 'netease' },
    { value: 'netease_hires', label: 'Hi-Res', platform: 'netease' },
    { value: 'netease_jyeffect', label: '高清臻音', platform: 'netease' },
    { value: 'netease_spatial', label: '沉浸环绕声', platform: 'netease' },
    { value: 'netease_master', label: '超清母带', platform: 'netease' },
    { value: 'netease_dolby', label: '杜比全景声', platform: 'netease', description: '浏览器兼容性有限' },
  ],
  tencent: [
    { value: 'tencent_flac', label: '无损', platform: 'tencent' },
    { value: 'tencent_master', label: '臻品母带', platform: 'tencent' },
  ],
  kugou: [
    { value: 'kugou_hires', label: '酷狗 Hi-Res', platform: 'kugou' },
    { value: 'kugou_master', label: '酷狗蝰蛇母带 2.0', platform: 'kugou' },
  ],
  kugou_concept: [
    { value: 'kugou_hires', label: '酷狗概念版 Hi-Res', platform: 'kugou_concept' },
    { value: 'kugou_master', label: '酷狗概念版 蝰蛇母带 2.0', platform: 'kugou_concept' },
  ],
  bilibili: [
    { value: 'bilibili_64', label: 'B站 64K', platform: 'bilibili' },
    { value: 'bilibili_132', label: 'B站 132K', platform: 'bilibili' },
    { value: 'bilibili_192', label: 'B站 192K', platform: 'bilibili' },
    { value: 'bilibili_hires', label: 'B站 Hi-Res', platform: 'bilibili' },
  ],
}

export function getAudioQualityOptions(statuses: PlatformAuthStatus[]): AudioQualityOption[] {
  void statuses
  // Room quality is shared by all providers. Provider-specific formats are
  // selected by the server from `highest`; exposing them here made a Tencent
  // or Kugou room appear to offer unrelated Netease formats.
  return [
    ...BASE_OPTIONS,
    { value: 999, label: '无损 SQ', description: '需要 VIP 账号' },
    { value: 'highest', label: '尽量高' },
  ]
}

export function getAudioQualityLabel(quality: AudioQuality, statuses: PlatformAuthStatus[] = []): string {
  const allOptions = [...BASE_OPTIONS, ...Object.values(PLATFORM_OPTIONS).flat()]
  return (
    [...getAudioQualityOptions(statuses), ...allOptions].find((option) => option.value === quality)?.label ??
    String(quality)
  )
}