video_url_parser 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 105c02a9f7993ca8dcd5f42adc892b265f9a9687
4
+ data.tar.gz: ee1cdce999596a2ec00a084ef1a4f697e89d85a8
5
+ SHA512:
6
+ metadata.gz: d279fc5e8791d8ea0c3e8b9284bcd3853710f3c885ce07e6170c0a8c22e3cccd8eeaeb94458790838fbcf4e2ae40711418076ebe1469e3bee4bbd4e0867cd162
7
+ data.tar.gz: 18f377c0f732246a22b63c6c8ab262dd16e0cd4489dad136c7cb4478a85038e04ed39523ad4a180ff69a7aedef7e0f572507f01b683c3b9539011035e35650a7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+
4
+ - 1.9.3-p551
5
+ - 2.0.0-p598
6
+ - 2.1.5
7
+ - 2.2.2
8
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in video_url_parser.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ guard :minitest do
2
+ # with Minitest::Unit
3
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
4
+ watch(%r{^lib/([^/]+)\.rb$}) { |m| "test/lib/test_#{m[1]}.rb" }
5
+ watch(%r{^lib/(.*/)([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
6
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
7
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Mike Kenyon
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,56 @@
1
+ # VideoURLParser
2
+
3
+ Parse out information from a web video URL. Want information about a YouTube or
4
+ Facebook video?
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'video_url_parser'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install video_url_parser
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ VideoURLParser.parse('http://youtube.com/watch?v=5Qg6G7I4RS4#t=2m32s
26
+ # => { id: '5Qg6G7I4RS4', provider: :youtube }
27
+
28
+ VideoURLParser.parse('https://www.facebook.com/McLaren.Racing/videos/vb.12254981412/10153309389781413')
29
+ # => { id: '10153309389781413', provider: :facebook }
30
+
31
+ VideoURLParser.parse('https://example.com')
32
+ # => nil
33
+ ```
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
38
+ `rake` to run the tests. You can also run `bin/console` for an
39
+ interactive prompt that will allow you to experiment.
40
+
41
+ ## Contributing
42
+
43
+ If you have a false negative, [I would love to hear
44
+ it](https://github.com/mkenyon/video_url_parser/issues/new).
45
+ If you would like support for other video providers,
46
+ please ask as well.
47
+
48
+ Bug reports and pull requests are welcome on GitHub at
49
+ https://github.com/mkenyon/video_url_parser.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT
55
+ License](http://opensource.org/licenses/MIT).
56
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push 'test'
6
+ t.pattern = 'test/**/*test_*.rb'
7
+ end
8
+
9
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'video_url_parser'
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ module VideoURLParser
2
+ module Providers
3
+ module Facebook
4
+ def self.supported?(url)
5
+ domains = ['facebook']
6
+ domains.any? do |domain|
7
+ regex = %r{^
8
+ (?:
9
+ (?:https?:)? # allow optional http: or https: scheme
10
+ //)? # We can assume a scheme if none is provided.
11
+ (?:(?:[\w.])+\.)? # can have any number of subdomains
12
+ #{domain} # must use the domain
13
+ \.(?:[\w.])+ # and some TLD, sub-TLD
14
+ }ix
15
+
16
+ url.match(regex)
17
+ end
18
+ end
19
+
20
+ def self.parse(url)
21
+ match = url.match(%r{
22
+ /videos/ # every URL starts with /videos/
23
+ (?:vb\.\d{11,}/)? # Pages' videos start with vb. and their account id number
24
+ (?<id>\d{16,}) # The video id!
25
+ }ix)
26
+ match = match || url.match(%r{
27
+ video\.php\? # Videos served by this php file
28
+ .* # other parameters
29
+ &?v= # the v parameter is the one we want
30
+ (?<id>\d{16,}) # The video id!
31
+
32
+ }ix)
33
+ return nil unless match
34
+
35
+ {
36
+ id: match[:id],
37
+ provider: :facebook
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,31 @@
1
+ module VideoURLParser
2
+ module Providers
3
+ module YouTube
4
+ def self.supported?(url)
5
+ domains = ['youtube', 'youtu']
6
+ domains.any? do |domain|
7
+ regex = %r{^
8
+ (?:
9
+ (?:https?:)? # allow optional http: or https: scheme
10
+ //)? # We can assume a scheme if none is provided.
11
+ (?:(?:[\w.])+\.)? # can have any number of subdomains
12
+ #{domain} # must use the domain
13
+ \.(?:[\w.])+ # and some TLD, sub-TLD
14
+ }ix
15
+
16
+ url.match(regex)
17
+ end
18
+ end
19
+
20
+ def self.parse(url)
21
+ match = url.match(/(?:(?:v|embed|be)\/|v=)(?<id>[\w\-]{11})/)
22
+ return nil unless match
23
+
24
+ {
25
+ id: match[:id],
26
+ provider: :youtube
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module VideoURLParser
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'video_url_parser/version'
2
+
3
+ require 'video_url_parser/providers/facebook'
4
+ require 'video_url_parser/providers/youtube'
5
+
6
+ module VideoURLParser
7
+ PROVIDERS = [
8
+ VideoURLParser::Providers::YouTube,
9
+ VideoURLParser::Providers::Facebook
10
+ ].freeze
11
+
12
+ def self.parse(url)
13
+ PROVIDERS.each do |provider|
14
+ return provider.parse(url) if provider.supported?(url)
15
+ end
16
+
17
+ nil
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'video_url_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'video_url_parser'
8
+ spec.version = VideoURLParser::VERSION
9
+ spec.authors = ['Mike Kenyon']
10
+ spec.email = ['mike.kenyon@gmail.com']
11
+
12
+ spec.summary = 'Parse URLs from YouTube videos or Facebook videos'
13
+ spec.description = 'Need to dynamically embed videos from YouTube or Facebook? Extract the video ID easily'
14
+ spec.homepage = 'https://github.com/mkenyon/video_url_parser'
15
+ spec.license = 'MIT'
16
+
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
+ else
20
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+ spec.required_ruby_version = '>= 1.9.3'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.10'
30
+ spec.add_development_dependency 'guard', '~> 2.12'
31
+ spec.add_development_dependency 'guard-minitest', '~> 2.4'
32
+ spec.add_development_dependency 'minitest', '~> 5.7'
33
+ spec.add_development_dependency 'minitest-reporters', '~> 1.0'
34
+ spec.add_development_dependency 'pry', '~> 0.10'
35
+ spec.add_development_dependency 'pry-byebug', '~> 3.1'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: video_url_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Kenyon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-04 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ description: Need to dynamically embed videos from YouTube or Facebook? Extract the
126
+ video ID easily
127
+ email:
128
+ - mike.kenyon@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/video_url_parser.rb
144
+ - lib/video_url_parser/providers/facebook.rb
145
+ - lib/video_url_parser/providers/youtube.rb
146
+ - lib/video_url_parser/version.rb
147
+ - video_url_parser.gemspec
148
+ homepage: https://github.com/mkenyon/video_url_parser
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ allowed_push_host: https://rubygems.org
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 1.9.3
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Parse URLs from YouTube videos or Facebook videos
173
+ test_files: []