video_preview 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c52fa9b24de02696a60217225231e074a213556f
4
+ data.tar.gz: ba69e0ec008bf976b272f98f3f1966081998599f
5
+ SHA512:
6
+ metadata.gz: ac3e70e9ad658dbc40897ab02f4d9ccffb6b88d8275c7e3fb495425154c634ff294ce4a7bbfd147b4561a7d409ee43fce2d6f2a2d9bbd99c6316e62d9d7c8aa6
7
+ data.tar.gz: 80dff27922989d138df436e5ea20c35508eeb3e2e567658abea07256d62230b8862f10eb71316d376f7f4898b8e66eedc613891bf3a5095077b8331fbe25e9f6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in web_video_preview.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Anton Davydov
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.
@@ -0,0 +1,50 @@
1
+ # VideoPreview
2
+ Simple library for preview video from web services. Supported formats:
3
+ * [Coub](http://coub.com)
4
+ * [Rutube](http://rutube.ru)
5
+ * [Vimeo](http://vimeo.com)
6
+ * [Youtube](http://youtube.com)
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'video_preview'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install video_preview
22
+
23
+ ## Usage
24
+
25
+ Just run in your code:
26
+
27
+ ``` ruby
28
+ VideoPreview.preview_url('http://vimeo.com/85883356')
29
+ # => "https://i.vimeocdn.com/video/463351470_640.jpg"
30
+ ```
31
+
32
+ Also you can set config option `default_image_url` in your initialize file:
33
+
34
+ ``` ruby
35
+ VideoPreview.configure do |config|
36
+ config.default_image_url = 'http://i0.kym-cdn.com/entries/icons/original/000/003/619/Untitled-1.jpg'
37
+ end
38
+ ```
39
+
40
+ By default you will see this picture:
41
+
42
+ ![foreveraloneimg](http://i0.kym-cdn.com/entries/icons/original/000/003/619/Untitled-1.jpg)
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/davydovanton/video_service/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ require 'video_preview/version'
2
+ require 'video_preview/configuration'
3
+ require 'video_preview/base'
4
+ require 'video_preview/video_services/empty'
5
+ require 'video_preview/video_services/coub'
6
+ require 'video_preview/video_services/rutube'
7
+ require 'video_preview/video_services/vimeo'
8
+ require 'video_preview/video_services/youtube'
9
+
10
+
11
+ module VideoPreview
12
+ class << self
13
+ attr_writer :configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def self.url(url)
25
+ VideoPreview::Base.url(url, @configuration)
26
+ end
27
+ end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module VideoPreview
6
+ class Base
7
+ class RequestError < StandardError; end
8
+
9
+ COUB_REGEXP = %r{(https?://)?(www.)?(coub\.com/(view|embed)/(?<id>[A-Za-z0-9]*))(/.+)?}
10
+ RUTUBE_REGEXP = %r{((https?://)?(www.)?rutube\.ru/(play|video)/(embed/)?(?<id>[A-Za-z0-9]*)(/.*)?)}
11
+ VIMEO_REGEXP = %r{(https?://)?(www.|player.)?vimeo\.com/(video/)?(?<id>[A-Za-z0-9._%-]*)((\?|#)\S+)?(/.+)?}
12
+ YOUTUBE_REGEXP = %r{(https?://)?(www.|m.)?(youtube\.com/watch\?v=|youtu\.be/|youtube\.com/watch\?feature=player_embedded&v=|youtube\.com/embed/|youtu\.be/)(?<id>[A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?(/.+)?}
13
+
14
+ attr_accessor :config
15
+
16
+ def self.url(url, config = Configuration.new)
17
+ video_service =
18
+ case url
19
+ when COUB_REGEXP then Coub.new(config, $~[:id])
20
+ when RUTUBE_REGEXP then Rutube.new(config, $~[:id])
21
+ when VIMEO_REGEXP then Vimeo.new(config, $~[:id])
22
+ when YOUTUBE_REGEXP then Youtube.new(config, $~[:id])
23
+ else
24
+ Empty.new(config)
25
+ end
26
+
27
+ video_service.preview_url
28
+ end
29
+
30
+ def initialize(config, id = nil)
31
+ @id = id
32
+ @config = config
33
+ end
34
+
35
+ def request_url
36
+ raise NotImplementedError
37
+ end
38
+
39
+ def request_json
40
+ return {} if request_url.empty?
41
+
42
+ response = Net::HTTP.get_response(URI.parse(request_url))
43
+ case response
44
+ when Net::HTTPSuccess
45
+ JSON.parse response.body
46
+ else
47
+ raise RequestError
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ module VideoPreview
2
+ class Configuration
3
+ attr_accessor :default_image_url
4
+
5
+ def initialize
6
+ @default_image_url = 'http://i0.kym-cdn.com/entries/icons/original/000/003/619/Untitled-1.jpg'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module VideoPreview
2
+ VERSION = '1.0'
3
+ end
@@ -0,0 +1,11 @@
1
+ module VideoPreview
2
+ class Coub < Base
3
+ def request_url
4
+ "http://coub.com/api/v2/coubs/#@id"
5
+ end
6
+
7
+ def preview_url
8
+ request_json['raw_video_thumbnail_url']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module VideoPreview
2
+ class Empty < Base
3
+ def preview_url
4
+ @config.default_image_url
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module VideoPreview
2
+ class Rutube < Base
3
+ def request_url
4
+ "http://rutube.ru/api/oembed/?url=http://rutube.ru/video/#@id/&format=json"
5
+ end
6
+
7
+ def preview_url
8
+ request_json['thumbnail_url']
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module VideoPreview
2
+ class Vimeo < Base
3
+ def request_url
4
+ "https://vimeo.com/api/v2/video/#@id.json"
5
+ end
6
+
7
+ def preview_url
8
+ request_json.first['thumbnail_large'] ||
9
+ request_json.first['thumbnail_medium'] ||
10
+ request_json.first['thumbnail_small']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module VideoPreview
2
+ class Youtube < Base
3
+ def request_url
4
+ "https://www.googleapis.com/youtube/v3/videos?part=0&id=@id"
5
+ end
6
+
7
+ def preview_url
8
+ request_json['data']['thumbnail']['hqDefault'] ||
9
+ request_json['data']['thumbnail']['sqDefault']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'video_preview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "video_preview"
8
+ spec.version = VideoPreview::VERSION
9
+ spec.authors = ["Anton Davydov"]
10
+ spec.email = ["antondavydov.o@gmail.com"]
11
+
12
+ spec.summary = %q{Simple library for preview video from web services (Youtube, Coub, Vimeo, etc).}
13
+ spec.description = %q{Simple library for preview video from web services (Youtube, Coub, Vimeo, etc).}
14
+ spec.homepage = "https://github.com/davydovanton/video_preview"
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.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: video_preview
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Anton Davydov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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
+ description: Simple library for preview video from web services (Youtube, Coub, Vimeo,
42
+ etc).
43
+ email:
44
+ - antondavydov.o@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/video_preview.rb
57
+ - lib/video_preview/base.rb
58
+ - lib/video_preview/configuration.rb
59
+ - lib/video_preview/version.rb
60
+ - lib/video_preview/video_services/coub.rb
61
+ - lib/video_preview/video_services/empty.rb
62
+ - lib/video_preview/video_services/rutube.rb
63
+ - lib/video_preview/video_services/vimeo.rb
64
+ - lib/video_preview/video_services/youtube.rb
65
+ - video_preview.gemspec
66
+ homepage: https://github.com/davydovanton/video_preview
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Simple library for preview video from web services (Youtube, Coub, Vimeo,
90
+ etc).
91
+ test_files: []
92
+ has_rdoc: