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
65064349
Commit
65064349
authored
Jan 29, 2019
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
斗鱼弹幕级b站消息队列添加
parent
c472b5c4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
4 deletions
+80
-4
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliMessageHandler.java
+2
-2
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliMessageListener.java
+13
-0
src/main/java/com/zhiwei/live/danmu/douyu/DouYuClient.java
+13
-2
src/main/java/com/zhiwei/live/danmu/douyu/Main.java
+52
-0
src/main/java/com/zhiwei/live/danmu/douyu/MessageHandler.java
+0
-0
No files found.
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliMessageHandler.java
View file @
65064349
...
@@ -65,8 +65,8 @@ public class BilibiliMessageHandler extends ChannelInboundHandlerAdapter{
...
@@ -65,8 +65,8 @@ public class BilibiliMessageHandler extends ChannelInboundHandlerAdapter{
Matcher
matcher
=
pattern
.
matcher
(
source
);
Matcher
matcher
=
pattern
.
matcher
(
source
);
while
(
matcher
.
find
())
{
while
(
matcher
.
find
())
{
JSONObject
dataJson
=
JSONObject
.
parseObject
(
matcher
.
group
());
JSONObject
dataJson
=
JSONObject
.
parseObject
(
matcher
.
group
());
Bilibili
Entity
bilibiliEntity
=
new
BilibiliEntity
(
dataJson
);
Bilibili
Message
bilibiliMessage
=
new
BilibiliMessage
(
dataJson
);
System
.
out
.
println
(
bilibili
Entity
.
toString
()
);
System
.
out
.
println
(
bilibili
Message
);
}
}
}
}
ReferenceCountUtil
.
release
(
msg
);
ReferenceCountUtil
.
release
(
msg
);
...
...
src/main/java/com/zhiwei/live/danmu/bilibili/BilibiliMessageListener.java
0 → 100644
View file @
65064349
package
com
.
zhiwei
.
live
.
danmu
.
bilibili
;
import
java.util.List
;
import
java.util.Vector
;
public
class
BilibiliMessageListener
{
public
static
List
<
BilibiliMessage
>
messages
=
new
Vector
<>();
public
static
void
addMessages
(
BilibiliMessage
bilibiliMessage
)
{
messages
.
add
(
bilibiliMessage
);
}
}
src/main/java/com/zhiwei/live/danmu/douyu/DouYuClient.java
View file @
65064349
package
com
.
zhiwei
.
live
.
danmu
.
douyu
;
package
com
.
zhiwei
.
live
.
danmu
.
douyu
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.net.SocketAddress
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
...
@@ -9,6 +11,7 @@ import java.util.List;
...
@@ -9,6 +11,7 @@ import java.util.List;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.zhiwei.crawler.proxy.ProxyHolder
;
import
com.zhiwei.live.danmu.douyu.constants.DouYuConstants
;
import
com.zhiwei.live.danmu.douyu.constants.DouYuConstants
;
import
com.zhiwei.live.danmu.douyu.constants.MsgType
;
import
com.zhiwei.live.danmu.douyu.constants.MsgType
;
import
com.zhiwei.live.danmu.douyu.entity.BaseMsg
;
import
com.zhiwei.live.danmu.douyu.entity.BaseMsg
;
...
@@ -45,7 +48,6 @@ public class DouYuClient {
...
@@ -45,7 +48,6 @@ public class DouYuClient {
private
MessageHandler
messageHandler
;
private
MessageHandler
messageHandler
;
private
List
<
MessageListener
>
messageListenerList
=
new
ArrayList
<>();
private
List
<
MessageListener
>
messageListenerList
=
new
ArrayList
<>();
public
DouYuClient
(
String
host
,
int
port
,
String
roomId
)
{
public
DouYuClient
(
String
host
,
int
port
,
String
roomId
)
{
this
.
host
=
host
;
this
.
host
=
host
;
this
.
port
=
port
;
this
.
port
=
port
;
...
@@ -54,6 +56,14 @@ public class DouYuClient {
...
@@ -54,6 +56,14 @@ public class DouYuClient {
this
.
init
();
this
.
init
();
}
}
public
DouYuClient
(
String
roomId
)
{
this
.
host
=
"openbarrage.douyutv.com"
;
this
.
port
=
8601
;
this
.
roomId
=
roomId
;
//初始化
this
.
init
();
}
/**
/**
* 初始化Client
* 初始化Client
*/
*/
...
@@ -68,7 +78,8 @@ public class DouYuClient {
...
@@ -68,7 +78,8 @@ public class DouYuClient {
private
void
connect
()
{
private
void
connect
()
{
try
{
try
{
logger
.
info
(
"从服务器({}:{})获取弹幕服务器数据"
,
host
,
port
);
logger
.
info
(
"从服务器({}:{})获取弹幕服务器数据"
,
host
,
port
);
socket
=
new
Socket
(
host
,
port
);
socket
=
new
Socket
(
ProxyHolder
.
NAT_PROXY
.
getProxy
());
socket
.
connect
(
new
InetSocketAddress
(
host
,
port
));
messageHandler
=
new
MessageHandler
(
socket
);
messageHandler
=
new
MessageHandler
(
socket
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
src/main/java/com/zhiwei/live/danmu/douyu/Main.java
0 → 100644
View file @
65064349
package
com
.
zhiwei
.
live
.
danmu
.
douyu
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.zhiwei.common.config.GroupType
;
import
com.zhiwei.crawler.proxy.ProxyFactory
;
import
com.zhiwei.live.danmu.douyu.entity.ChatMsg
;
/**
* 功能描述:
*
* @auther: coffee
* @date: 2018-07-04 19:37:41
* 修改日志:
*/
public
class
Main
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
Main
.
class
);
private
static
final
String
registry
=
"zookeeper://192.168.0.36:2181"
;
private
static
final
String
group
=
"local"
;
static
{
ProxyFactory
.
init
(
registry
,
group
,
GroupType
.
PROVIDER
);
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
DouYuClient
client
=
new
DouYuClient
(
"3084150"
);
client
.
registerMessageListener
(
new
MessageListener
<
ChatMsg
>()
{
@Override
public
void
read
(
ChatMsg
message
)
{
//logger.info(message.toChatStr());
// System.out.println(message.toChatStr());
}
});
client
.
registerMessageListener
(
new
MessageListener
<
String
>()
{
@Override
public
void
read
(
String
message
)
{
System
.
out
.
println
(
message
);
// logger.info(message);
}
});
client
.
login
();
client
.
sync
();
Thread
.
sleep
(
30000
);
client
.
exit
();
}
}
src/main/java/com/zhiwei/live/danmu/douyu/MessageHandler.java
View file @
65064349
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