danmu 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +15 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/danmu +4 -0
- data/bin/setup +8 -0
- data/danmu.gemspec +37 -0
- data/lib/danmu.rb +6 -0
- data/lib/danmu/cli.rb +17 -0
- data/lib/danmu/clients/danmu_client.rb +215 -0
- data/lib/danmu/douyu_client.rb +53 -0
- data/lib/danmu/misc/logging.rb +27 -0
- data/lib/danmu/models/message.rb +29 -0
- data/lib/danmu/models/room_info.rb +29 -0
- data/lib/danmu/version.rb +3 -0
- metadata +174 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6a1eb297ddee86eee1d955d91ec029206a9f959f
|
|
4
|
+
data.tar.gz: 64adbb4586c34636c5f56bbb9beafa509e4bd313
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2633d9b19334312cad5b0f9870a3c51ff6b29bfbd9750b5061e1b6637f5a197e1ef3d24301e32bf6cfbb78588ebddba22e6bcf602e077c4bdb052c5eebdda70e
|
|
7
|
+
data.tar.gz: 34e72602d50a752b5382564ac03ac1f761fdb238596d530995d9ecf2060f62f7e4e0ad8b3caf62fc168b21aa80998701dbf03371099e8245550c001e36908c44
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
|
7
|
+
|
|
8
|
+
We are committed to making participation in this project a harassment-free
|
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior by participants include:
|
|
14
|
+
|
|
15
|
+
* The use of sexualized language or imagery
|
|
16
|
+
* Personal attacks
|
|
17
|
+
* Trolling or insulting/derogatory comments
|
|
18
|
+
* Public or private harassment
|
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
|
20
|
+
addresses, without explicit permission
|
|
21
|
+
* Other unethical or unprofessional conduct
|
|
22
|
+
|
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
|
+
threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
+
Conduct may be permanently removed from the project team.
|
|
33
|
+
|
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
|
35
|
+
when an individual is representing the project or its community.
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
+
reported by contacting a project maintainer at twocucao@gmail.com. All
|
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
+
incident.
|
|
43
|
+
|
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
45
|
+
version 1.3.0, available at
|
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
47
|
+
|
|
48
|
+
[homepage]: http://contributor-covenant.org
|
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 twocucao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Danmu
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
git clone https://github.com/twocucao/danmu.git
|
|
8
|
+
cd danmu
|
|
9
|
+
bundle
|
|
10
|
+
bundle exec bin/danmu douyu http://www.douyutv.com/301712
|
|
11
|
+
```
|
|
12
|
+
## License
|
|
13
|
+
|
|
14
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
15
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "danmu"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/danmu
ADDED
data/bin/setup
ADDED
data/danmu.gemspec
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'danmu/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "danmu"
|
|
8
|
+
spec.version = Danmu::VERSION
|
|
9
|
+
spec.authors = ["twocucao"]
|
|
10
|
+
spec.email = ["twocucao@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{斗鱼弹幕助手,终端下读取斗鱼的弹幕}
|
|
13
|
+
spec.description = %q{斗鱼弹幕助手}
|
|
14
|
+
spec.homepage = "https://github.com/twocucao/danmu"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
|
+
|
|
34
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
|
35
|
+
spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.7.2'
|
|
36
|
+
spec.add_dependency 'awesome_print', '~> 1.6', '>= 1.6.1'
|
|
37
|
+
end
|
data/lib/danmu.rb
ADDED
data/lib/danmu/cli.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
require_relative './douyu_client'
|
|
3
|
+
|
|
4
|
+
module Danmu
|
|
5
|
+
class DanmuShow < Thor
|
|
6
|
+
|
|
7
|
+
desc "douyu [url/id/shortname]", "DouyuDanmuClient For Ruby"
|
|
8
|
+
long_desc <<-DANMU
|
|
9
|
+
输入url/主播id或者短名就可以对弹幕进行抓取
|
|
10
|
+
DANMU
|
|
11
|
+
option :statistic
|
|
12
|
+
def douyu( url )
|
|
13
|
+
DouyuClient.new( url )
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'socket'
|
|
3
|
+
require 'digest'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require_relative '../models/message'
|
|
6
|
+
require_relative '../misc/logging'
|
|
7
|
+
|
|
8
|
+
# INFO 代表的是一些琐碎的操作
|
|
9
|
+
# DEBUG
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DanmuClient
|
|
13
|
+
include Logging
|
|
14
|
+
|
|
15
|
+
DANMU_SERVER = "danmu.douyutv.com"
|
|
16
|
+
DANMU_PORT = 8602
|
|
17
|
+
|
|
18
|
+
def initialize(room,auth_dst_ip,auth_dst_port)
|
|
19
|
+
@room = room
|
|
20
|
+
@room_id = room.room_id
|
|
21
|
+
@auth_dst_ip = auth_dst_ip
|
|
22
|
+
@auth_dst_port = auth_dst_port
|
|
23
|
+
@dev_id = SecureRandom.uuid.to_s.gsub('-','').upcase
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def start
|
|
27
|
+
do_main
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def do_main
|
|
31
|
+
logger.info("准备登陆认证")
|
|
32
|
+
do_login
|
|
33
|
+
print_room_status
|
|
34
|
+
logger.info("准备获取弹幕")
|
|
35
|
+
loop { get_danmu }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def do_login
|
|
40
|
+
@danmu_auth_socket = TCPSocket.new @auth_dst_ip,@auth_dst_port
|
|
41
|
+
@danmu_socket = TCPSocket.new DANMU_SERVER,DANMU_PORT
|
|
42
|
+
logger.info("初始化DAMMU_SOCKET和DANMU_AUTH_SOCKET")
|
|
43
|
+
send_auth_loginreq_msg
|
|
44
|
+
str = @danmu_auth_socket.recv(4000)
|
|
45
|
+
#puts "<>1<><"+str
|
|
46
|
+
if str.include? "live_stat@=0"
|
|
47
|
+
@live_stat = "离线"
|
|
48
|
+
elsif str.include? "live_stat@=1"
|
|
49
|
+
@live_stat = "在线"
|
|
50
|
+
@username= str[/\/username@=(.+)\/nickname/,1]
|
|
51
|
+
#puts "----" + @username
|
|
52
|
+
str = @danmu_auth_socket.recv(4000)
|
|
53
|
+
#puts "<>2<><"+str
|
|
54
|
+
@gid = str[/\/gid@=(\d+)\//,1]
|
|
55
|
+
@weight = str[/\/weight@=(\d+)\//,1]
|
|
56
|
+
@fans_count = str[/\/fans_count@=(\d+)\//,1]
|
|
57
|
+
#puts "<->" + @live_stat.to_s + @weight.to_s + @fans_count.to_s
|
|
58
|
+
#puts @gid + "----"
|
|
59
|
+
send_qrl_msg
|
|
60
|
+
str = @danmu_auth_socket.recv(4000)
|
|
61
|
+
#puts "<>3<><"+str
|
|
62
|
+
str = @danmu_auth_socket.recv(4000)
|
|
63
|
+
#puts "<>4<><"+str
|
|
64
|
+
send_keeplive_msg
|
|
65
|
+
str = @danmu_auth_socket.recv(4000)
|
|
66
|
+
#puts "<>5<><"+str
|
|
67
|
+
data = "type@=loginreq/username@="+@username+"/password@=1234567890123456/roomid@=" + @room_id.to_s + "/"
|
|
68
|
+
all_data = message(data)
|
|
69
|
+
@danmu_socket.write all_data
|
|
70
|
+
#puts all_data
|
|
71
|
+
str = @danmu_socket.recv(4000)
|
|
72
|
+
#puts str
|
|
73
|
+
send_join_group_msg
|
|
74
|
+
logger.info("发送心跳包")
|
|
75
|
+
do_keeplive
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def message(content)
|
|
81
|
+
Message.new(content).to_s
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def do_keeplive
|
|
85
|
+
Thread.new do
|
|
86
|
+
loop do
|
|
87
|
+
#puts "--> KeepAlive"
|
|
88
|
+
send_keeplive_msg
|
|
89
|
+
sleep 40
|
|
90
|
+
@danmu_socket.write message("type@=keeplive/tick@=" + timestamp + "/")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def send_keeplive_msg
|
|
96
|
+
data = "type@=keeplive/tick@=" + timestamp + "/vbw@=0/k@=19beba41da8ac2b4c7895a66cab81e23/"
|
|
97
|
+
msg = message(data)
|
|
98
|
+
@danmu_auth_socket.write msg
|
|
99
|
+
end
|
|
100
|
+
def send_auth_loginreq_msg
|
|
101
|
+
time = timestamp
|
|
102
|
+
vk = Digest::MD5.hexdigest(time + "7oE9nPEG9xXV69phU31FYCLUagKeYtsF" + @dev_id)
|
|
103
|
+
data = "type@=loginreq/username@=/ct@=0/password@=/roomid@="+@room_id.to_s+"/devid@="+@dev_id + "/rt@="+timestamp+"/vk@="+vk+"/ver@=20150929/"
|
|
104
|
+
msg = message(data)
|
|
105
|
+
@danmu_auth_socket.write msg
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def send_loginreq_msg
|
|
109
|
+
data = "type@=loginreq/username@="+@username+"/password@=1234567890123456/roomid@="+@room_id.to_s+"/"
|
|
110
|
+
msg = message(data)
|
|
111
|
+
@danmu_socket.write msg
|
|
112
|
+
end
|
|
113
|
+
def send_join_group_msg
|
|
114
|
+
data = "type@=joingroup/rid@=" + @room_id.to_s + "/gid@="+@gid+"/"
|
|
115
|
+
msg = message(data)
|
|
116
|
+
@danmu_socket.write msg
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def send_qrl_msg
|
|
120
|
+
data = "type@=qrl/rid@=" + @room_id.to_s + "/"
|
|
121
|
+
msg = message(data)
|
|
122
|
+
@danmu_auth_socket.write msg
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def get_danmu
|
|
126
|
+
danmu_data = @danmu_socket.recv(4000).force_encoding("UTF-8")
|
|
127
|
+
if not danmu_data.include? "type@="
|
|
128
|
+
logger.info "非消息"
|
|
129
|
+
elsif danmu_data.include? "type@=error"
|
|
130
|
+
logger.info "弹幕认证超时"
|
|
131
|
+
else
|
|
132
|
+
#logger.info(danmu_data)
|
|
133
|
+
#puts danmu_data
|
|
134
|
+
type = danmu_data[danmu_data.index("type@=")..-3]
|
|
135
|
+
str = type.gsub('@S','/').gsub('@A=',':').gsub('@=',':').encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8')
|
|
136
|
+
type = str[/type:(.+?)\//,1]
|
|
137
|
+
#puts type
|
|
138
|
+
if type == "chatmessage"
|
|
139
|
+
type_zh = "弹幕"
|
|
140
|
+
sender_id = str[/\/sender:(.+?)\//,1]
|
|
141
|
+
nickname = str[/\/snick:(.+?)\//,1]
|
|
142
|
+
content = str[/\/content:(.+?)\//,1]
|
|
143
|
+
strength = str[/\/strength:(.+?)\//,1]
|
|
144
|
+
level = str[/\/level:(\d+?)\//,1]
|
|
145
|
+
time = Time.now.to_s
|
|
146
|
+
puts "|" + type_zh + "| " + align_left_str(nickname,20," ") + align_left_str("<Lv:#{level}>",8," ") + align_left_str("(#{sender_id})",13," ") + align_left_str("[#{strength}]",10," ") + "@ #{time}: #{content} "
|
|
147
|
+
elsif type == "userenter"
|
|
148
|
+
type_zh = "入房"
|
|
149
|
+
user_id = str[/\/:id:(.+?)\//,1]
|
|
150
|
+
nickname = str[/\/nick:(.+?)\//,1]
|
|
151
|
+
strength = str[/\/strength:(.+?)\//,1]
|
|
152
|
+
time = Time.now.to_s
|
|
153
|
+
level = str[/\/level:(\d+)\//,1]
|
|
154
|
+
puts "|" + type_zh + "| " + align_left_str(nickname,20," ") + align_left_str("<Lv:#{level}>",8," ") + align_left_str("(#{user_id})",13," ") + align_left_str("[#{strength}]",10," ") + "@ #{time}"
|
|
155
|
+
#puts "|#{type_zh}| #{nickname} <Lv:#{level}> (#{user_id}) [#{strength}] @ #{time}"
|
|
156
|
+
elsif type == "dgn"
|
|
157
|
+
type_zh = "未知"
|
|
158
|
+
level = str[/\/level:(\d+?)\//,1]
|
|
159
|
+
user_id = str[/\/sid:(.+?)\//,1]
|
|
160
|
+
nickname = str[/\/src_ncnm:(.+?)\//,1]
|
|
161
|
+
hits = str[/\/hits:(.+?)\//,1]
|
|
162
|
+
time = Time.now.to_s
|
|
163
|
+
puts "|" + type_zh + "| " + align_left_str(nickname,20," ") + align_left_str("<Lv:#{level}>",8," ") + align_left_str("(#{user_id})",13," ") + align_left_str("[#{"Unknown"}]",10," ") + "@ #{time}: #{hits} hits "
|
|
164
|
+
#puts "|#{type_zh}| #{nickname} <Lv:#{level}> (#{user_id}) @ #{time}"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def recv
|
|
171
|
+
@danmu_socket.recv(4000)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def stop
|
|
175
|
+
@danmu_socket.close
|
|
176
|
+
@danmu_auth_socket.close
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def timestamp
|
|
180
|
+
Time.now.to_i.to_s
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def print_room_status()
|
|
184
|
+
puts "========================================="
|
|
185
|
+
puts "= Room Infomation ="
|
|
186
|
+
puts "========================================="
|
|
187
|
+
puts "= 房间: #{@room.room_name}(#{@room.room_id})"
|
|
188
|
+
puts "= 主播: #{@room.owner_name}"
|
|
189
|
+
puts "= 公告: #{@room.room_gg_show}"
|
|
190
|
+
puts "= 标签: #{@room.room_tags}"
|
|
191
|
+
puts "= 在线: #{@live_stat}"
|
|
192
|
+
puts "= 粉丝: #{@fans_count}"
|
|
193
|
+
puts "= 财产: #{@weight}"
|
|
194
|
+
puts "= DANMU IP DST : #{@auth_dst_ip}:#{@auth_dst_port}\t="
|
|
195
|
+
puts "========================================="
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def align_left_str(raw_str,max_length,filled_chr)
|
|
199
|
+
my_length = 0
|
|
200
|
+
for i in 0...raw_str.size
|
|
201
|
+
if raw_str[i].ord > 127 || raw_str[i].ord <=0
|
|
202
|
+
my_length += 1
|
|
203
|
+
end
|
|
204
|
+
my_length += 1
|
|
205
|
+
end
|
|
206
|
+
if (max_length - my_length) > 0
|
|
207
|
+
raw_str + filled_chr * ( max_length - my_length )
|
|
208
|
+
else
|
|
209
|
+
raw_str
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'awesome_print'
|
|
4
|
+
require_relative './models/room_info'
|
|
5
|
+
require_relative './clients/danmu_client'
|
|
6
|
+
require 'json'
|
|
7
|
+
require 'nokogiri'
|
|
8
|
+
|
|
9
|
+
class DouyuClient
|
|
10
|
+
DOUYU_PREFIX = "http://www.douyutv.com/"
|
|
11
|
+
|
|
12
|
+
def initialize(url)
|
|
13
|
+
init_config
|
|
14
|
+
if url.include? DOUYU_PREFIX
|
|
15
|
+
else
|
|
16
|
+
url = DOUYU_PREFIX + url
|
|
17
|
+
end
|
|
18
|
+
room_html = open(url).read
|
|
19
|
+
json1 = room_html[/var\s\$ROOM\s=\s({.*})/,1]
|
|
20
|
+
json2 = room_html[/var\sroom_args\s=\s({.*})/,1]
|
|
21
|
+
json1_format = valid_json?(json1)
|
|
22
|
+
json2_format = valid_json?(json2)
|
|
23
|
+
if json1_format && json2_format
|
|
24
|
+
room = RoomInfo.new(json1_format)
|
|
25
|
+
#ap room
|
|
26
|
+
auth_servers = valid_json?(URI::decode(json2_format['server_config']))
|
|
27
|
+
auth_server_ip = auth_servers[0]["ip"]
|
|
28
|
+
auth_server_port = auth_servers[0]["port"]
|
|
29
|
+
client = DanmuClient.new(room,auth_server_ip,auth_server_port)
|
|
30
|
+
client.start
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def filter_for_wireshark json_array
|
|
35
|
+
ap json_array
|
|
36
|
+
str = ""
|
|
37
|
+
for i in 0...json_array.length
|
|
38
|
+
str += 'tcp.port==' + json_array[i]["port"] + '||'
|
|
39
|
+
end
|
|
40
|
+
puts str[0..-3]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def valid_json?(json)
|
|
45
|
+
JSON.parse(json)
|
|
46
|
+
rescue
|
|
47
|
+
false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def init_config()
|
|
51
|
+
# 初始化Log
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'logger'
|
|
3
|
+
|
|
4
|
+
module Logging
|
|
5
|
+
class << self
|
|
6
|
+
def logger
|
|
7
|
+
@logger ||= Logger.new($stdout)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def logger=(logger)
|
|
11
|
+
@logger = logger
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Addition
|
|
16
|
+
def self.included(base)
|
|
17
|
+
class << base
|
|
18
|
+
def logger
|
|
19
|
+
Logging.logger
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def logger
|
|
25
|
+
Logging.logger
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
class Message
|
|
3
|
+
# 向斗鱼发送的消息
|
|
4
|
+
# 1.通信协议长度,后四个部分的长度,四个字节
|
|
5
|
+
# 2.第二部分与第一部分一样
|
|
6
|
+
# 3.请求代码,发送给斗鱼的话,内容为0xb1,0x02, 斗鱼返回的代码为0xb2,0x02
|
|
7
|
+
# 4.发送内容
|
|
8
|
+
# 5.末尾字节
|
|
9
|
+
def initialize(content)
|
|
10
|
+
@length = [content.size + 9, 0x00, 0x00, 0x00].pack('c*')
|
|
11
|
+
@code = @length.dup
|
|
12
|
+
@magic = [0xb1, 0x02, 0x00, 0x00].pack('c*')
|
|
13
|
+
@content = content
|
|
14
|
+
@end = [0x00].pack('c*')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_s
|
|
18
|
+
@length + @code + @magic + @content + @end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def self.parse_content(message_all)
|
|
23
|
+
message_all[10, -2].unpack('c*')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
#m = Message.new("type@=chatmessage/rescode@=0/sender@=33528585/content@=......6666/snick@=CindyB/cd@=5/maxl@=20/chatmsgid@=9543d4703ae0432d65e9060000000000/col@=0/ct@=2/gid@=7/rid@=15780/sui@=id@A=33528585@Snick@A=CindyB@Srg@A=1@Spg@A=1@Sstrength@A=0@Sver@A=20150331@Sm_deserve_lev@A=0@Scq_cnt@A=0@Sbest_dlev@A=0@Slevel@A=1@Sgt@A=0@S/")
|
|
29
|
+
#p m.to_s
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
class RoomInfo
|
|
4
|
+
attr_accessor :room_id, :room_name, :room_gg_show, :owner_name, :owner_uid, :room_tags
|
|
5
|
+
|
|
6
|
+
def initialize(json)
|
|
7
|
+
#@json = json
|
|
8
|
+
@room_id = json["room_id"]
|
|
9
|
+
@room_name = json["room_name"]
|
|
10
|
+
@room_gg_show = Nokogiri::HTML(json["room_gg"]["show"]).text
|
|
11
|
+
@room_gg_status = json["room_gg"]["status"]
|
|
12
|
+
@room_gg_pass = json["room_gg"]["pass"]
|
|
13
|
+
@room_pic = json["room_id"]
|
|
14
|
+
@owner_uid = json["owner_uid"]
|
|
15
|
+
@owner_name = json["owner_name"]
|
|
16
|
+
@room_url = json["room_url"]
|
|
17
|
+
@show_id = json["show_id"]
|
|
18
|
+
@room_pwd = json["room_pwd"]
|
|
19
|
+
@cate_id = json["cate_id"]
|
|
20
|
+
@near_show_time = json["near_show_time"]
|
|
21
|
+
@room_tags = []
|
|
22
|
+
room_tags_json = json["all_tag_list"]
|
|
23
|
+
room_tags_size = json["room_tag_list"].size
|
|
24
|
+
for i in 0...(room_tags_size)
|
|
25
|
+
@room_tags << room_tags_json[json["room_tag_list"][i]]["name"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: danmu
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- twocucao
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.11'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.11'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: thor
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.19.1
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.19.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: nokogiri
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.6'
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: 1.6.7.2
|
|
79
|
+
type: :runtime
|
|
80
|
+
prerelease: false
|
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - "~>"
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '1.6'
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 1.6.7.2
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: awesome_print
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '1.6'
|
|
96
|
+
- - ">="
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: 1.6.1
|
|
99
|
+
type: :runtime
|
|
100
|
+
prerelease: false
|
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - "~>"
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '1.6'
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: 1.6.1
|
|
109
|
+
description: 斗鱼弹幕助手
|
|
110
|
+
email:
|
|
111
|
+
- twocucao@gmail.com
|
|
112
|
+
executables: []
|
|
113
|
+
extensions: []
|
|
114
|
+
extra_rdoc_files: []
|
|
115
|
+
files:
|
|
116
|
+
- ".DS_Store"
|
|
117
|
+
- ".gitignore"
|
|
118
|
+
- ".idea/.name"
|
|
119
|
+
- ".idea/.rakeTasks"
|
|
120
|
+
- ".idea/danmu.iml"
|
|
121
|
+
- ".idea/encodings.xml"
|
|
122
|
+
- ".idea/misc.xml"
|
|
123
|
+
- ".idea/modules.xml"
|
|
124
|
+
- ".idea/vcs.xml"
|
|
125
|
+
- ".idea/workspace.xml"
|
|
126
|
+
- ".rspec"
|
|
127
|
+
- ".travis.yml"
|
|
128
|
+
- CODE_OF_CONDUCT.md
|
|
129
|
+
- Gemfile
|
|
130
|
+
- LICENSE.txt
|
|
131
|
+
- README.md
|
|
132
|
+
- Rakefile
|
|
133
|
+
- bin/.DS_Store
|
|
134
|
+
- bin/console
|
|
135
|
+
- bin/danmu
|
|
136
|
+
- bin/setup
|
|
137
|
+
- danmu.gemspec
|
|
138
|
+
- lib/.DS_Store
|
|
139
|
+
- lib/danmu.rb
|
|
140
|
+
- lib/danmu/.DS_Store
|
|
141
|
+
- lib/danmu/cli.rb
|
|
142
|
+
- lib/danmu/clients/danmu_client.rb
|
|
143
|
+
- lib/danmu/douyu_client.rb
|
|
144
|
+
- lib/danmu/misc/.DS_Store
|
|
145
|
+
- lib/danmu/misc/logging.rb
|
|
146
|
+
- lib/danmu/models/message.rb
|
|
147
|
+
- lib/danmu/models/room_info.rb
|
|
148
|
+
- lib/danmu/version.rb
|
|
149
|
+
homepage: https://github.com/twocucao/danmu
|
|
150
|
+
licenses:
|
|
151
|
+
- MIT
|
|
152
|
+
metadata:
|
|
153
|
+
allowed_push_host: https://rubygems.org
|
|
154
|
+
post_install_message:
|
|
155
|
+
rdoc_options: []
|
|
156
|
+
require_paths:
|
|
157
|
+
- lib
|
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
|
+
requirements:
|
|
160
|
+
- - ">="
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: '0'
|
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
|
+
requirements:
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: '0'
|
|
168
|
+
requirements: []
|
|
169
|
+
rubyforge_project:
|
|
170
|
+
rubygems_version: 2.5.1
|
|
171
|
+
signing_key:
|
|
172
|
+
specification_version: 4
|
|
173
|
+
summary: 斗鱼弹幕助手,终端下读取斗鱼的弹幕
|
|
174
|
+
test_files: []
|