Skip to content

Commit

Permalink
Complete send damnu
Browse files Browse the repository at this point in the history
  • Loading branch information
pelucky committed Aug 15, 2017
1 parent 02bffd9 commit 5cb02d3
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 119 deletions.
137 changes: 76 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## What can it do!
- It can collect danmu from Douyu TV
- After package, you can edit conf/config.properties to change Room_id
- As default, it send "#签到 时间戳" one time, so you can set it in crontab to run in the certain time.
- After package, you should change conf/config.properties.samples to config.properties to change Room_id
- Thanks to [@meanevo](https://github.com/meanevo/douyu-danmaku_checkin-helper)!

## Result

Expand All @@ -14,68 +16,68 @@ pel@raspberrypi:~/DouyuDanmu/target $ OpenJDK Zero VM warning: TieredCompilation
19:54:37.809 [main] INFO com.pelucky.danmu.util.TcpSocketClient - Connect to Server 124.95.174.146:8601.
19:54:37.934 [main] INFO com.pelucky.danmu.util.TcpSocketClient - Open Socket successfully
19:54:37.960 [main] INFO com.pelucky.danmu.util.Danmu - Danmu start succefully!
AcerSword: 赢了
浮夸的谎言: 这个叫啥游戏
斑驳o: 汪涵玩的确实不错
吼吼吼吼吼犀利: 老大练练李广
黄昏过后丶: 66666666666
彡宇: 66666666666
36摄氏度的阳光: 不容易
佰殇: 厉害了老大
AcerSword: Ӯ��
����Ļ���: �����ɶ��Ϸ
�߲�o: �������ȷʵ����
������Ϭ��: �ϴ��������
�ƻ����ؼ: 66666666666
����: 66666666666
36���϶ȵ�����: ������
����: �������ϴ�
yuyuyu123554: 6666666
ppykj001: 2333333333333
汉升汉升: 666666
我clgb: 666666666
是选择遗忘: 对面放水的厉害
自由的人生: 老大威武
静了光阴: 6666
天堂不也就这样: 水友演得好啊
V999999999999999: 厉害了,我的猴
折灬戟沉丿沙: 谁玩游戏不想赢啊,放锤子水
姐姐别摸我: 弹幕大神很NB
谢广坤666666: 6666
吃河蟹的痞老板: 阔以
有一点小简单: 这个游戏 表哥永远在
国民男神丶GeTao: 666
龘靐齾龗: 66666666666
��������: 666666
��clgb: 666666666
��ѡ������: �����ˮ������
���ɵ�����: �ϴ�����
���˹���: 6666
���ò�Ҳ������: ˮ���ݵúð�
V999999999999999: �����ˣ��ҵĺ�
����ꪳ�دɳ: ˭����Ϸ����Ӯ�����Ŵ���ˮ
��������: ��Ļ�����NB
���666666: 6666
�Ժ�з��Ʀ�ϰ�: ����
��һ��С��: �����Ϸ �����Զ��
��������ؼGeTao: 666
���h����: 66666666666
Mass0000: 66666666666
小梵家: 666666
fhjmuqueen: 爱看不看 赢了就是放水??草泥马的
纸币3: 666696
或许行123: 666666666666666
肥皂就用臭肥皂: 躺赢?
fzzzzzzzzzzzzz: 全是老大和队友一点点琢磨的那些说菜的好意思?
虫小七: 厉害啦 弟弟
褐瞳2016: 老大哪个区
暗黑の瓜皮: 终于赢了
瑾小主: 首胜啊
Treasure雨丶: 总算赢了一局
有一点小简单: 这配音
ganda2002: 可终于赢嘞
���: 666666
fhjmuqueen: �������� Ӯ�˾��Ƿ�ˮ�����������
ֽ��3: 666696
������123: 666666666666666
������ó�����: ��Ӯ��
fzzzzzzzzzzzzz: ȫ���ϴ�Ͷ���һ�����ĥ����Щ˵�˵ĺ���˼��
��С��: ������ �ܵ�
��ͫ2016: �ϴ��ĸ���
���ڤι�Ƥ: ����Ӯ��
�С��: ��ʤ��
Treasure��ؼ: ����Ӯ��һ��
��һ��С��: ������
ganda2002: ������Ӯ��
FadedUs: 66666666666
寅子家的冰箱贴: 6666666666666
chs303007: 终于赢了
waericdh: 老大笑了
黄昏过后丶: 666666666666666666666
eve封尘: 这配音是不是表哥配音的
均失: 66666666666
大貔貅兽: 66666666666666666666
Z空空即空空: 猴笑一个
折灬戟沉丿沙: 66666666666666666666
谛不凡: 老大在那个服务器啊
hongjiaming1: 终于赢了
壞槢慣: 振作啊 弟弟
简爱别逗: 66666666666
就是不吃鱼0: 喷子真多爱看看就看不看关键走
啊哈啊哈呵110: 终于赢了。。
月夜枫姜军: 看下甲片
我clgb: 666666666666
堕落的路西法11: 险些掉段
奥斯特里茨的阳光: 老大厉害了!!
小母牛不下崽: 66
水中深穴: 66666666666666
邪神魂: 更新你吗
A站二胡帝: 赢了
���Ӽҵı�����: 6666666666666
chs303007: ����Ӯ��
waericdh: �ϴ�Ц��
�ƻ����ؼ: 666666666666666666666
eve�⳾: �������Dz��DZ��������
��ʧ: 66666666666
��������: 66666666666666666666
Z�տռ��տ�: ��Цһ��
����ꪳ�دɳ: 66666666666666666666
�в���: �ϴ����Ǹ���������
hongjiaming1: ����Ӯ��
�Ę��T: ������ �ܵ�
�򰮱�: 66666666666
���Dz�����0: ������మ�����Ϳ������ؼ���
����������110: ����Ӯ�ˡ���
��ҹ�㽪��: ���¼�Ƭ
��clgb: 666666666666
�����·����11: ��Щ����
��˹����ĵ�����: �ϴ������ˣ���
Сĸţ������: 66
ˮ����Ѩ: 66666666666666
��: ��������
Aվ������: Ӯ��
```

## Environment
Expand All @@ -90,12 +92,25 @@ mvn clean package
cd target
Linux start:sh run.sh start
Linux Stop:sh run.sh stop
Windows: java -cp danmu-0.0.1-SNAPSHOT.jar;.\conf com.pelucky.danmu.DanmuApp
Windows: java -cp danmu-0.x.x-SNAPSHOT.jar;.\conf com.pelucky.danmu.DanmuApp
```
## Configuration

```
danmu_server=openbarrage.douyutv.com # Open Barrage's server, Should not change!
danmu_port=8601 # Port, Should not change!
danmu_port=8601 # Open Barrage's Port, Should not change!
auth_server=119.90.49.89 # Auth server, Should not change!
auth_port=8092 # Auth server's Port, Should not change!
username=xxxxx # Copy from cookies
ltkid=xxxxxx # Copy from cookies, change it when cookies failed
stk=xxxxxx # Copy from cookies, change it when cookies failed
room_id=71415 # Room_id of Douyu TV
```

## TODO list
1. Auto login
- Because the cookies will change after about one week, so you should change ltkid, stk after the cookie has failed
2. %'s problem
- When receive message has '%' in it, the receive thread will crash cos of unable to phrase messages.
3. Rework the code
- The send and receive part can divid into two different parts.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.pelucky.danmu</groupId>
<artifactId>danmu</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.1-SNAPSHOT</version>
<name>Danmu</name>
<description>Grap danmu from DouyuTV</description>
<build>
Expand Down
2 changes: 1 addition & 1 deletion src/assembly/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mkdir -p logs
JVM_OPTS='-XX:+TieredCompilation -Xmx1024m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=100M -Dfile.encoding=UTF-8'

CLASS_PATH="danmu-0.0.1-SNAPSHOT.jar":./conf
CLASS_PATH="danmu-0.1.1-SNAPSHOT.jar":./conf

case $1 in
start)
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/pelucky/danmu/DanmuApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,13 +19,23 @@ public static void main(String[] args) {

String danmu_server = null;
int danmu_port = 0;
String auth_server = null;
int auth_port = 0;
String room_id = null;
String username = null;
String ltkid = null;
String stk = null;
try {
inputStream = DanmuApp.class.getClassLoader().getResourceAsStream("config.properties");
properties.load(inputStream);
danmu_server = properties.getProperty("danmu_server", "openbarrage.douyutv.com");
danmu_port = Integer.valueOf(properties.getProperty("danmu_port", "8601"));
auth_server = properties.getProperty("auth_server", "119.90.49.89");
auth_port = Integer.valueOf(properties.getProperty("auth_port", "8092"));
room_id = properties.getProperty("room_id");
username = properties.getProperty("username");
ltkid = properties.getProperty("ltkid");
stk = properties.getProperty("stk");
} catch (IOException e) {
e.printStackTrace();
} finally {
Expand All @@ -35,15 +47,23 @@ public static void main(String[] args) {
}
}
}
Danmu danmu = new Danmu(danmu_server, danmu_port, room_id);
danmu.start();
Danmu danmu = new Danmu(danmu_server, danmu_port, auth_server, auth_port, room_id, username, ltkid, stk);

