youtube_video_id 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +12 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +8 -0
- data/lib/youtube_video_id.rb +2 -0
- data/lib/youtube_video_id/version.rb +3 -0
- data/lib/youtube_video_id/youtube_video_id_extractor.rb +39 -0
- data/youtube_video_id.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c55981003564f6fefc1d89a1b2b6d89d04470e7e
|
|
4
|
+
data.tar.gz: fb14d32d1afc3be48a5d41180368ca2c1a6fb2e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3251b758b0d1efba3486de5189ca1157a0677cb4dea68d9746ffe8436380a89f64790d5e3b9afb7206d0f5c328b7adae20176ff53ad9cd3b04606e98f80d1896
|
|
7
|
+
data.tar.gz: c7654a5ea5a04c9879eb94afcb17f8975a3e555052f9ce123fb1a193a31c2f277cab5be38b8afbc2a2763aa7271051f93687ecf9915bd698ba468ca29e887bf1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
|
7
|
+
|
|
8
|
+
We are committed to making participation in this project a harassment-free
|
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior by participants include:
|
|
14
|
+
|
|
15
|
+
* The use of sexualized language or imagery
|
|
16
|
+
* Personal attacks
|
|
17
|
+
* Trolling or insulting/derogatory comments
|
|
18
|
+
* Public or private harassment
|
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
|
20
|
+
addresses, without explicit permission
|
|
21
|
+
* Other unethical or unprofessional conduct
|
|
22
|
+
|
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
|
+
threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
+
Conduct may be permanently removed from the project team.
|
|
33
|
+
|
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
|
35
|
+
when an individual is representing the project or its community.
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
+
reported by contacting a project maintainer at bastiankres@gmail.com. All
|
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
+
incident.
|
|
43
|
+
|
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
45
|
+
version 1.3.0, available at
|
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
47
|
+
|
|
48
|
+
[homepage]: http://contributor-covenant.org
|
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Bastian Kres
|
|
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,91 @@
|
|
|
1
|
+
# youtube_video_id
|
|
2
|
+
|
|
3
|
+
This gem makes it easy to extract the YouTube video ID from a YouTube video url.
|
|
4
|
+
|
|
5
|
+
These urls come in various forms and it is not exactly trivial to get the video ID out of them. This is where this gem comes in.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Code status
|
|
9
|
+
|
|
10
|
+
[](https://travis-ci.org/krewast/youtube_video_id)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'youtube_video_id'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
$ bundle
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
$ gem install youtube_video_id
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
At first, don't forget to require the gem in your script or project after the installation.
|
|
33
|
+
|
|
34
|
+
require 'youtube_video_id'
|
|
35
|
+
|
|
36
|
+
### Extract the YouTube video ID
|
|
37
|
+
|
|
38
|
+
If you have any YouTube url you can simply extract the video ID (if there is a valid one) with the "extract" method:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
YoutubeVideoId.extract('https://www.youtube.com/watch?v=YQHsXMglC9A') # => 'YQHsXMglC9A'
|
|
42
|
+
YoutubeVideoId.extract('https://www.youtube.com/watch?v=YQHsXMg') # => '' (ID too short and therefore not valid)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The method supports urls in these formats:
|
|
46
|
+
|
|
47
|
+
https://www.youtube.com/watch?v=YQHsXMglC9A
|
|
48
|
+
https://www.youtube.com/v/YQHsXMglC9A
|
|
49
|
+
https://www.youtube.com/embed/YQHsXMglC9A
|
|
50
|
+
https://www.youtube.com/user/SomeChannel#p/a/u/1/YQHsXMglC9A
|
|
51
|
+
https://youtu.be/YQHsXMglC9A
|
|
52
|
+
https://m.youtube.com/watch?v=YQHsXMglC9A
|
|
53
|
+
https://m.youtube.com/v/YQHsXMglC9A
|
|
54
|
+
|
|
55
|
+
Additional parameters or fragment identifiers don't matter. The method knows how to handle those:
|
|
56
|
+
|
|
57
|
+
https://www.youtube.com/watch?v=YQHsXMglC9A&feature=youtu.be
|
|
58
|
+
https://www.youtube.com/watch?feature=youtu.be&v=YQHsXMglC9A
|
|
59
|
+
https://www.youtube.com/watch?v=YQHsXMglC9A#t=0m15s
|
|
60
|
+
|
|
61
|
+
It's also not important whether a the url contains information about the protocol or not. The extract methods works with all variants:
|
|
62
|
+
|
|
63
|
+
youtube.com/watch?v=YQHsXMglC9A
|
|
64
|
+
//www.youtube.com/watch?v=YQHsXMglC9A
|
|
65
|
+
http://www.youtube.com/watch?v=YQHsXMglC9A
|
|
66
|
+
https://www.youtube.com/watch?v=YQHsXMglC9A
|
|
67
|
+
|
|
68
|
+
### Check whether a given YouTube video ID is valid
|
|
69
|
+
|
|
70
|
+
If you already have a string and want to check whether it could be a YouTube video ID you can use the method called 'youtube_video_id_is_valid?'. It returns either true or false:
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
YoutubeVideoId.youtube_video_id_is_valid?('YQHsXMglC9A') # => true
|
|
74
|
+
YoutubeVideoId.youtube_video_id_is_valid?('YQHsXMg') # => false (ID too short and therefore not valid)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Please note that this method doesn't "really" check if an ID is valid in the sense that there actually EXISTS a video with this ID. Instead, the method checks if the given video ID "looks right" and could possibly be a valid Youtube video ID.
|
|
78
|
+
|
|
79
|
+
If you want to make sure whether there actually is a video for a given ID you'll have to consult the [YouTube API](https://developers.google.com/youtube/v3/docs/videos).
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## Contributing
|
|
83
|
+
|
|
84
|
+
If you have any valid urls that link to a YouTube video but for some reason don't work with this gem I would be happy to be notified!
|
|
85
|
+
|
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/krewast/youtube_video_id. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module YoutubeVideoId
|
|
2
|
+
def self.extract(url)
|
|
3
|
+
return '' unless /(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|user)\/))([^\?&\"'>]+)/.match(url)
|
|
4
|
+
|
|
5
|
+
# Special case for URLs that look similar to this: https://www.youtube.com/user/SomeChannel#p/a/u/1/YQHsXMglC9A
|
|
6
|
+
if /user/.match(url)
|
|
7
|
+
youtube_video_id = url.strip[-11..-1]
|
|
8
|
+
return self.youtube_video_id_is_valid?(youtube_video_id) ? youtube_video_id : ''
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
delimiter = ''
|
|
12
|
+
if /\?v=/.match(url) # There has to be a differentiation between "?v=" and "&v=". See "Test case A"
|
|
13
|
+
delimiter = '?v='
|
|
14
|
+
elsif /&v=/.match(url)
|
|
15
|
+
delimiter = '&v='
|
|
16
|
+
elsif /v\//.match(url)
|
|
17
|
+
delimiter = 'v/'
|
|
18
|
+
elsif /embed/.match(url)
|
|
19
|
+
delimiter = 'embed/'
|
|
20
|
+
elsif /youtu.be/.match(url)
|
|
21
|
+
delimiter = 'youtu.be/'
|
|
22
|
+
else
|
|
23
|
+
return ''
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Remove everything before the delimiter and the delimiter itself
|
|
27
|
+
# The video ID and possibly some parameters remain.
|
|
28
|
+
# Remove those parameters by selecting the right range of characters
|
|
29
|
+
youtube_video_id = (url.split(delimiter)[1])[0...11]
|
|
30
|
+
|
|
31
|
+
self.youtube_video_id_is_valid?(youtube_video_id) ? youtube_video_id : ''
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.youtube_video_id_is_valid?(youtube_video_id)
|
|
35
|
+
# Check if the ID can possibly be valid or not (based on length and allowed characters)
|
|
36
|
+
return false if youtube_video_id.length != 11
|
|
37
|
+
/[a-zA-Z0-9_-]{11}/.match(youtube_video_id) ? true : false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'youtube_video_id/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "youtube_video_id"
|
|
8
|
+
spec.version = YoutubeVideoId::VERSION
|
|
9
|
+
spec.authors = ["krewast"]
|
|
10
|
+
spec.email = ["bastiankres@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{This gem makes it easy to extract the YouTube video IDs from YouTube video urls.}
|
|
13
|
+
spec.description = %q{This gem makes it easy to extract the YouTube video IDs from YouTube video urls. These urls come in various forms and it is not exactly trivial to get the video ID out of them. This is where this gem comes to help.}
|
|
14
|
+
spec.homepage = "https://github.com/krewast/youtube_video_id"
|
|
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.7"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
spec.add_development_dependency "test-unit", "~> 3.2"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: youtube_video_id
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- krewast
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-07-30 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.7'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
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
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: test-unit
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.2'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.2'
|
|
55
|
+
description: This gem makes it easy to extract the YouTube video IDs from YouTube
|
|
56
|
+
video urls. These urls come in various forms and it is not exactly trivial to get
|
|
57
|
+
the video ID out of them. This is where this gem comes to help.
|
|
58
|
+
email:
|
|
59
|
+
- bastiankres@gmail.com
|
|
60
|
+
executables: []
|
|
61
|
+
extensions: []
|
|
62
|
+
extra_rdoc_files: []
|
|
63
|
+
files:
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- CODE_OF_CONDUCT.md
|
|
67
|
+
- Gemfile
|
|
68
|
+
- LICENSE.txt
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- lib/youtube_video_id.rb
|
|
72
|
+
- lib/youtube_video_id/version.rb
|
|
73
|
+
- lib/youtube_video_id/youtube_video_id_extractor.rb
|
|
74
|
+
- youtube_video_id.gemspec
|
|
75
|
+
homepage: https://github.com/krewast/youtube_video_id
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata: {}
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 2.5.1
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: This gem makes it easy to extract the YouTube video IDs from YouTube video
|
|
99
|
+
urls.
|
|
100
|
+
test_files: []
|