video_info 1.6.0 → 2.0.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.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/README.md +11 -11
  5. data/Rakefile +1 -1
  6. data/lib/video_info.rb +30 -7
  7. data/lib/video_info/provider.rb +15 -8
  8. data/lib/video_info/providers/vimeo.rb +7 -11
  9. data/lib/video_info/providers/vkontakte.rb +30 -49
  10. data/lib/video_info/providers/youtube.rb +5 -5
  11. data/lib/video_info/version.rb +2 -2
  12. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/date/.yml +14 -14
  13. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/description/.yml +16 -14
  14. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/duration/.yml +17 -15
  15. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/height/.yml +16 -14
  16. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/keywords/.yml +17 -15
  17. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_large/.yml +15 -13
  18. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_medium/.yml +16 -14
  19. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/thumbnail_small/.yml +15 -13
  20. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/title/.yml +16 -14
  21. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/view_count/.yml +17 -15
  22. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/width/.yml +16 -14
  23. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/description/.yml +1024 -1336
  24. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/duration/.yml +1024 -1336
  25. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_code/.yml +1036 -1348
  26. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/embed_url/.yml +1036 -1348
  27. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/height/.yml +1024 -1336
  28. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/keywords/.yml +1098 -0
  29. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/title/.yml +1036 -1348
  30. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/view_count/.yml +1024 -1336
  31. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/width/.yml +1024 -1336
  32. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/date/.yml +14 -13
  33. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/description/.yml +14 -13
  34. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/duration/.yml +14 -13
  35. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/keywords/.yml +14 -13
  36. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_large/.yml +14 -13
  37. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_medium/.yml +14 -13
  38. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/thumbnail_small/.yml +14 -13
  39. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/title/.yml +16 -15
  40. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/view_count/.yml +14 -13
  41. data/spec/lib/video_info/provider_spec.rb +29 -9
  42. data/spec/lib/video_info/providers/vimeo_spec.rb +11 -11
  43. data/spec/lib/video_info/providers/vkontakte_spec.rb +4 -3
  44. data/spec/lib/video_info/providers/youtube_spec.rb +19 -19
  45. data/spec/lib/video_info_spec.rb +23 -23
  46. data/spec/spec_helper.rb +8 -2
  47. data/video_info.gemspec +5 -2
  48. metadata +6 -104
  49. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_code/.yml +0 -69
  50. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/embed_url/.yml +0 -69
  51. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/provider/.yml +0 -69
  52. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/url/.yml +0 -69
  53. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029/video_id/.yml +0 -69
  54. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_iframe_attributes/.yml +0 -69
  55. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_and_url_attributes/.yml +0 -69
  56. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/provider/.yml +0 -69
  57. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_/group/_url/video_id/.yml +0 -69
  58. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/provider/.yml +0 -69
  59. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/with_video_898029_in_text/video_id/.yml +0 -69
  60. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/date/.yml +0 -1410
  61. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/provider/.yml +0 -1410
  62. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/url/.yml +0 -1410
  63. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_id/.yml +0 -1410
  64. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vkontakte/with_video_39576223_108370515/video_owner/.yml +0 -1369
  65. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/.yml +0 -62
  66. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_arbitrary_iframe_attributes/provider/.yml +0 -62
  67. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/.yml +0 -62
  68. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_iframe_attributes/provider/.yml +0 -62
  69. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/provider/.yml +0 -65
  70. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_JM9NgvjjVng_in_youtu_be_url/video_id/.yml +0 -65
  71. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/provider/.yml +0 -66
  72. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/url/.yml +0 -66
  73. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_after_params/video_id/.yml +0 -66
  74. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/provider/.yml +0 -66
  75. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_e_path/video_id/.yml +0 -66
  76. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/provider/.yml +0 -66
  77. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_embed_path/video_id/.yml +0 -66
  78. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/provider/.yml +0 -66
  79. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_path/video_id/.yml +0 -66
  80. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/provider/.yml +0 -66
  81. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/url/.yml +0 -66
  82. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_VeasFckfMHY_in_user_url/video_id/.yml +0 -66
  83. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/provider/.yml +0 -62
  84. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_Xp6CXF-Cesg/video_id/.yml +0 -62
  85. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_code/.yml +0 -62
  86. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/embed_url/.yml +0 -62
  87. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/height/.yml +0 -62
  88. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/provider/.yml +0 -62
  89. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/url/.yml +0 -62
  90. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/video_id/.yml +0 -62
  91. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_mZqGqE0D0n4/width/.yml +0 -62
  92. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/.yml +0 -62
  93. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/provider/.yml +0 -62
  94. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_oQ49W_xKzKA/video_id/.yml +0 -62
  95. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/provider/.yml +0 -62
  96. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/with_video_url_in_text/video_id/.yml +0 -62
  97. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/provider/.yml +0 -65
  98. data/spec/fixtures/vcr_cassettes/VideoInfo_Providers_Youtube/without_http_or_www/video_id/.yml +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5bfff718ac239bdc03fcb92af2455394dd97d05
