youtube_addy 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/youtube_addy.rb +23 -12
  3. metadata +7 -9
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e022f0da8711aaa4506f32e4816f5e8c3ca413ac
4
+ data.tar.gz: b94a2bcf5e378856259b924306e2e9ff0f89f1b4
5
+ SHA512:
6
+ metadata.gz: 213c42405f2fb5521a828d8b810c10e0b6e9f7a6964d6cfb070870c3c1c91fa264fc2e274660b75cc42154c0bae4e0992272da50869a35224d8afddbae87fd3d
7
+ data.tar.gz: 7f7b6f9a0ba17a42a68ba0352cd6291e05b0d4a87bd1075a06ac36d5427fa1d83473da39f688dcf528e47280a837274c4be42f02f8d376fd9392c752bb33aa43
@@ -1,28 +1,39 @@
1
1
  class YouTubeAddy
2
- URL_Formats = {
3
- regular: /^(https?:\/\/)?(www\.)?youtube.com\/watch\?(.*\&)?v=([^&]+)/,
4
- shortened: /^(https?:\/\/)?(www\.)?youtu.be\/([^&]+)/,
5
- invalid_chars: /[^a-zA-Z0-9\:\/\?\=\&\$\-\_\.\+\!\*\'\(\)\,]/
2
+ URL_FORMATS = {
3
+ regular: /^(https?:\/\/)?(www\.)?youtube.com\/watch\?(.*\&)?v=(?<id>[^&]+)/,
4
+ shortened: /^(https?:\/\/)?(www\.)?youtu.be\/(?<id>[^&]+)/,
5
+ embed: /^(https?:\/\/)?(www\.)?youtube.com\/embed\/(?<id>[^&]+)/,
6
+ embed_as3: /^(https?:\/\/)?(www\.)?youtube.com\/v\/(?<id>[^?]+)/,
7
+ chromeless_as3: /^(https?:\/\/)?(www\.)?youtube.com\/apiplayer\?video_id=(?<id>[^&]+)/
6
8
  }
7
9
 
10
+ INVALID_CHARS = /[^a-zA-Z0-9\:\/\?\=\&\$\-\_\.\+\!\*\'\(\)\,]/
11
+
8
12
  def self.has_invalid_chars?(youtube_url)
9
- !URL_Formats[:invalid_chars].match(youtube_url).nil?
13
+ !INVALID_CHARS.match(youtube_url).nil?
10
14
  end
11
15
 
12
16
  def self.extract_video_id(youtube_url)
13
17
  return nil if has_invalid_chars?(youtube_url)
14
18
 
15
- if match = URL_Formats[:regular].match(youtube_url)
16
- return match[4]
17
- elsif match = URL_Formats[:shortened].match(youtube_url)
18
- return match[3]
19
+ URL_FORMATS.values.each do |format_regex|
20
+ match = format_regex.match(youtube_url)
21
+ return match[:id] if match
19
22
  end
20
-
21
- nil
22
23
  end
23
24
 
24
25
  def self.youtube_embed_url(youtube_url, width = 420, height = 315)
25
26
  vid_id = extract_video_id(youtube_url)
26
27
  %(<iframe width="#{width}" height="#{height}" src="http://www.youtube.com/embed/#{vid_id}" frameborder="0" allowfullscreen></iframe>)
27
28
  end
28
- end
29
+
30
+ def self.youtube_regular_url(youtube_url)
31
+ vid_id = extract_video_id(youtube_url)
32
+ "http://www.youtube.com/watch?v=#{ vid_id }"
33
+ end
34
+
35
+ def self.youtube_shortened_url(youtube_url)
36
+ vid_id = extract_video_id(youtube_url)
37
+ "http://youtu.be/#{ vid_id }"
38
+ end
39
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youtube_addy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Wright
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-11-15 00:00:00.000000000Z
11
+ date: 2011-11-15 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Parse youtube addresses and generate embed html code
15
14
  email: davidwright at gmail dot com
@@ -20,26 +19,25 @@ files:
20
19
  - lib/youtube_addy.rb
21
20
  homepage: https://github.com/hanzq/youtube_addy/
22
21
  licenses: []
22
+ metadata: {}
23
23
  post_install_message:
24
24
  rdoc_options: []
25
25
  require_paths:
26
26
  - lib
27
27
  required_ruby_version: !ruby/object:Gem::Requirement
28
- none: false
29
28
  requirements:
30
- - - ! '>='
29
+ - - '>='
31
30
  - !ruby/object:Gem::Version
32
31
  version: '0'
33
32
  required_rubygems_version: !ruby/object:Gem::Requirement
34
- none: false
35
33
  requirements:
36
- - - ! '>='
34
+ - - '>='
37
35
  - !ruby/object:Gem::Version
38
36
  version: '0'
39
37
  requirements: []
40
38
  rubyforge_project:
41
- rubygems_version: 1.8.10
39
+ rubygems_version: 2.0.14
42
40
  signing_key:
43
- specification_version: 3
41
+ specification_version: 4
44
42
  summary: YouTube address helper
45
43
  test_files: []