niconico 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6c8ec6d8e97f5b09a642ef672cdeeb5abd92ab3
4
- data.tar.gz: c90979d2f36e626d1560cba1e469f01222043931
3
+ metadata.gz: 36a98bd1ac8a923065e75fb31ce853304d878dd6
4
+ data.tar.gz: 6117581998277bd370b01516ab7f4f33c5f07c6c
5
5
  SHA512:
6
- metadata.gz: 55c044ba6cd293d95491271834e994774697df728f897028bf1f924544f382ddc13cb5679833d80761453f6f93baf217a52bb2c5030e884be97da2dd24216993
7
- data.tar.gz: 6f2bdf570c70d805a4b266de5bc2bbe62d84dcf50df3fbe969288657db088e2d4d677150ccd356e26ab90cfd23f8f4b3300379eb3d99f0fbe989c2f6ff78dc2d
6
+ metadata.gz: f597570ac2329a7cd8da0bb401e735aa1242e2da6e35eb4d80d369ada23e1ca1deebe9cc7541afb6b9be4088b62b6aebb006c90251ad4adb910b5d669482ee0d
7
+ data.tar.gz: e8b48d6985978f6f00d3fd3d7965c36661b289824d7346066a16beb34cf1787683e1baaf8f89a4a65a036037365cc424162520e9532b9dd93a4e9ff1067971e8
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,7 @@
1
+ - __You should use English__ for commits, pull request's title, description, and comments basically.
2
+
3
+ - I'll ask you to do translation if you've posted in Japanese.
4
+ - Don't worry for poor English :)
5
+ - 基本英語でコミットコメントを残し、pull request のタイトル、コメントを書いてください。
6
+ - 日本語で書いた場合英語にするようにお願いをしています。
7
+
data/lib/niconico.rb CHANGED
@@ -46,3 +46,4 @@ end
46
46
  require_relative './niconico/video'
47
47
  require_relative './niconico/mylist'
48
48
  require_relative './niconico/ranking'
49
+ require_relative './niconico/channel'
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'json'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+ require_relative './video'
6
+
7
+ class Niconico
8
+ def channel_videos(ch)
9
+ login unless @logined
10
+
11
+ rss = Nokogiri::XML(open("http://ch.nicovideo.jp/#{ch}/video?rss=2.0", &:read))
12
+
13
+ rss.search('channel item').map do |item|
14
+ title = item.at('title').inner_text
15
+ link = item.at('link').inner_text
16
+ Video.new(self, link.sub(/^.+\/watch\//, ''), title: title)
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  class Niconico
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -20,6 +20,7 @@ class Niconico
20
20
  def initialize(parent, video_id, defer=nil)
21
21
  @parent = parent
22
22
  @agent = parent.agent
23
+ @fetched = false
23
24
  @thread_id = @id = video_id
24
25
  @url = "#{Niconico::URL[:watch]}#{@id}"
25
26
 
@@ -35,6 +36,7 @@ class Niconico
35
36
  end
36
37
 
37
38
  def economy?; @eco; end
39
+ def fetched?; @fetched; end
38
40
 
39
41
  def get(options = {})
40
42
  begin
@@ -67,31 +69,41 @@ class Niconico
67
69
  @description ||= d.inner_html unless d.nil?
68
70
 
69
71
  @video_url = getflv[:url]
70
- @eco = !(/low$/ =~ @video_url).nil?
71
- @type = case @video_url.match(/^http:\/\/(.+\.)?nicovideo\.jp\/smile\?(.+?)=.*$/).to_a[2]
72
- when 'm'; :mp4
73
- when 's'; :swf
74
- else; :flv
75
- end
72
+ if @video_url
73
+ @eco = !(/low$/ =~ @video_url).nil?
74
+ @type = case @video_url.match(/^http:\/\/(.+\.)?nicovideo\.jp\/smile\?(.+?)=.*$/).to_a[2]
75
+ when 'm'; :mp4
76
+ when 's'; :swf
77
+ else; :flv
78
+ end
79
+ end
76
80
  @tags ||= @page.search("#video_tags a[rel=tag]").map(&:inner_text)
77
81
  @mylist_comment ||= nil
78
82
 
83
+ @fetched = true
79
84
  @page
80
85
  end
81
86
 
87
+ def available?
88
+ !!video_url
89
+ end
90
+
82
91
  def get_video
83
- @agent.get_file(@video_url)
92
+ raise VideoUnavailableError unless available?
93
+ @agent.get_file(video_url)
84
94
  end
85
95
 
86
96
  def get_video_by_other
97
+ raise VideoUnavailableError unless available?
87
98
  {cookie: @agent.cookie_jar.cookies(URI.parse(@video_url)),
88
- url: @video_url}
99
+ url: video_url}
89
100
  end
90
101
 
91
102
  def inspect
92
- "#<Niconico::Video: #{@id}.#{@type} \"#{@title}\"#{@eco ? " low":""}>"
103
+ "#<Niconico::Video: #{@id}.#{@type} \"#{@title}\"#{@eco ? " low":""}#{(fetched? && !@video_url) ? ' (unavailable)' : ''}#{fetched? ? '' : ' (defered)'}>"
93
104
  end
94
105
 
95
106
  class NotFound < StandardError; end
107
+ class VideoUnavailableError < StandardError; end
96
108
  end
97
109
  end
data/niconico.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = "wrapper of Mechanize, optimized for nicovideo. :)"
13
13
 
14
14
  s.add_dependency "mechanize", '>= 2.7.3'
15
+ s.add_dependency "nokogiri", '>= 1.6.1'
15
16
 
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: niconico
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Fukumori (sora_h)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.7.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.1
27
41
  description: wrapper of Mechanize, optimized for nicovideo. :)
28
42
  email:
29
43
  - her@sorah.jp
@@ -32,10 +46,12 @@ extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
34
48
  - ".gitignore"
49
+ - CONTRIBUTING.md
35
50
  - Gemfile
36
51
  - README.mkd
37
52
  - Rakefile
38
53
  - lib/niconico.rb
54
+ - lib/niconico/channel.rb
39
55
  - lib/niconico/mylist.rb
40
56
  - lib/niconico/ranking.rb
41
57
  - lib/niconico/version.rb