philk-tvdbparty 0.1.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/lib/tvdbmapper.rb +62 -0
- data/lib/tvdbparty.rb +89 -0
- metadata +71 -0
data/lib/tvdbmapper.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
=begin rdoc
|
|
2
|
+
This is just HappyMapper classes for the various XML files that come out of the zip file from TheTVDB. I didn't map everything, just the ones that seemed important.
|
|
3
|
+
=end
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "zip/zip"
|
|
6
|
+
require "happymapper"
|
|
7
|
+
|
|
8
|
+
module TVDBMapper
|
|
9
|
+
class Series
|
|
10
|
+
include HappyMapper
|
|
11
|
+
tag 'Series'
|
|
12
|
+
|
|
13
|
+
element :id, String, :tag => "id"
|
|
14
|
+
element :actors, String, :tag => "Actors"
|
|
15
|
+
element :overview, String, :tag => "Overview"
|
|
16
|
+
element :seriesid, String, :tag => "SeriesID"
|
|
17
|
+
element :seriesname, String, :tag => "SeriesName"
|
|
18
|
+
element :genre, String, :tag => "Genre"
|
|
19
|
+
element :imdb, String, :tag => "IMDB_ID"
|
|
20
|
+
element :language, String, :tag => "Language"
|
|
21
|
+
element :network, String, :tag => "Network"
|
|
22
|
+
element :rating, String, :tag => "Rating"
|
|
23
|
+
element :zap2it, String, :tag => "zap2it_id"
|
|
24
|
+
end
|
|
25
|
+
class Episodes
|
|
26
|
+
include HappyMapper
|
|
27
|
+
tag 'Episode'
|
|
28
|
+
|
|
29
|
+
element :id, String, :tag => "id"
|
|
30
|
+
element :name, String, :tag => "EpisodeName"
|
|
31
|
+
element :director, String, :tag => "Director"
|
|
32
|
+
element :number, String, :tag => "EpisodeNumber"
|
|
33
|
+
element :name, String, :tag => "value"
|
|
34
|
+
element :overview, String, :tag => "Overview"
|
|
35
|
+
element :season, String, :tag => "SeasonNumber"
|
|
36
|
+
element :writer, String, :tag => "Writer"
|
|
37
|
+
element :banner, String, :tag => "filename"
|
|
38
|
+
element :airdate, String, :tag => "FirstAired"
|
|
39
|
+
end
|
|
40
|
+
class Banners
|
|
41
|
+
include HappyMapper
|
|
42
|
+
tag 'Banner'
|
|
43
|
+
|
|
44
|
+
element :id, String, :tag => "id"
|
|
45
|
+
element :path, String, :tag => "BannerPath"
|
|
46
|
+
element :type, String, :tag => "BannerType"
|
|
47
|
+
element :type2, String, :tag => "BannerType2"
|
|
48
|
+
element :language, String, :tag => "Language"
|
|
49
|
+
element :thumb, String, :tag => "ThumbnailPath"
|
|
50
|
+
element :vignette, String, :tag => "VignettePath"
|
|
51
|
+
end
|
|
52
|
+
class Actors
|
|
53
|
+
include HappyMapper
|
|
54
|
+
tag 'Actor'
|
|
55
|
+
|
|
56
|
+
element :id, String, :tag => "id"
|
|
57
|
+
element :image, String, :tag => "Image"
|
|
58
|
+
element :name, String, :tag => "Name"
|
|
59
|
+
element :role, String, :tag => "Role"
|
|
60
|
+
element :sortorder, String, :tag => "SortOrder"
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/tvdbparty.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
=begin rdoc
|
|
2
|
+
Author: Phil Kates (mailto:me@philkates.com)
|
|
3
|
+
=end
|
|
4
|
+
require "rubygems"
|
|
5
|
+
require "httparty"
|
|
6
|
+
require "cgi"
|
|
7
|
+
require "uri"
|
|
8
|
+
require "net/http"
|
|
9
|
+
require "tvdbmapper"
|
|
10
|
+
|
|
11
|
+
=begin rdoc
|
|
12
|
+
Create a TVShow.new like this.
|
|
13
|
+
tvshow = TVShow.new(:series_name => "The Wire")
|
|
14
|
+
OR
|
|
15
|
+
tvshow = TVShow.new(:series_id => "79126")
|
|
16
|
+
=end
|
|
17
|
+
class TVShow
|
|
18
|
+
include HTTParty
|
|
19
|
+
format :xml
|
|
20
|
+
attr_accessor :mirror, :series_name, :series_id, :series, :actors, :episodes, :banners
|
|
21
|
+
def initialize(params)
|
|
22
|
+
@api_key = "BC7240CD299E99B5"
|
|
23
|
+
@series_name = params[:series_name]
|
|
24
|
+
@series_id = params[:series_id]
|
|
25
|
+
result = self.class.get("http://www.thetvdb.com/api/#{@api_key}/mirrors.xml")
|
|
26
|
+
@mirror = result["Mirrors"]["Mirror"]["mirrorpath"]
|
|
27
|
+
self.class.base_uri @mirror
|
|
28
|
+
end
|
|
29
|
+
def get_series_by_name # TODO : Find series by name?
|
|
30
|
+
res = self.class.get("/api/GetSeries.php?seriesname=" + CGI::escape(@series_name.to_s))
|
|
31
|
+
if res["Data"].to_s =~ /.*connection to localhost.*/
|
|
32
|
+
raise "TVDB API Down"
|
|
33
|
+
else
|
|
34
|
+
res = res["Data"]["Series"]
|
|
35
|
+
end
|
|
36
|
+
if res.is_a?(Hash)
|
|
37
|
+
@series_id = res["seriesid"]
|
|
38
|
+
return [res]
|
|
39
|
+
elsif res.is_a?(Array)
|
|
40
|
+
return res
|
|
41
|
+
else
|
|
42
|
+
raise "Unexpected Data Type Returned #{res.class}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
def get_series_as_zip(path)
|
|
46
|
+
check_series_id
|
|
47
|
+
if path.is_a? String
|
|
48
|
+
path = Pathname.new(path)
|
|
49
|
+
end
|
|
50
|
+
res = Net::HTTP.get URI.parse("http://zip.thetvdb.com/data/zip/en/#{@series_id}.zip")
|
|
51
|
+
file = File.open(path + "testing.zip", 'w')
|
|
52
|
+
file.write(res)
|
|
53
|
+
file.close
|
|
54
|
+
|
|
55
|
+
zipfile = Zip::ZipFile.open(path + "testing.zip")
|
|
56
|
+
zipfile.extract("en.xml", path + "en.xml")
|
|
57
|
+
zipfile.extract("actors.xml", path + "actors.xml")
|
|
58
|
+
zipfile.extract("banners.xml", path + "banners.xml")
|
|
59
|
+
zipfile.close
|
|
60
|
+
|
|
61
|
+
@series_xml = File.open(path + "en.xml", 'r').readlines.to_s
|
|
62
|
+
@actor_xml = File.open(path + "actors.xml", 'r').readlines.to_s
|
|
63
|
+
@banner_xml = File.open(path + "banners.xml", 'r').readlines.to_s
|
|
64
|
+
|
|
65
|
+
@series = TVDBMapper::Series.parse(@series_xml).first
|
|
66
|
+
@episodes = TVDBMapper::Episodes.parse(@series_xml)
|
|
67
|
+
@actors = TVDBMapper::Actors.parse(@actor_xml)
|
|
68
|
+
@banners = TVDBMapper::Banners.parse(@banner_xml)
|
|
69
|
+
|
|
70
|
+
FileUtils.rm(path + "en.xml")
|
|
71
|
+
FileUtils.rm(path + "actors.xml")
|
|
72
|
+
FileUtils.rm(path + "banners.xml")
|
|
73
|
+
FileUtils.rm(path + "testing.zip")
|
|
74
|
+
end
|
|
75
|
+
def find_by_episode(season, episode_number)
|
|
76
|
+
season = season.to_s
|
|
77
|
+
episode_number = episode_number.to_s
|
|
78
|
+
@episodes.select { |e| e.number == episode_number && e.season == season }.first
|
|
79
|
+
end
|
|
80
|
+
def get_episode_banner(image_path)
|
|
81
|
+
Net::HTTP.get URI.parse("http://images.thetvdb.com/banners/#{image_path}")
|
|
82
|
+
end
|
|
83
|
+
private
|
|
84
|
+
def check_series_id
|
|
85
|
+
if @series_id == nil
|
|
86
|
+
raise "series_id must not be nil"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: philk-tvdbparty
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Phil Kates
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-12-11 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: httparty
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.2.2
|
|
23
|
+
version:
|
|
24
|
+
- !ruby/object:Gem::Dependency
|
|
25
|
+
name: happymapper
|
|
26
|
+
version_requirement:
|
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: "0"
|
|
32
|
+
version:
|
|
33
|
+
description: TODO
|
|
34
|
+
email: me@philkates.com
|
|
35
|
+
executables: []
|
|
36
|
+
|
|
37
|
+
extensions: []
|
|
38
|
+
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
|
|
41
|
+
files:
|
|
42
|
+
- lib/tvdbmapper.rb
|
|
43
|
+
- lib/tvdbparty.rb
|
|
44
|
+
has_rdoc: true
|
|
45
|
+
homepage: http://github.com/philk/tvdbparty
|
|
46
|
+
post_install_message:
|
|
47
|
+
rdoc_options: []
|
|
48
|
+
|
|
49
|
+
require_paths:
|
|
50
|
+
- lib
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: "0"
|
|
56
|
+
version:
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: "0"
|
|
62
|
+
version:
|
|
63
|
+
requirements: []
|
|
64
|
+
|
|
65
|
+
rubyforge_project:
|
|
66
|
+
rubygems_version: 1.2.0
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 2
|
|
69
|
+
summary: TODO
|
|
70
|
+
test_files: []
|
|
71
|
+
|