film_snob 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c009c58d2b98f35b7e85895c3e4da9bffb2a3deb
4
+ data.tar.gz: e52c4ca5a5e484e1115ece13a4d79feb1a2fdac0
5
+ SHA512:
6
+ metadata.gz: 65741c40b8b2567c17eb71684ae45730db46a8321ea966d290fbf7649abc45c19791c3372024e5c3b5fa24ea68a4d6dd05e487ad9d8ba85a0732ef1999709af6
7
+ data.tar.gz: 2524c5efca4066ee12b725ddee326a07d19ceffcc2312399ffe04a09d036d93b0773aa668eba5b1847800c07eac89dee84cadfe7f288195f97dc0456949dfa5c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in film_snob.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Max Jacobson
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,44 @@
1
+ # film_snob
2
+
3
+ Helps parse URLs of web videos.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'film_snob'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install film_snob
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ snob = FilmSnob.new("https://www.youtube.com/watch?v=GwT3zH16w3s")
23
+ snob.watchable? #=> true
24
+ snob.site #=> :youtube
25
+ snob.id #=> 'GwT3zH16w3s'
26
+ ```
27
+
28
+ ## Supported video providers
29
+
30
+ * YouTube
31
+ * Vimeo
32
+ * Hulu
33
+
34
+ ## Testing
35
+
36
+ Run `rake` to run all of the rspecs.
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/maxjacobson/film_snob/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/film_snob.gemspec ADDED
@@ -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 'film_snob/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "film_snob"
8
+ spec.version = FilmSnob::VERSION
9
+ spec.authors = ["Max Jacobson"]
10
+ spec.email = ["max@hardscrabble.net"]
11
+ spec.summary = %q{Help understand URLs for video sites}
12
+ spec.description = %q{Help understand URLs for video sites}
13
+ spec.homepage = "https://github.com/maxjacobson/film_snob"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta2"
24
+ spec.add_development_dependency "debugger"
25
+ end
@@ -0,0 +1,3 @@
1
+ class FilmSnob
2
+ class NotSupportURLError < StandardError; end
3
+ end
@@ -0,0 +1,15 @@
1
+ class FilmSnob
2
+ class Hulu < VideoSite
3
+
4
+ def self.valid_url_patterns
5
+ [
6
+ %r{https?://(?:(?:www).)?hulu.com/watch/(\d+)}
7
+ ]
8
+ end
9
+
10
+ def clean_url
11
+ "http://www.hulu.com/watch/#{id}"
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require "film_snob/vimeo"
2
+ require "film_snob/youtube"
3
+ require "film_snob/hulu"
4
+
5
+ class FilmSnob
6
+ class UrlToVideo
7
+
8
+ VIDEO_SITES = [
9
+ Vimeo,
10
+ YouTube,
11
+ Hulu
12
+ ]
13
+
14
+ attr_reader :url
15
+
16
+ def initialize(url)
17
+ @url = url
18
+ end
19
+
20
+ def video
21
+ site.nil?? nil : site.new(url)
22
+ end
23
+
24
+ private
25
+
26
+ def site
27
+ @site ||= VIDEO_SITES.find do |site|
28
+ site.valid_url_patterns.any? do |pattern|
29
+ pattern.match(url)
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ class FilmSnob
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ class FilmSnob
2
+ class VideoSite
3
+
4
+ attr_reader :url
5
+
6
+ def initialize(url)
7
+ @url = url
8
+ end
9
+
10
+ def id
11
+ @id ||= matching_pattern.match(url)[1]
12
+ end
13
+
14
+ def site
15
+ @site ||= self.class.to_s.split('::').last.downcase.to_sym
16
+ end
17
+
18
+ def self.valid_url_patterns
19
+ []
20
+ end
21
+
22
+ private
23
+
24
+ def matching_pattern
25
+ self.class.valid_url_patterns.find do |pattern|
26
+ pattern.match(url)
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require "film_snob/video_site"
2
+
3
+ class FilmSnob
4
+ class Vimeo < VideoSite
5
+
6
+ def self.valid_url_patterns
7
+ [
8
+ %r{https?://vimeo.com/(\d{1,})},
9
+ %r{https?://vimeo.com/m/(\d{1,})},
10
+ %r{https?://vimeo.com/couchmode/\w+/[\w:]+/(\d{1,})}
11
+ ]
12
+ end
13
+
14
+ def clean_url
15
+ "https://vimeo.com/#{id}"
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ class FilmSnob
2
+ class YouTube < VideoSite
3
+
4
+ def self.valid_url_patterns
5
+ [
6
+ %r{https?://(?:(?:www|m).)?youtube.com/watch\?v=([\w\d]+)},
7
+ %r{https?://(?:(?:www|m).)?youtu.be/([\w\d]+)}
8
+ ]
9
+ end
10
+
11
+ def clean_url
12
+ "https://www.youtube.com/watch?v=#{id}"
13
+ end
14
+
15
+ end
16
+ end
data/lib/film_snob.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "film_snob/version"
2
+ require "film_snob/url_to_video"
3
+ require "film_snob/exceptions"
4
+
5
+ class FilmSnob
6
+ attr_reader :url, :video
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ @video = FilmSnob::UrlToVideo.new(url).video
11
+ end
12
+
13
+ def site
14
+ complain_about_bad_urls!(:site)
15
+ video.site
16
+ end
17
+
18
+ def id
19
+ complain_about_bad_urls!(:id)
20
+ video.id
21
+ end
22
+
23
+ def clean_url
24
+ complain_about_bad_urls!(:clean_url)
25
+ video.clean_url
26
+ end
27
+
28
+ def watchable?
29
+ !video.nil?
30
+ end
31
+
32
+ private
33
+
34
+ def complain_about_bad_urls!(method)
35
+ raise NotSupportURLError.new("Can not call FilmSnob##{method} because #{url} is not a supported URL.") unless watchable?
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,86 @@
1
+ require 'film_snob'
2
+
3
+ describe FilmSnob do
4
+
5
+ describe 'not supported URLs' do
6
+
7
+ it 'should handle non-supported URLs gracefully' do
8
+ snob = FilmSnob.new("http://hardscrabble.net")
9
+ expect(snob.video).to be_nil
10
+ end
11
+
12
+ it 'should raise an exception if you push your luck' do
13
+ snob = FilmSnob.new("http://hardscrabble.net")
14
+ expect(snob).to_not be_watchable
15
+ expect{snob.id}.to raise_error(FilmSnob::NotSupportURLError)
16
+ end
17
+
18
+ end
19
+
20
+ describe 'YouTube URLs' do
21
+
22
+ it 'should parse normal YouTube URLs' do
23
+ snob = FilmSnob.new("https://www.youtube.com/watch?v=7q5Ltr0qc8c")
24
+ expect(snob).to be_watchable
25
+ expect(snob.id).to eq "7q5Ltr0qc8c"
26
+ expect(snob.site).to eq :youtube
27
+ end
28
+
29
+ it 'should parse mobile YouTube URLs' do
30
+ snob = FilmSnob.new("https://m.youtube.com/watch?v=6dyeFalOjw0&feature=youtu.be")
31
+ expect(snob.id).to eq "6dyeFalOjw0"
32
+ expect(snob.site).to eq :youtube
33
+ expect(snob.clean_url).to eq "https://www.youtube.com/watch?v=6dyeFalOjw0"
34
+ end
35
+
36
+ it 'should parse short YouTube URLs' do
37
+ snob = FilmSnob.new("http://youtu.be/1Ee4bfu_t3c")
38
+ expect(snob.id).to eq "1Ee4bfu_t3c"
39
+ expect(snob.site).to eq :youtube
40
+ expect(snob.clean_url).to eq "https://www.youtube.com/watch?v=1Ee4bfu_t3c"
41
+ end
42
+
43
+ end
44
+
45
+ describe 'vimeo URLs' do
46
+ it 'should parse https vimeo URLs' do
47
+ snob = FilmSnob.new("https://vimeo.com/16010689")
48
+ expect(snob.id).to eq "16010689"
49
+ expect(snob.site).to eq :vimeo
50
+ end
51
+
52
+ it 'should parse http vimeo URLs' do
53
+ snob = FilmSnob.new("http://vimeo.com/16010689")
54
+ expect(snob.id).to eq "16010689"
55
+ expect(snob.site).to eq :vimeo
56
+ end
57
+
58
+ it 'should parse mobile vimeo URLs' do
59
+ snob = FilmSnob.new("http://vimeo.com/m/16010689")
60
+ expect(snob.id).to eq "16010689"
61
+ expect(snob.site).to eq :vimeo
62
+ expect(snob.clean_url).to eq "https://vimeo.com/16010689"
63
+ end
64
+
65
+ it 'should parse couchmode vimeo URLs' do
66
+ snob = FilmSnob.new("https://vimeo.com/couchmode/staffpicks/sort:date/91157088")
67
+ expect(snob.id).to eq "91157088"
68
+ expect(snob.site).to eq :vimeo
69
+
70
+ snob2 = FilmSnob.new("https://vimeo.com/couchmode/watchlater/sort:date/51020067")
71
+ expect(snob2.id).to eq "51020067"
72
+ expect(snob2.site).to eq :vimeo
73
+ end
74
+
75
+
76
+ end
77
+
78
+ describe 'hulu URLs' do
79
+ it 'should parse hulu URLs' do
80
+ snob = FilmSnob.new("http://www.hulu.com/watch/285095")
81
+ expect(snob.id).to eq '285095'
82
+ expect(snob.site).to eq :hulu
83
+ end
84
+ end
85
+
86
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: film_snob
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Jacobson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-13 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0.beta2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0.beta2
55
+ - !ruby/object:Gem::Dependency
56
+ name: debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Help understand URLs for video sites
70
+ email:
71
+ - max@hardscrabble.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - film_snob.gemspec
82
+ - lib/film_snob.rb
83
+ - lib/film_snob/exceptions.rb
84
+ - lib/film_snob/hulu.rb
85
+ - lib/film_snob/url_to_video.rb
86
+ - lib/film_snob/version.rb
87
+ - lib/film_snob/video_site.rb
88
+ - lib/film_snob/vimeo.rb
89
+ - lib/film_snob/youtube.rb
90
+ - spec/film_snob_spec.rb
91
+ homepage: https://github.com/maxjacobson/film_snob
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.1.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Help understand URLs for video sites
115
+ test_files:
116
+ - spec/film_snob_spec.rb