the_tvdb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  TheTvdb.setup do |config|
2
- config.api_key = 'ABC123DEF456GHI7' # Your API here, get one at http://thetvdb.com/?tab=apiregister
2
+ # config.api_key = 'ABC123DEF456GHI7' # Your API key here, get one at http://thetvdb.com/?tab=apiregister
3
3
  end
@@ -22,7 +22,7 @@ module TheTvdb
22
22
  @dvd_episode_number = info['DVD_episodenumber']
23
23
  @dvd_chapter = info['DVD_chapter']
24
24
  @absolute_number = info['absolute_number']
25
- @image_url = "#{TheTvdb.gateway.mirror}/banners/#{info['filename']}"
25
+ @image_url = "#{TheTvdb.gateway.mirror}/banners/#{info['filename']}" unless info['filename'].nil?
26
26
  @imdb_id = info['IMDB_ID']
27
27
  @language = info['Language']
28
28
  @prodiction_code = info['ProductionCode']
@@ -35,9 +35,26 @@ module TheTvdb
35
35
 
36
36
  def to_hash
37
37
  {
38
- remote_id: @remote_id, name: @name, description: @description,
39
- season_remote_id: @season_remote_id, season_number: @season_number,
40
- number: @number, aired_at: @aired_at
38
+ remote_id: @remote_id,
39
+ name: @name,
40
+ description: @description,
41
+ season_remote_id: @season_remote_id,
42
+ season_number: @season_number,
43
+ number: @number,
44
+ aired_at: @aired_at,
45
+ guest_stars: @guest_stars,
46
+ director: @director,
47
+ writer: @writer,
48
+ updated_at: @updated_at,
49
+ dvd_disc: @dvd_disc,
50
+ dvd_season: @dvd_season,
51
+ dvd_episode_number: @dvd_episode_number,
52
+ dvd_chapter: @dvd_chapter,
53
+ absolute_number: @absolute_number,
54
+ image_url: @image_url,
55
+ imdb_id: @imdb_id,
56
+ language: @language,
57
+ production_code: @production_code
41
58
  }
42
59
  end
43
60
 
@@ -25,9 +25,8 @@ module TheTvdb
25
25
 
26
26
  attr_accessor :api_key, :mirror, :api_path, :last_updated
27
27
 
28
- # TODO: setup a reliable env system for apikey
29
28
  def initialize(api_key = nil)
30
- @api_key = config.api_key
29
+ @api_key = config.api_key || ENV['TVDBKEY']
31
30
  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
32
31
  @mirror = get_mirror
33
32
  @api_path = "#{@mirror}/api/#{@api_key}"
@@ -45,18 +44,22 @@ module TheTvdb
45
44
  end
46
45
 
47
46
  def update(time)
47
+ raise "A time reference to get updates is required. Please use set_time to fetch a first reference" unless (time || last_updated)
48
48
  hash = xml_to_hash "#{endpoint}/Updates.php?time=#{time || last_updated}", 'Items'
49
49
  end
50
50
 
51
51
  def time
52
- @last_updated = xml_to_hash "#{endpoint}/Updates.php?type=none", 'Time'
52
+ xml_to_hash "#{endpoint}/Updates.php?type=none", 'Time'
53
+ end
54
+
55
+ # Useful for first time updating
56
+ def set_time
57
+ @last_updated = time
53
58
  end
54
59
 
55
60
  def get_series(name)
56
61
  doc = open_xml "#{endpoint}/GetSeries.php?seriesname=#{URI.escape(name)}"
57
- result = doc.css('Series').map { |series| Hash.from_xml(series.to_s)['Series'] }
58
- #puts result.to_yaml
59
- result
62
+ doc.css('Series').map { |series| Hash.from_xml(series.to_s)['Series'] }
60
63
  end
61
64
 
62
65
  def get_series_package(seriesid, language = 'en')
@@ -67,9 +70,7 @@ module TheTvdb
67
70
  unzip_file("#{zip_path}/#{seriesid}.zip", "#{data_path}/xml/#{seriesid}")
68
71
  xml_to_hash "#{data_path}/xml/#{seriesid}/#{language}.xml", 'Data'
69
72
  rescue Exception => e
70
- puts "Could not retrieve series package"
71
- puts "#{@api_path}/series/#{seriesid}/all/#{language}.zip"
72
- nil
73
+ puts "Could not retrieve series package - #{@api_path}/series/#{seriesid}/all/#{language}.zip"
73
74
  end
74
75
  end
75
76
 
