thetvdb 0.1

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.
Files changed (2) hide show
  1. data/lib/thetvdb.rb +61 -0
  2. metadata +45 -0
@@ -0,0 +1,61 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'uri'
4
+
5
+ module TheTVDB
6
+ class Client
7
+ include Enumerable
8
+ attr_reader :apikey
9
+ def initialize(apikey)
10
+ @apikey = apikey
11
+ @base_url = "http://www.thetvdb.com"
12
+ @results = {}
13
+ end
14
+ def search(query, options = {})
15
+ default_options = { lang: 'en' }
16
+ options = default_options.merge(options)
17
+ query = URI.encode(query)
18
+ search_url = "#{@base_url}/api/GetSeries.php?seriesname=#{query}&language=#{options[:lang]}"
19
+ doc = Nokogiri::XML(open(search_url))
20
+ @results = doc.xpath('//Series').map do |item|
21
+ {
22
+ id: item.xpath('seriesid').text,
23
+ name: item.xpath('SeriesName').text,
24
+ overview: item.xpath('Overview').text,
25
+ }
26
+ end
27
+ @pointer = 0
28
+ @results
29
+ end
30
+ def seriesname
31
+ if @results.count > 0 then
32
+ @results[@pointer][:name]
33
+ end
34
+ end
35
+ def each(&block)
36
+ @results.each(&block)
37
+ end
38
+ def get_episode_info(season, episode, options = {})
39
+ default_options = { lang: 'en' }
40
+ options = default_options.merge(options)
41
+ season = Integer(season)
42
+ episode = Integer(episode)
43
+ url = "#{@base_url}/api/#{@apikey}/series/#{@results[@pointer][:id]}/default/#{season}/#{episode}/#{options[:lang]}.xml"
44
+ doc = Nokogiri::XML(open(url))
45
+ showinfo = doc.xpath('//Episode').first
46
+ result = {
47
+ tvdb_id: showinfo.xpath('id').text,
48
+ series_id: showinfo.xpath('seriesid').text,
49
+ show: @results[@pointer][:name],
50
+ season: season,
51
+ episode: episode,
52
+ name: showinfo.xpath('EpisodeName').text,
53
+ first_aired: showinfo.xpath('FirstAired').text,
54
+ director: showinfo.xpath('Director').text,
55
+ overview: showinfo.xpath('Overview').text,
56
+ imdb_id: showinfo.xpath('IMDB_ID').text,
57
+ }
58
+ result
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thetvdb
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zan Loy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: zan.loy@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/thetvdb.rb
21
+ homepage: http://zanloy.com/scripts/ruby/thetvdb/
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.24
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Very simple interfact to TheTVDB API
45
+ test_files: []