fix: align uniapp live stream metadata fields
This commit is contained in:
@@ -67,6 +67,16 @@ const normalizeUrl = (value: unknown) => {
|
||||
return text
|
||||
}
|
||||
|
||||
const getFetchStatusText = (value: unknown) => {
|
||||
const text = normalizeText(value)
|
||||
if (!text) return ''
|
||||
const normalized = text.toLowerCase()
|
||||
if (normalized === 'success' || normalized === '1') return '已抓取'
|
||||
if (normalized === 'pending' || normalized === '0') return '待抓取'
|
||||
if (normalized === 'failed' || normalized === '-1') return '抓取失败'
|
||||
return text
|
||||
}
|
||||
|
||||
const formatMetaTime = (value: unknown) => {
|
||||
const text = normalizeText(value)
|
||||
if (!text) return ''
|
||||
@@ -101,8 +111,8 @@ const lineTitle = computed(() => {
|
||||
const lineMetaText = computed(() => {
|
||||
const line = props.line || {}
|
||||
const parts = [
|
||||
normalizeText(line.status_text) || normalizeText(line.status_desc) || normalizeText(line.status),
|
||||
formatMetaTime(line.updated_at || line.update_time),
|
||||
getFetchStatusText(line.fetch_status),
|
||||
formatMetaTime(line.last_fetch_at || line.update_time),
|
||||
].filter(Boolean)
|
||||
return parts.length ? parts.join(' · ') : '请选择可用直播线路后打开'
|
||||
})
|
||||
@@ -111,12 +121,18 @@ const sourceUrl = computed(() => normalizeUrl(props.line?.source_url))
|
||||
|
||||
const buildStreamOption = (option: MatchLiveStreamOption | undefined, index: number) => {
|
||||
if (!option) return null
|
||||
const url =
|
||||
normalizeUrl(option.play_url_m3u8) ||
|
||||
normalizeUrl(option.play_url) ||
|
||||
normalizeUrl(option.url) ||
|
||||
normalizeUrl(option.default_play_url) ||
|
||||
normalizeUrl(option.live_url)
|
||||
const url = (
|
||||
[
|
||||
option.default_play_url,
|
||||
option.play_url_m3u8,
|
||||
option.play_url_hd_m3u8,
|
||||
option.play_url_flv,
|
||||
option.play_url_hd_flv,
|
||||
option.play_url,
|
||||
option.url,
|
||||
option.live_url,
|
||||
].map((item) => normalizeUrl(item)).find(Boolean) || ''
|
||||
)
|
||||
if (!url) return null
|
||||
return {
|
||||
...option,
|
||||
@@ -136,6 +152,15 @@ const streamOptions = computed(() => {
|
||||
const line = props.line || {}
|
||||
const options: PopupStreamOption[] = []
|
||||
const seen = new Set<string>()
|
||||
const fallbackFields: Array<{ field: keyof MatchLiveLineItem; label: string }> = [
|
||||
{ field: 'default_play_url', label: '默认线路' },
|
||||
{ field: 'play_url_m3u8', label: 'M3U8 线路' },
|
||||
{ field: 'play_url_hd_m3u8', label: '高清 M3U8' },
|
||||
{ field: 'play_url_flv', label: 'FLV 线路' },
|
||||
{ field: 'play_url_hd_flv', label: '高清 FLV' },
|
||||
{ field: 'play_url', label: '备用线路' },
|
||||
{ field: 'live_url', label: '直播地址' },
|
||||
]
|
||||
|
||||
const pushOption = (option: MatchLiveStreamOption | undefined, index: number) => {
|
||||
const built = buildStreamOption(option, index)
|
||||
@@ -148,25 +173,11 @@ const streamOptions = computed(() => {
|
||||
line.stream_options.forEach((item, index) => pushOption(item, index))
|
||||
}
|
||||
|
||||
const defaultPlayUrl = normalizeUrl(line.default_play_url)
|
||||
if (defaultPlayUrl && !seen.has(defaultPlayUrl)) {
|
||||
pushOption({ label: '默认线路', url: defaultPlayUrl }, options.length)
|
||||
}
|
||||
|
||||
const playUrlM3u8 = normalizeUrl(line.play_url_m3u8)
|
||||
if (playUrlM3u8 && !seen.has(playUrlM3u8)) {
|
||||
pushOption({ label: 'M3U8 线路', play_url_m3u8: playUrlM3u8 }, options.length)
|
||||
}
|
||||
|
||||
const playUrl = normalizeUrl(line.play_url)
|
||||
if (playUrl && !seen.has(playUrl)) {
|
||||
pushOption({ label: '备用线路', play_url: playUrl }, options.length)
|
||||
}
|
||||
|
||||
const liveUrl = normalizeUrl(line.live_url)
|
||||
if (liveUrl && !seen.has(liveUrl)) {
|
||||
pushOption({ label: '直播地址', live_url: liveUrl }, options.length)
|
||||
}
|
||||
fallbackFields.forEach(({ field, label }) => {
|
||||
const value = normalizeUrl(line[field])
|
||||
if (!value || seen.has(value)) return
|
||||
pushOption({ label, [field]: value }, options.length)
|
||||
})
|
||||
|
||||
return options
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user