class DouyuClient

Constants

DOUYU_PREFIX

Public Class Methods

new(url) click to toggle source
# File lib/danmu/douyu_client.rb, line 11
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

Public Instance Methods

filter_for_wireshark(json_array) click to toggle source
# File lib/danmu/douyu_client.rb, line 33
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() click to toggle source
# File lib/danmu/douyu_client.rb, line 49
def init_config()
  # 初始化Log
end
valid_json?(json) click to toggle source
# File lib/danmu/douyu_client.rb, line 43
def valid_json?(json)
  JSON.parse(json)
rescue
  false
end