video_chat_get 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +39 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +67 -17
  5. data/lib/file_operats/file_operat_chatdata.rb +11 -9
  6. data/lib/requests/request.rb +8 -6
  7. data/lib/site_list/mildom_analyze.rb +17 -20
  8. data/lib/site_list/openrec_analyze.rb +20 -47
  9. data/lib/site_list/twitcasting_analyze.rb +112 -0
  10. data/lib/site_list/whowatch_analyze.rb +8 -10
  11. data/lib/site_list/youtubelive_analyze.rb +69 -85
  12. data/lib/video_chat_get.rb +7 -5
  13. data/lib/video_chat_get/version.rb +1 -1
  14. data/vendor/bundle/ruby/2.5.0/bin/htmldiff +1 -1
  15. data/vendor/bundle/ruby/2.5.0/bin/ldiff +1 -1
  16. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/json-2.3.0/gem.build_complete +0 -0
  17. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/json-2.3.0/gem_make.out +13 -0
  18. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/json-2.3.0/json/ext/generator.bundle +0 -0
  19. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/json-2.3.0/json/ext/parser.bundle +0 -0
  20. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/json-2.3.0/mkmf.log +60 -0
  21. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/nokogiri-1.10.9/gem.build_complete +0 -0
  22. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/nokogiri-1.10.9/gem_make.out +21 -21
  23. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/nokogiri-1.10.9/mkmf.log +542 -0
  24. data/vendor/bundle/ruby/2.5.0/extensions/{x86_64-darwin-16 → x86_64-darwin-18}/2.5.0/nokogiri-1.10.9/nokogiri/nokogiri.bundle +0 -0
  25. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/Makefile +16 -15
  26. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/html_document.o +0 -0
  27. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/html_element_description.o +0 -0
  28. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/html_entity_lookup.o +0 -0
  29. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/html_sax_parser_context.o +0 -0
  30. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/html_sax_push_parser.o +0 -0
  31. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/nokogiri.bundle +0 -0
  32. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/nokogiri.o +0 -0
  33. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_attr.o +0 -0
  34. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_attribute_decl.o +0 -0
  35. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_cdata.o +0 -0
  36. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_comment.o +0 -0
  37. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_document.o +0 -0
  38. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_document_fragment.o +0 -0
  39. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_dtd.o +0 -0
  40. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_element_content.o +0 -0
  41. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_element_decl.o +0 -0
  42. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_encoding_handler.o +0 -0
  43. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_entity_decl.o +0 -0
  44. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_entity_reference.o +0 -0
  45. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_io.o +0 -0
  46. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_namespace.o +0 -0
  47. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_node.o +0 -0
  48. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_node_set.o +0 -0
  49. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_processing_instruction.o +0 -0
  50. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_reader.o +0 -0
  51. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_relax_ng.o +0 -0
  52. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_sax_parser.o +0 -0
  53. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_sax_parser_context.o +0 -0
  54. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_sax_push_parser.o +0 -0
  55. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_schema.o +0 -0
  56. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_syntax_error.o +0 -0
  57. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_text.o +0 -0
  58. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xml_xpath_context.o +0 -0
  59. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri/xslt_stylesheet.o +0 -0
  60. data/vendor/bundle/ruby/2.5.0/gems/nokogiri-1.10.9/lib/nokogiri/nokogiri.bundle +0 -0
  61. data/vendor/bundle/ruby/2.5.0/specifications/diff-lcs-1.3.gemspec +2 -2
  62. data/vendor/bundle/ruby/2.5.0/specifications/httpclient-2.8.3.gemspec +2 -2
  63. data/vendor/bundle/ruby/2.5.0/specifications/json-2.3.0.gemspec +0 -0
  64. data/vendor/bundle/ruby/2.5.0/specifications/mini_portile2-2.4.0.gemspec +2 -2
  65. data/vendor/bundle/ruby/2.5.0/specifications/nokogiri-1.10.9.gemspec +2 -2
  66. data/vendor/bundle/ruby/2.5.0/specifications/rake-10.5.0.gemspec +2 -2
  67. data/vendor/bundle/ruby/2.5.0/specifications/rspec-3.9.0.gemspec +2 -2
  68. data/vendor/bundle/ruby/2.5.0/specifications/rspec-core-3.9.2.gemspec +2 -2
  69. data/vendor/bundle/ruby/2.5.0/specifications/rspec-expectations-3.9.2.gemspec +2 -2
  70. data/vendor/bundle/ruby/2.5.0/specifications/rspec-mocks-3.9.1.gemspec +2 -2
  71. data/vendor/bundle/ruby/2.5.0/specifications/rspec-support-3.9.3.gemspec +2 -2
  72. metadata +14 -12
  73. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-16/2.5.0/json-2.3.0/gem_make.out +0 -13
  74. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-16/2.5.0/json-2.3.0/mkmf.log +0 -60
  75. data/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-16/2.5.0/nokogiri-1.10.9/mkmf.log +0 -542
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5face6a3d0ab762647671b20730566d92e5b9fc4b519b13aa7c59f6cab2e8d43
4
- data.tar.gz: 01edaee8d261c536e2b29602f877a59cb10847684cfdb001d54072164f3d51fe
3
+ metadata.gz: e4c548904d898fbcd56d725e6b7a7dd45df9f8d1a6133f279e0e7edb8a679bac
4
+ data.tar.gz: 29a668bf9086627306e46d436e93a4d1391cea3467e34791092f6f2332802c03
5
5
  SHA512:
