ttvdb 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +100 -0
- data/Rakefile +1 -0
- data/examples/ttvdb_example.rb +27 -0
- data/lib/ttvdb.rb +12 -0
- data/lib/ttvdb/client.rb +66 -0
- data/lib/ttvdb/episode.rb +21 -0
- data/lib/ttvdb/season.rb +12 -0
- data/lib/ttvdb/series.rb +83 -0
- data/lib/ttvdb/version.rb +3 -0
- data/ttvdb.gemspec +25 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f175e7222b5c8c526e4594e50438168996e2402
|
4
|
+
data.tar.gz: ba8694c7d81d5b004b694bc967ef21b6cac185dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 444a34b040bb8b3fe64c87c48ae307497cc39034e2dfdc893c1e1901b0b8fe3fc400690be2ef5196f527e7d77893150d56350c44cd44ff4512efe49e2ed49320
|
7
|
+
data.tar.gz: 7c0de0ccc8d84595c9665699d2d7b5db0efaa4ca02437a7dd31076efb4e64fca08fc7bd6e69a7630e50a6aace62356261e52c5dbe8140c5379cc80ab18f0c2df
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Konrad Lother
|
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,100 @@
|
|
1
|
+
# TTVDB
|
2
|
+
|
3
|
+
This is another [TheTVDB.com](http://www.thetvdb.com) API library. The others out there didn't fit my needs (if they even worked).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'ttvdb'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install ttvdb
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Require the gem
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'ttvdb'
|
26
|
+
```
|
27
|
+
|
28
|
+
Create a ```TTVDB::Client``` instance
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
client = TTVDB::Client.new(options={})
|
32
|
+
```
|
33
|
+
|
34
|
+
| key | value | description
|
35
|
+
| --- | :---: | --- |
|
36
|
+
| ```:api_key``` | api key | Your TheTVDB API Key, *optional* |
|
37
|
+
| ```:api_url``` | http://www.thetvdb.com/api/ | API Url, *optional* |
|
38
|
+
| ```:language```|```en```,```de```,```fr```,... | The language code to use. Fallback is ```en```, *optional* |
|
39
|
+
|
40
|
+
Fetch series by name. Returns an array of series if result count is more than 1.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
series = client.get_series "Saber Rider"
|
44
|
+
```
|
45
|
+
|
46
|
+
Results to an array of 3 ```TTVDB::Series``` instances.
|
47
|
+
|
48
|
+
# Example
|
49
|
+
|
50
|
+
This is an example script that fetches a series by ARGV. if ARGV is an integer, it ill fetch it by its id otherwise by its name. It will then print a little overview about the series.
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
```bash
|
54
|
+
$ ruby ttvdb_example.rb "Galaxy Rangers"
|
55
|
+
# or
|
56
|
+
$ ruby ttvdb_example.rb 77772
|
57
|
+
```
|
58
|
+
|
59
|
+
## Code
|
60
|
+
```ruby
|
61
|
+
#!/usr/bin/env ruby
|
62
|
+
require "ttvdb"
|
63
|
+
|
64
|
+
TTVDB.logger.level = Logger::WARN
|
65
|
+
|
66
|
+
client = TTVDB::Client.new
|
67
|
+
series = nil
|
68
|
+
|
69
|
+
if ARGV[0].to_i > 0
|
70
|
+
series = [client.get_series_by_id(ARGV[0].to_i)]
|
71
|
+
else
|
72
|
+
series = client.get_series ARGV[0]
|
73
|
+
end
|
74
|
+
|
75
|
+
series.each do |serie|
|
76
|
+
puts serie.name
|
77
|
+
puts "Overview:"
|
78
|
+
puts serie.overview
|
79
|
+
|
80
|
+
puts ""
|
81
|
+
serie.seasons.each do |season, episodes|
|
82
|
+
puts "Season: %02d" % season
|
83
|
+
episodes.each do |number, episode|
|
84
|
+
puts " #%02d - %s" % [number, episode.name]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
See the ```examples/``` folder for a complete list of examples. I try to make them as easy to understand as possible.
|
92
|
+
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it ( http://github.com/<my-github-username>/ttvdb/fork )
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "ttvdb"
|
3
|
+
|
4
|
+
TTVDB.logger.level = Logger::WARN
|
5
|
+
|
6
|
+
client = TTVDB::Client.new
|
7
|
+
series = nil
|
8
|
+
|
9
|
+
if ARGV[0].to_i > 0
|
10
|
+
series = [client.get_series_by_id(ARGV[0].to_i)]
|
11
|
+
else
|
12
|
+
series = client.get_series ARGV[0]
|
13
|
+
end
|
14
|
+
|
15
|
+
series.each do |serie|
|
16
|
+
puts serie.name
|
17
|
+
puts "Overview:"
|
18
|
+
puts serie.overview
|
19
|
+
|
20
|
+
puts ""
|
21
|
+
serie.seasons.each do |season, episodes|
|
22
|
+
puts "Season: %02d" % season
|
23
|
+
episodes.each do |number, episode|
|
24
|
+
puts " #%02d - %s" % [number, episode.name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ttvdb.rb
ADDED
data/lib/ttvdb/client.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'ttvdb/series'
|
2
|
+
require 'ttvdb/episode'
|
3
|
+
|
4
|
+
class TTVDB::Client
|
5
|
+
attr_writer :language
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
@opts = {
|
9
|
+
:api_url => 'http://www.thetvdb.com/api/',
|
10
|
+
:api_key => '530293E55310DAB2',
|
11
|
+
:language => 'en',
|
12
|
+
}.merge!opts
|
13
|
+
@language = @opts[:language]
|
14
|
+
@apikey = @opts[:api_key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_series_by_id id
|
18
|
+
lookup = "series/#{id}/#{@opts[:language]}.xml"
|
19
|
+
begin
|
20
|
+
hsh = XmlSimple.xml_in(client[lookup].get)
|
21
|
+
return TTVDB::Series.new(hsh["Series"][0], :client => self)
|
22
|
+
rescue Exception => e
|
23
|
+
raise
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_series name
|
28
|
+
_client = RestClient::Resource.new("#{@opts[:api_url]}/GetSeries.php", :headers => { :params => { 'seriesname' => name, 'language' => @language }})
|
29
|
+
begin
|
30
|
+
hsh = XmlSimple.xml_in(_client.get)
|
31
|
+
return [] unless hsh["Series"]
|
32
|
+
series = []
|
33
|
+
hsh["Series"].each do |s|
|
34
|
+
serie = TTVDB::Series.new(s, :client => self)
|
35
|
+
next if serie.language != @language
|
36
|
+
series << serie
|
37
|
+
end
|
38
|
+
return series
|
39
|
+
rescue Exception => e
|
40
|
+
TTVDB.logger.error { "Error while fetching series: #{e.message}" }
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_episodes_by_series_id id
|
46
|
+
lookup = "series/#{id}/all/#{@opts[:language]}.xml"
|
47
|
+
begin
|
48
|
+
hsh = XmlSimple.xml_in(client[lookup].get)
|
49
|
+
return [] unless hsh["Episode"]
|
50
|
+
episodes = []
|
51
|
+
hsh["Episode"].each do |e|
|
52
|
+
episodes << TTVDB::Episode.new(e, :client => self)
|
53
|
+
end
|
54
|
+
return episodes
|
55
|
+
rescue Exception => e
|
56
|
+
TTVDB.logger.error("get_episodes_by_series_id") { "Could not create hash from result: #{e.message}" }
|
57
|
+
raise
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def client
|
63
|
+
@client ||= RestClient::Resource.new("#{@opts[:api_url]}/#{@apikey}/")
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class TTVDB::Episode
|
2
|
+
attr_reader :id, :number, :name, :overview, :season_id, :series_id,
|
3
|
+
:combined_number, :combined_season
|
4
|
+
|
5
|
+
attr_writer :client, :series
|
6
|
+
|
7
|
+
def initialize(data, options={})
|
8
|
+
options.merge! data
|
9
|
+
@id = options["id"][0].to_i rescue nil
|
10
|
+
@number = options["EpisodeNumber"][0].to_i rescue nil
|
11
|
+
@name = options["EpisodeName"][0] rescue nil
|
12
|
+
@overview = options["Overview"][0] rescue nil
|
13
|
+
@season_id = options["seasonid"][0].to_i rescue nil
|
14
|
+
@series_id = options["seriesid"][0].to_i rescue nil
|
15
|
+
@combined_number = options["Combined_episodenumber"][0].to_i rescue nil
|
16
|
+
@combined_season = options["Combined_season"][0].to_i rescue nil
|
17
|
+
@client = options[:client] rescue nil
|
18
|
+
@series = options[:series] rescue nil
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/ttvdb/season.rb
ADDED
data/lib/ttvdb/series.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
class TTVDB::Series
|
2
|
+
attr_reader :id, :actors, :airs_dayofweek, :airs_time,
|
3
|
+
:content_rating, :first_aired, :genre, :imdb_id, :language,
|
4
|
+
:network, :network_id, :overview, :rating, :rating_count,
|
5
|
+
:runtime, :series_id, :series_name, :status, :added, :added_by,
|
6
|
+
:banner, :fanart, :last_updated, :poster, :zap2it_id, :episodes, :seasons,
|
7
|
+
:name
|
8
|
+
|
9
|
+
attr_writer :client
|
10
|
+
|
11
|
+
def initialize(data, options={})
|
12
|
+
options.merge! data
|
13
|
+
@id = options["id"][0].to_i rescue nil
|
14
|
+
@actors = options["Actors"][0].split("|").compact rescue []
|
15
|
+
@airs_dayofweek = options["Airs_DayOfWeek"][0] rescue nil
|
16
|
+
@airs_time = options["Airs_Time"][0] rescue nil
|
17
|
+
@content_rating = options["ContentRating"][0].to_f rescue 0
|
18
|
+
@first_aired = Time.parse(options["FirstAired"][0]) rescue nil
|
19
|
+
@genre = options["Genre"][0].split("|").compact rescue []
|
20
|
+
@imdb_id = options["IMDB_ID"][0].to_i rescue nil
|
21
|
+
@language = options["language"][0] rescue nil
|
22
|
+
@language ||= options["Language"][0] rescue "en"
|
23
|
+
@network = options["Network"][0] rescue nil
|
24
|
+
@network_id = options["NetworkID"][0] rescue nil
|
25
|
+
@overview = options["Overview"][0] rescue nil
|
26
|
+
@rating = options["Rating"][0].to_f rescue 0
|
27
|
+
@rating_count = options["RatingCount"][0] rescue 0
|
28
|
+
@runtime = options["Runtime"][0].to_i rescue nil
|
29
|
+
@runtime ||= options["runtime"][0].to_i rescue 0
|
30
|
+
@series_id = options["SeriesID"][0].to_i rescue nil
|
31
|
+
@series_name = options["SeriesName"][0] rescue nil
|
32
|
+
@name = @series_name
|
33
|
+
@status = options["Status"][0].downcase rescue nil
|
34
|
+
@added = options["added"][0] rescue nil
|
35
|
+
@added_by = options["addedBy"][0] rescue nil
|
36
|
+
@banner = options["banner"][0] rescue nil
|
37
|
+
@fanart = options["fanart"][0] rescue nil
|
38
|
+
@last_updated = Time.at(options["lastupdated"][0].to_i) rescue nil
|
39
|
+
@poster = options["poster"][0] rescue nil
|
40
|
+
@zap2it_id = options["zap2it_id"][0] rescue nil
|
41
|
+
@client = options[:client] rescue nil
|
42
|
+
@seasons = {}
|
43
|
+
TTVDB.logger.debug { "Series language: #{@language}" }
|
44
|
+
fetch_episodes
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
private
|
49
|
+
def fetch_episodes
|
50
|
+
raise Exception, "client not configured" unless @client
|
51
|
+
@episodes = @client.get_episodes_by_series_id @id
|
52
|
+
return unless @episodes
|
53
|
+
@episodes.each do |episode|
|
54
|
+
unless @seasons[episode.combined_season]
|
55
|
+
@seasons[episode.combined_season] = {}
|
56
|
+
end
|
57
|
+
@seasons[episode.combined_season][episode.number] = episode
|
58
|
+
end
|
59
|
+
sort_episodes!
|
60
|
+
end
|
61
|
+
|
62
|
+
def sort_episodes!
|
63
|
+
special = []
|
64
|
+
sorted = {}
|
65
|
+
@seasons.each do |season, data|
|
66
|
+
data.each do |n, e|
|
67
|
+
if season == 0
|
68
|
+
special << e
|
69
|
+
else
|
70
|
+
sorted[season] ||= []
|
71
|
+
sorted[season] << e
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
sorted = Hash[sorted.sort_by {|k,v| k.to_i }]
|
76
|
+
new_episodes = []
|
77
|
+
sorted.each do |season, episodes|
|
78
|
+
new_episodes << episodes
|
79
|
+
end
|
80
|
+
new_episodes << special # specials at the end
|
81
|
+
@episodes = new_episodes.flatten.compact
|
82
|
+
end
|
83
|
+
end
|
data/ttvdb.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 'ttvdb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ttvdb"
|
8
|
+
spec.version = TTVDB::VERSION
|
9
|
+
spec.authors = ["Konrad Lother"]
|
10
|
+
spec.email = ["konrad@corpex.de"]
|
11
|
+
spec.summary = %q{The TVDB API Library}
|
12
|
+
spec.description = %q{The TVDB API Library - Another the tvdb api library}
|
13
|
+
spec.homepage = "https://github.com/lotherk/ttvdb"
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "xml-simple"
|
24
|
+
spec.add_dependency "rest-client"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ttvdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konrad Lother
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-10 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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: xml-simple
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: The TVDB API Library - Another the tvdb api library
|
70
|
+
email:
|
71
|
+
- konrad@corpex.de
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- examples/ttvdb_example.rb
|
82
|
+
- lib/ttvdb.rb
|
83
|
+
- lib/ttvdb/client.rb
|
84
|
+
- lib/ttvdb/episode.rb
|
85
|
+
- lib/ttvdb/season.rb
|
86
|
+
- lib/ttvdb/series.rb
|
87
|
+
- lib/ttvdb/version.rb
|
88
|
+
- ttvdb.gemspec
|
89
|
+
homepage: https://github.com/lotherk/ttvdb
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.1.10
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: The TVDB API Library
|
113
|
+
test_files: []
|