apple_trailers 0.0.3

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,21 @@
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
+
19
+ lib/.DS_Store
20
+
21
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p362@apple_trailers"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.17.7 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apple_trailers.gemspec
4
+ gemspec
5
+
6
+ gem 'json'
7
+ gem 'nokogiri'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sean Stavropoulos
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,55 @@
1
+ # AppleTrailers
2
+
3
+ Pulls recently added movie trailers from trailers.apple.com. Includes basic information about the movie, including genre, production studio, title, release date, rating, and the url of the highest definition videos available.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'apple_trailers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install apple_trailers
18
+
19
+ ## Usage
20
+
21
+ movies = AppleTrailers.just_added
22
+
23
+ movies.count
24
+ => 80
25
+
26
+ movie = movies.first
27
+
28
+ movie.title
29
+ => "The Call"
30
+
31
+ movie.studio
32
+ => "Sony Pictures"
33
+
34
+ movie.rating
35
+ => "Not yet rated"
36
+
37
+ movie.genre
38
+ => "Thriller"
39
+
40
+ movie.description
41
+ => "When veteran 911 operator, Jordan (Halle Berry), takes a life-altering call from a teenage girl (Abigail Breslin) who has just been abducted, she realizes that she must confront a killer from her past in order to save the girl's life."
42
+
43
+ movie.trailers.first.title
44
+ => "The Call - Trailer"
45
+
46
+ movie.trailers.first.url
47
+ => "http://trailers.apple.com/movies/sony_pictures/thecall/call-tlr1b_h1080p.mov"
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'apple_trailers/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "apple_trailers"
8
+ gem.version = AppleTrailers::VERSION
9
+ gem.authors = ["Sean Stavropoulos"]
10
+ gem.email = ["seans@fullscreen.net"]
11
+ gem.description = "Gathers movie and trailer information from Apple Trailers."
12
+ gem.summary = "Gathers movie and trailer information from Apple Trailers."
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,29 @@
1
+ require "apple_trailers/version"
2
+ require "apple_trailers/movie"
3
+ require "apple_trailers/trailer"
4
+ require 'json'
5
+ require 'net/http'
6
+
7
+ module AppleTrailers
8
+ @@trailer_domain = "trailers.apple.com"
9
+ @@trailer_path = "/trailers/home/feeds/just_added.json"
10
+
11
+ def self.just_added
12
+ parse_movies(JSON.parse(Net::HTTP.get(@@trailer_domain, @@trailer_path)))
13
+ end
14
+
15
+ def self.parse_movies(movie_list)
16
+ movie_list.collect do |trailer_info|
17
+ Movie.new({
18
+ location: trailer_info['location'],
19
+ title: trailer_info['title'],
20
+ directors: trailer_info['directors'],
21
+ actors: trailer_info['actors'],
22
+ moviesite: trailer_info['moviesite'],
23
+ rating: trailer_info['rating'],
24
+ genre: trailer_info['genre'][0],
25
+ studio: trailer_info['studio']
26
+ })
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ require 'nokogiri'
2
+
3
+ module AppleTrailers
4
+ class Movie
5
+ attr_accessor :location, :title, :moviesite, :rating, :genre, :studio, :directors, :actors
6
+
7
+ def initialize(options)
8
+ options.each { |key, value| instance_variable_set("@"+key.to_s, value)}
9
+ end
10
+
11
+ def description
12
+ doc = Nokogiri::HTML(Net::HTTP.get(URI(["http://trailers.apple.com", @location].join(''))))
13
+ doc.at('meta[@name="Description"]/@content').value
14
+ end
15
+
16
+ def trailers
17
+ doc = Nokogiri::HTML(Net::HTTP.get(URI(["http://trailers.apple.com", @location, "includes/playlists/web.inc"].join(''))))
18
+ doc.css('.trailer').count > 1 ? get_multiple_trailers(doc) : get_single_trailer(doc)
19
+ end
20
+
21
+ private
22
+
23
+ def get_single_trailer(doc)
24
+ trailer = doc.css('.target-quicktimeplayer').max { |b1, b2| b1.text.to_i <=> b2.text.to_i}
25
+ [ Trailer.new({ movie: self, url: trailer.attributes['href'].value, type: doc.css('h3').first.content }) ]
26
+ end
27
+
28
+ def get_multiple_trailers(doc)
29
+ trailer_groups = doc.css('.trailer')
30
+ hd_trailers = trailer_groups.reject { |group| group.css('.target-quicktimeplayer').empty? }.collect { |group| group.css('.target-quicktimeplayer').max { |b1, b2| b1.text.to_i <=> b2.text.to_i} }
31
+ hd_trailers.collect { |trailer| Trailer.new({ movie: self, url: trailer.attributes['href'].value, type: doc.css('h3').first.content }) }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ require 'nokogiri'
2
+
3
+ module AppleTrailers
4
+ class Trailer
5
+ attr_accessor :movie, :url, :type
6
+
7
+ def initialize(options)
8
+ options.each { |key, value| instance_variable_set("@"+key.to_s, value)}
9
+ end
10
+
11
+ def title
12
+ "#{@movie.title} - #{@type}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module AppleTrailers
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apple_trailers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - Sean Stavropoulos
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-09-18 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Gathers movie and trailer information from Apple Trailers.
22
+ email:
23
+ - seans@fullscreen.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - .rvmrc
33
+ - Gemfile
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - apple_trailers.gemspec
38
+ - lib/apple_trailers.rb
39
+ - lib/apple_trailers/movie.rb
40
+ - lib/apple_trailers/trailer.rb
41
+ - lib/apple_trailers/version.rb
42
+ has_rdoc: true
43
+ homepage: ""
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Gathers movie and trailer information from Apple Trailers.
72
+ test_files: []
73
+