// Start Danmu server for receiving danmu
/*danmu.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}*/

// Auth server for send danmu
danmu.authDanmu();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

danmu.sendDanmu("fuxxxxx");
danmu.sendDanmu("#签到 " +new Date().toString());
}
}
7 changes: 1 addition & 6 deletions src/main/java/com/pelucky/danmu/thread/ReceiveData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ public void run() {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
InputStream inputStream = tcpSocketClient.getSocket().getInputStream();

byte[] msg = new byte[1024];
byte[] msg = new byte[10240];
int line = 0;
line = inputStream.read(msg);
byteOutput.write(msg, 0, line);
byte[] receiveMsg = byteOutput.toByteArray();
tcpSocketClient.getDouyuProtocolMessage().receivedMessageContent(receiveMsg);

// for (byte b : receiveMsg) {
// System.out.print(b);
// }
// System.out.println();
} catch (IOException e) {
logger.info("Receive IO error!");
logger.info(e.getMessage());
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/com/pelucky/danmu/util/Danmu.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ public class Danmu {
private ReceiveData receiveData;
private ReceiveData receiveDataAuth;
private String roomID;
private String username;
private String ltkid;
private String stk;

public Danmu(String danmu_server, int danmu_port, String roomID) {
public Danmu(String danmu_server, int danmu_port, String auth_server, int auth_port, String roomID, String username, String ltkid, String stk) {
tcpSocketClient = new TcpSocketClient(danmu_server, danmu_port);
keepaliveSender = new KeepaliveSender(tcpSocketClient);
receiveData = new ReceiveData(tcpSocketClient);

tcpSocketClientAuth = new TcpSocketClient("119.90.49.89", 8092);
tcpSocketClientAuth = new TcpSocketClient(auth_server, auth_port);
receiveDataAuth = new ReceiveData(tcpSocketClientAuth);
this.roomID = roomID;
this.username = username;
this.ltkid = ltkid;
this.stk = stk;
}

public void start() {
Expand All @@ -37,59 +43,62 @@ public void start() {
}

private void sendKeepalive() {
new Thread(keepaliveSender).start();
Thread thread = new Thread(keepaliveSender);
thread.setName("DanmuServerKeepaliveThread");
thread.start();
}

private void receiveData() {
new Thread(receiveData).start();
Thread thread = new Thread(receiveData);
thread.setName("DanmuServerReceiveThread");
thread.start();
}

/**
*
* Auth server, The
*/
public void authDanmu() {
// Auth server
new Thread(receiveDataAuth).start();
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);// 获取当前时间戳
String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();// 构造uuid作为devid参数
String vk = MD5Util.MD5(timestamp + "7oE9nPEG9xXV69phU31FYCLUagKeYtsF" + uuid);// vk参数
// Auth server's receive data
/*Thread thread = new Thread(receiveDataAuth);
thread.setName("AuthServerReceiveThread");
thread.start();*/

String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();
String vk = MD5Util.MD5(timestamp + "7oE9nPEG9xXV69phU31FYCLUagKeYtsF" + uuid);
// String vk = MD5Util.MD5(timestamp +
// "r5*^5;}2#\\${XF[h+;'./.Q'1;,-]f'p[" + uuid);// vk参数

String username = "auto_uiccRqlXfM";
String ltkid = "61087243";
String stk = "50402ea12d0f5cec";
String loginreqInfo = "type@=loginreq/username@=" + username + "/ct@=0/password@=/roomid@=" + roomID
+ "/devid@=" + uuid + "/rt@=" + timestamp + "/vk@=" + vk + "/ver@=20150929/aver@=2017073111/ltkid@="
+ ltkid + "/biz@=1/stk@=" + stk + "/";

tcpSocketClientAuth.sendData(loginreqInfo);

// Auth server's keepalive
/*Thread keepAliveThread = new Thread(new KeepaliveSender(tcpSocketClientAuth));
keepAliveThread.setName("AuthServerReceiveThread");
keepAliveThread.start();*/
}

public void sendDanmu(String message) {
// byte [] messageByte = DouyuProtocolMessage.encodeMessage(message);
message = DouyuProtocolMessage.encodeMessage(message);
System.out.println("message: " + message);
System.out.println();
// byte[] messageByte = new byte[] { (byte) 0xe6, (byte) 0xb5, (byte) 0x8b, (byte) 0xe8, (byte) 0xaf, (byte) 0x95 };
logger.info("Send message: {}", message);
tcpSocketClientAuth.sendData("type@=chatmessage/receiver@=0/content@=" + message
+ "/scope@=/col@=0/pid@=/p2p@=0/nc@=0/rev@=0/ifs@=0/");
}
}

/**
* Created by Brucezz on 2016/01/04. DouyuCrawler
* https://github.com/brucezz/DouyuCrawler
*/
class MD5Util {
public static String MD5(String s) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
try {
// 获得MD5摘要算法的 MessageDigest 对象
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// 使用指定的字节更新摘要, 获得密文
byte[] md = mdInst.digest(s.getBytes());
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
Expand Down
Loading

0 comments on commit 5cb02d3

Please sign in to comment.