72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
/** 与 electron youtubeConfigUtils 对齐(远程控制仅用于展示/解析) */
|
|
|
|
export function parseYoutubeStreamKeySuffix(iniContent: string): string {
|
|
for (const line of iniContent.split(/\r?\n/)) {
|
|
const t = line.trim()
|
|
if (t.startsWith('#') || !t) continue
|
|
const m = t.match(/^(?:key|stream_key)\s*=\s*(.+)$/i)
|
|
if (m) {
|
|
const v = m[1].trim().split(/[#;]/)[0].trim()
|
|
if (v && !v.startsWith('rtmp')) return v.length > 8 ? v.slice(-8) : v
|
|
if (v.includes('live2/')) {
|
|
const parts = v.split('/')
|
|
const last = parts[parts.length - 1] || ''
|
|
return last.length > 8 ? last.slice(-8) : last
|
|
}
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
|
|
export function extractDouyinLiveUrls(urlIni: string): string[] {
|
|
const out: string[] = []
|
|
for (const line of urlIni.split(/\r?\n/)) {
|
|
const t = line.trim()
|
|
if (!t || t.startsWith('#')) continue
|
|
if (!/douyin\.com|v\.douyin\.com/i.test(t)) continue
|
|
const full = t.match(/(https?:\/\/live\.douyin\.com\/[a-zA-Z0-9_-]+)/i)
|
|
if (full) {
|
|
out.push(full[1].replace(/^http:\/\//i, 'https://'))
|
|
continue
|
|
}
|
|
const rel = t.match(/live\.douyin\.com\/([a-zA-Z0-9_-]+)/i)
|
|
if (rel) {
|
|
out.push(`https://live.douyin.com/${rel[1]}`)
|
|
continue
|
|
}
|
|
const n = t.match(/(\d{8,})/)
|
|
if (n) out.push(`https://live.douyin.com/${n[1]}`)
|
|
}
|
|
return [...new Set(out)].slice(0, 16)
|
|
}
|
|
|
|
export function extractDouyinRoomHints(urlIni: string): string[] {
|
|
const out: string[] = []
|
|
for (const line of urlIni.split(/\r?\n/)) {
|
|
const t = line.trim()
|
|
if (!t || t.startsWith('#')) continue
|
|
if (!/douyin\.com|v\.douyin\.com/i.test(t)) continue
|
|
const m = t.match(/live\.douyin\.com\/([a-zA-Z0-9_-]+)/i)
|
|
if (m) {
|
|
out.push(m[1])
|
|
continue
|
|
}
|
|
const n = t.match(/(\d{8,})/)
|
|
out.push(n ? n[1] : t.slice(0, 96))
|
|
}
|
|
return [...new Set(out)].slice(0, 12)
|
|
}
|
|
|
|
export function douyinRoomAndHref(douyinUrl: string | undefined, urlIni: string): { room: string; href: string } {
|
|
const combined = `${urlIni}\n${douyinUrl ?? ''}`
|
|
const urls = extractDouyinLiveUrls(combined)
|
|
const hints = extractDouyinRoomHints(combined)
|
|
const room = hints[0] || '—'
|
|
const href = urls[0] || (hints[0] ? `https://live.douyin.com/${hints[0]}` : '')
|
|
return { room, href }
|
|
}
|
|
|
|
export function proChannelPm2Process(channelId: string): string {
|
|
return `youtube2__${channelId}`
|
|
}
|