Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
live-crawler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhiwei
live-crawler
Commits
03582197
Commit
03582197
authored
Jan 29, 2019
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
弹幕采集修改为由roomId修改为roomUrl,发现有很多链接中没有房间id信息
parent
65bd8bb3
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
15 deletions
+21
-15
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliClient.java
+2
-2
src/main/java/com/zhiwei/live/danmu/douyu/DouyuClient.java
+2
-2
src/main/java/com/zhiwei/live/danmu/pandam/PandamClient.java
+12
-2
src/test/java/com/zhiwei/live/test/danmu/BilibiliDanMuTest.java
+1
-2
src/test/java/com/zhiwei/live/test/danmu/DouYuDanMuTest.java
+2
-3
src/test/java/com/zhiwei/live/test/danmu/PanDamDanMuTest.java
+2
-4
No files found.
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliClient.java
View file @
03582197
...
...
@@ -31,9 +31,9 @@ public class BilibiliClient {
* @param roomId
* @throws Exception
*/
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Id
)
throws
Exception
{
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Url
)
throws
Exception
{
//根据房间号获取真实房间号
RoomInfo
roomInfo
=
BilibiliRoomInfoCrawler
.
getRoomInfoByRoomUrl
(
room
Id
);
RoomInfo
roomInfo
=
BilibiliRoomInfoCrawler
.
getRoomInfoByRoomUrl
(
room
Url
);
if
(
Objects
.
nonNull
(
roomInfo
))
{
//获取弹幕服务器地址
String
url
=
"https://live.bilibili.com/api/player?id=cid:"
+
roomInfo
.
getRoomId
();
...
...
src/main/java/com/zhiwei/live/danmu/douyu/DouyuClient.java
View file @
03582197
...
...
@@ -31,9 +31,9 @@ public class DouyuClient {
* @param roomId
* @throws Exception
*/
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Id
)
throws
Exception
{
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Url
)
throws
Exception
{
// 根据房间号获取真实房间号
RoomInfo
roomInfo
=
DouYuRoomInfoCrawler
.
getRoomInfoByRoomUrl
(
room
Id
);
RoomInfo
roomInfo
=
DouYuRoomInfoCrawler
.
getRoomInfoByRoomUrl
(
room
Url
);
if
(
Objects
.
nonNull
(
roomInfo
))
{
// 建立弹幕连接
Connector
.
asynchronizedTcpConnect
(
new
NioEventLoopGroup
(),
HOST
,
PORT
,
new
IdleStateHandler
(
0
,
30
,
45
),
...
...
src/main/java/com/zhiwei/live/danmu/pandam/PandamClient.java
View file @
03582197
package
com
.
zhiwei
.
live
.
danmu
.
pandam
;
import
java.util.Objects
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.crawler.core.HttpBoot
;
import
com.zhiwei.crawler.core.RequestUtils
;
import
com.zhiwei.live.bean.RoomInfo
;
import
com.zhiwei.live.danmu.util.Connector
;
import
com.zhiwei.live.danmu.util.DataCallBack
;
import
com.zhiwei.live.roominfo.PandamTVRoomInfoCrawler
;
import
io.netty.channel.nio.NioEventLoopGroup
;
import
io.netty.handler.timeout.IdleStateHandler
;
...
...
@@ -27,8 +31,11 @@ public class PandamClient {
* @param roomId
* @throws Exception
*/
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Id
)
throws
Exception
{
public
static
void
getDanmu
(
DataCallBack
dataCallBack
,
String
room
Url
)
throws
Exception
{
//根据房间号获取弹幕服务器地址
RoomInfo
roomInfo
=
PandamTVRoomInfoCrawler
.
getRoomInfoByRoomUrl
(
roomUrl
);
if
(
Objects
.
nonNull
(
roomInfo
))
{
String
roomId
=
roomInfo
.
getRoomId
();
Request
request
=
RequestUtils
.
wrapGet
(
"http://riven.panda.tv/chatroom/getinfo?roomid="
+
roomId
);
String
host
=
null
;
int
port
=
-
1
;
...
...
@@ -37,7 +44,7 @@ public class PandamClient {
try
(
Response
response
=
httpBoot
.
syncCall
(
request
))
{
json
=
JSON
.
parseObject
(
response
.
body
().
string
());
if
(
json
.
getInteger
(
"errno"
)
!=
0
)
{
throw
new
IllegalStateException
(
"房间号: "
+
roomId
+
" 不存在"
);
throw
new
IllegalStateException
(
"房间号: "
+
roomUrl
+
" 不存在"
);
}
json
=
json
.
getJSONObject
(
"data"
);
String
[]
address
=
json
.
getJSONArray
(
"chat_addr_list"
).
getString
(
0
).
split
(
":"
);
...
...
@@ -53,6 +60,9 @@ public class PandamClient {
String
ts
=
json
.
getString
(
"ts"
);
Connector
.
asynchronizedTcpConnect
(
new
NioEventLoopGroup
(),
host
,
port
,
new
IdleStateHandler
(
0
,
30
,
45
),
new
PandamMessageHandler
(
dataCallBack
,
appid
,
rid
,
ts
,
sign
,
authType
)).
sync
();
}
else
{
}
}
}
src/test/java/com/zhiwei/live/test/danmu/BilibiliDanMuTest.java
View file @
03582197
...
...
@@ -8,7 +8,6 @@ public class BilibiliDanMuTest {
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
String
roomUrl
=
"https://live.bilibili.com/139"
;
String
roomId
=
roomUrl
.
replaceAll
(
"https://live.bilibili.com/"
,
""
);
try
{
BilibiliClient
.
getDanmu
(
new
DataCallBack
()
{
@Override
...
...
@@ -18,7 +17,7 @@ public class BilibiliDanMuTest {
System
.
out
.
println
(
"-------------"
+
bilibiliMessage
.
toString
());
}
}
},
roomId
);
},
roomUrl
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
src/test/java/com/zhiwei/live/test/danmu/DouYuDanMuTest.java
View file @
03582197
...
...
@@ -7,8 +7,7 @@ import com.zhiwei.live.danmu.util.DataCallBack;
public
class
DouYuDanMuTest
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
String
roomUrl
=
"https://live.bilibili.com/139"
;
String
roomId
=
roomUrl
.
replaceAll
(
"https://live.bilibili.com/"
,
""
);
String
roomUrl
=
"https://www.douyu.com/4372875"
;
try
{
DouyuClient
.
getDanmu
(
new
DataCallBack
()
{
@Override
...
...
@@ -18,7 +17,7 @@ public class DouYuDanMuTest {
System
.
out
.
println
(
"-------------"
+
douyuMessage
.
toString
());
}
}
},
room
Id
);
},
room
Url
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
src/test/java/com/zhiwei/live/test/danmu/PanDamDanMuTest.java
View file @
03582197
...
...
@@ -7,7 +7,7 @@ import com.zhiwei.live.danmu.util.DataCallBack;
public
class
PanDamDanMuTest
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
room
Id
=
"
337852"
;
String
room
Url
=
"https://www.panda.tv/
337852"
;
try
{
PandamClient
.
getDanmu
(
new
DataCallBack
()
{
@Override
...
...
@@ -17,11 +17,9 @@ public class PanDamDanMuTest {
System
.
out
.
println
(
"-------------"
+
pandamMessage
.
toString
());
}
}
},
room
Id
);
},
room
Url
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment