youtube_images 1.0.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.
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +9 -0
- data/lib/youtube_images.rb +36 -0
- data/lib/youtube_images/version.rb +3 -0
- data/spec/youtube_images_spec.rb +44 -0
- data/youtube_images.gemspec +23 -0
- metadata +98 -0
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
youtube_images
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-1.9.3-p385
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Rahul Trikha
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
**YouTube Images** can be used to extract thumbnails/images for a given youtube video ID or URL without a developer ID. It uses a URL constructor instead of an API
|
|
4
|
+
|
|
5
|
+
## Requirement
|
|
6
|
+
|
|
7
|
+
Ruby 1.9 or greater
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
YouTube Images is released as a Ruby Gem. The gem is to be installed within a Ruby
|
|
12
|
+
or Rails application. To install, simply add the following to your Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
# Gemfile
|
|
16
|
+
gem 'youtube_images'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
After updating your bundle, you can use YouTubeImages::For("video-id") function within your ruby code
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
For example if you want to fetch the default thumbnail for youtube URL you can do something like this
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=5zVaFjSxAZs")[:default]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Advanced Usage
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=5zVaFjSxAZs")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
will return a hash for default, medium, high and maximum dimension images
|
|
36
|
+
|
|
37
|
+
So to access different dimension images you can do something like this
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=5zVaFjSxAZs")[:medium]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ruby
|
|
44
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=5zVaFjSxAZs")[:high]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=5zVaFjSxAZs")[:maximum]
|
|
49
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "youtube_images/version"
|
|
2
|
+
|
|
3
|
+
module YouTubeImages
|
|
4
|
+
|
|
5
|
+
class IncorrectYouTubeID < Exception; end
|
|
6
|
+
|
|
7
|
+
def self.For(id_or_url, secure=false)
|
|
8
|
+
id = id_or_url[/[\w]+$/]
|
|
9
|
+
|
|
10
|
+
raise IncorrectYouTubeID if id.nil? || (id.length < 11)
|
|
11
|
+
|
|
12
|
+
url_prefix = url_constructor(secure, id)
|
|
13
|
+
|
|
14
|
+
{
|
|
15
|
+
default: "#{url_prefix}/default.jpg",
|
|
16
|
+
medium: "#{url_prefix}/hqdefault.jpg",
|
|
17
|
+
high: "#{url_prefix}/mqdefault.jpg",
|
|
18
|
+
maximum: "#{url_prefix}/maxresdefault.jpg"
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def self.uri
|
|
25
|
+
"img.youtube.com/vi"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.protocol(secure)
|
|
29
|
+
secure ? "https" : "http"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.url_constructor(secure, id)
|
|
33
|
+
"#{protocol(secure)}://#{uri}/#{id}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require 'minitest/pride'
|
|
3
|
+
require "youtube_images"
|
|
4
|
+
|
|
5
|
+
describe YouTubeImages do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@images_hash = {
|
|
9
|
+
default: "http://img.youtube.com/vi/onghF8NYbPw/default.jpg",
|
|
10
|
+
medium: "http://img.youtube.com/vi/onghF8NYbPw/hqdefault.jpg",
|
|
11
|
+
high: "http://img.youtube.com/vi/onghF8NYbPw/mqdefault.jpg",
|
|
12
|
+
maximum: "http://img.youtube.com/vi/onghF8NYbPw/maxresdefault.jpg"
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "when asked about images for a invalid youtube video" do
|
|
17
|
+
|
|
18
|
+
it "must respond with an exception if the URL is invalid" do
|
|
19
|
+
proc { YouTubeImages::For("http://asd") }.must_raise YouTubeImages::IncorrectYouTubeID
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "must respond with an exception if the URL is invalid" do
|
|
23
|
+
proc { YouTubeImages::For("asdfasd") }.must_raise YouTubeImages::IncorrectYouTubeID
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "when asked about images for a youtube ID" do
|
|
29
|
+
|
|
30
|
+
it "must respond with an image" do
|
|
31
|
+
YouTubeImages::For("onghF8NYbPw").must_equal @images_hash
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "when asked about images for a youtube URL" do
|
|
37
|
+
|
|
38
|
+
it "must respond with an image" do
|
|
39
|
+
YouTubeImages::For("http://www.youtube.com/watch?v=onghF8NYbPw").must_equal @images_hash
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'youtube_images/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "youtube_images"
|
|
8
|
+
spec.version = YoutubeImages::VERSION
|
|
9
|
+
spec.authors = ["Rahul Trikha"]
|
|
10
|
+
spec.email = ["rahul.trikha@gmail.com"]
|
|
11
|
+
spec.description = %q{Extract thumbnails/image for a given youtube video ID or URL without a developer ID. It uses a URL constructor instead of an API}
|
|
12
|
+
spec.summary = %q{Extract thumbnails for a given youtube video ID or URL without a developer ID}
|
|
13
|
+
spec.homepage = "http://rahult.github.io/youtube_images/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: youtube_images
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Rahul Trikha
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: bundler
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.3'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.3'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rake
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: Extract thumbnails/image for a given youtube video ID or URL without
|
|
47
|
+
a developer ID. It uses a URL constructor instead of an API
|
|
48
|
+
email:
|
|
49
|
+
- rahul.trikha@gmail.com
|
|
50
|
+
executables: []
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- .gitignore
|
|
55
|
+
- .ruby-gemset
|
|
56
|
+
- .ruby-version
|
|
57
|
+
- Gemfile
|
|
58
|
+
- LICENSE.txt
|
|
59
|
+
- README.md
|
|
60
|
+
- Rakefile
|
|
61
|
+
- lib/youtube_images.rb
|
|
62
|
+
- lib/youtube_images/version.rb
|
|
63
|
+
- spec/youtube_images_spec.rb
|
|
64
|
+
- youtube_images.gemspec
|
|
65
|
+
homepage: http://rahult.github.io/youtube_images/
|
|
66
|
+
licenses:
|
|
67
|
+
- MIT
|
|
68
|
+
post_install_message:
|
|
69
|
+
rdoc_options: []
|
|
70
|
+
require_paths:
|
|
71
|
+
- lib
|
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
segments:
|
|
79
|
+
- 0
|
|
80
|
+
hash: 1375972798781748379
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
none: false
|
|
83
|
+
requirements:
|
|
84
|
+
- - ! '>='
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
segments:
|
|
88
|
+
- 0
|
|
89
|
+
hash: 1375972798781748379
|
|
90
|
+
requirements: []
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 1.8.25
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 3
|
|
95
|
+
summary: Extract thumbnails for a given youtube video ID or URL without a developer
|
|
96
|
+
ID
|
|
97
|
+
test_files:
|
|
98
|
+
- spec/youtube_images_spec.rb
|