Class: DouyuClient
- Inherits:
-
Object
- Object
- DouyuClient
- Defined in:
- lib/danmu/douyu_client.rb
Constant Summary collapse
- DOUYU_PREFIX =
"http://www.douyutv.com/"
Instance Method Summary collapse
- #filter_for_wireshark(json_array) ⇒ Object
- #init_config ⇒ Object
-
#initialize(url) ⇒ DouyuClient
constructor
A new instance of DouyuClient.
- #valid_json?(json) ⇒ Boolean
Constructor Details
#initialize(url) ⇒ DouyuClient
Returns a new instance of DouyuClient.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/danmu/douyu_client.rb', line 12 def initialize(url) init_config if url.include? DOUYU_PREFIX else url = DOUYU_PREFIX + url end room_html = open(url).read json1 = room_html[/var\s\$ROOM\s=\s({.*})/,1] json2 = room_html[/var\sroom_args\s=\s({.*})/,1] json1_format = valid_json?(json1) json2_format = valid_json?(json2) if json1_format && json2_format room = RoomInfo.new(json1_format) #ap room auth_servers = valid_json?(URI::decode(json2_format['server_config'])) auth_server_ip = auth_servers[0]["ip"] auth_server_port = auth_servers[0]["port"] client = DanmuClient.new(room,auth_server_ip,auth_server_port) client.start end end |
Instance Method Details
#filter_for_wireshark(json_array) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/danmu/douyu_client.rb', line 34 def filter_for_wireshark json_array ap json_array str = "" for i in 0...json_array.length str += 'tcp.port==' + json_array[i]["port"] + '||' end puts str[0..-3] end |
#init_config ⇒ Object
50 51 52 |
# File 'lib/danmu/douyu_client.rb', line 50 def init_config() # 初始化Log end |
#valid_json?(json) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/danmu/douyu_client.rb', line 44 def valid_json?(json) JSON.parse(json) rescue false end |