eztv 0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +9 -0
- data/eztv.gemspec +27 -0
- data/lib/example.rb +18 -0
- data/lib/eztv.rb +90 -0
- data/test/eztv_test.rb +38 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6443f768a92e9e5fac65c6455d7b89283eb516e
|
4
|
+
data.tar.gz: 0e59e5cd414b3a4d614650513f05a43054824744
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0eb05abb995c278043f42a7a229e2c5658cb5e2439bed628c378d9b1f72413c4acb624e10afd183ca395ea1fa381308c1413067c8d6b09ddf1893d4f97554c40
|
7
|
+
data.tar.gz: d416f28539b91799cbfff861d4f113700adc2b73b826a77bf60cd0e64918f6958da46f33a734d4ac09d1e6fbdcc7ec96a180c6dcdba2ca6683683fea546e17a5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Damir Svrtan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# EZTV
|
2
|
+
|
3
|
+
A Ruby scraper for the catastrophic EZTV API. It is not using the RSS feed since it doesn't work well, so it scrapes the search results.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'eztv'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install eztv
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
white_collar = EZTV::Series.new("white collar")
|
23
|
+
|
24
|
+
white_collar.episodes.each do |episode|
|
25
|
+
puts episode.magnet_link
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "Number of seasons: #{white_collar.seasons.count}"
|
29
|
+
puts "Number of episodes in season 1: #{white_collar.season(1).count}"
|
30
|
+
|
31
|
+
nonny = EZTV::Series.new("nonny")
|
32
|
+
begin
|
33
|
+
nonny.episodes
|
34
|
+
rescue EZTV::SeriesNotFoundError => e
|
35
|
+
puts e.message
|
36
|
+
=> "Unable to find 'nonny' on https://eztv.it."
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( http://github.com/<my-github-username>/eztv/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/eztv.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "eztv"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Damir Svrtan"]
|
9
|
+
spec.email = ["damir.svrtan@gmail.com"]
|
10
|
+
spec.summary = "EZTV wrapper in Ruby"
|
11
|
+
spec.description = "EZTV wrapper for the catastrophic EZTV API."
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "minitest"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "nokogiri"
|
25
|
+
spec.add_runtime_dependency "httparty"
|
26
|
+
spec.add_runtime_dependency "pry"
|
27
|
+
end
|
data/lib/example.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'eztv'
|
2
|
+
|
3
|
+
white_collar = EZTV::Series.new("white collar")
|
4
|
+
|
5
|
+
white_collar.episodes.each do |episode|
|
6
|
+
puts episode.magnet_link
|
7
|
+
end
|
8
|
+
|
9
|
+
puts "Number of seasons: #{white_collar.seasons.count}"
|
10
|
+
puts "Number of episodes in season 1: #{white_collar.season(1).count}"
|
11
|
+
|
12
|
+
|
13
|
+
nonny = EZTV::Series.new("nonny")
|
14
|
+
begin
|
15
|
+
nonny.episodes
|
16
|
+
rescue EZTV::SeriesNotFoundError => e
|
17
|
+
puts e.message
|
18
|
+
end
|
data/lib/eztv.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
module EZTV
|
6
|
+
class SeriesNotFoundError < StandardError
|
7
|
+
def initialize(series)
|
8
|
+
msg = "Unable to find '#{series.name}' on https://eztv.it."
|
9
|
+
super(msg)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Series
|
14
|
+
include HTTParty
|
15
|
+
base_uri 'http://eztv.it'
|
16
|
+
|
17
|
+
attr_reader :name
|
18
|
+
|
19
|
+
def initialize(name)
|
20
|
+
@name = name
|
21
|
+
@options = { body: {'SearchString' => @name}}
|
22
|
+
end
|
23
|
+
|
24
|
+
def episodes
|
25
|
+
return @episodes if @episodes
|
26
|
+
|
27
|
+
result = self.class.post('/search/',@options)
|
28
|
+
document = Nokogiri::HTML(result)
|
29
|
+
|
30
|
+
episodes = document.css('html body div#header_holder table.forum_header_border tr.forum_header_border')
|
31
|
+
|
32
|
+
raise SeriesNotFoundError.new(self) if episodes.empty?
|
33
|
+
|
34
|
+
episodes = episodes.reject do |episode|
|
35
|
+
episode.css('img').first.attributes['title'].value.match(/Show Description about #{name}/i).nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
@episodes = EpisodeFactory.create(episodes)
|
39
|
+
end
|
40
|
+
|
41
|
+
def episode(season, episode_number)
|
42
|
+
episodes.find do |episode|
|
43
|
+
episode.season == season and episode.episode_number == episode_number
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def season(season)
|
48
|
+
episodes.find_all {|episode| episode.season == season }
|
49
|
+
end
|
50
|
+
|
51
|
+
def seasons
|
52
|
+
episodes.group_by {|episode| episode.season }.to_hash.values
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module EpisodeFactory
|
57
|
+
def self.create(episodes_array)
|
58
|
+
episodes = episodes_array.reverse.map do |episode_hash|
|
59
|
+
Episode.new(episode_hash)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Episode
|
65
|
+
SE_FORMAT = /S(\d{1,2})E(\d{1,2})/
|
66
|
+
X_FORMAT = /(\d{1,2})x(\d{1,2})/
|
67
|
+
|
68
|
+
attr_accessor :season, :episode_number, :links, :magnet_link
|
69
|
+
|
70
|
+
def initialize(episode_node)
|
71
|
+
inner_text = episode_node.css('td.forum_thread_post a.epinfo').first.inner_text
|
72
|
+
season_episode_match_data = inner_text.match(SE_FORMAT) || inner_text.match(X_FORMAT)
|
73
|
+
|
74
|
+
@season = season_episode_match_data[1].to_i
|
75
|
+
@episode_number = season_episode_match_data[2].to_i
|
76
|
+
|
77
|
+
links_data = episode_node.css('td.forum_thread_post')[2]
|
78
|
+
|
79
|
+
@magnet_link = links_data.css('a.magnet').first.attributes['href'].value
|
80
|
+
|
81
|
+
@links = links_data.css('a')[2..-1].map do |a_element|
|
82
|
+
a_element['href']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def s01e01_format
|
87
|
+
@s01e01_format ||= "S" + season.to_s.rjust(2,'0') + "E" + season.to_s.rjust(2,'0')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/test/eztv_test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require 'eztv'
|
3
|
+
class TestExistingSeries < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@white_collar = EZTV::Series.new("white collar")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_series_name
|
9
|
+
assert_equal "white collar", @white_collar.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_episodes_count
|
13
|
+
assert_equal 75, @white_collar.episodes.count
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_seasons_count
|
17
|
+
assert_equal 5, @white_collar.seasons.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_first_episode
|
21
|
+
first_episode = @white_collar.episodes.first
|
22
|
+
assert_equal 1, first_episode.episode_number
|
23
|
+
assert_equal 1, first_episode.season
|
24
|
+
assert_equal "S01E01", first_episode.s01e01_format
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class TestNonExistingSeries < Minitest::Test
|
29
|
+
def setup
|
30
|
+
@nonny = EZTV::Series.new("nonny")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_raises_if_not_found
|
34
|
+
assert_raises EZTV::SeriesNotFoundError do
|
35
|
+
@nonny.episodes
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eztv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damir Svrtan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: EZTV wrapper for the catastrophic EZTV API.
|
98
|
+
email:
|
99
|
+
- damir.svrtan@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- eztv.gemspec
|
111
|
+
- lib/example.rb
|
112
|
+
- lib/eztv.rb
|
113
|
+
- test/eztv_test.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.0.3
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: EZTV wrapper in Ruby
|
138
|
+
test_files:
|
139
|
+
- test/eztv_test.rb
|