6
- metadata.gz: 12c16efdabf9b58691c2b2d28574311cdd2823567dfe72e1dfec63709b86c4806277772201531b16761910afc68bb3d618d3ef1892b30f4a23bd58acb18e41a0
7
- data.tar.gz: 5dfabfc662a3f62721c178632f8cfe6ea156d6c3cec0e946b09db285cb8a150177ecde8b0f824722cbd2dd1f9819af3b08b7b6e11ed0c019778fbce686b840d9
6
+ metadata.gz: 2a0123fff8d7773855e61ce3a7ff5aaf4dc94a0b361902ee7c3133ddc5f32897ea2a6092d920f85fffdd67ca129a77860b1a8e07f4232751ab447a4bd53fe6d4
7
+ data.tar.gz: 9b9e4a2071cd9f3674c66982f378d205d38f6dd814280455444cf521f48dd9fa3a401b5c4269ef2883fa617344bd5214404d8f1ef7e629d2e4dc1507c4fff8d3
@@ -0,0 +1,39 @@
1
+ version: 2.1
2
+ executors:
3
+ my-executor:
4
+ docker:
5
+ - image: circleci/ruby:2.5.8-node-browsers
6
+
7
+ jobs:
8
+ test:
9
+ executor: my-executor
10
+ steps:
11
+ - checkout
12
+
13
+ - restore_cache:
14
+ name: cache lord
15
+ key: gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
16
+
17
+ - run:
18
+ name: bundle install
19
+ command: bundle check --path=vendor/bundle || bundle install --path vendor/bundle --clean --jobs 4 --retry 3
20
+
21
+ - save_cache:
22
+ name: save cache
23
+ key: gem-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
24
+ paths:
25
+ - ./vendor/bundle
26
+
27
+ - run:
28
+ name: bundle exec rake spec
29
+ command: bundle exec rake spec
30
+
31
+ workflows:
32
+ version: 2
33
+ test-:
34
+ jobs:
35
+ - test:
36
+ filters:
37
+ branches:
38
+ only:
39
+ - master
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- video_chat_get (0.1.1)
4
+ video_chat_get (0.1.6)
5
5
  httpclient (~> 2.8.3)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
data/README.md CHANGED
@@ -1,8 +1,18 @@
1
1
  # VideoChatGet
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/video_chat_get`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This is a ruby ​​package that gets a list of chats from the broadcasts of video distribution sites.
4
+
5
+ ## Support sites
6
+ |site_name |status |
7
+ |:---|:---:|
8
+ |mildom |◯ |
9
+ |niconico | |
10
+ |openrec |◯ |
11
+ |twitcasting |◯ |
12
+ |twitch | |
13
+ |whowatch |◯ |
14
+ |youtubelive |◯ |
4
15
 
5
- TODO: Delete this and the text above, and describe your gem
6
16
 
7
17
  ## Installation
8
18
 
@@ -28,27 +38,67 @@ use CLI:
28
38
 
29
39
  ### In code
30
40
  ```ruby