@@ -88,8 +89,7 @@ module TheTvdb
88
89
  location = (xml =~ URI::regexp) ? open(xml) : File.open(xml)
89
90
  Nokogiri::XML(location)
90
91
  rescue Exception => e
91
- p e
92
- #puts e.backtrace
92
+ puts "Could not open XML file at #{xml}"
93
93
  end
94
94
  end
95
95
 
@@ -100,15 +100,6 @@ module TheTvdb
100
100
  result[selector] if selector.present?
101
101
  end
102
102
 
103
- # def xmlurl_to_array(url, selector = nil)
104
- # if selector
105
- # document = open_xml(url).css(selector)
106
- #
107
- # else
108
- # Array.from_xml(open_xml(url).to_s)
109
- # end
110
- # end
111
-
112
103
  def unzip_file (file, destination)
113
104
  Zip::ZipFile.open(file) { |zip_file|
114
105
  zip_file.each { |f|
data/lib/the_tvdb/show.rb CHANGED
@@ -1,7 +1,7 @@
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,
5
5
  :first_aired, :imdb_id, :zap2it_id, :language
6
6
 
7
7
  def self.search(name)
@@ -12,23 +12,33 @@ module TheTvdb
12
12
  def self.find(remote_id)
13
13
  info = TheTvdb.gateway.get_series_package(remote_id)
14
14
  show = self.new(info['Series'])
15
- show.episodes = info['Episode'].map {|e| TheTvdb::Episode.new(e) }
15
+ show.episodes = info['Episode'].blank? ? [] : [ info['Episode'] ].flatten.map {|e| TheTvdb::Episode.new(e) }
16
16
  show
17
17
  end
18
18
 
19
19
  def initialize(info)
20
20
  @remote_id = info['id'].to_i
21
21
  @name = info['SeriesName']
22
- @banner = "#{TheTvdb.gateway.mirror}/banners/#{info['banner']}"
22
+ @banner = "#{TheTvdb.gateway.mirror}/banners/#{info['banner']}" unless info['banner'].nil?
23
23
  @description = info['Overview']
24
24
  @imdb_id = info['IMDB_ID']
25
25
  @zap2it_id = info['zap2it_id']
26
26
  @first_aired = info['FirstAired']
27
27
  @language = info['language']
28
+ @episodes = []
28
29
  end
29
30
 
30
31
  def to_hash
31
- { remote_id: @remote_id, name: @name, banner: @banner, description: @description }
32
+ {
33
+ remote_id: @remote_id,
34
+ name: @name,
35
+ banner: @banner,
36
+ description: @description,
37
+ first_aired: @first_aired,
38
+ imdb_id: @imdb_id,
39
+ zap2it_id: @zap2it_id,
40
+ language: @language
41
+ }
32
42
  end
33
43
 
34
44
  end
@@ -1,3 +1,3 @@
1
1
  module TheTvdb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/the_tvdb.rb CHANGED
@@ -26,7 +26,7 @@ module TheTvdb
26
26
  def self.update(timestamp = nil)
27
27
  update_hash = gateway.update(timestamp)
28
28
  result = { time: update_hash['Time'].to_i }
29
- result[:shows] = update_hash['Series'].map {|show_remote_id| Show.find(show_remote_id) }
29
+ result[:shows] = update_hash['Series'].map {|show_remote_id| Show.find(show_remote_id) } if update_hash['Series']
30
30
  gateway.last_updated = result[:time]
31
31
  result
32
32
  end
@@ -833,4 +833,162 @@ http_interactions:
833
833
  \ </Mirror>\n</Mirrors>\n"
834
834
  http_version:
835
835
  recorded_at: Mon, 24 Dec 2012 15:05:53 GMT
836
+ - request:
837
+ method: get
838
+ uri: http://www.thetvdb.com/api//GetSeries.php?seriesname=Good%20Girls%20Don't
839
+ body:
840
+ encoding: US-ASCII
841
+ string: ''
842
+ headers:
843
+ Accept:
844
+ - ! '*/*'
845
+ User-Agent:
846
+ - Ruby
847
+ response:
848
+ status:
849
+ code: 200
850
+ message: OK
851
+ headers:
852
+ Server:
853
+ - cloudflare-nginx
854
+ Date:
855
+ - Fri, 28 Dec 2012 00:32:17 GMT
856
+ Content-Type:
857
+ - text/xml; charset=utf-8
858
+ Transfer-Encoding:
859
+ - chunked
860
+ Connection:
861
+ - keep-alive
862
+ X-Powered-By:
863
+ - PHP/5.2.6-1+lenny16
864
+ Cache-Control:
865
+ - max-age=900
866
+ Expires:
867
+ - Fri, 28 Dec 2012 00:47:16 GMT
868
+ Vary:
869
+ - User-Agent,Accept-Encoding
870
+ Set-Cookie:
871
+ - __cfduid=d1e23e844cef2d1e98714d7a07e742d0c1356654736; expires=Mon, 23-Dec-2019
872
+ 23:50:00 GMT; path=/; domain=.thetvdb.com
873
+ Cf-Ray:
874
+ - 27aa52874da048b
875
+ body:
876
+ encoding: US-ASCII
877
+ string: ! '<?xml version="1.0" encoding="UTF-8" ?>
878
+
879
+ <Data>
880
+
881
+ <Series>
882
+
883
+ <seriesid>127281</seriesid>
884
+
885
+ <language>en</language>
886
+
887
+ <SeriesName>Good Girls Don''t</SeriesName>
888
+
889
+ <FirstAired>2004-06-04</FirstAired>
890
+
891
+ <IMDB_ID>tt0413572</IMDB_ID>
892
+
893
+ <id>127281</id>
894
+
895
+ </Series>
896
+
897
+ </Data>'
898
+ http_version:
899
+ recorded_at: Fri, 28 Dec 2012 00:32:17 GMT
900
+ - request:
901
+ method: get
902
+ uri: http://thetvdb.com/api/1234567898765432/series/77856/all/en.zip
903
+ body:
904
+ encoding: US-ASCII
905
+ string: ''
906
+ headers:
907
+ Accept:
908
+ - ! '*/*'
909
+ User-Agent:
910
+ - Ruby
911
+ response:
912
+ status:
913
+ code: 200
914
+ message: !binary |-
915
+ T0s=
916
+ headers:
917
+ !binary "U2VydmVy":
918
+ - !binary |-
919
+ Y2xvdWRmbGFyZS1uZ2lueA==
920
+ !binary "RGF0ZQ==":
921
+ - !binary |-
922
+ RnJpLCAyOCBEZWMgMjAxMiAwMTowOTozOSBHTVQ=
923
+ !binary "Q29udGVudC1UeXBl":
924
+ - !binary |-
925
+ YXBwbGljYXRpb24vemlw
926
+ !binary "Q29udGVudC1MZW5ndGg=":
927
+ - !binary |-
928
+ MTYzMQ==
929
+ !binary "Q29ubmVjdGlvbg==":
930
+ - !binary |-
931
+ a2VlcC1hbGl2ZQ==
932
+ !binary "TGFzdC1Nb2RpZmllZA==":
933
+ - !binary |-
934
+ V2VkLCAxOSBPY3QgMjAxMSAwNjo0OTozOCBHTVQ=
935
+ !binary "RXhwaXJlcw==":
936
+ - !binary |-
937
+ RnJpLCAyOCBEZWMgMjAxMiAwMToyNDozOCBHTVQ=
938
+ !binary "Q2FjaGUtQ29udHJvbA==":
939
+ - !binary |-
940
+ bWF4LWFnZT05MDA=
941
+ !binary "QWNjZXB0LVJhbmdlcw==":
942
+ - !binary |-
943
+ Ynl0ZXM=
944
+ !binary "U2V0LUNvb2tpZQ==":
945
+ - !binary |-
946
+ X19jZmR1aWQ9ZGEyYjMzN2NhZDJiZTUxNDBlYzA5YTJlMzlkODI5ODZiMTM1
947
+ NjY1Njk3ODsgZXhwaXJlcz1Nb24sIDIzLURlYy0yMDE5IDIzOjUwOjAwIEdN
948
+ VDsgcGF0aD0vOyBkb21haW49LnRoZXR2ZGIuY29t
949
+ !binary "Q2YtUmF5":
950
+ - !binary |-
951
+ MjdhZGJlNGQyOGEwNDhi
952
+ body:
953
+ encoding: ASCII-8BIT
954
+ string: !binary |-
955
+ UEsDBBQAAAAIADO+Uj+RQK0HqwMAAFcIAAAGABUAZW4ueG1sVVQJAAMCc55O
956
+ AXOeTlV4BAAAAAAAnVZLcyI3EL5Ttf+hy4fsxeblGJvK7GzZYG/Y2KxrTewj
957
+ pUENqJiRWEljQoofn27NA3CcQ/bATPf3dasl9WOIPv+VpfCK1imjP510mu0T
958
+ QD0zUunFp5M/J3dnVyfwOW5EQ+FFHD2hVejiBkCkZHx5eXXRi1okMXA988a6
959
+ eHedCg1jsVZod9fWI3w1S+2M3g3yNN3CdzVbCivdjmH4PU8S0khxS3hEpXF3
960
+ r7QUcC827HNvcuUQvqSo9e6RHlt4EtoTE7XKgCG2sm46FNtv8xfEVUzcMVDb
961
+ TFSGFR1kZgZGe9T+u/B0amKPdba4I3tPTijjTr/XPWv3z9qdqHUAs9UX1JZX
962
+ L96MjB6GN9PRkLBKYvRe6EUuFhijjlq1wswY/cbYVTy+GUStSjkgwlJ7mZlv
963
+ lLxXhZv4BdOZyRC8Ab9EGBr90cNApCk8IAzozlOFsMiVRBAeJs8wIesmjA04
964
+ YzRaUA5GZiPgGT2lWQurKJFfc0l5gIfZH2IL0oq5RwlKl0GubbYlgexImVPi
965
+ HCxV5jCdQ0LJXIDzdIm0OvvAIy3pmh8a8KExWaJFjqgNoFSUSJjTzy8Jckuz
966
+ acJoDluTw8bk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t96k1ymIuML8rGOv/b
983
+ iAyAayWK6agYcdZ1IdjU8oyCs58akp2sUSyMJNjJd42Os2sSjg7WhLvXEuaj
984
+ dc2LU+jEkLO/IePsJt7Lw6jsGoRnW5G3lJZ+jNHL1pgLHHRZSad8WryI4WFl
985
+ WLenU2enpcdx2lewR02YFp7G4K0mJWErP5O/9SRK21Z7hJVBSkuPBzF635EX
986
+ OEpq/rk1u33wb1BLAQIXAxQAAAAIADO+Uj+RQK0HqwMAAFcIAAAGAA0AAAAA
987
+ AAEAAAD/gQAAAABlbi54bWxVVAUAAwJznk5VeAAAUEsBAhcDFAAAAAgAM75S
988
+ P9/mWqU1AAAAPAAAAAsADQAAAAAAAQAAAP+B5AMAAGJhbm5lcnMueG1sVVQF
989
+ AAMBc55OVXgAAFBLAQIXAxQAAAAIADO+Uj/xURvd6QAAABEEAAAKAA0AAAAA
990
+ AAEAAAD/gVcEAABhY3RvcnMueG1sVVQFAAMBc55OVXgAAFBLBQYAAAAAAwAD
991
+ AMwAAAB9BQAAAAA=
992
+ http_version:
993
+ recorded_at: Fri, 28 Dec 2012 01:09:39 GMT
836
994
  recorded_with: VCR 2.3.0
@@ -43,4 +43,17 @@ describe TheTvdb::Episode do
43
43
 
44
44
  end
45
45
 
46
+ end
47
+
48
+ describe "Weird case episode" do
49
+
50
+ before do
51
+ VCR.insert_cassette 'weird_episode', record: :new_episodes
52
+ end
53
+
54
+ after do
55
+ VCR.eject_cassette
56
+ end
57
+
58
+
46
59
  end
@@ -17,7 +17,6 @@ describe TheTvdb::Gateway do
17
17
  describe "#time" do
18
18
  it "should return the current server time for update purposes" do
19
19
  gateway.time.should == '1356080760'
20
- gateway.last_updated.should == '1356080760'
21
20
  end
22
21
  end
23
22
 
@@ -30,6 +30,11 @@ describe TheTvdb::Show do
30
30
  show.language.should == 'en'
31
31
  end
32
32
 
33
+ it "should return nil as a banner on no image" do
34
+ no_image_show = TheTvdb::Show.search("Good Girls Don't").first
35
+ no_image_show.banner.should be_nil
36
+ end
37
+
33
38
  end
34
39
 
35
40
  describe ".find" do
@@ -42,6 +47,12 @@ describe TheTvdb::Show do
42
47
  episode.name.should == 'Blackwater'
43
48
  end
44
49
 
50
+ it "should return an array of episodes even if there is just one episode" do
51
+ one_episode_show = TheTvdb::Show.find(77856)
52
+ one_episode_show.episodes.size.should == 1
53
+ end
54
+
55
+
45
56
  end
46
57
 
47
58
  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.1.0
4
+ version: 0.1.1
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-24 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri