the_tvdb 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/the_tvdb/episode.rb +17 -30
- data/lib/the_tvdb/gateway.rb +8 -11
- data/lib/the_tvdb/show.rb +7 -3
- data/lib/the_tvdb/version.rb +1 -1
- data/lib/the_tvdb.rb +3 -3
- data/spec/fixtures/tvdb_cassettes/shows.yml +46 -0
- data/spec/lib/the_tvdb/episode_spec.rb +16 -0
- data/spec/lib/the_tvdb/show_spec.rb +5 -0
- metadata +2 -2
data/lib/the_tvdb/episode.rb
CHANGED
@@ -1,16 +1,31 @@
|
|
1
1
|
module TheTvdb
|
2
2
|
class Episode
|
3
3
|
|
4
|
-
attr_accessor :remote_id, :season_remote_id, :season_number, :name, :number, :aired_at, :description
|
4
|
+
attr_accessor :remote_id, :season_remote_id, :season_number, :name, :number, :aired_at, :description,
|
5
|
+
:guest_stars, :director, :writer, :updated_at, :dvd_disc, :dvd_season, :dvd_episode_number, :dvd_chapter,
|
6
|
+
:absolute_number, :image_url, :imdb_id, :language, :production_code
|
5
7
|
|
6
8
|
def initialize(info)
|
7
9
|
@remote_id = info['id'].to_i
|
8
10
|
@season_remote_id = info['seasonid'].to_i
|
9
|
-
@season_number = info['
|
11
|
+
@season_number = info['SeasonNumber'].to_i
|
10
12
|
@name = info['EpisodeName']
|
11
13
|
@number = info['EpisodeNumber'].to_i
|
12
14
|
@aired_at = info['FirstAired']
|
13
15
|
@description = info['Overview']
|
16
|
+
@guest_stars = info['GuestStars']
|
17
|
+
@director = info['Director']
|
18
|
+
@writer = info['Writer']
|
19
|
+
@updated_at = Time.at(info['lastupdated'].to_i)
|
20
|
+
@dvd_disc = info['DVD_discid']
|
21
|
+
@dvd_season = info['DVD_season']
|
22
|
+
@dvd_episode_number = info['DVD_episodenumber']
|
23
|
+
@dvd_chapter = info['DVD_chapter']
|
24
|
+
@absolute_number = info['absolute_number']
|
25
|
+
@image_url = "#{TheTvdb.gateway.mirror}/banners/#{info['filename']}"
|
26
|
+
@imdb_id = info['IMDB_ID']
|
27
|
+
@language = info['Language']
|
28
|
+
@prodiction_code = info['ProductionCode']
|
14
29
|
end
|
15
30
|
|
16
31
|
def self.find(remote_id)
|
@@ -28,31 +43,3 @@ module TheTvdb
|
|
28
43
|
|
29
44
|
end
|
30
45
|
end
|
31
|
-
|
32
|
-
# For reference, the episode yaml:
|
33
|
-
#
|
34
|
-
# id: '4245778'
|
35
|
-
# seasonid: '473271'
|
36
|
-
# EpisodeNumber: '9'
|
37
|
-
# EpisodeName: Blackwater
|
38
|
-
# FirstAired: '2012-05-28'
|
39
|
-
# GuestStars:
|
40
|
-
# Director: Neil Marshall
|
41
|
-
# Writer: George R. R. Martin
|
42
|
-
# Overview: Tyrion and the Lannisters fight for their lives as Stannis’ fleet assaults King’s Landing.
|
43
|
-
# ProductionCode:
|
44
|
-
# lastupdated: '1352849383'
|
45
|
-
# flagged: '0'
|
46
|
-
# DVD_discid:
|
47
|
-
# DVD_season: '2'
|
48
|
-
# DVD_episodenumber: '9.0'
|
49
|
-
# DVD_chapter:
|
50
|
-
# absolute_number: '19'
|
51
|
-
# filename: episodes/121361/4245778.jpg
|
52
|
-
# seriesid: '121361'
|
53
|
-
# mirrorupdate: '2012-11-13 15:28:01'
|
54
|
-
# IMDB_ID: tt2084342
|
55
|
-
# EpImgFlag: '2'
|
56
|
-
# Rating: '8.4'
|
57
|
-
# SeasonNumber: '2'
|
58
|
-
# Language: en
|
data/lib/the_tvdb/gateway.rb
CHANGED
@@ -23,11 +23,14 @@ module TheTvdb
|
|
23
23
|
config.episodes_path
|
24
24
|
end
|
25
25
|
|
26
|
+
attr_accessor :api_key, :mirror, :api_path, :last_updated
|
27
|
+
|
26
28
|
# TODO: setup a reliable env system for apikey
|
27
29
|
def initialize(api_key = nil)
|
28
30
|
@api_key = config.api_key
|
29
31
|
raise 'No API key was provided. Please set one as TheTvdb::Configuration.apikey or as an environment variable (e.g.: `export TVDBKEY=1234567898765432`).' if !@api_key
|
30
32
|
@mirror = get_mirror
|
33
|
+
@api_path = "#{@mirror}/api/#{@api_key}"
|
31
34
|
end
|
32
35
|
|
33
36
|
ENDPOINT = 'http://www.thetvdb.com/api/'
|
@@ -36,20 +39,15 @@ module TheTvdb
|
|
36
39
|
ENDPOINT
|
37
40
|
end
|
38
41
|
|
39
|
-
# def api_key
|
40
|
-
# APIKEY
|
41
|
-
# end
|
42
|
-
|
43
42
|
def get_mirror
|
44
43
|
hash = xml_to_hash "#{endpoint}#{@api_key}/mirrors.xml", 'Mirror'
|
45
|
-
|
44
|
+
hash['mirrorpath']
|
46
45
|
end
|
47
46
|
|
48
47
|
def update(time)
|
49
48
|
hash = xml_to_hash "#{endpoint}/Updates.php?time=#{time || last_updated}", 'Items'
|
50
49
|
end
|
51
50
|
|
52
|
-
attr_accessor :last_updated
|
53
51
|
def time
|
54
52
|
@last_updated = xml_to_hash "#{endpoint}/Updates.php?type=none", 'Time'
|
55
53
|
end
|
@@ -64,14 +62,13 @@ module TheTvdb
|
|
64
62
|
def get_series_package(seriesid, language = 'en')
|
65
63
|
begin
|
66
64
|
open("#{zip_path}/#{seriesid}.zip", 'wb') do |file|
|
67
|
-
file << open("#{@
|
65
|
+
file << open("#{@api_path}/series/#{seriesid}/all/#{language}.zip").read
|
68
66
|
end
|
69
67
|
unzip_file("#{zip_path}/#{seriesid}.zip", "#{data_path}/xml/#{seriesid}")
|
70
68
|
xml_to_hash "#{data_path}/xml/#{seriesid}/#{language}.xml", 'Data'
|
71
69
|
rescue Exception => e
|
72
|
-
|
73
|
-
|
74
|
-
puts "#{@mirror}/series/#{seriesid}/all/#{language}.zip"
|
70
|
+
puts "Could not retrieve series package"
|
71
|
+
puts "#{@api_path}/series/#{seriesid}/all/#{language}.zip"
|
75
72
|
nil
|
76
73
|
end
|
77
74
|
end
|
@@ -79,7 +76,7 @@ module TheTvdb
|
|
79
76
|
def get_episode_details(episodeid, language = 'en')
|
80
77
|
file_path = "#{episodes_path}/#{episodeid}.xml"
|
81
78
|
open(file_path, 'wb') do |file|
|
82
|
-
file << open("#{@
|
79
|
+
file << open("#{@api_path}/episodes/#{episodeid}/#{language}.xml").read
|
83
80
|
end
|
84
81
|
xml_to_hash(file_path, 'Episode')
|
85
82
|
end
|
data/lib/the_tvdb/show.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module TheTvdb
|
2
2
|
class Show
|
3
3
|
|
4
|
-
attr_accessor :remote_id, :name, :banner, :description, :episodes, :seasons
|
4
|
+
attr_accessor :remote_id, :name, :banner, :description, :episodes, :seasons,
|
5
|
+
:first_aired, :imdb_id, :zap2it_id, :language
|
5
6
|
|
6
7
|
def self.search(name)
|
7
8
|
shows = TheTvdb.gateway.get_series(name)
|
@@ -18,9 +19,12 @@ module TheTvdb
|
|
18
19
|
def initialize(info)
|
19
20
|
@remote_id = info['id'].to_i
|
20
21
|
@name = info['SeriesName']
|
21
|
-
@banner = info['banner']
|
22
|
+
@banner = "#{TheTvdb.gateway.mirror}/banners/#{info['banner']}"
|
22
23
|
@description = info['Overview']
|
23
|
-
|
24
|
+
@imdb_id = info['IMDB_ID']
|
25
|
+
@zap2it_id = info['zap2it_id']
|
26
|
+
@first_aired = info['FirstAired']
|
27
|
+
@language = info['language']
|
24
28
|
end
|
25
29
|
|
26
30
|
def to_hash
|
data/lib/the_tvdb/version.rb
CHANGED
data/lib/the_tvdb.rb
CHANGED
@@ -21,10 +21,10 @@ module TheTvdb
|
|
21
21
|
# Starting from the last update recorded on the gateway, a hash with the new
|
22
22
|
# update time and the updated shows are returned
|
23
23
|
#
|
24
|
-
# @param [Integer] timestamp the last update timestamp (if not provided the last_updated attribute of
|
24
|
+
# @param [Integer] timestamp the last update timestamp (if not provided the last_updated attribute of Gateway is used instead)
|
25
25
|
# @return [Hash] the new last_updated time and the Shows that have been updated
|
26
|
-
def self.update(
|
27
|
-
update_hash = gateway.update(
|
26
|
+
def self.update(timestamp = nil)
|
27
|
+
update_hash = gateway.update(timestamp)
|
28
28
|
result = { time: update_hash['Time'].to_i }
|
29
29
|
result[:shows] = update_hash['Series'].map {|show_remote_id| Show.find(show_remote_id) }
|
30
30
|
gateway.last_updated = result[:time]
|
@@ -787,4 +787,50 @@ http_interactions:
|
|
787
787
|
YWN0b3JzLnhtbFVUBQADIyHUUFV4AABQSwUGAAAAAAMAAwDMAAAAoi8AAAAA
|
788
788
|
http_version:
|
789
789
|
recorded_at: Fri, 21 Dec 2012 09:07:11 GMT
|
790
|
+
- request:
|
791
|
+
method: get
|
792
|
+
uri: http://www.thetvdb.com/api/1234567898765432/mirrors.xml
|
793
|
+
body:
|
794
|
+
encoding: US-ASCII
|
795
|
+
string: ''
|
796
|
+
headers:
|
797
|
+
Accept:
|
798
|
+
- ! '*/*'
|
799
|
+
User-Agent:
|
800
|
+
- Ruby
|
801
|
+
response:
|
802
|
+
status:
|
803
|
+
code: 200
|
804
|
+
message: OK
|
805
|
+
headers:
|
806
|
+
Server:
|
807
|
+
- cloudflare-nginx
|
808
|
+
Date:
|
809
|
+
- Mon, 24 Dec 2012 15:05:53 GMT
|
810
|
+
Content-Type:
|
811
|
+
- text/xml
|
812
|
+
Transfer-Encoding:
|
813
|
+
- chunked
|
814
|
+
Connection:
|
815
|
+
- keep-alive
|
816
|
+
Last-Modified:
|
817
|
+
- Mon, 24 Dec 2012 15:00:04 GMT
|
818
|
+
Vary:
|
819
|
+
- Accept-Encoding
|
820
|
+
Expires:
|
821
|
+
- Mon, 24 Dec 2012 15:20:53 GMT
|
822
|
+
Cache-Control:
|
823
|
+
- max-age=900
|
824
|
+
Set-Cookie:
|
825
|
+
- __cfduid=ded407954e27e753fec08053c0413972b1356361553; expires=Mon, 23-Dec-2019
|
826
|
+
23:50:00 GMT; path=/; domain=.thetvdb.com
|
827
|
+
Cf-Ray:
|
828
|
+
- 25eaf5b6b12048b
|
829
|
+
body:
|
830
|
+
encoding: US-ASCII
|
831
|
+
string: ! "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<Mirrors>\n <Mirror>\n
|
832
|
+
\ <id>1</id>\n <mirrorpath>http://thetvdb.com</mirrorpath>\n <typemask>7</typemask>\n
|
833
|
+
\ </Mirror>\n</Mirrors>\n"
|
834
|
+
http_version:
|
835
|
+
recorded_at: Mon, 24 Dec 2012 15:05:53 GMT
|
790
836
|
recorded_with: VCR 2.3.0
|
@@ -21,8 +21,24 @@ describe TheTvdb::Episode do
|
|
21
21
|
it "should return all the info of the episode" do
|
22
22
|
episode.name.should == 'Blackwater'
|
23
23
|
episode.number.should == 9
|
24
|
+
episode.season_number.should == 2
|
24
25
|
episode.aired_at.should == '2012-05-28'
|
25
26
|
episode.description.should == "Tyrion and the Lannisters fight for their lives as Stannis’ fleet assaults King’s Landing."
|
27
|
+
episode.season_remote_id.should == 473271
|
28
|
+
episode.guest_stars.should be_nil
|
29
|
+
episode.director.should == 'Neil Marshall'
|
30
|
+
episode.writer.should == 'George R. R. Martin'
|
31
|
+
episode.updated_at.should == Time.at(1352849383)
|
32
|
+
# episode.flagged.should == '0'
|
33
|
+
episode.dvd_disc.should be_nil
|
34
|
+
episode.dvd_season.should == '2'
|
35
|
+
episode.dvd_episode_number.should == '9.0'
|
36
|
+
episode.dvd_chapter.should be_nil
|
37
|
+
episode.absolute_number.should == '19'
|
38
|
+
episode.image_url.should == 'http://thetvdb.com/banners/episodes/121361/4245778.jpg'
|
39
|
+
episode.imdb_id.should == 'tt2084342'
|
40
|
+
episode.language.should == 'en'
|
41
|
+
episode.production_code.should be_nil
|
26
42
|
end
|
27
43
|
|
28
44
|
end
|
@@ -23,6 +23,11 @@ describe TheTvdb::Show do
|
|
23
23
|
show.remote_id.should == 121361
|
24
24
|
description = 'Based on the fantasy novel series "A Song of Ice and Fire," Game of Thrones explores the story of an epic battle among seven kingdoms and two ruling families in the only game that matters - the Game of Thrones. All seek control of the Iron Throne, the possession of which ensures survival through the 40-year winter to come.'
|
25
25
|
show.description.should == description
|
26
|
+
show.imdb_id.should == 'tt0944947'
|
27
|
+
show.zap2it_id.should == 'SH01389809'
|
28
|
+
show.first_aired.should == '2011-04-17'
|
29
|
+
show.banner.should == 'http://thetvdb.com/banners/graphical/121361-g26.jpg'
|
30
|
+
show.language.should == 'en'
|
26
31
|
end
|
27
32
|
|
28
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_tvdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|