Skip to content

Commit

Permalink
wip: get roominfo
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Oct 29, 2024
1 parent 36d8bf7 commit 7cf68e2
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 78 deletions.
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const NAV_BY_DEFAULT_BROWSER = 'NAV_BY_DEFAULT_BROWSER'
export const SELECT_DIR = 'SELECT_DIR'
export const GET_LIVE_URLS = 'GET_LIVE_URLS'
export const GET_ROOM_INFO = 'GET_ROOM_INFO'
export const START_STREAM_RECORD = 'START_STREAM_RECORD'
export const STOP_STREAM_RECORD = 'STOP_STREAM_RECORD'
export const STREAM_RECORD_END = 'STREAM_RECORD_END'
Expand Down
10 changes: 2 additions & 8 deletions src/main/crawler/capture-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ export function captureError(fn) {
const realArgs = args.slice(0, args.length - 1)
try {
const res = await fn.apply(this, realArgs)
writeLog(`Fetch Live Res: ${JSON.stringify(res, null, 2)}`)
writeLog(`Fetch Res: ${JSON.stringify(res, null, 2)}`)
return res
} catch (e) {
const message = e.message

writeLog(`Fetch Live Error: ${message}`)
writeLog(`Fetch Error: ${message}`)

log('error:', message)

// if (message.includes('timeout')) {
// return {
// code: CRAWLER_ERROR_CODE.TIMEOUT
// }
// }

if (message === ERROR_MESSAGE.INVALID_PROXY) {
return {
code: CRAWLER_ERROR_CODE.INVALID_PROXY
Expand Down
256 changes: 196 additions & 60 deletions src/main/crawler/index.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,201 @@
import debug from 'debug'

import { getBilibiliLiveUrlsPlugin } from './plugins/bilibili'
import { getCCLiveUrlsPlugin } from './plugins/cc'
import { getDouYinLiveUrlsPlugin } from './plugins/douyin'
import { getDouyuLiveUrlsPlugin } from './plugins/douyu'
import { getHuyaLiveUrlsPlugin } from './plugins/huya'
import { getKuaishouLiveUrlsPlugin } from './plugins/kuaishou'
import { getYoutubeLiveUrlsPlugin } from './plugins/youtube'
import { getTwitchLiveUrlsPlugin } from './plugins/twitch'
import { getTiktokLiveUrlsPlugin } from './plugins/tiktok'
import { getWeiboLiveUrlsPlugin } from './plugins/weibo'
import { getHuaJiaoLiveUrlsPlugin } from './plugins/huajiao'
import { getTaobaoLiveUrlsPlugin } from './plugins/taobao'
import { getBigoLiveUrlsPlugin } from './plugins/bigo'
import { getYYLiveUrlsPlugin } from './plugins/yy'
import { getJDLiveUrlsPlugin } from './plugins/jd'
import { getMomoLiveUrlsPlugin } from './plugins/momo'
import { getShiGuangLiveUrlsPlugin } from './plugins/shiguang'
import { getVvLiveUrlsPlugin } from './plugins/vv'
import { getChangLiaoLiveUrlsPlugin } from './plugins/changliao'
import { get17LiveUrlsPlugin } from './plugins/17live'
import { getXhsUrlsPlugin } from './plugins/xhs'
import { getKilakilaLiveUrlsPlugin } from './plugins/kilakila'
import { getAcFunLiveUrlsPlugin } from './plugins/acfun'
import { getBilibiliLiveUrlsPlugin, getBilibiliRoomInfoPlugin } from './plugins/bilibili'
import { getCCLiveUrlsPlugin, getCCRoomInfoPlugin } from './plugins/cc'
import { getDouYinLiveUrlsPlugin, getDouYinRoomInfoPlugin } from './plugins/douyin'
import { getDouyuLiveUrlsPlugin, getDouyuRoomInfoPlugin } from './plugins/douyu'
import { getHuyaLiveUrlsPlugin, getHuyaRoomInfoPlugin } from './plugins/huya'
import { getKuaishouLiveUrlsPlugin, getKuaishouRoomInfoPlugin } from './plugins/kuaishou'
import { getYoutubeLiveUrlsPlugin, getYoutubeRoomInfoPlugin } from './plugins/youtube'
import { getTwitchLiveUrlsPlugin, getTwitchRoomInfoPlugin } from './plugins/twitch'
import { getTiktokLiveUrlsPlugin, getTiktokRoomInfoPlugin } from './plugins/tiktok'
import { getWeiboLiveUrlsPlugin, getWeiboRoomInfoPlugin } from './plugins/weibo'
import { getHuaJiaoLiveUrlsPlugin, getHuaJiaoRoomInfoPlugin } from './plugins/huajiao'
import { getTaobaoLiveUrlsPlugin, getTaobaoRoomInfoPlugin } from './plugins/taobao'
import { getBigoLiveUrlsPlugin, getBigoRoomInfoPlugin } from './plugins/bigo'
import { getYYLiveUrlsPlugin, getYYRoomInfoPlugin } from './plugins/yy'
import { getJDLiveUrlsPlugin, getJDRoomInfoPlugin } from './plugins/jd'
import { getMomoLiveUrlsPlugin, getMomoRoomInfoPlugin } from './plugins/momo'
import { getShiGuangLiveUrlsPlugin, getShiGuangRoomInfoPlugin } from './plugins/shiguang'
import { getVvLiveUrlsPlugin, getVvRoomInfoPlugin } from './plugins/vv'
import { getChangLiaoLiveUrlsPlugin, getChangLiaoRoomInfoPlugin } from './plugins/changliao'
import { get17LiveUrlsPlugin, get17LiveRoomInfoPlugin } from './plugins/17live'
import { getXhsUrlsPlugin, getXhsRoomInfoPlugin } from './plugins/xhs'
import { getKilakilaLiveUrlsPlugin, getKilakilaRoomInfoPlugin } from './plugins/kilakila'
import { getAcFunLiveUrlsPlugin, getAcFunRoomInfoPlugin } from './plugins/acfun'

import { CRAWLER_ERROR_CODE } from '../../code'

const log = debug('fideo-crawler')

const hostnameToPlatformCrawlerFnMap = {
'www.youtube.com': getYoutubeLiveUrlsPlugin,
'youtube.com': getYoutubeLiveUrlsPlugin,
'www.youtube.com': {
getLiveUrlsFn: getYoutubeLiveUrlsPlugin,
getRoomInfoFn: getYoutubeRoomInfoPlugin
},
'youtube.com': {
getLiveUrlsFn: getYoutubeLiveUrlsPlugin,
getRoomInfoFn: getYoutubeRoomInfoPlugin
},

'www.twitch.tv': getTwitchLiveUrlsPlugin,
'twitch.tv': getTwitchLiveUrlsPlugin,
'www.twitch.tv': {
getLiveUrlsFn: getTwitchLiveUrlsPlugin,
getRoomInfoFn: getTwitchRoomInfoPlugin
},
'twitch.tv': {
getLiveUrlsFn: getTwitchLiveUrlsPlugin,
getRoomInfoFn: getTwitchRoomInfoPlugin
},

'www.tiktok.com': getTiktokLiveUrlsPlugin,
'tiktok.com': getTiktokLiveUrlsPlugin,
'www.tiktok.com': {
getLiveUrlsFn: getTiktokLiveUrlsPlugin,
getRoomInfoFn: getTiktokRoomInfoPlugin
},
'tiktok.com': {
getLiveUrlsFn: getTiktokLiveUrlsPlugin,
getRoomInfoFn: getTiktokRoomInfoPlugin
},

'live.douyin.com': getDouYinLiveUrlsPlugin,
'v.douyin.com': getDouYinLiveUrlsPlugin,
'live.douyin.com': {
getLiveUrlsFn: getDouYinLiveUrlsPlugin,
getRoomInfoFn: getDouYinRoomInfoPlugin
},
'v.douyin.com': {
getLiveUrlsFn: getDouYinLiveUrlsPlugin,
getRoomInfoFn: getDouYinRoomInfoPlugin
},

'live.kuaishou.com': getKuaishouLiveUrlsPlugin,
'live.bilibili.com': getBilibiliLiveUrlsPlugin,
'live.kuaishou.com': {
getLiveUrlsFn: getKuaishouLiveUrlsPlugin,
getRoomInfoFn: getKuaishouRoomInfoPlugin
},

'cc.163.com': getCCLiveUrlsPlugin,
'live.bilibili.com': {
getLiveUrlsFn: getBilibiliLiveUrlsPlugin,
getRoomInfoFn: getBilibiliRoomInfoPlugin
},

'www.huajiao.com': getHuaJiaoLiveUrlsPlugin,
'huajiao.com': getHuaJiaoLiveUrlsPlugin,
'cc.163.com': {
getLiveUrlsFn: getCCLiveUrlsPlugin,
getRoomInfoFn: getCCRoomInfoPlugin
},

'weibo.com': getWeiboLiveUrlsPlugin,
'www.weibo.com': getWeiboLiveUrlsPlugin,
'www.huajiao.com': {
getLiveUrlsFn: getHuaJiaoLiveUrlsPlugin,
getRoomInfoFn: getHuaJiaoRoomInfoPlugin
},

'www.douyu.com': getDouyuLiveUrlsPlugin,
'douyu.com': getDouyuLiveUrlsPlugin,
'huajiao.com': {
getLiveUrlsFn: getHuaJiaoLiveUrlsPlugin,
getRoomInfoFn: getHuaJiaoRoomInfoPlugin
},

'tbzb.taobao.com': getTaobaoLiveUrlsPlugin,
'weibo.com': {
getLiveUrlsFn: getWeiboLiveUrlsPlugin,
getRoomInfoFn: getWeiboRoomInfoPlugin
},
'www.weibo.com': {
getLiveUrlsFn: getWeiboLiveUrlsPlugin,
getRoomInfoFn: getWeiboRoomInfoPlugin
},

'www.bigo.tv': getBigoLiveUrlsPlugin,
'bigo.tv': getBigoLiveUrlsPlugin,
'www.douyu.com': {
getLiveUrlsFn: getDouyuLiveUrlsPlugin,
getRoomInfoFn: getDouyuRoomInfoPlugin
},
'douyu.com': {
getLiveUrlsFn: getDouyuLiveUrlsPlugin,
getRoomInfoFn: getDouyuRoomInfoPlugin
},

'www.yy.com': getYYLiveUrlsPlugin,
'yy.com': getYYLiveUrlsPlugin,
'tbzb.taobao.com': {
getLiveUrlsFn: getTaobaoLiveUrlsPlugin,
getRoomInfoFn: getTaobaoRoomInfoPlugin
},

'www.huya.com': getHuyaLiveUrlsPlugin,
'huya.com': getHuyaLiveUrlsPlugin,
'www.bigo.tv': {
getLiveUrlsFn: getBigoLiveUrlsPlugin,
getRoomInfoFn: getBigoRoomInfoPlugin
},
'bigo.tv': {
getLiveUrlsFn: getBigoLiveUrlsPlugin,
getRoomInfoFn: getBigoRoomInfoPlugin
},

'lives.jd.com': getJDLiveUrlsPlugin,
'www.yy.com': {
getLiveUrlsFn: getYYLiveUrlsPlugin,
getRoomInfoFn: getYYRoomInfoPlugin
},
'yy.com': {
getLiveUrlsFn: getYYLiveUrlsPlugin,
getRoomInfoFn: getYYRoomInfoPlugin
},

'web.immomo.com': getMomoLiveUrlsPlugin,
'www.huya.com': {
getLiveUrlsFn: getHuyaLiveUrlsPlugin,
getRoomInfoFn: getHuyaRoomInfoPlugin
},
'huya.com': {
getLiveUrlsFn: getHuyaLiveUrlsPlugin,
getRoomInfoFn: getHuyaRoomInfoPlugin
},

'www.rengzu.com': getShiGuangLiveUrlsPlugin,
'lives.jd.com': {
getLiveUrlsFn: getJDLiveUrlsPlugin,
getRoomInfoFn: getJDRoomInfoPlugin
},

'h5webcdn-pro.vvxqiu.com': getVvLiveUrlsPlugin,
'web.immomo.com': {
getLiveUrlsFn: getMomoLiveUrlsPlugin,
getRoomInfoFn: getMomoRoomInfoPlugin
},

'www.tlclw.com': getChangLiaoLiveUrlsPlugin,
'tlclw.com': getChangLiaoLiveUrlsPlugin,
'www.rengzu.com': {
getLiveUrlsFn: getShiGuangLiveUrlsPlugin,
getRoomInfoFn: getShiGuangRoomInfoPlugin
},

'www.17.live': get17LiveUrlsPlugin,
'17.live': get17LiveUrlsPlugin,
'h5webcdn-pro.vvxqiu.com': {
getLiveUrlsFn: getVvLiveUrlsPlugin,
getRoomInfoFn: getVvRoomInfoPlugin
},

'www.xiaohongshu.com': getXhsUrlsPlugin,
'xiaohongshu.com': getXhsUrlsPlugin,
'www.tlclw.com': {
getLiveUrlsFn: getChangLiaoLiveUrlsPlugin,
getRoomInfoFn: getChangLiaoRoomInfoPlugin
},
'tlclw.com': {
getLiveUrlsFn: getChangLiaoLiveUrlsPlugin,
getRoomInfoFn: getChangLiaoRoomInfoPlugin
},

'live.kilakila.cn': getKilakilaLiveUrlsPlugin,
'www.17.live': {
getLiveUrlsFn: get17LiveUrlsPlugin,
getRoomInfoFn: get17LiveRoomInfoPlugin
},
'17.live': {
getLiveUrlsFn: get17LiveUrlsPlugin,
getRoomInfoFn: get17LiveRoomInfoPlugin
},

'live.acfun.cn': getAcFunLiveUrlsPlugin
'www.xiaohongshu.com': {
getLiveUrlsFn: getXhsUrlsPlugin,
getRoomInfoFn: getXhsRoomInfoPlugin
},
'xiaohongshu.com': {
getLiveUrlsFn: getXhsUrlsPlugin,
getRoomInfoFn: getXhsRoomInfoPlugin
},

'live.kilakila.cn': {
getLiveUrlsFn: getKilakilaLiveUrlsPlugin,
getRoomInfoFn: getKilakilaRoomInfoPlugin
},

'live.acfun.cn': {
getLiveUrlsFn: getAcFunLiveUrlsPlugin,
getRoomInfoFn: getAcFunRoomInfoPlugin
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -124,7 +234,7 @@ export async function getLiveUrls(info, writeLog) {
}
}

const getLiveUrlsFn = hostnameToPlatformCrawlerFnMap[host]
const getLiveUrlsFn = hostnameToPlatformCrawlerFnMap[host]?.getLiveUrlsFn

// TODO: 判断是否是支持的平台但是url不对,提供更好的错误提示
if (!getLiveUrlsFn) {
Expand All @@ -137,3 +247,29 @@ export async function getLiveUrls(info, writeLog) {
log('res:', res)
return res
}

export async function getRoomInfo(info, writeLog) {
const { roomUrl, proxy, cookie } = info
let host
try {
host = new URL(roomUrl).host
} catch (e) {
console.error(e)
return {
code: CRAWLER_ERROR_CODE.INVALID_URL
}
}

const getRoomInfoFn = hostnameToPlatformCrawlerFnMap[host]?.getRoomInfoFn

// TODO: 判断是否是支持的平台但是url不对,提供更好的错误提示
if (!getRoomInfoFn) {
return {
code: CRAWLER_ERROR_CODE.NOT_SUPPORT
}
}

const res = await getRoomInfoFn(roomUrl, { proxy, cookie }, writeLog)
log('res:', res)
return res
}
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/kuaishou.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ async function baseGetKuaishouLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetKuaishouRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getKuaishouLiveUrlsPlugin = captureError(baseGetKuaishouLiveUrlsPlugin)
export const getKuaishouRoomInfoPlugin = captureError(baseGetKuaishouRoomInfoPlugin)
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/momo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ async function baseGetMomoLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetMomoRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getMomoLiveUrlsPlugin = captureError(baseGetMomoLiveUrlsPlugin)
export const getMomoRoomInfoPlugin = captureError(baseGetMomoRoomInfoPlugin)
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/shiguang.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ async function baseGetShiGuangLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetShiGuangRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getShiGuangLiveUrlsPlugin = captureError(baseGetShiGuangLiveUrlsPlugin)
export const getShiGuangRoomInfoPlugin = captureError(baseGetShiGuangRoomInfoPlugin)
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/taobao.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,10 @@ async function baseGetTaobaoLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetTaobaoRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getTaobaoLiveUrlsPlugin = captureError(baseGetTaobaoLiveUrlsPlugin)
export const getTaobaoRoomInfoPlugin = captureError(baseGetTaobaoRoomInfoPlugin)
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/tiktok.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ async function baseGetTiktokLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetTiktokRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getTiktokLiveUrlsPlugin = captureError(baseGetTiktokLiveUrlsPlugin)
export const getTiktokRoomInfoPlugin = captureError(baseGetTiktokRoomInfoPlugin)
6 changes: 6 additions & 0 deletions src/main/crawler/plugins/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ async function baseGetTwitchLiveUrlsPlugin(roomUrl, others = {}) {
}
}

async function baseGetTwitchRoomInfoPlugin(roomUrl, others = {}) {
const roomId = getRoomIdByUrl(roomUrl)
const { proxy, cookie } = others
}

export const getTwitchLiveUrlsPlugin = captureError(baseGetTwitchLiveUrlsPlugin)
export const getTwitchRoomInfoPlugin = captureError(baseGetTwitchRoomInfoPlugin)
Loading

0 comments on commit 7cf68e2

Please sign in to comment.