4
- data.tar.gz: 556d2e23987b37bc175ce9603a0a367aa986fac8
3
+ metadata.gz: 8574cb4c5ee1da037895282d4afeebaf4266f19b
4
+ data.tar.gz: 65a5e6e34b10aecc9ee7e95f6ef2aa873493b7f3
5
5
  SHA512:
6
- metadata.gz: ea918f3867fe980ea5f86e415ab672ddb3e78a6a01f4ddb3ef13121c7f86e08e5ada9d243c4d9e36cdf29ca358b6fc676a544d50b44bb1b5cfa4a77a3e3874b0
7
- data.tar.gz: ef6e684d5c501b35af781265a0ad0f7efdc2ca0e5403652895d02c9e0398c1393820205bd816cffaf83182225c1a079204662c788e072e03f8a631ef47082784
6
+ metadata.gz: 338de9b7de8a9cac837dff5cabd23ad9643d63d50275989dc7e0fb3077b4b79bc4dc9fcc95e1bededd1371ade6bbc5d9aaed6cb570aa3cf0d984a0c43bad1f4d
7
+ data.tar.gz: 91a541df1be27bfe9e2517368bb2255777e9d7cd3f9bcdd02177e8b4f21f42251b031cb192c6b4f047e1790f18c5c16db3e5a33dbcacbcd25f7d48ec1c4d1db6
data/.travis.yml CHANGED
@@ -1,10 +1,7 @@
1
1
  language: ruby
2
2
  bundler_args: --without tool
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.3
6
5
  - 2.0.0
7
- - jruby-18mode
8
6
  - jruby-19mode
9
- - rbx-18mode
10
7
  - rbx-19mode
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in video_info.gemspec
4
4
  gemspec
5
5
 
6
- gem 'coveralls', :require => false
6
+ gem 'coveralls', require: false
7
7
 
8
8
  group :tool do
9
9
  gem 'ruby_gntp'
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/video_info.png)](http://badge.fury.io/rb/video_info) [![Build Status](https://travis-ci.org/thibaudgg/video_info.png?branch=master)](https://travis-ci.org/thibaudgg/video_info) [![Dependency Status](https://gemnasium.com/thibaudgg/video_info.png)](https://gemnasium.com/thibaudgg/video_info) [![Code Climate](https://codeclimate.com/github/thibaudgg/video_info.png)](https://codeclimate.com/github/thibaudgg/video_info) [![Coverage Status](https://coveralls.io/repos/thibaudgg/video_info/badge.png?branch=master)](https://coveralls.io/r/thibaudgg/video_info)
4
4
 
5
- Simple Ruby Gem to get video info from YouTube and Vimeo url.
5
+ Simple Ruby Gem to get video info from YouTube, Vimeo and VK url.
6
6
 
7
- Tested against Ruby 1.8.7, 1.9.3, 2.0.0 and the latest versions of JRuby & Rubinius.
7
+ Tested against Ruby 1.9.3, 2.0.0 and the latest versions of JRuby & Rubinius.
8
8
 
9
9
  Install
10
10
  --------
@@ -17,7 +17,7 @@ Usage
17
17
  -----
18
18
 
19
19
  ``` ruby
20
- video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4")
20
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
21
21
  # video.video_id => "mZqGqE0D0n4"
22
22
  # video.provider => "YouTube"
23
23
  # video.title => "Cherry Bloom - King Of The Knife"
@@ -30,7 +30,7 @@ video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4")
30
30
  # video.embed_url => "http://www.youtube.com/embed/mZqGqE0D0n4"
31
31
  # video.embed_code => "'<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"
32
32
 
33
- video = VideoInfo.get("http://vimeo.com/898029")
33
+ video = VideoInfo.new("http://vimeo.com/898029")
34
34
  # video.video_id => "898029"
35
35
  # video.provider => "Vimeo"
36
36
  # video.title => "Cherry Bloom - King Of The Knife"
@@ -51,16 +51,16 @@ Options
51
51
  -------
52
52
 
53
53
  ``` ruby
54
- video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "User-Agent" => "My YouTube Mashup Robot/1.0")
55
- video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/")
56
- video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/",
54
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "User-Agent" => "My YouTube Mashup Robot/1.0")
55
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/")
56
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", "Referer" => "http://my-youtube-mashup.com/",
57
57
  "User-Agent" => "My YouTube Mashup Robot/1.0")
