allocine_parser 1.5.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 +4 -0
- data/Gemfile +3 -0
- data/History.txt +7 -0
- data/Manifest.txt +0 -0
- data/README.rdoc +74 -0
- data/allocine_parser.gemspec +24 -0
- data/lib/allocine_parser.rb +15 -0
- data/lib/allocine_parser/allocine_base.rb +113 -0
- data/lib/allocine_parser/cli.rb +109 -0
- data/lib/allocine_parser/episode.rb +65 -0
- data/lib/allocine_parser/movie.rb +9 -0
- data/lib/allocine_parser/movie_list.rb +21 -0
- data/lib/allocine_parser/search.rb +31 -0
- data/lib/allocine_parser/season.rb +63 -0
- data/lib/allocine_parser/serie.rb +54 -0
- data/lib/allocine_parser/version.rb +3 -0
- data/script/console +12 -0
- data/spec/allocine/episode_spec.rb +39 -0
- data/spec/allocine/movie_spec.rb +83 -0
- data/spec/allocine/season_spec.rb +32 -0
- data/spec/allocine/serie_spec.rb +0 -0
- data/spec/spec_helper.rb +15 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/History.txt
ADDED
data/Manifest.txt
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= allocine
|
2
|
+
|
3
|
+
Allows you to search and inspect movies and series from allocine API
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This packages allows you to easy access publicly available data from Allocine API.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
Allocine currently features the following:
|
12
|
+
|
13
|
+
* Querying details movie info
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
Movies:
|
18
|
+
|
19
|
+
i = Allocine::Movie.new("20754")
|
20
|
+
|
21
|
+
i.title
|
22
|
+
#=> "Star Wars : Episode I - La Menace fantôme"
|
23
|
+
|
24
|
+
|
25
|
+
Serie:
|
26
|
+
|
27
|
+
i = Allocine::Serie.new(223)
|
28
|
+
i.title
|
29
|
+
#=> "Lost, les disparus"
|
30
|
+
|
31
|
+
|
32
|
+
Season:
|
33
|
+
|
34
|
+
i = Allocine::Season.new(12277)
|
35
|
+
i.episode_ids
|
36
|
+
#=> [233014, 233015, 233016, 233017, 233018, 233019, 233020, 233021, 233022, 233023, 233024, 233025, 233026, 233027, 233028, 233029, 233030, 247699]
|
37
|
+
|
38
|
+
Episode:
|
39
|
+
|
40
|
+
s = Allocine::Episode.new(233014)
|
41
|
+
s.title
|
42
|
+
#=> "On efface tout"
|
43
|
+
|
44
|
+
== TESTING:
|
45
|
+
|
46
|
+
You'll need rspec installed to run the specs.
|
47
|
+
|
48
|
+
$ bundle install
|
49
|
+
$ rspec spec
|
50
|
+
|
51
|
+
== LICENSE:
|
52
|
+
|
53
|
+
(The MIT License)
|
54
|
+
|
55
|
+
Copyright (c) 2011 Matthieu Lamarque
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
58
|
+
a copy of this software and associated documentation files (the
|
59
|
+
'Software'), to deal in the Software without restriction, including
|
60
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
61
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
62
|
+
permit persons to whom the Software is furnished to do so, subject to
|
63
|
+
the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
70
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
71
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
72
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
73
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
74
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "allocine/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "allocine_parser"
|
7
|
+
s.version = Allocine::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Matthieu Lamarque"]
|
10
|
+
s.email = ["lamarque.matthieu@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/mlamarque/allocine"
|
12
|
+
s.summary = %q{Easily access the API information on Allocine API.}
|
13
|
+
s.description = %q{Easily use Ruby to find information on allocine API.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "allocine_parser"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
# s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
s.add_development_dependency 'rdoc'
|
23
|
+
s.add_development_dependency 'rspec', '~> 1.3.2'
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'open-uri'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'awesome_print'
|
7
|
+
|
8
|
+
require 'allocine_parser/allocine_base'
|
9
|
+
require 'allocine_parser/movie'
|
10
|
+
require 'allocine_parser/movie_list'
|
11
|
+
require 'allocine_parser/search'
|
12
|
+
require 'allocine_parser/version'
|
13
|
+
require 'allocine_parser/serie'
|
14
|
+
require 'allocine_parser/season'
|
15
|
+
require 'allocine_parser/episode'
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
# Represents a AllocineBase
|
8
|
+
class AllocineBase
|
9
|
+
attr_accessor :id, :url, :title
|
10
|
+
|
11
|
+
def initialize(allocine_id, title = nil)
|
12
|
+
@id = allocine_id
|
13
|
+
@url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the name of the director
|
17
|
+
def directors
|
18
|
+
document["castingShort"]["directors"].split(", ") rescue nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns an array with cast members
|
22
|
+
def actors
|
23
|
+
document["castingShort"]["actors"].split(", ") rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns an array of genres (as strings)
|
27
|
+
def genres
|
28
|
+
document["genre"].collect {|gender| gender["$"]} rescue nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns an array of countries as strings.
|
32
|
+
def countries
|
33
|
+
document["nationality"].collect {|nation| nation["$"]} rescue nil
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the duration of the movie in minutes as an integer.
|
37
|
+
def length
|
38
|
+
document["runtime"].to_i/60 rescue nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a string containing the URL to the movie poster.
|
42
|
+
def poster
|
43
|
+
document["poster"]["href"] rescue nil
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns a string containing trailer code.
|
47
|
+
def trailer_id
|
48
|
+
document["trailer"]["code"] rescue nil
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns a string containing the URL to the movie trailer.
|
52
|
+
def trailer
|
53
|
+
document["trailer"]["href"] rescue nil
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a float containing the average user rating
|
57
|
+
def press_rating
|
58
|
+
document["statistics"]["pressRating"] rescue nil
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns an int containing the number of user ratings
|
62
|
+
def user_rating
|
63
|
+
document["statistics"]["userRating"] rescue nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns a string containing the title
|
67
|
+
def title(force_refresh = false)
|
68
|
+
if @title && !force_refresh
|
69
|
+
@title
|
70
|
+
else
|
71
|
+
@title = document["title"] rescue nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns originalTitle.
|
76
|
+
def original_title
|
77
|
+
document["originalTitle"] rescue nil
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# Returns release date for the movie.
|
82
|
+
def release_date
|
83
|
+
document["release"]["releaseDate"] rescue nil
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return production Year for the movie
|
87
|
+
def production_year
|
88
|
+
document["productionYear"]
|
89
|
+
end
|
90
|
+
|
91
|
+
def plot(short = true)
|
92
|
+
short ? document["synopsisShort"] : document["synopsis"]
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def document
|
98
|
+
@document ||= Allocine::Movie.find_by_id(@id)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.find_by_id(allocine_id)
|
102
|
+
url = "http://api.allocine.fr/rest/v3/movie?code=#{allocine_id}&profile=large&format=json&partner=YW5kcm9pZC12M3M"
|
103
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["movie"] rescue nil
|
104
|
+
end
|
105
|
+
|
106
|
+
# Convenience method for search
|
107
|
+
def self.search(query)
|
108
|
+
Allocine::Search.new(query).movies
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# require 'optparse'
|
2
|
+
#
|
3
|
+
# module Allocine
|
4
|
+
# class CLI
|
5
|
+
#
|
6
|
+
# # Run the imdb command
|
7
|
+
# #
|
8
|
+
# # Searching
|
9
|
+
# #
|
10
|
+
# # imdb Star Trek
|
11
|
+
# #
|
12
|
+
# # Get a movie, supply a 7 digit IMDB id or the IMDB URL
|
13
|
+
# #
|
14
|
+
# # imdb 0095016
|
15
|
+
# # imdb http://akas.imdb.com/title/tt0796366/
|
16
|
+
# #
|
17
|
+
# def self.execute(stdout, arguments=[])
|
18
|
+
#
|
19
|
+
# @stdout = stdout
|
20
|
+
#
|
21
|
+
# @stdout.puts "IMDB Scraper #{Imdb::VERSION}"
|
22
|
+
#
|
23
|
+
# options = {
|
24
|
+
# }
|
25
|
+
# mandatory_options = %w( )
|
26
|
+
#
|
27
|
+
# parser = OptionParser.new do |opts|
|
28
|
+
# opts.banner = <<-BANNER.gsub(/^ /,'')
|
29
|
+
#
|
30
|
+
# Usage: #{File.basename($0)} Search Query
|
31
|
+
# #{File.basename($0)} 0095016
|
32
|
+
#
|
33
|
+
# BANNER
|
34
|
+
# opts.separator ""
|
35
|
+
# opts.on("-v", "--version",
|
36
|
+
# "Show the current version.") { stdout.puts "IMDB #{Imdb::VERSION}"; exit }
|
37
|
+
# opts.on("-h", "--help",
|
38
|
+
# "Show this help message.") { stdout.puts opts; exit }
|
39
|
+
# opts.parse!(arguments)
|
40
|
+
#
|
41
|
+
# if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
42
|
+
# stdout.puts opts; exit
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# query = arguments.join(" ").strip
|
47
|
+
# exit if query.blank?
|
48
|
+
#
|
49
|
+
# movie, search = nil, nil
|
50
|
+
#
|
51
|
+
# # If ID, fetch movie
|
52
|
+
# if query.match(/(\d\d\d\d\d\d\d)/) || query.downcase.match(/^http:\/\/[www.]*imdb.com\/title\/tt(.+)\/$/)
|
53
|
+
# fetch_movie($1)
|
54
|
+
# else
|
55
|
+
# search_movie(query)
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# def self.fetch_movie(imdb_id)
|
60
|
+
# @stdout.puts
|
61
|
+
# @stdout.puts " - fetching movie #{imdb_id}"
|
62
|
+
#
|
63
|
+
# movie = Imdb::Movie.new(imdb_id)
|
64
|
+
#
|
65
|
+
# display_movie_details(movie)
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# def self.search_movie(query)
|
69
|
+
# @stdout.puts
|
70
|
+
# @stdout.puts " - searching for \"#{query}\""
|
71
|
+
#
|
72
|
+
# search = Imdb::Search.new(query)
|
73
|
+
#
|
74
|
+
# if search.movies.size == 1
|
75
|
+
# display_movie_details(search.movies.first)
|
76
|
+
# else
|
77
|
+
# display_search_results(search.movies)
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def self.display_movie_details(movie)
|
82
|
+
# title = "#{movie.title} (#{movie.year})"
|
83
|
+
# id = "ID #{movie.id}"
|
84
|
+
#
|
85
|
+
# @stdout.puts
|
86
|
+
# @stdout.puts "#{title}#{" " * (75 - 1 - title.length - id.length)}#{id} "
|
87
|
+
# @stdout.puts "=" * 75
|
88
|
+
# @stdout.puts "Rating: #{movie.rating}"
|
89
|
+
# @stdout.puts "Duration: #{movie.length} minutes"
|
90
|
+
# @stdout.puts "Directed by: #{movie.director.join(", ")}"
|
91
|
+
# @stdout.puts "Cast: #{movie.cast_members[0..4].join(", ")}"
|
92
|
+
# @stdout.puts "Genre: #{movie.genres.join(", ")}"
|
93
|
+
# @stdout.puts "Plot: #{movie.plot}"
|
94
|
+
# @stdout.puts "Poster URL: #{movie.poster}"
|
95
|
+
# @stdout.puts "IMDB URL: #{movie.url}"
|
96
|
+
# @stdout.puts "=" * 75
|
97
|
+
# @stdout.puts
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# def self.display_search_results(movies = [])
|
101
|
+
# movies = movies[0..9] # limit to ten top hits
|
102
|
+
#
|
103
|
+
# movies.each do |movie|
|
104
|
+
# @stdout.puts " > #{movie.id} | #{movie.title}"
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# end
|
109
|
+
# end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
class Episode
|
4
|
+
|
5
|
+
# Represent an Episode on Allocine website
|
6
|
+
# s = Allocine::Episode.new(233014)
|
7
|
+
# e = s.title
|
8
|
+
|
9
|
+
attr_accessor :title, :synopsis, :number, :release_date
|
10
|
+
|
11
|
+
def initialize(allocine_id)
|
12
|
+
@id = allocine_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the season parent
|
16
|
+
def season
|
17
|
+
Allocine::Season.new(document["parentSeason"]["code"])
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the serie parent
|
21
|
+
def serie
|
22
|
+
Allocine::Serie.new(document["parentSeries"]["code"])
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the title
|
26
|
+
def title
|
27
|
+
document["title"] rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the original title
|
31
|
+
def original_title
|
32
|
+
document["originalTitle"] rescue nil
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the broadcast date
|
36
|
+
def original_broadcast_date
|
37
|
+
document["originalBroadcastDate"] rescue nil
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the plot
|
41
|
+
def plot(short = true)
|
42
|
+
short == true ? document["synopsisShort"] : document["synopsis"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def episode_number_series
|
46
|
+
document["episodeNumberSeries"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def episode_number_season
|
50
|
+
document["episodeNumberSeason"]
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def document
|
56
|
+
@document ||= Allocine::Episode.find_by_id(@id)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find_by_id(allocine_id)
|
60
|
+
url = "http://api.allocine.fr/rest/v3/episode?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
|
61
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["episode"]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
class MovieList
|
4
|
+
def movies
|
5
|
+
@movies ||= parse_movies
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def parse_movies
|
10
|
+
id, originalTitle = nil
|
11
|
+
movies = []
|
12
|
+
document["movie"].each do |element|
|
13
|
+
id = element['code']
|
14
|
+
title = element['originalTitle']
|
15
|
+
movies << Allocine::Movie.new(id, originalTitle)
|
16
|
+
end
|
17
|
+
movies
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
class Search < MovieList
|
4
|
+
attr_reader :query
|
5
|
+
|
6
|
+
# Initialize a new Allocine search with the specified query
|
7
|
+
#
|
8
|
+
# search = Allocine::Search.new("Superman")
|
9
|
+
#
|
10
|
+
def initialize(query)
|
11
|
+
@query = query
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns an array of Allocine::Movie objects for easy search result yielded.
|
15
|
+
def movies
|
16
|
+
@movies ||= parse_movies
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def document
|
21
|
+
@document ||= Allocine::Search.query(@query)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.query(query)
|
25
|
+
url = "http://api.allocine.fr/rest/v3/search?partner=YW5kcm9pZC12M3M&filter=movie,tvseries&q=#{query}&format=json"
|
26
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(URI.encode(url))).body)["feed"] rescue nil
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
class Season
|
4
|
+
attr_accessor :id, :url, :season_number, :episodes
|
5
|
+
|
6
|
+
# Represent a serie Season on Allocine website
|
7
|
+
# s = Allocine::Season.new(12277)
|
8
|
+
# e = s.episodes.first
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(id)
|
12
|
+
@id = id
|
13
|
+
@episodes = []
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns parent serie
|
17
|
+
def serie
|
18
|
+
Allocine::Serie.new(document["parentSeries"]["code"])
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns season number
|
22
|
+
def season_number
|
23
|
+
document["seasonNumber"] rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns numbers of episode
|
27
|
+
def episode_count
|
28
|
+
document["episodeCount"] rescue nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns numbers of episode
|
32
|
+
def episode_numbers
|
33
|
+
document["episode"].size rescue nil
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns an Array of episode ids
|
37
|
+
def episode_ids
|
38
|
+
document["episode"].map { |episode| episode["code"]} rescue []
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns an Array of Allocine::Episode
|
42
|
+
def episodes
|
43
|
+
s = []
|
44
|
+
episode_ids.each do |allocine_id|
|
45
|
+
s << Allocine::Episode.new(allocine_id)
|
46
|
+
end
|
47
|
+
s
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def document
|
53
|
+
@document ||= Allocine::Season.find_by_id(@id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.find_by_id(allocine_id)
|
57
|
+
url = "http://api.allocine.fr/rest/v3/season?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
|
58
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["season"]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
class Serie < AllocineBase
|
4
|
+
|
5
|
+
# s = Allocine::Serie.new(223)
|
6
|
+
# e = s.seasons.first.episodes.first
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(allocine_id, title = nil)
|
10
|
+
@id = allocine_id
|
11
|
+
@url = "http://api.allocine.fr/rest/v3/tvseries?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
|
12
|
+
end
|
13
|
+
|
14
|
+
def number_of_seasons
|
15
|
+
document["seasonCount"] rescue nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def number_of_episodes
|
19
|
+
document["episodeCount"] rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def year_start
|
23
|
+
document["yearStart"] rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def year_end
|
27
|
+
document["yearEnd"] rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def season_ids
|
31
|
+
document["season"].map { |season| season["code"]} rescue []
|
32
|
+
end
|
33
|
+
|
34
|
+
def seasons
|
35
|
+
s = []
|
36
|
+
season_ids.each do |allocine_id|
|
37
|
+
s << Allocine::Season.new(allocine_id)
|
38
|
+
end
|
39
|
+
s
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def document
|
45
|
+
@document ||= Allocine::Serie.find_by_id(@id)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.find_by_id(allocine_id)
|
49
|
+
url = "http://api.allocine.fr/rest/v3/tvseries?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json"
|
50
|
+
JSON.parse(Net::HTTP.get_response(URI.parse(url)).body)["tvseries"]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
|
6
|
+
require "awesome_print"
|
7
|
+
|
8
|
+
libs = " -r irb/completion"
|
9
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
10
|
+
libs << " -r /Users/matthieu/Dev/rails/perso/allocine/lib/allocine_api.rb"
|
11
|
+
puts "Loading allocine gem"
|
12
|
+
exec "#{irb} #{libs} --simple-prompt"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
4
|
+
|
5
|
+
# This test uses "Lost - season 6 episode 1" as a testing sample:
|
6
|
+
#
|
7
|
+
# http://api.allocine.fr/rest/v3/episode?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json
|
8
|
+
#
|
9
|
+
|
10
|
+
describe "Allocine::Episode" do
|
11
|
+
|
12
|
+
describe "valid episode" do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@episode = Allocine::Episode.new("233014")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find the plot" do
|
19
|
+
@episode.plot.should eql("Deux situations parallèles se font face. Dans la première, l'explosion a eu l'effet escompté. A bord du vol Oceanic 815 entre Sydney à Los Angeles, l'appareil subit de violentes turbulences qui cessent rapidement. Mais des choses ont changé : Desmond est là alors qu'à l'origine, il n'était pas à bord...")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find the title" do
|
23
|
+
@episode.title.should =~ /On efface tout/
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find the the broadcast date" do
|
27
|
+
@episode.original_broadcast_date.should eql("2010-02-02")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find the serie parent" do
|
31
|
+
@episode.serie.id.should eql(223)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find the season parent" do
|
35
|
+
@episode.season.id.should eql(12277)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
4
|
+
|
5
|
+
# This test uses "Star Wars : Episode I - La Menace fantôme " as a testing sample:
|
6
|
+
#
|
7
|
+
# http://api.allocine.fr/rest/v3/movie?code=20754&profile=large&format=json&partner=YW5kcm9pZC12M3M
|
8
|
+
#
|
9
|
+
|
10
|
+
describe "Allocine::Movie" do
|
11
|
+
|
12
|
+
describe "valid movie" do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@movie = Allocine::Movie.new("20754")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find the cast members" do
|
19
|
+
cast = @movie.actors
|
20
|
+
|
21
|
+
cast.should be_an(Array)
|
22
|
+
cast.should include("Liam Neeson")
|
23
|
+
cast.should include("Natalie Portman")
|
24
|
+
cast.should include("Jake Lloyd")
|
25
|
+
cast.should include("Ian McDiarmid")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should find the directors" do
|
29
|
+
@movie.directors.should be_an(Array)
|
30
|
+
@movie.directors.size.should eql(1)
|
31
|
+
@movie.directors.first.should =~ /George Lucas/
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find the genres" do
|
35
|
+
genres = @movie.genres
|
36
|
+
genres.should be_an(Array)
|
37
|
+
genres.should include('Science fiction')
|
38
|
+
genres.should include('Fantastique')
|
39
|
+
genres.should include('Aventure')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find the countries" do
|
43
|
+
countries = @movie.countries
|
44
|
+
|
45
|
+
countries.should be_an(Array)
|
46
|
+
countries.size.should eql(1)
|
47
|
+
countries.should include('U.S.A.')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should find the length (in minutes)" do
|
51
|
+
@movie.length.should eql(133)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should find the plot" do
|
55
|
+
@movie.plot.should eql("Il y a bien longtemps, dans une galaxie très lointaine... La Fédération du Commerce impose par la force la taxation des routes commerciales à la pacifique planète Naboo. Les chevaliers Jedi Qui-Gon Jinn et Obi-Wan Kenobi sont envoyés sur place...")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should find the poster" do
|
59
|
+
@movie.poster.should eql("http://images.allocine.fr/medias/nmedia/18/86/24/04/19835018.jpg")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find the press rating" do
|
63
|
+
@movie.press_rating.should eql(3.125)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should find the title" do
|
67
|
+
@movie.title.should =~ /Star Wars : Episode I - La Menace fantôme/
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find the production year" do
|
71
|
+
@movie.production_year.should eql(1999)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should find the release date" do
|
75
|
+
@movie.release_date.should eql("1999-10-13")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should find the trailer" do
|
79
|
+
@movie.trailer.should eql("http://www.allocine.fr/blogvision/19259278")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
4
|
+
|
5
|
+
# This test uses "Lost - season 6" as a testing sample:
|
6
|
+
#
|
7
|
+
# http://api.allocine.fr/rest/v3/season?partner=YW5kcm9pZC12M3M&code=#{allocine_id}&profile=large&format=json
|
8
|
+
#
|
9
|
+
|
10
|
+
describe "Allocine::Season" do
|
11
|
+
|
12
|
+
describe "valid season" do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@serie = Allocine::Season.new("12277")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find the season_number" do
|
19
|
+
@serie.season_number.should eql(6)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find the episode count" do
|
23
|
+
@serie.episode_count.should eql(18)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find the serie parent" do
|
27
|
+
@serie.serie.id.should eql(223)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require 'spec'
|
4
|
+
rescue LoadError
|
5
|
+
require 'rubygems'
|
6
|
+
gem 'rspec'
|
7
|
+
# require 'spec'
|
8
|
+
end
|
9
|
+
|
10
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
11
|
+
require 'allocine'
|
12
|
+
|
13
|
+
def read_fixture(path)
|
14
|
+
File.read(File.expand_path(File.join(File.dirname(__FILE__), "fixtures", path)))
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: allocine_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthieu Lamarque
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-06 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rdoc
|
17
|
+
requirement: &2165201360 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2165201360
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2165200860 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2165200860
|
37
|
+
description: Easily use Ruby to find information on allocine API.
|
38
|
+
email:
|
39
|
+
- lamarque.matthieu@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- History.txt
|
47
|
+
- Manifest.txt
|
48
|
+
- README.rdoc
|
49
|
+
- allocine_parser.gemspec
|
50
|
+
- lib/allocine_parser.rb
|
51
|
+
- lib/allocine_parser/allocine_base.rb
|
52
|
+
- lib/allocine_parser/cli.rb
|
53
|
+
- lib/allocine_parser/episode.rb
|
54
|
+
- lib/allocine_parser/movie.rb
|
55
|
+
- lib/allocine_parser/movie_list.rb
|
56
|
+
- lib/allocine_parser/search.rb
|
57
|
+
- lib/allocine_parser/season.rb
|
58
|
+
- lib/allocine_parser/serie.rb
|
59
|
+
- lib/allocine_parser/version.rb
|
60
|
+
- script/console
|
61
|
+
- spec/allocine/episode_spec.rb
|
62
|
+
- spec/allocine/movie_spec.rb
|
63
|
+
- spec/allocine/season_spec.rb
|
64
|
+
- spec/allocine/serie_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/mlamarque/allocine
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: allocine_parser
|
87
|
+
rubygems_version: 1.6.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Easily access the API information on Allocine API.
|
91
|
+
test_files: []
|