31
- obj=Youtubelive_analyze.new(videourl)
32
- chat_list=obj.chat_scrape
41
+ require 'video_chat_get'
42
+
43
+ #mildom
44
+ obj=Mildom_analyze.new(url)
45
+ video_info=obj.videoinfo
46
+ chat_list=obj.chat_scrape()
47
+
48
+ #openrec
49
+ obj=Openrec_analyze.new(url)
50
+ video_info=obj.videoinfo
51
+ chat_list=obj.chat_scrape()
52
+
53
+ #twitcasting
54
+ obj=Twitcasting_analyze.new(url)
55
+ video_info=obj.videoinfo
56
+ chat_list=obj.chat_scrape()
57
+
58
+ #whowatch
59
+ obj=Whowatch_analyze.new(url)
60
+ video_info=obj.videoinfo
61
+ chat_list=obj.chat_scrape()
62
+
63
+ #youtubelive
64
+ obj=Youtubelive_analyze.new(url)
65
+ video_info=obj.videoinfo
66
+ chat_list=obj.chat_scrape()
67
+
68
+ ```
69
+
70
+ ## Document
71
+ Basically use instance method
72
+
73
+ ↓ Example of use
74
+ ```ruby
75
+ obj=Youtubelive_analyze.new(url)
76
+ video_info=obj.videoinfo
77
+ chat_list=obj.chat_scrape()
33
78
  ```
34
79
 
35
- ## Support sites
36
- |site_name |status |
37
- |:---|:---:|
38
- |mildom |◯ |
39
- |niconico | |
40
- |openrec |◯ |
41
- |twitcast | |
42
- |twitch | |
43
- |whowatch |◯ |
44
- |youtubelive |◯ |
80
+ ### instance variable
81
+ @videoinfo
82
+
83
+ ・Returns: hash
84
+    We can acquire broadcast frame information.
45
85
 
86
+ ### instance method
87
+ #chat_scrape(log_flag=true,log_path="./videoid.txt")
88
+
89
+ Parameters:
90
+    ・log_flag:boolean (default=true)
91
+     Whether to write chat list to file, write when true.
46
92
 
47
- ## Development
93
+    ・log_path:string (default="./videoid.txt")
94
+     File path to write chat list.
48
95
 
49
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+ Returns:
97
+    ・chat_list:array
98
+     Chat data list. Chat information is stored as dictionary data,
99
+     and this dictionary data exists for the number of chats.
50
100
 
51
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
101
+     chat_list=[hash,hash,...]
52
102
 
53
103
  ## Contributing
54
104
 
@@ -1,15 +1,17 @@
1
1
 
2
2
  def file_write(data_list,log_flag,log_path)
3
3
 
4
- if log_flag==true then
5
- File.open(log_path,"w") do |file|
6
- data_list.each do |chat|
7
- file.puts chat
8
- end
9
- end
10
- puts "Scraping finished!! , log_flag true , chat log path is (#{log_path}) "
11
- else
4
+ if log_flag==false
12
5
  puts "Scraping finished!! , log_flag false , chat log path is (no_path) "
6
+ return
13
7
  end
14
-
8
+
9
+ File.open(log_path,"w") do |file|
10
+ data_list.each do |chat|
11
+ file.puts chat
12
+ end
13
+ end
14
+ puts "Scraping finished!! , log_flag true , chat log path is (#{log_path}) "
15
+
16
+ return
15
17
  end
@@ -5,16 +5,15 @@ require 'open-uri'
5
5
 
6
6
 
7
7
  def request_json_parse(url)
8
- body_dic={}
9
8
 
10
9
  client=HTTPClient.new()
11
10
  response=client.get(url)
12
11
 
13
12
  if response.status==200
14
- body_dic=JSON.parse(response.body)
13
+ return JSON.parse(response.body),response.status
15
14
  end
16
15
 
17
- return body_dic,response.status
16
+ return nil,response.status
18
17
  end
19
18
 
20
19
 
@@ -22,13 +21,16 @@ def request_json_parse(url)
22
21
 
23
22
  charset=nil
24
23
  status=[]
25
- response=open(url,opt) do |f|
24
+ response=URI.open(url,opt) do |f|
26
25
  charset=f.charset
27
26
  status=f.status
28
27
  f.read
29
28
  end
30
29
 
31
- response_body=Nokogiri::HTML.parse(response,nil,charset)
32
- return response_body,status
30
+ if status[0]=="200"
31
+ return Nokogiri::HTML.parse(response,nil,charset),status
32
+ end
33
+
34
+ return nil,status
33
35
  end
34
36
 
@@ -15,57 +15,54 @@ class Mildom_analyze<Video_analyze
15
15
  @VIDEOINFO_REQEST_URL="https://cloudac.mildom.com/nonolive/videocontent/playback/getPlaybackDetail?v_id="
16
16
  @CHAT_REQEST_URL="https://cloudac.mildom.com/nonolive/videocontent/chat/replay?video_id="
17
17
  @CHAT_REQEST_PARAMETER="&time_offset_ms="
18
- @CHAT_STARTTIME="0"
19
18
 
20
19
  @video_url=url
21
- @video_id=videoid_get!(@video_url)
20
+ @video_id=videoid_get()
22
21
  @videoinfo,@videoinfo_request_status=request_json_parse(@VIDEOINFO_REQEST_URL+@video_id)
23
22
  @chatlog_filepath="./"+@video_id+".txt"
24
23
  end
25
24
 
26
25
 
27
- def videoid_get!(url)
28
- videoid=url.split("=")[1].split("&")[0]
29
- return videoid
26
+ def videoid_get()
27
+ return @video_url.split("/")[5].split("&")[0]
30
28
  end
31
29
 
32
30
 
33
31
  def chat_nextpage_get(time_key)
34
- time_key=time_key.to_s
35
- chat_request_url=@CHAT_REQEST_URL+@video_id+@CHAT_REQEST_PARAMETER+time_key
36
- return chat_request_url
32
+ return @CHAT_REQEST_URL+@video_id+@CHAT_REQEST_PARAMETER+time_key.to_s
37
33
  end
38
34
 
39
35
 
40
36
  def chat_scrape(log_flag=true,log_path=@chatlog_filepath)
41
37
 
42
- next_url=chat_nextpage_get(@CHAT_STARTTIME)
43
- chat_body,chat_status=request_json_parse(next_url)
44
-
45
- time_length=@videoinfo["body"]["playback"]["video_length"]
46
- next_time=0
47
38
  chat_list=[]
48
-
39
+ next_time=0
40
+ time_length=@videoinfo["body"]["playback"]["video_length"]
49
41
 
50
42
  while next_time<=time_length do
51
-
43
+
44
+ chat_body=chat_body_get(next_time)
52
45
  chat_body["body"]["models"][0]["detail"][0..-1].each do |chat|
53
46
  chat_list.push chat
54
47
  end
55
48
 
56
49
  next_time=chat_body["body"]["models"][0]["summary"]["end_offset_ms"]
57
- next_url=chat_nextpage_get(next_time)
58
- chat_body,chat_status=request_json_parse(next_url)
59
50
  progressbar(next_time,time_length)
51
+ sleep(1)
60
52
  end
61
53
 
62
54
  file_write(chat_list,log_flag,log_path)
63
55
  return chat_list
64
56
  end
65
57
 
66
- public :chat_scrape
67
- private :videoid_get!, :chat_nextpage_get
68
58
 
69
- end
59
+ def chat_body_get(next_time)
60
+ next_url=chat_nextpage_get(next_time)
61
+ chat_body,_=request_json_parse(next_url)
62
+ return chat_body
63
+ end
70
64
 
65
+ public :chat_scrape
66
+ private :videoid_get, :chat_nextpage_get, :chat_body_get
71
67
 
68
+ end
@@ -3,36 +3,7 @@ require 'requests/request'
3
3
  require 'progressbars/progressbar'
4
4
  require 'file_operats/file_operat_chatdata'
5
5
 
6
-
7
6
  """
8
- Openrec_analyze
9
-
10
- ・Explanation
11
- get chat data from openrec
12
-
13
- ・use
14
- obj=Openrec_analyze.new(url)
15
- obj.chat_scrape
16
-
17
- ・instance variable
18
- video_id(String):video identifier
19
- videoinfo(Hash):Video information
20
- videoinfo_request_status(Integer):Videoinformation request statuscode
21
-
22
- ・method
23
- private method:
24
- videoid_get!(url)
25
- chat_nextpage_get(time_key)
26
-
27
- public method:
28
- chat_scrape()
29
- chatinfo_request_status()
30
-
31
- ・test
32
- Check if the request statuscode is 200
33
-
34
- videoinfo_request_status==200
35
- chatinfo_request_status==200
36
7
  """
37
8
 
38
9
  class Openrec_analyze<Video_analyze
@@ -46,16 +17,15 @@ class Openrec_analyze<Video_analyze
46
17
  @CHAT_REQEST_PARAMETER2="&is_including_system_message=false"
47
18
 
48
19
  @video_url=url
49
- @video_id=videoid_get!(@video_url)
20
+ @video_id=videoid_get()
50
21
  @videoinfo,@videoinfo_request_status=request_json_parse(@VIDEOINFO_REQEST_URL+@video_id)
51
22
  @chatlog_filepath="./"+@video_id+".txt"
52
23
 
53
24
  end
54
25
 
55
26
 
56
- def videoid_get!(url)
57
- videoid=url.split("/")[4].split("&")[0]
58
- return videoid
27
+ def videoid_get()
28
+ return @video_url.split("/")[4].split("&")[0]
59
29
  end
60
30
 
61
31
 
@@ -66,40 +36,43 @@ class Openrec_analyze<Video_analyze
66
36
  def chat_nextpage_get(time_key)
67
37
  #datatime型→time型→iso8601型
68
38
  time_key=DateTime.parse(time_key).to_time.utc.iso8601
69
- chat_request_url=@VIDEOINFO_REQEST_URL+@video_id+@CHAT_REQEST_PARAMETER1+time_key+@CHAT_REQEST_PARAMETER2
70
-
71
- return chat_request_url
39
+ return @VIDEOINFO_REQEST_URL+@video_id+@CHAT_REQEST_PARAMETER1+time_key+@CHAT_REQEST_PARAMETER2
72
40
  end
73
41
 
74
42
 
75
43
  def chat_scrape(log_flag=true,log_path=@chatlog_filepath)
76
44
 
77
- start_time=@videoinfo["started_at"]
78
- end_time=@videoinfo["ended_at"]
79
- next_url=chat_nextpage_get(start_time)
80
- chat_body,chat_status=request_json_parse(next_url)
81
-
82
45
  chat_list=[]
83
- next_time=""
84
46
  head=0
47
+ next_time=@videoinfo["started_at"]
48
+ chat_body=chat_body_get(next_time)
85
49
 
86
50
  while !(chat_body[head..-1].empty?) do
51
+
87
52
  chat_body[head..-1].each do |chat|
88
53
  chat_list.push chat
89
54
  next_time=chat["posted_at"]
90
55
  end
91
-
56
+
57
+ chat_body=chat_body_get(next_time)
92
58
  head=1
93
- next_url=chat_nextpage_get(next_time)
94
- chat_body,chat_status=request_json_parse(next_url)
95
- progressbar(next_time,end_time)
59
+
60
+ progressbar(next_time,@videoinfo["ended_at"])
61
+ sleep(1)
96
62
  end
97
63
 
98
64
  file_write(chat_list,log_flag,log_path)
99
65
  return chat_list
100
66
  end
101
67
 
68
+
69
+ def chat_body_get(next_time)
70
+ next_url=chat_nextpage_get(next_time)
71
+ chat_body,_=request_json_parse(next_url)
72
+ return chat_body
73
+ end
74
+
102
75
  public :chat_scrape
103
- private :videoid_get!, :chat_nextpage_get
76
+ private :videoid_get, :chat_nextpage_get, :chat_body_get
104
77
 
105
78
  end
@@ -0,0 +1,112 @@
1
+ require 'site_list/video_analyze'
2
+ require 'requests/request'
3
+ require 'progressbars/progressbar'
4
+ require 'file_operats/file_operat_chatdata'
5
+
6
+ class Twitcasting_analyze<Video_analyze
7
+
8
+ attr_reader :video_id, :user_id, :videoinfo, :videoinfo_request_status
9
+
10
+ def initialize(url)
11
+
12
+ @video_url=url
13
+ @video_id=videoid_get()
14
+ @user_id=userid_get()
15
+
16
+ @videoinfo_request_body,@videoinfo_request_status=request_html_parse(@video_url,{})
17
+ @videoinfo=videoinfo_get()
18
+
19
+ @chat_request_url="https://twitcasting.tv/"+@user_id+"/moviecomment/"+@video_id
20
+ @chat_request_body,@chat_request_status=request_html_parse(@chat_request_url,{})
21
+
22
+ @chatlog_filepath="./"+@video_id+".txt"
23
+ end
24
+
25
+
26
+ def videoid_get()
27
+ return @video_url.split("/")[5].split("&")[0]
28
+ end
29
+
30
+
31
+ def userid_get()
32
+ return @video_url.split("/")[3]
33
+ end
34
+
35
+
36
+ def videoinfo_get()
37
+
38
+ videoinfo={}
39
+ videoinfo["user_name"]=@videoinfo_request_body.at_css(".tw-user-nav-name").text.strip
40
+ videoinfo["video_title"]=@videoinfo_request_body.at_css("#movie_title_content").text
41
+ videoinfo["video_time"]=@videoinfo_request_body.at_css(".tw-player-duration-time").text.strip
42
+ videoinfo["video_start_time"]=@videoinfo_request_body.at_css(".tw-player-meta__status_item > time")[:datetime]
43
+
44
+ videoinfo_polymer=@videoinfo_request_body.css(".tw-player-meta__status").css(".tw-player-meta__status_item")
45
+ i=0
46
+ videoinfo_polymer.each do |fact|
47
+ if i==1 then
48
+ videoinfo["total_view"]=fact.text.strip.split(":",2)[1]
49
+ return videoinfo
50
+ end
51
+ i+=1
52
+ end
53
+
54
+ return videoinfo
55
+ end
56
+
57
+
58
+ def chat_page_range()
59
+ size=@chat_request_body.css(".paging").css("a").size()
60
+ range=@chat_request_body.css(".paging").css("a")[size-1].text
61
+ return range.to_i
62
+ end
63
+
64
+
65
+ def chat_date_get(chatinfo_body)
66
+
67
+ chat_list=[]
68
+ chat_fact_dic={}
69
+
70
+ chatinfo_body.css(".tw-comment-history-item").each do |chat|
71
+ chat_fact_dic["comment"]=chat.at_css(".tw-comment-history-item__content__text").text.strip
72
+ chat_fact_dic["user_name"]=chat.at_css(".tw-comment-history-item__details__user-link").text.strip
73
+ chat_fact_dic["time"]=chat.at_css(".tw-comment-history-item__info__date")[:datetime]
74
+ chat_list.push(chat_fact_dic)
75
+ chat_fact_dic={}
76
+ end
77
+
78
+ return chat_list
79
+ end
80
+
81
+
82
+ def chat_scrape(log_flag=true,log_path=@chatlog_filepath)
83
+
84
+ chat_list=[]
85
+ chatinfo_body=@chat_request_body
86
+ page_range=chat_page_range()
87
+ page_count=0
88
+
89
+ while page_count<=page_range do
90
+ begin
91
+ chat_list+=chat_date_get(chatinfo_body)
92
+ page_count+=1
93
+ next_url=@chat_request_url+"-"+"#{page_count}"
94
+ chatinfo_body,_=request_html_parse(next_url,{})
95
+ progressbar(page_count,page_range)
96
+ sleep(1)
97
+
98
+ rescue
99
+ break
100
+ end
101
+
102
+ end
103
+
104
+ chat_list.reverse!
105
+ file_write(chat_list,log_flag,log_path)
106
+ return chat_list
107
+ end
108
+
109
+ public :chat_scrape
110
+ private :videoid_get, :userid_get, :videoinfo_get, :chat_page_range, :chat_date_get
111
+
112
+ end