youtube_id 0.0.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in youtube_id.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rodrigo Navarro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # YoutubeId
2
+
3
+ Simple video id extraction from youtube urls.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'youtube_id'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install youtube_id
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ YoutubeID.from("http//www.youtube.com/watch?v=RCUkmUXMd_k") # => "RCUkmUXMd_k"
23
+ ```
24
+
25
+ We currently support these url formats:
26
+ `http://www.youtube.com/v/RCUkmUXMd_k`
27
+ `http://www.youtube.com/v/RCUkmUXMd_k?version=3&hl=en_US&rel=0`
28
+ `http://www.youtube.com/embed/RCUkmUXMd_k?rel=0`
29
+ `http://www.youtube.com/watch?v=RCUkmUXMd_k`
30
+ `http://www.youtube.com/watch?v=RCUkmUXMd_k&feature=related`
31
+ `http://www.youtube.com/watch?v=RCUkmUXMd_k#t=0m10s`
32
+ `http://www.youtube.com/user/ForceD3strategy#p/a/u/0/8WVTOUh53QY`
33
+ `http://youtu.be/RCUkmUXMd_k`
34
+
35
+ See the specs for more detailed information.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ require "youtube_id/version"
2
+
3
+ module YoutubeID
4
+ FORMATS = [
5
+ %r(https?://youtu\.be/(.+?)\b),
6
+ %r(https?://www\.youtube\.com/watch\?v=(.*?)(&|#|$)),
7
+ %r(https?://www\.youtube\.com/embed/(.*?)(\?|$)),
8
+ %r(https?://www\.youtube\.com/v/(.*?)(#|\?|$)),
9
+ %r(https?://www\.youtube\.com/user/.*?#\w/\w/\w/\w/(.+)\b)
10
+ ]
11
+
12
+ def self.from(video_url)
13
+ video_url.strip!
14
+ FORMATS.find { |format| video_url =~ format } and $1
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module YoutubeID
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "youtube_id"
2
+
3
+ describe YoutubeID do
4
+ describe ".from" do
5
+ subject { described_class.from url }
6
+
7
+ %w(http https).each do |protocol|
8
+ context "direct format" "/v/:id" do
9
+ let(:url) { "#{protocol}://www.youtube.com/v/RCUkmUXMd_k" }
10
+ it { should == "RCUkmUXMd_k" }
11
+ end
12
+
13
+ context "legacy embed format" "/v/:id?version=3&hl=en_US&rel=0" do
14
+ let(:url) { "#{protocol}://www.youtube.com/v/RCUkmUXMd_k?version=3&hl=en_US&rel=0" }
15
+ it { should == "RCUkmUXMd_k" }
16
+ end
17
+
18
+ context "embed format" "/embed/RCUkmUXMd_k?rel=0" do
19
+ let(:url) { "#{protocol}://www.youtube.com/embed/RCUkmUXMd_k?rel=0" }
20
+ it { should == "RCUkmUXMd_k" }
21
+
22
+ context "without parameters" do
23
+ let(:url) { "#{protocol}://www.youtube.com/embed/RCUkmUXMd_k" }
24
+ it { should == "RCUkmUXMd_k" }
25
+ end
26
+ end
27
+
28
+ context "standard format", "/watch?v=:id" do
29
+ let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k" }
30
+ it { should == "RCUkmUXMd_k" }
31
+
32
+ context "with additional parameters" do
33
+ let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k&feature=related" }
34
+ it { should == "RCUkmUXMd_k" }
35
+ end
36
+
37
+ context "with start time specification" do
38
+ let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k#t=0m10s" }
39
+ it { should == "RCUkmUXMd_k" }
40
+ end
41
+ end
42
+
43
+ context "user video format", "/user/name#p/a/u/0/:id" do
44
+ let(:url) { "#{protocol}://www.youtube.com/user/ForceD3strategy#p/a/u/0/8WVTOUh53QY" }
45
+ it { should == "8WVTOUh53QY" }
46
+ end
47
+
48
+ context "shor url format", "//youtu.be/RCUkmUXMd_k" do
49
+ let(:url) { "#{protocol}://youtu.be/RCUkmUXMd_k" }
50
+ it { should == "RCUkmUXMd_k" }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/youtube_id/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Rodrigo Navarro", "Paulo Silva", "Cassiano D'Andrea"]
6
+ gem.email = ["rnavarro1@gmail.com", "puloms@hotmail.com", "cassiano.dandrea@tagview.com.br"]
7
+ gem.description = %q{Easily extract the video id from youtube videos urls}
8
+ gem.summary = %q{Easily extract the video id from youtube videos urls}
9
+ gem.homepage = "https://github.com/reu/youtube_id"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
14
+ gem.name = "youtube_id"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = YoutubeID::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: youtube_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Navarro
9
+ - Paulo Silva
10
+ - Cassiano D'Andrea
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-05-08 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &2152164580 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *2152164580
27
+ description: Easily extract the video id from youtube videos urls
28
+ email:
29
+ - rnavarro1@gmail.com
30
+ - puloms@hotmail.com
31
+ - cassiano.dandrea@tagview.com.br
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/youtube_id.rb
42
+ - lib/youtube_id/version.rb
43
+ - spec/youtube_id_spec.rb
44
+ - youtube_id.gemspec
45
+ homepage: https://github.com/reu/youtube_id
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: -1505085228670528075
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ segments:
67
+ - 0
68
+ hash: -1505085228670528075
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Easily extract the video id from youtube videos urls
75
+ test_files: []