Skip to content

Commit

Permalink
添加B站采集
Browse files Browse the repository at this point in the history
  • Loading branch information
iamllitog committed Oct 8, 2018
1 parent f656827 commit f401a05
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export default {
{label: '战旗', value: 'zhanqi'},
{label: '龙珠', value: 'longzhu'},
{label: '火猫', value: 'huomao'},
{label: '虎牙', value: 'huya'}
{label: '虎牙', value: 'huya'},
{label: 'B站', value: 'bilibili'}
]
}
},
Expand Down
53 changes: 53 additions & 0 deletions server/searchengin/bilibili.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import crawlUtil from '../util/crawlUtil'
import mysqlUtil from '../util/mysqlUtil'

let BASE_URL = 'https://live.bilibili.com'
let VIDEO_AJAX_URL = 'https://api.live.bilibili.com/room/v1/room/get_user_recommend?page='

const task = {
start () {
console.log('bilibili:开始抓取')
return mysqlUtil.deleteDataByPlatform('bilibili')
.then(() => task.getVideos())
.then((data) => {
console.log('bilibili:抓取完成')
return data
})
},
getVideos (pageNum) {
if (!pageNum) pageNum = 1
let canTurnPage = false
return crawlUtil.getHtmlTextByUrl(VIDEO_AJAX_URL + pageNum)
.then((text) => {
let datalist = JSON.parse(text).data
let videos = []
datalist.forEach((video) => {
if (video.online >= 100) {
videos.push({
title: video.title,
url: `${BASE_URL}/${video.link}`,
imageUrl: video.system_cover,
author: video.uname,
personNum: video.online,
category: '暂无分类',
platform: 'bilibili'
})
}
})

canTurnPage = datalist.length <= videos.length
console.log(videos.length);
return task.store(videos)
})
.then(() => {
if (canTurnPage) {
return task.getVideos(pageNum + 1)
}
})
},
store (videos) {
return mysqlUtil.insertDataByPlatform('bilibili', videos)
}
}

export default task
1 change: 0 additions & 1 deletion server/searchengin/douyu.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const task = {
platform: 'douyu'
})
})

canTurnPage = videos.length >= 120 && pageNum <= 150
return task.store(videos)
})
Expand Down
1 change: 0 additions & 1 deletion server/searchengin/huomao.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const task = {
})
}
})

canTurnPage = channelList.length <= videos.length
return task.store(videos)
})
Expand Down
1 change: 0 additions & 1 deletion server/searchengin/huya.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const task = {
platform: 'huya'
})
})

canTurnPage = videos.length >= 120 && pageNum <= 200
return task.store(videos)
})
Expand Down
2 changes: 2 additions & 0 deletions server/searchengin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import quanminTask from './quanmin'
import zhanqiTask from './zhanqi'
import longzhuTask from './longzhu'
import huyaTask from './huya'
import bilibiliTask from './bilibili'
import promiseUtil from '../util/promiseUtil'

let time = 2 * 60 * 1000
Expand All @@ -17,6 +18,7 @@ export default function () {
.then(() => (promiseUtil.timeRetryPromise(zhanqiTask.start, time, 3)))
.then(() => (promiseUtil.timeRetryPromise(longzhuTask.start, time, 3)))
.then(() => (promiseUtil.timeRetryPromise(huyaTask.start, time, 3)))
.then(() => (promiseUtil.timeRetryPromise(bilibiliTask.start, time, 3)))
.catch((err) => {
console.error(err)
})
Expand Down
Binary file added static/platform_logo/bilibili.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f401a05

Please sign in to comment.