58
58
  ```
59
59
  You can also use **symbols** instead of strings (any non-word (`/[^a-z]/i`) character would be converted to hyphen).
60
60
 
61
61
  ``` ruby
62
- video = VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", :referer => "http://my-youtube-mashup.com/",
63
- :user_agent => "My YouTube Mashup Robot/1.0")
62
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4", :referer => "http://my-youtube-mashup.com/",
63
+ user_agent: "My YouTube Mashup Robot/1.0")
64
64
  ```
65
65
 
66
66
  User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current VideoInfo version, e.g. **"VideoInfo/0.2.7"**.
@@ -70,10 +70,10 @@ It supports all openURI header fields (options), for more information see: [open
70
70
  You can also include an `iframe_attributes` or `url_attributes` hash to the `embed_code` method to include arbitrary attributes in the iframe embed code or as additional URL params:
71
71
 
72
72
  ``` ruby
73
- VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:iframe_attributes => { :width => 800, :height => 600, "data-key" => "value" })
73
+ VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(iframe_attributes: { width: 800, height: 600, "data-key" => "value" })
74
74
  => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>
75
75
 
76
- 'VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:url_attributes => { :autoplay => 1 })
76
+ 'VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(url_attributes: { autoplay: 1 })
77
77
  => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'
78
78
  ```
79
79
 
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require 'bundler/gem_tasks'
2
2
 
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
- task :default => :spec
5
+ task default: :spec
data/lib/video_info.rb CHANGED
@@ -1,23 +1,46 @@
1
1
  require 'video_info/version'
2
2
  require 'video_info/provider'
3
+ require 'forwardable'
4
+
5
+ class VideoInfo
6
+ class UrlError < StandardError; end
7
+ extend Forwardable
3
8
 
4
- module VideoInfo
5
9
  PROVIDERS = %w[Vimeo Vkontakte Youtube]
6
10
  PROVIDERS.each { |p| require "video_info/providers/#{p.downcase}" }
7
11
 
8
- def self.get(url, options = {})
9
- if provider_const = _providers_const.detect { |p| p.usable?(url) }
10
- provider_const.new(url, options)
11
- end
12
+ def_delegators :@provider, :provider, :video_id, :video_owner, :url, :data
13
+ def_delegators :@provider, :title, :description, :keywords, :view_count
14
+ def_delegators :@provider, :date, :duration, :width, :height
15
+ def_delegators :@provider, :thumbnail_small, :thumbnail_medium, :thumbnail_large
16
+ def_delegators :@provider, :embed_code, :embed_url
17
+
18
+ def initialize(url, options = {})
19
+ @provider = _select_provider(url, options)
20
+ end
21
+
22
+ def self.get(*args)
23
+ new(*args)
12
24
  end
13
25
 
14
26
  def self.usable?(url)
15
- !!_providers_const.detect { |p| p.usable?(url) }
27
+ new(url)
28
+ true
29
+ rescue UrlError
30
+ false
16
31
  end
17
32
 
18
33
  private
19
34
 
20
- def self._providers_const
35
+ def _select_provider(url, options)
36
+ if provider_const = _providers_const.detect { |p| p.usable?(url) }
37
+ provider_const.new(url, options)
38
+ else
39
+ raise UrlError, "Url is not usable by any Providers: #{url}"
40
+ end
41
+ end
42
+
43
+ def _providers_const
21
44
  PROVIDERS.map { |p| Providers.const_get(p) }
22
45
  end
23
46
  end
@@ -1,14 +1,13 @@
1
- require "addressable/uri"
1
+ require 'addressable/uri'
2
2
 
3
- module VideoInfo
3
+ class VideoInfo
4
4
  class Provider
5
- attr_accessor :url, :options, :iframe_attributes, :video_id, :video
5
+ attr_accessor :url, :options, :iframe_attributes, :video_id, :data
6
6
 
7
7
  def initialize(url, options = {})
8
8
  @options = _clean_options(options)
9
9
  @url = url
10
10
  _set_video_id_from_url
11
- _set_info_from_api if _valid_video_id?
12
11
  end
13
12
 
14
13
  def self.usable?(url)
@@ -23,6 +22,10 @@ module VideoInfo
23
22
  "<iframe #{iframe_attrs.reject(&:empty?).join(" ")}></iframe>"
24
23
  end
25
24
 
25
+ def data
26
+ @data ||= _set_data_from_api
27
+ end
28
+
26
29
  private
27
30
 
28
31
  def _clean_options(options)
@@ -36,9 +39,9 @@ module VideoInfo
36
39
  options
37
40
  end
38
41
 
39
- def _set_info_from_api
42
+ def _set_data_from_api
40
43
  uri = open(_api_url, options)
41
- @video = MultiJson.load(uri.read)
44
+ MultiJson.load(uri.read)
42
45
  end
43
46
 
44
47
  def _not_openuri_option_symbol?(key)
@@ -50,7 +53,10 @@ module VideoInfo
50
53
  end
51
54
 
52
55
  def _set_video_id_from_url
53
- url.gsub(_url_regex) { @video_id = $1 || $2 || $3 }
56
+ @url.gsub(_url_regex) { @video_id = $1 || $2 || $3 }
57
+ unless _valid_video_id?
58
+ raise UrlError, "Url is not valid, video_id is not found: #{url}"
59
+ end
54
60
  end
55
61
 
56
62
  def _valid_video_id?
@@ -66,10 +72,11 @@ module VideoInfo
66
72
  end
67
73
 
68
74
  def _embed_url(options)
75
+ url_scheme = options.fetch(:url_scheme, 'http')
69
76
  url_attrs = options.fetch(:url_attributes, {})
70
77
  url_attrs = _default_url_attributes.merge(url_attrs)
71
78
 
72
- url = embed_url
79
+ url = "#{url_scheme}://#{embed_url}"
73
80
  url += "?#{_hash_to_params(url_attrs)}" unless url_attrs.empty?
74
81
  url
75
82
  end
@@ -1,7 +1,7 @@
1
1
  require 'open-uri'
2
2
  require 'multi_json'
3
3
 
4
- module VideoInfo
4
+ class VideoInfo
5
5
  module Providers
6
6
  class Vimeo < Provider
7
7
 
@@ -13,10 +13,6 @@ module VideoInfo
13
13
  'Vimeo'
14
14
  end
15
15
 
16
- def url
17
- video ? video['url'] : @url
18
- end
19
-
20
16
  %w[title description thumbnail_small thumbnail_medium thumbnail_large].each do |method|
21
17
  define_method(method) { video[method] }
22
18
  end
@@ -30,7 +26,7 @@ module VideoInfo
30
26
  end
31
27
 
32
28
  def embed_url
33
- "http://player.vimeo.com/video/#{video_id}"
29
+ "player.vimeo.com/video/#{video_id}"
34
30
  end
35
31
 
36
32
  def date
@@ -42,7 +38,7 @@ module VideoInfo
42
38
  end
43
39
 
44
40
  def video
45
- @video && @video.first
41
+ data && data.first
46
42
  end
47
43
 
48
44
  private
@@ -60,10 +56,10 @@ module VideoInfo
60
56
  end
61
57
 
62
58
  def _default_url_attributes
63
- { :title => 0,
64
- :byline => 0,
65
- :portrait => 0,
66
- :autoplay => 0 }
59
+ { title: 0,
60
+ byline: 0,
61
+ portrait: 0,
62
+ autoplay: 0 }
67
63
  end
68
64
 
69
65
  end
@@ -8,7 +8,7 @@ if RUBY_VERSION.to_i < 2
8
8
  require 'iconv'
9
9
  end
10
10
 
11
- module VideoInfo
11
+ class VideoInfo
12
12
  module Providers
13
13
  class Vkontakte < Provider
14
14
  attr_accessor :video_owner
@@ -21,72 +21,53 @@ module VideoInfo
21
21
  'Vkontakte'
22
22
  end
23
23
 
24
- %w[description keywords].each do |method|
25
- define_method(method) { HTMLEntities.new.decode(video[:description]) }
24
+ def description
25
+ content = data[/<meta name="description" content="(.*)" \/>/,1]
26
+ HTMLEntities.new.decode(content)
26
27
  end
28
+ alias_method :keywords, :description
27
29
 
28
- %w[width height duration view_count].each do |method|
29
- define_method(method) { video[method.to_sym].to_i }
30
- end
31
-
32
- def title
33
- video[:title]
34
- end
35
-
36
- def embed_url
37
- "http://vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{video[:hash]}"
38
- end
39
-
40
- private
41
-
42
- def _parse_hash
43
- @html[/hash2\\":\\"(\w+)/,1]
30
+ def width
31
+ { 240 => 320,
32
+ 360 => 480,
33
+ 480 => 640,
34
+ 720 => 1280
35
+ }[height]
44
36
  end
45
37
 
46
- def _parse_view_count
47
- @html[/mv_num_views\\"><b>(\d+)/,1].to_i
38
+ def height
39
+ data[/url(\d+)/,1].to_i
48
40
  end
49
41
 
50
- def _parse_title
51
- @html[/<title>(.*)<\/title>/,1].gsub(" | ВКонтакте", "")
42
+ def title
43
+ data[/<title>(.*)<\/title>/,1].gsub(" | ВКонтакте", "")
52
44
  end
53
45
 
54
- def _parse_duration
55
- @html[/"duration":(\d+)/,1].to_i
46
+ def view_count
47
+ data[/mv_num_views\\">(\d+)/,1].to_i
56
48
  end
57
49
 
58
- def _parse_height
59
- @html[/url(\d+)/,1].to_i
50
+ def embed_url
51
+ "vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{_data_hash}"
60
52
  end
61
53
 
62
- def _get_width(height)
63
- { 240 => 320,
64
- 360 => 480,
65
- 480 => 640,
66
- 720 => 1280
67
- }[height]
54
+ def duration
55
+ data[/"duration":(\d+)/,1].to_i
68
56
  end
69
57
 
70
- def _parse_description
71
- @html[/<meta name="description" content="(.*)" \/>/,1]
72
- end
58
+ private
73
59
 
74
- def _set_info_from_api
60
+ def _set_data_from_api
75
61
  uri = open(_api_url, options)
76
62
  if RUBY_VERSION.to_i < 2
77
- @html = Iconv.iconv('utf-8', 'cp1251', uri.read)[0]
63
+ Iconv.iconv('utf-8', 'cp1251', uri.read)[0]
78
64
  else
79
- @html = uri.read.encode("UTF-8")
65
+ uri.read.encode("UTF-8")
80
66
  end
81
- @video = {
82
- :hash => _parse_hash,
83
- :view_count => _parse_view_count,
84
- :title => _parse_title,
85
- :duration => _parse_duration,
86
- :width => _get_width(_parse_height),
87
- :height => _parse_height,
88
- :description => _parse_description
89
- }
67
+ end
68
+
69
+ def _data_hash
70
+ data[/hash2\\":\\"(\w+)/,1]
90
71
  end
91
72
 
92
73
  def _set_video_id_from_url
@@ -102,7 +83,7 @@ module VideoInfo
102
83
  end
103
84
 
104
85
  def _default_iframe_attributes
105
- { :allowfullscreen => "allowfullscreen" }
86
+ { allowfullscreen: "allowfullscreen" }
106
87
  end
107
88
 
108
89
  def _default_url_attributes
@@ -1,7 +1,7 @@
1
1
  require 'open-uri'
2
2
  require 'multi_json'
3
3
 
4
- module VideoInfo
4
+ class VideoInfo
5
5
  module Providers
6
6
  class Youtube < Provider
7
7
 
@@ -30,7 +30,7 @@ module VideoInfo
30
30
  end
31
31
 
32
32
  def embed_url
33
- "http://www.youtube.com/embed/#{video_id}"
33
+ "www.youtube.com/embed/#{video_id}"
34
34
  end
35
35
 
36
36
  def date
@@ -64,7 +64,7 @@ module VideoInfo
64
64
  end
65
65
 
66
66
  def _default_iframe_attributes
67
- { :allowfullscreen => "allowfullscreen" }
67
+ { allowfullscreen: "allowfullscreen" }
68
68
  end
69
69
 
70
70
  def _default_url_attributes
@@ -72,11 +72,11 @@ module VideoInfo
72
72
  end
73
73
 
74
74
  def _video_entry
75
- video['entry']
75
+ data['entry']
76
76
  end
77
77
 
78
78
  def _video_media_group
79
- video['entry']['media$group']
79
+ data['entry']['media$group']
80
80
  end
81
81
 
82
82
  def _video_thumbnail(id)
@@ -1,3 +1,3 @@
1
- module VideoInfo
2
- VERSION = '1.6.0'
1
+ class VideoInfo
2
+ VERSION = '2.0.0'
3
3
  end
@@ -8,7 +8,7 @@ http_interactions:
8
8
  string: ''
9
9
  headers:
10
10
  User-Agent:
11
- - VideoInfo/1.5.0
11
+ - VideoInfo/1.6.0
12
12
  Accept-Encoding:
13
13
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
14
  Accept:
@@ -23,15 +23,15 @@ http_interactions:
23
23
  X-Ratelimit-Limit:
24
24
  - '3600'
25
25
  X-Ratelimit-Remaining:
26
- - '3597'
26
+ - '3599'
27
27
  X-Ratelimit-Reset:
28
- - '1381179443'
28
+ - '1382701011'
29
29
  Expires:
30
- - Mon, 07 Oct 2013 19:58:24 GMT
30
+ - Fri, 25 Oct 2013 10:37:52 GMT
31
31
  Last-Modified:
32
- - Thu, 03 Oct 2013 09:04:59 GMT
32
+ - Sun, 20 Oct 2013 01:45:34 GMT
33
33
  Etag:
34
- - '"a1c9549c51ba7682be6cd968cbd7c1fb"'
34
+ - '"c632ac4e6ac3e1fcd30be3046eb936b0"'
35
35
  X-Dns-Prefetch-Control:
36
36
  - 'on'
37
37
  Vary:
@@ -39,15 +39,15 @@ http_interactions:
39
39
  Content-Type:
40
40
  - application/json
41
41
  Content-Length:
42
- - '497'
42
+ - '498'
43
43
  Accept-Ranges:
44
44
  - bytes
45
45
  Date:
46
- - Mon, 07 Oct 2013 19:57:27 GMT
46
+ - Fri, 25 Oct 2013 10:36:53 GMT
47
47
  X-Varnish:
48
- - 636839230 636837831
48
+ - 1698943940 1698943341
49
49
  Age:
50
- - '3'
50
+ - '2'
51
51
  Via:
52
52
  - 1.1 varnish
53
53
  X-Varnish-Cache:
@@ -55,15 +55,15 @@ http_interactions:
55
55
  Connection:
56
56
  - close
57
57
  X-Vserver:
58
- - 10.90.128.196
58
+ - 10.90.128.197
59
59
  body:
60
60
  encoding: UTF-8
61
61
  string: '[{"id":898029,"title":"Cherry Bloom - King Of The Knife","description":"The
62
62
  first video from the upcoming album Secret Sounds, to download in-stores April
63
63
  14. Checkout http:\/\/www.cherrybloom.net","url":"http:\/\/vimeo.com\/898029","upload_date":"2008-04-14
64
64
  13:10:39","thumbnail_small":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_100.jpg","thumbnail_medium":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_200.jpg","thumbnail_large":"http:\/\/b.vimeocdn.com\/ts\/343\/731\/34373130_640.jpg","user_id":206215,"user_name":"Octave
65
- Zangs","user_url":"http:\/\/vimeo.com\/octave","user_portrait_small":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_30.jpg","user_portrait_medium":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_75.jpg","user_portrait_large":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_100.jpg","user_portrait_huge":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_300.jpg","stats_number_of_likes":11,"stats_number_of_plays":4555,"stats_number_of_comments":4,"duration":175,"width":640,"height":360,"tags":"cherry
65
+ Zangs","user_url":"http:\/\/vimeo.com\/octave","user_portrait_small":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_30.jpg","user_portrait_medium":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_75.jpg","user_portrait_large":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_100.jpg","user_portrait_huge":"http:\/\/b.vimeocdn.com\/ps\/257\/715\/2577152_300.jpg","stats_number_of_likes":11,"stats_number_of_plays":4557,"stats_number_of_comments":4,"duration":175,"width":640,"height":360,"tags":"cherry
66
66
  bloom, secret sounds, king of the knife, rock, alternative","embed_privacy":"anywhere"}]'
67
67
  http_version:
68
- recorded_at: Mon, 07 Oct 2013 19:57:27 GMT
69
- recorded_with: VCR 2.5.0
68
+ recorded_at: Fri, 25 Oct 2013 10:36:53 GMT
69
+ recorded_with: VCR 2.6.0