nicoalert 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/nicoalert.rb +6 -0
- data/lib/nicoalert/client.rb +73 -0
- data/lib/nicoalert/community.rb +15 -0
- data/lib/nicoalert/live.rb +53 -0
- data/lib/nicoalert/version.rb +3 -0
- data/nicoalert.gemspec +22 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/nicoalert.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'socket'
|
6
|
+
|
7
|
+
module Nicoalert
|
8
|
+
class Client
|
9
|
+
attr_reader :mail
|
10
|
+
|
11
|
+
def initialize(mail, password)
|
12
|
+
@mail = mail
|
13
|
+
@password = password
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_id
|
17
|
+
@user_id ||= status.css('user_id').text
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_hash
|
21
|
+
@user_hash ||= status.css('user_hash').text
|
22
|
+
end
|
23
|
+
|
24
|
+
def addr
|
25
|
+
@addr ||= status.css('ms addr').text
|
26
|
+
end
|
27
|
+
|
28
|
+
def port
|
29
|
+
@port ||= status.css('ms port').text
|
30
|
+
end
|
31
|
+
|
32
|
+
def thread
|
33
|
+
@thread ||= status.css('ms thread').text
|
34
|
+
end
|
35
|
+
|
36
|
+
def communities
|
37
|
+
@communities ||= status.css('communities community_id').map(&:text)
|
38
|
+
end
|
39
|
+
|
40
|
+
def connect(&block)
|
41
|
+
TCPSocket.open(addr, port) do |socket|
|
42
|
+
socket <<
|
43
|
+
%{<thread thread="#{thread}" version="20061206" res_from="-1" />\0}
|
44
|
+
while line = socket.gets("\0")
|
45
|
+
item = Nokogiri::XML.fragment(line.sub("\0", ''))
|
46
|
+
next unless chat = item.css('chat')
|
47
|
+
id, community, user = chat.text.split(',')
|
48
|
+
next unless id && community && user
|
49
|
+
block.call Live.new(id, community)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def ticket
|
57
|
+
unless @ticket
|
58
|
+
login = Nokogiri::XML(
|
59
|
+
RestClient.post(LOGIN_URI, mail: @mail, password: @password))
|
60
|
+
@ticket = login.css('ticket').text
|
61
|
+
end
|
62
|
+
@ticket
|
63
|
+
end
|
64
|
+
|
65
|
+
def status
|
66
|
+
@status ||= Nokogiri::XML(
|
67
|
+
RestClient.get(STATUS_URI, params: { ticket: ticket }))
|
68
|
+
end
|
69
|
+
|
70
|
+
LOGIN_URI = 'https://secure.nicovideo.jp/secure/login?site=nicolive_antenna'
|
71
|
+
STATUS_URI = 'http://live.nicovideo.jp/api/getalertstatus'
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'rest-client'
|
5
|
+
|
6
|
+
module Nicoalert
|
7
|
+
class Live
|
8
|
+
attr_reader :id, :community_id
|
9
|
+
|
10
|
+
def initialize(id, community_id)
|
11
|
+
@id = id
|
12
|
+
@community_id = community_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def title
|
16
|
+
@title ||= info.css('streaminfo title').text
|
17
|
+
end
|
18
|
+
|
19
|
+
def description
|
20
|
+
@description ||= info.css('streaminfo description').text
|
21
|
+
end
|
22
|
+
|
23
|
+
def provider_type
|
24
|
+
@provider_type ||= info.css('streaminfo provider_type').text.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def uri
|
28
|
+
@uri ||= "#{LIVE_URI}#@id"
|
29
|
+
end
|
30
|
+
|
31
|
+
def community_name
|
32
|
+
@name ||= info.css('communityinfo name').text
|
33
|
+
end
|
34
|
+
|
35
|
+
def community_thumbnail
|
36
|
+
@thumbnail ||= URI.parse(info.css('communityinfo thumbnail').text)
|
37
|
+
end
|
38
|
+
|
39
|
+
def community
|
40
|
+
@community ||= Community.new(community_id, community_name, community_thumbnail)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def info
|
46
|
+
@info ||= Nokogiri::XML(RestClient.get("#{INFO_URI}#@id"))
|
47
|
+
end
|
48
|
+
|
49
|
+
INFO_URI = 'http://live.nicovideo.jp/api/getstreaminfo/lv'
|
50
|
+
LIVE_URI = 'http://live.nicovideo.jp/watch/lv'
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/nicoalert.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "nicoalert/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nicoalert"
|
7
|
+
s.version = Nicoalert::VERSION
|
8
|
+
s.authors = ["mono"]
|
9
|
+
s.email = ["mono@monoweb.info"]
|
10
|
+
s.homepage = "http://monoweb.info/"
|
11
|
+
s.summary = %q{A Ruby wrapper of Niconama Alert API}
|
12
|
+
|
13
|
+
s.rubyforge_project = "nicoalert"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency "rest-client"
|
21
|
+
s.add_runtime_dependency "nokogiri"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nicoalert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mono
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &70125299309740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70125299309740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: nokogiri
|
27
|
+
requirement: &70125299309260 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70125299309260
|
36
|
+
description:
|
37
|
+
email:
|
38
|
+
- mono@monoweb.info
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Rakefile
|
46
|
+
- lib/nicoalert.rb
|
47
|
+
- lib/nicoalert/client.rb
|
48
|
+
- lib/nicoalert/community.rb
|
49
|
+
- lib/nicoalert/live.rb
|
50
|
+
- lib/nicoalert/version.rb
|
51
|
+
- nicoalert.gemspec
|
52
|
+
homepage: http://monoweb.info/
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: nicoalert
|
72
|
+
rubygems_version: 1.8.15
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A Ruby wrapper of Niconama Alert API
|
76
|
+
test_files: []
|