comment_move 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 +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/comment_move.gemspec +26 -0
- data/exe/comment_move +25 -0
- data/lib/comment_move.rb +81 -0
- data/lib/comment_move/get_playerstatus.rb +17 -0
- data/lib/comment_move/get_waybackkey.rb +10 -0
- data/lib/comment_move/login.rb +25 -0
- data/lib/comment_move/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea7789d236b7f3a6a60413aebfa70b64988631fc
|
4
|
+
data.tar.gz: 63be3834278b9b185596bef6bf2b4cb2b83c935e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d141ba9a6fb92432b26887cdf7d888f0cd77a3a89eb7ab3bd8f3df2a9778503db2b04df4c06f78701344997c6d6ba05ce80970d08530ffea6f1b880e42e643d
|
7
|
+
data.tar.gz: c00f0eeead4ec0dbc68737d40877f02138d878aab08eb7908e87b986f57b7d362aea9617f4781f6ed3afd8b288c0ca510ea50db9dfc4d38c95ac2e9dba7792c3
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Masaya Takeda
|
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,16 @@
|
|
1
|
+
# CommentMove
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'comment_move'
|
7
|
+
|
8
|
+
lv = NicovideoLiveBrodcast.new.tap do |niconico|
|
9
|
+
niconico.username = 'hogefuga@844196.com'
|
10
|
+
niconico.password = 'password'
|
11
|
+
niconico.create_usersission
|
12
|
+
end
|
13
|
+
|
14
|
+
comment = lv.get_comment 'lv844196'
|
15
|
+
# => [{:no=>1, :date=>2015-09-28 00:22:02 +0900, :user_id=>"507820", :premium=>true, :type=>"user", :anonymity=>false, :comment=>"540円払ってよくこんな放送できるな"}, ...
|
16
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "comment_move"
|
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/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'comment_move/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "comment_move"
|
8
|
+
spec.version = CommentMove::VERSION
|
9
|
+
spec.authors = ["Masaya Takeda"]
|
10
|
+
spec.email = ["844196@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ニコ生過去分のコメントを取得するやつ}
|
13
|
+
spec.description = %q{ニコ生から過去放送分のコメントを取得してきます。ライブラリと簡単なCLIツールを入れておきます。}
|
14
|
+
spec.homepage = "https://github.com/844196"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency 'nokogiri'
|
26
|
+
end
|
data/exe/comment_move
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'comment_move'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
OptionParser.new do |opt|
|
7
|
+
opt.banner = "Usage:\n comment_move <mailaddress> <password> <lv>"
|
8
|
+
opt.version = CommentMove::VERSION
|
9
|
+
opt.parse!(ARGV)
|
10
|
+
end
|
11
|
+
|
12
|
+
exit 1 unless ARGV.size == 3
|
13
|
+
|
14
|
+
lv = NicovideoLiveBrodcast.new.tap do |niconico|
|
15
|
+
niconico.username = ARGV[0]
|
16
|
+
niconico.password = ARGV[1]
|
17
|
+
niconico.create_usersission
|
18
|
+
end
|
19
|
+
|
20
|
+
comment = lv.get_comment ARGV[2]
|
21
|
+
|
22
|
+
puts %w(No Date Type isPremium? is184? UserId Comment).join("\t")
|
23
|
+
comment.each do |ele|
|
24
|
+
puts [ele[:no], ele[:date], ele[:type], ele[:premium], ele[:anonymity], ele[:user_id], ele[:comment]].join("\t")
|
25
|
+
end
|
data/lib/comment_move.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "comment_move/version"
|
2
|
+
require "comment_move/login.rb"
|
3
|
+
require "comment_move/get_playerstatus.rb"
|
4
|
+
require "comment_move/get_waybackkey.rb"
|
5
|
+
require "time"
|
6
|
+
|
7
|
+
class NicovideoAccount
|
8
|
+
include CommentMove
|
9
|
+
attr_accessor :username, :password, :user_session
|
10
|
+
|
11
|
+
def create_usersission
|
12
|
+
@user_session = login(@username, @password)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class NicovideoLiveBrodcast < NicovideoAccount
|
17
|
+
def get_comment(lv)
|
18
|
+
lv = lv
|
19
|
+
playerstatus = get_playerstatus(lv, @user_session)
|
20
|
+
waybackkey = get_waybackkey(playerstatus[:thread], @user_session)
|
21
|
+
|
22
|
+
data = {
|
23
|
+
thread: playerstatus[:thread],
|
24
|
+
version: 20061206,
|
25
|
+
res_from: -1000,
|
26
|
+
waybackkey: waybackkey,
|
27
|
+
user_id: playerstatus[:user]
|
28
|
+
}
|
29
|
+
|
30
|
+
comments = []
|
31
|
+
TCPSocket.open(playerstatus[:addr], playerstatus[:port]) do |socket|
|
32
|
+
req = "<thread #{data.map {|k,v| "#{k}=\"#{v}\"" }.join(' ')}/>\0"
|
33
|
+
socket.write(req)
|
34
|
+
|
35
|
+
loop do
|
36
|
+
stream = socket.gets("\0")
|
37
|
+
xml = Nokogiri::XML(stream)
|
38
|
+
|
39
|
+
next if xml.xpath('//chat').empty?
|
40
|
+
break if xml.text == '/disconnect' && xml.xpath('/chat').attr('premium').text == '2'
|
41
|
+
|
42
|
+
h = xml.xpath('/chat').first.attributes.map{|k,v| [k.to_sym,v.text] }.to_h
|
43
|
+
h.delete_if {|k,_| [:thread, :vpos, :date_usec, :locale, :name, :mail].include?(k) }
|
44
|
+
|
45
|
+
h[:type] ||= nil
|
46
|
+
h[:premium] ||= 0
|
47
|
+
h[:anonymity] ||= false
|
48
|
+
h[:comment] = xml.text.gsub(/[\r\n]/, '')
|
49
|
+
|
50
|
+
h.each do |k,v|
|
51
|
+
case k
|
52
|
+
when :no
|
53
|
+
h[k] = v.to_i
|
54
|
+
when :anonymity
|
55
|
+
h[k] = true if v == '1'
|
56
|
+
when :date
|
57
|
+
h[k] = Time.at(v.to_i)
|
58
|
+
when :premium
|
59
|
+
case v.to_i
|
60
|
+
when 0
|
61
|
+
h[k] = false
|
62
|
+
h[:type] = 'user'
|
63
|
+
when 1
|
64
|
+
h[k] = true
|
65
|
+
h[:type] = 'user'
|
66
|
+
when 2
|
67
|
+
h[k] = nil
|
68
|
+
h[:type] = 'system'
|
69
|
+
when 3
|
70
|
+
h[k] = nil
|
71
|
+
h[:type] = 'operator'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
comments.push(h)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
comments
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module CommentMove
|
5
|
+
def get_playerstatus(lv, user_session)
|
6
|
+
url = Net::HTTP.new('watch.live.nicovideo.jp')
|
7
|
+
res = url.get("/api/getplayerstatus?v=#{lv}", {'Cookie' => "user_session=#{user_session}"})
|
8
|
+
xml = Nokogiri::XML(res.body)
|
9
|
+
|
10
|
+
{
|
11
|
+
user: xml.xpath('//user/user_id').text,
|
12
|
+
addr: xml.xpath('//ms//addr').text,
|
13
|
+
port: xml.xpath('//ms//port').text.to_i,
|
14
|
+
thread: xml.xpath('//ms//thread').text
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module CommentMove
|
5
|
+
def get_waybackkey(thread, user_session)
|
6
|
+
url = Net::HTTP.new('watch.live.nicovideo.jp')
|
7
|
+
res = url.get("/api/getwaybackkey?thread=#{thread}", {'Cookie' => "user_session=#{user_session}"})
|
8
|
+
res.body[/waybackkey=(.+)/, 1]
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
module CommentMove
|
4
|
+
def login(mail, password)
|
5
|
+
https = Net::HTTP.new('secure.nicovideo.jp', 443)
|
6
|
+
https.use_ssl = true
|
7
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
8
|
+
response = https.start do |https|
|
9
|
+
https.post('/secure/login?site=niconico', "mail=#{mail}&password=#{password}")
|
10
|
+
end
|
11
|
+
|
12
|
+
user_session = nil
|
13
|
+
response.get_fields('set-cookie').each do |cookie|
|
14
|
+
cookie.split('; ').each do |param|
|
15
|
+
pair = param.split('=')
|
16
|
+
if pair[0] == 'user_session'
|
17
|
+
user_session = pair[1] unless pair[1] == 'deleted'
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
break unless user_session.nil?
|
22
|
+
end
|
23
|
+
user_session
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: comment_move
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masaya Takeda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-28 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ニコ生から過去放送分のコメントを取得してきます。ライブラリと簡単なCLIツールを入れておきます。
|
56
|
+
email:
|
57
|
+
- 844196@gmail.com
|
58
|
+
executables:
|
59
|
+
- comment_move
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- comment_move.gemspec
|
72
|
+
- exe/comment_move
|
73
|
+
- lib/comment_move.rb
|
74
|
+
- lib/comment_move/get_playerstatus.rb
|
75
|
+
- lib/comment_move/get_waybackkey.rb
|
76
|
+
- lib/comment_move/login.rb
|
77
|
+
- lib/comment_move/version.rb
|
78
|
+
homepage: https://github.com/844196
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: ニコ生過去分のコメントを取得するやつ
|
102
|
+
test_files: []
|