epguides 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -0
- data/lib/epguides.rb +7 -0
- data/lib/epguides/episode.rb +25 -0
- data/lib/epguides/episode_list.rb +11 -0
- data/lib/epguides/season.rb +14 -0
- data/lib/epguides/show.rb +68 -0
- data/lib/epguides/version.rb +3 -0
- metadata +131 -0
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Epguides
|
2
|
+
========
|
3
|
+
|
4
|
+
Epguides makes it easy to look up TV episode information from http://epguides.com if you know either the season and episode number or the air date of an episode.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
gem install epguides
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'epguides'
|
16
|
+
#=> true
|
17
|
+
|
18
|
+
show = Epguides::Show.search("The Colbert Report")
|
19
|
+
#=> #<Epguides::Show:0x007fc001c71618 @slug=nil, @url="http://epguides.com/ColbertReport/">
|
20
|
+
show.name
|
21
|
+
#=> "The Colbert Report"
|
22
|
+
episode = show.season(8).episode(33)
|
23
|
+
#=> #<Epguides::Episode:0x007fc001b794b8 @season="8", @number="33", @prod_number="", @air_date=#<Date: 2012-03-08 ((2455995j,0s,0n),+0s,2299161j)>, @title="Don Fleming, Elvis Costello, Emmylou Harris">
|
24
|
+
|
25
|
+
show2 = Epguides::Show.new(:slug => 'Archer')
|
26
|
+
#=> #<Epguides::Show:0x007fcdf388ed20 @slug="Archer", @url=nil>
|
27
|
+
show2.episodes.first
|
28
|
+
#=> #<Epguides::Episode:0x007fcdf34a4840 @season="1", @number="01", @prod_number="AR01001", @air_date=#<Date: 2009-09-17 ((2455092j,0s,0n),+0s,2299161j)>, @title="Mole Hunt [Trailer]">
|
29
|
+
show2.episodes.find_by_air_date(Date.new(2013,2,21))
|
30
|
+
#=> #<Epguides::Episode:0x007fcdf34951b0 @season="4", @number="06", @prod_number="XAR04007", @air_date=#<Date: 2013-02-21 ((2456345j,0s,0n),+0s,2299161j)>, @title="Once Bitten">
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
License
|
35
|
+
-------
|
36
|
+
MIT
|
data/lib/epguides.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Epguides
|
2
|
+
class Episode
|
3
|
+
REGX = /(\d+)\s+(\d+)-(\d+)\s+(.*)\s+(\d*\/*\w{3}\/\d{2})\s+(.+\Z)/
|
4
|
+
|
5
|
+
attr_reader :season, :number, :air_date, :title
|
6
|
+
|
7
|
+
def initialize(season, number, prod_number, air_date, title)
|
8
|
+
@season = season
|
9
|
+
@number = number
|
10
|
+
@prod_number = prod_number.strip
|
11
|
+
@air_date = parse_date(air_date)
|
12
|
+
@title = title.strip
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_date(date)
|
18
|
+
if /\d+\/\w{3}\/\d{2}/.match(date)
|
19
|
+
DateTime.strptime(date, "%d/%b/%y").to_date
|
20
|
+
else
|
21
|
+
''
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'json'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'rest-client'
|
6
|
+
|
7
|
+
module Epguides
|
8
|
+
class Show
|
9
|
+
attr_reader :slug, :url
|
10
|
+
|
11
|
+
def initialize(args={})
|
12
|
+
@slug = args[:slug]
|
13
|
+
@url = args[:url]
|
14
|
+
end
|
15
|
+
|
16
|
+
def episodes
|
17
|
+
return @episodes if @episodes
|
18
|
+
@episodes = EpisodeList.new
|
19
|
+
parse_table.each do |row|
|
20
|
+
if m = Episode::REGX.match(row)
|
21
|
+
@episodes << Episode.new(m[2], m[3], m[4], m[5], m[6])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@episodes
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
doc.css('//h1').text
|
29
|
+
end
|
30
|
+
|
31
|
+
def season(n)
|
32
|
+
Season.new(n.to_s, episodes.find_by_season(n))
|
33
|
+
end
|
34
|
+
|
35
|
+
def seasons
|
36
|
+
pattern = Regexp.new("•\\s+Season\\s+(\\d+)")
|
37
|
+
list.scan(pattern).map do |s|
|
38
|
+
Season.new(self, s.first)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def url
|
43
|
+
@url ||= "http://epguides.com/#{@slug}/"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.search(q)
|
47
|
+
search_url = 'http://ajax.googleapis.com/ajax/services/search/web' +
|
48
|
+
'?v=1.0&q=allintitle: site:epguides.com '
|
49
|
+
results = JSON.parse RestClient.get(URI.escape(search_url + q))
|
50
|
+
new url: results['responseData']['results'].first['url']
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def doc
|
56
|
+
Nokogiri::HTML(open(url))
|
57
|
+
end
|
58
|
+
|
59
|
+
def list
|
60
|
+
doc.xpath('//div[@id = "eplist"]').text
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_table
|
64
|
+
titles = doc.xpath('//div[@id = "eplist"]//a').text
|
65
|
+
doc.xpath('//div[@id = "eplist"]').text.split("\r\n")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epguides
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Manning
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.7.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.7.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.5.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.6
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rest-client
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.6.7
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: minitest
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 4.6.2
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 4.6.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: turn
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.9.6
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.9.6
|
94
|
+
description: Query the epguides.com website for TV show information.
|
95
|
+
email: matt.manning@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- README.md
|
101
|
+
- lib/epguides.rb
|
102
|
+
- lib/epguides/episode.rb
|
103
|
+
- lib/epguides/episode_list.rb
|
104
|
+
- lib/epguides/season.rb
|
105
|
+
- lib/epguides/show.rb
|
106
|
+
- lib/epguides/version.rb
|
107
|
+
homepage: https://github.com/mattmanning/epguides
|
108
|
+
licenses: []
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Query the epguides.com website for TV show information.
|
131
|
+
test_files: []
|