addic7ed 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGFlY2ZmZmQxNjY4ZmE3ZmRkY2E1NzRiYjY3ZGYyN2I0NmZmNjViMg==
5
- data.tar.gz: !binary |-
6
- OWMxMzRlYjMwNDM0ZTUzMjVmOTRiM2I0NTg4ZDAwODFmYWQ5YWI2ZQ==
2
+ SHA1:
3
+ metadata.gz: 57ad3d69c430c7a8a03656461871412130e86bc2
4
+ data.tar.gz: 45bcf71317aa9d27d21b4d899324dda51c0a2dbc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGNiN2E1NDA1NjNiODg1YjA4YzhiN2FmMjMzNDY5NTlkNjIzYTcwMDczZDA5
10
- MDE1N2FjNDQ5NTZkOGEyYjAyNDU2MWY5NTg1Yzg2NmYzZjBkZmNiOTVmNmUz
11
- NDA5NTdlMmUwNDBiZWM1YjcyOTQxNmM5MjAxN2M3ZjAwMTY5OTA=
12
- data.tar.gz: !binary |-
13
- MWM3MjNhMTY5YmJiNDg4ZjlmZmRiMjViYTQ3ZTRiYmFhMWQ3MDdkMGNkMDQ4
14
- YWNiOWQ1YWQ5YmUyZGExODEzYWRlMTQ3YzcxOWI2MGIxY2ExM2I5ZTYzN2E4
15
- NjQ1ZThmZDZhYjQyNTIzYTAxMDRiMTI4N2FlZWZiNWY0Y2M4MWY=
6
+ metadata.gz: 3988226f6b255c145487c43410e5c288fe4c49f89480df759eb514a6ef8bddfa693c595d1517b30f81ebf6eb1e955f5c69955608bb25cbccfff2c66863d9c097
7
+ data.tar.gz: 967506087a44bd2865c0a8026ec401d37a86670bbcf218d8b7ef503258fe592f744d2ecb60a96210fbfc97626d9cf208a4ed4ca771a961805a04437a6d346e35
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Michael Baudino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/addic7ed CHANGED
@@ -128,8 +128,8 @@ options[:filenames].each do |filename|
128
128
  rescue Addic7ed::SubtitleCannotBeSaved
129
129
  puts "The downloaded subtitle could not be saved as #{filename.gsub(/\.\w{3}$/, '.srt')}. Skipping.".gsub(/^/, options[:verbose] ? ' ' : '') unless options[:quiet]
130
130
  next
131
- rescue Addic7ed::WTFError => e
132
- puts "WTF (I sincerely have no idea what I'm doing): #{e.message}".gsub(/^/, options[:verbose] ? ' ' : '') unless options[:quiet]
131
+ rescue Addic7ed::HTTPError => e
132
+ puts "Network error: #{e.message}".gsub(/^/, options[:verbose] ? ' ' : '') unless options[:quiet]
133
133
  next
134
134
  end
135
135
 
data/lib/addic7ed.rb CHANGED
@@ -4,3 +4,4 @@ require 'addic7ed/errors'
4
4
  require 'addic7ed/filename'
5
5
  require 'addic7ed/episode'
6
6
  require 'addic7ed/subtitle'
7
+ require 'addic7ed/parser'
@@ -1,4 +1,3 @@
1
- require 'nokogiri'
2
1
  require 'net/http'
3
2
  require 'open-uri'
4
3
 
@@ -12,95 +11,84 @@ module Addic7ed
12
11
  end
13
12
 
14
13
  def url(lang = 'fr')
15
- raise LanguageNotSupported unless LANGUAGES[lang]
14
+ check_language_availability(lang)
16
15
  @localized_urls ||= {}
17
16
  @localized_urls[lang] ||= "http://www.addic7ed.com/serie/#{@filename.encoded_showname}/#{@filename.season}/#{@filename.episode}/#{LANGUAGES[lang][:id]}"
18
17
  end
19
18
 
20
19
  def subtitles(lang = 'fr')
21
- raise LanguageNotSupported unless LANGUAGES[lang]
22
- unless @subtitles and @subtitles[lang]
23
- @subtitles ||= {}
24
- @subtitles[lang] ||= []
25
- response = Net::HTTP.get_response(URI(url(lang)))
26
- raise EpisodeNotFound if response.body == " "
27
- doc = Nokogiri::HTML(response.body)
28
- raise NoSubtitleFound unless doc.css('select#filterlang ~ font[color="yellow"]').empty?
29
- sublist_node = doc.css('#container95m table.tabel95 table.tabel95')
30
- raise NoSubtitleFound if sublist_node.size == 0
31
- sublist_node.each do |sub_node|
32
- @subtitles[lang] << parse_subtitle_node(sub_node, lang)
33
- end
34
- end
35
- @subtitles[lang]
20
+ check_language_availability(lang)
21
+ find_subtitles(lang) unless @subtitles and @subtitles[lang]
22
+ return @subtitles[lang]
36
23
  end
37
24
 
38
25
  def best_subtitle(lang = 'fr')
39
- raise LanguageNotSupported unless LANGUAGES[lang]
40
- unless @best_subtitle and @best_subtitle[lang]
41
- @best_subtitle ||= {}
42
- subtitles(lang).each do |sub|
43
- if sub.status == 'Completed' and (sub.version == @filename.group or COMPATIBILITY_720P[sub.version] == @filename.group)
44
- @best_subtitle[lang] = sub unless @best_subtitle[lang] and (@best_subtitle[lang].downloads > sub.downloads or @best_subtitle[lang].via == 'http://addic7ed.com')
45
- end
46
- end
47
- raise NoSubtitleFound unless @best_subtitle[lang]
48
- end
26
+ check_language_availability(lang)
27
+ find_best_subtitle(lang) unless @best_subtitle and @best_subtitle[lang]
49
28
  return @best_subtitle[lang]
50
29
  end
51
30
 
52
- def download_best_subtitle!(lang = 'fr', redirect_limit = 8)
53
- raise WTFError.new('Too many HTTP redirects') if redirect_limit == 0
54
- begin
55
- uri = URI(best_subtitle(lang).url)
56
- response = Net::HTTP.start(uri.hostname, uri.port) do |http|
57
- request = Net::HTTP::Get.new(uri.request_uri)
58
- # Addic7ed needs the Referer to be correct. User-agent is just here to fake a real browser request, because we never know...
59
- request['Referer'] = url(lang)
60
- request['User-Agent'] = USER_AGENTS.sample
61
- http.request(request)
62
- end
63
- rescue
64
- raise DownloadError
65
- end
31
+ def download_best_subtitle!(lang, http_redirect_limit = 8)
32
+ raise HTTPError.new('Too many HTTP redirects') unless http_redirect_limit > 0
33
+ uri = URI(best_subtitle(lang).url)
34
+ response = get_http_response(uri, url(lang))
66
35
  if response.kind_of?(Net::HTTPRedirection)
67
- # Addic7ed is serving redirection URL not-encoded.
68
- # Ruby does not support it yet (see http://bugs.ruby-lang.org/issues/7396)
69
- best_subtitle(lang).url = URI.escape(response['location'])
70
- raise DownloadLimitReached if /^\/downloadexceeded.php/.match best_subtitle(lang).url
71
- download_best_subtitle!(lang, redirect_limit - 1)
36
+ follow_redirection(lang, response['location'], http_redirect_limit)
72
37
  else
73
- begin
74
- open "#{filename}".gsub(/\.\w{3}$/, '.srt'), 'w' do |f|
75
- f << response.body
76
- end
77
- rescue
78
- raise SubtitleCannotBeSaved
79
- end
38
+ save_subtitle response.body
80
39
  end
81
40
  end
82
41
 
83
42
  protected
84
43
 
85
- def parse_subtitle_node(sub_node, lang)
86
- begin
87
- version_node = sub_node.css('.NewsTitle').first
88
- version = version_node.content.gsub(/ \nVersion /, '').gsub(/,.*/, '')
89
- language_node = sub_node.css('.language').first
90
- language = language_node.content.gsub(/\A\W*/, '').gsub(/[^\w\)]*\z/, '')
91
- raise WTFError.new("We're asking for #{LANGUAGES[lang][:name].capitalize} subtitles and Addic7ed gives us #{language.capitalize} subtitles") if LANGUAGES[lang][:name].downcase != language.downcase
92
- status_node = sub_node.css('tr:nth-child(3) td:nth-child(4) b').first
93
- status = status_node.content.strip
94
- url_node = sub_node.css('a.buttonDownload').last
95
- url = 'http://www.addic7ed.com' + url_node['href']
96
- via_node = sub_node.css('tr:nth-child(3) td:first-child a').first
97
- via = via_node['href'] if via_node
98
- downloads_node = sub_node.css('tr:nth-child(4) td.newsDate').first
99
- downloads = /(?<downloads>\d*) Downloads/.match(downloads_node.content)[:downloads]
100
- Addic7ed::Subtitle.new(version, language, status, url, via, downloads)
101
- rescue
102
- raise ParsingError
44
+ def find_subtitles(lang)
45
+ initialize_language(lang)
46
+ parser = Addic7ed::Parser.new(self, lang)
47
+ @subtitles[lang] = parser.extract_subtitles
48
+ end
49
+
50
+ def find_best_subtitle(lang)
51
+ @best_subtitle ||= {}
52
+ subtitles(lang).each do |sub|
53
+ @best_subtitle[lang] = sub if sub.works_for? @filename.group and sub.can_replace? @best_subtitle[lang]
54
+ end
55
+ raise NoSubtitleFound unless @best_subtitle[lang]
56
+ end
57
+
58
+ def check_language_availability(lang)
59
+ raise LanguageNotSupported unless LANGUAGES[lang]
60
+ end
61
+
62
+ def initialize_language(lang)
63
+ @subtitles ||= {}
64
+ @subtitles[lang] ||= []
65
+ end
66
+
67
+ def get_http_response(uri, referer)
68
+ Net::HTTP.start(uri.hostname, uri.port) do |http|
69
+ request = Net::HTTP::Get.new(uri.request_uri)
70
+ # Addic7ed needs the Referer to be correct. User-agent is just here to fake a real browser request.
71
+ request['Referer'] = referer
72
+ request['User-Agent'] = USER_AGENTS.sample
73
+ http.request(request)
74
+ end
75
+ rescue
76
+ raise DownloadError
77
+ end
78
+
79
+ def follow_redirection(lang, new_uri, http_redirect_limit)
80
+ # Addic7ed is serving redirection URL not-encoded, but Ruby does not support it (see http://bugs.ruby-lang.org/issues/7396)
81
+ best_subtitle(lang).url = URI.escape(new_uri)
82
+ raise DownloadLimitReached if /^\/downloadexceeded.php/.match best_subtitle(lang).url
83
+ download_best_subtitle!(lang, http_redirect_limit - 1)
84
+ end
85
+
86
+ def save_subtitle(content)
87
+ open "#{filename}".gsub(/\.\w{3}$/, '.srt'), 'w' do |f|
88
+ f << content
103
89
  end
90
+ rescue
91
+ raise SubtitleCannotBeSaved
104
92
  end
105
93
 
106
94
  end
@@ -1,22 +1,9 @@
1
1
  module Addic7ed
2
- class InvalidFilename < StandardError
3
- end
4
- class ShowNotFound < StandardError
5
- end
6
- class EpisodeNotFound < StandardError
7
- end
8
- class LanguageNotSupported < StandardError
9
- end
10
- class ParsingError < StandardError
11
- end
12
- class NoSubtitleFound < StandardError
13
- end
14
- class DownloadError < StandardError
15
- end
16
- class DownloadLimitReached < StandardError
17
- end
18
- class SubtitleCannotBeSaved < StandardError
19
- end
20
- class WTFError < StandardError
21
- end
2
+ exceptions = [
3
+ :InvalidFilename, :ShowNotFound, :EpisodeNotFound, :LanguageNotSupported,
4
+ :ParsingError, :NoSubtitleFound, :DownloadError, :DownloadLimitReached,
5
+ :SubtitleCannotBeSaved, :HTTPError
6
+ ]
7
+
8
+ exceptions.each { |e| const_set(e, Class.new(StandardError)) }
22
9
  end
@@ -0,0 +1,86 @@
1
+ require 'nokogiri'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+
5
+ module Addic7ed
6
+ class Parser
7
+
8
+ def initialize(episode, lang)
9
+ @episode, @lang = episode, lang
10
+ @subtitles = []
11
+ end
12
+
13
+ def extract_subtitles
14
+ @dom = subtitles_page_dom
15
+ check_subtitles_presence
16
+ parse_subtitle_nodes_list
17
+ @subtitles
18
+ end
19
+
20
+ protected
21
+
22
+ def subtitles_page_dom
23
+ response = Net::HTTP.get_response(URI(@episode.url(@lang)))
24
+ raise EpisodeNotFound unless response.body
25
+ Nokogiri::HTML(response.body)
26
+ end
27
+
28
+ def check_subtitles_presence
29
+ raise NoSubtitleFound unless @dom.css('select#filterlang ~ font[color="yellow"]').empty?
30
+ end
31
+
32
+ def parse_subtitle_nodes_list
33
+ sublist_node = @dom.css('#container95m table.tabel95 table.tabel95')
34
+ raise NoSubtitleFound if sublist_node.size == 0
35
+ sublist_node.each do |sub_node|
36
+ @subtitles << parse_subtitle_node(sub_node)
37
+ end
38
+ end
39
+
40
+ def parse_subtitle_node(sub_node)
41
+ version = extract_version(sub_node)
42
+ language = extract_language(sub_node)
43
+ status = extract_status(sub_node)
44
+ url = extract_url(sub_node)
45
+ source = extract_source(sub_node)
46
+ downloads = extract_downloads(sub_node)
47
+ Addic7ed::Subtitle.new(version, language, status, url, source, downloads)
48
+ end
49
+
50
+ def extract_version(sub_node)
51
+ version_node = sub_node.css('.NewsTitle').first
52
+ raise Addic7ed::ParsingError unless version_node
53
+ version_node.content.gsub(/ \nVersion /, '').gsub(/,.*/, '')
54
+ end
55
+
56
+ def extract_language(sub_node)
57
+ language_node = sub_node.css('.language').first
58
+ raise Addic7ed::ParsingError unless language_node
59
+ language_node.content.gsub(/\A\W*/, '').gsub(/[^\w\)]*\z/, '')
60
+ end
61
+
62
+ def extract_status(sub_node)
63
+ status_node = sub_node.css('tr:nth-child(3) td:nth-child(4) b').first
64
+ raise Addic7ed::ParsingError unless status_node
65
+ status_node.content.strip
66
+ end
67
+
68
+ def extract_url(sub_node)
69
+ url_node = sub_node.css('a.buttonDownload').last
70
+ raise Addic7ed::ParsingError unless url_node
71
+ 'http://www.addic7ed.com' + url_node['href']
72
+ end
73
+
74
+ def extract_source(sub_node)
75
+ source_node = sub_node.css('tr:nth-child(3) td:first-child a').first
76
+ source_node['href'] if source_node
77
+ end
78
+
79
+ def extract_downloads(sub_node)
80
+ downloads_node = sub_node.css('tr:nth-child(4) td.newsDate').first
81
+ raise Addic7ed::ParsingError unless downloads_node
82
+ /(?<downloads>\d*) Downloads/.match(downloads_node.content)[:downloads]
83
+ end
84
+
85
+ end
86
+ end
@@ -17,7 +17,19 @@ module Addic7ed
17
17
  "#{url}\t->\t#{@version} (#{language}, #{status}) [#{@downloads} downloads]#{" (via #{via})" if @via}"
18
18
  end
19
19
 
20
- private
20
+ def works_for?(version = '')
21
+ is_completed? and is_compatible_with? version
22
+ end
23
+
24
+ def can_replace?(other_sub)
25
+ return false unless is_completed?
26
+ return true if other_sub.nil?
27
+ language == other_sub.language and
28
+ is_compatible_with? other_sub.version and
29
+ is_more_popular_than? other_sub
30
+ end
31
+
32
+ protected
21
33
 
22
34
  def normalized_version(version)
23
35
  version.
@@ -30,5 +42,21 @@ module Addic7ed
30
42
  upcase
31
43
  end
32
44
 
45
+ def is_completed?
46
+ status == 'Completed'
47
+ end
48
+
49
+ def is_compatible_with?(other_version)
50
+ version == other_version or
51
+ COMPATIBILITY_720P[version] == other_version or
52
+ COMPATIBILITY_720P[other_version] == version
53
+ end
54
+
55
+ def is_more_popular_than?(other_sub)
56
+ return true if other_sub.nil?
57
+ return false if other_sub.via == 'http://addic7ed.com'
58
+ return downloads > other_sub.downloads
59
+ end
60
+
33
61
  end
34
62
  end
@@ -1,3 +1,3 @@
1
1
  module Addic7ed
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -2,17 +2,22 @@ require 'spec_helper'
2
2
  require './lib/addic7ed'
3
3
 
4
4
  describe Addic7ed do
5
+
5
6
  it 'should define SHOWS_URL' do
6
7
  Addic7ed::SHOWS_URL.should_not be_nil
7
8
  end
9
+
8
10
  it 'should define EPISODES_URL' do
9
11
  Addic7ed::EPISODES_URL.should_not be_nil
10
12
  end
13
+
11
14
  it 'should define EPISODE_REDIRECT_URL' do
12
15
  Addic7ed::EPISODE_REDIRECT_URL.should_not be_nil
13
16
  end
17
+
14
18
  it 'should define LANGUAGES' do
15
19
  Addic7ed::LANGUAGES.should_not be_nil
16
20
  Addic7ed::LANGUAGES['fr'].should == {name: 'French', id: 8}
17
21
  end
22
+
18
23
  end
@@ -2,10 +2,13 @@ require 'spec_helper'
2
2
  require './lib/addic7ed'
3
3
 
4
4
  describe Addic7ed::Episode do
5
+
5
6
  before :all do
6
- @filename = 'Californication.S06E07.720p.HDTV.x264-2HD.mkv'
7
- @filename_show_not_found = 'Show.Not.Found.S06E07.720p.HDTV.x264-2HD.mkv'
8
- @filename_episode_not_found = 'Californication.S06E42.720p.HDTV.x264-2HD.mkv'
7
+ @filename = 'The.Walking.Dead.S03E02.720p.HDTV.x264-EVOLVE.mkv'
8
+ @filename_show_not_found = 'Show.Not.Found.S03E02.720p.HDTV.x264-EVOLVE.mkv'
9
+ @filename_episode_not_found = 'The.Walking.Dead.S03E42.720p.HDTV.x264-EVOLVE.mkv'
10
+ @filename_compatible_group = 'The.Walking.Dead.S03E04.HDTV.XviD-ASAP.mkv'
11
+ @episode = Addic7ed::Episode.new(@filename)
9
12
  end
10
13
 
11
14
  it 'should create valid instance given valid argument' do
@@ -15,89 +18,106 @@ describe Addic7ed::Episode do
15
18
  end
16
19
 
17
20
  describe '#url' do
18
- before :all do
19
- @episode = Addic7ed::Episode.new(@filename)
20
- end
21
+
21
22
  it 'should return a show localized URL given existing episode' do
22
- @episode.url('fr').should == 'http://www.addic7ed.com/serie/Californication/6/7/8'
23
- @episode.url('es').should == 'http://www.addic7ed.com/serie/Californication/6/7/4'
23
+ @episode.url('fr').should == 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/8'
24
+ @episode.url('es').should == 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/4'
24
25
  end
26
+
25
27
  it 'should use French as default language' do
26
28
  @episode.url.should == @episode.url('fr')
27
29
  end
30
+
28
31
  it 'should raise LanguageNotSupported given an unsupported language code' do
29
32
  expect{
30
33
  @episode.url('aa')
31
34
  }.to raise_error(Addic7ed::LanguageNotSupported)
32
35
  end
36
+
33
37
  end
34
38
 
35
39
  describe '#subtitles' do
36
- before :all do
37
- @filename = 'The.Walking.Dead.S03E02.720p.HDTV.x264-IMMERSE.mkv'
38
- @episode = Addic7ed::Episode.new(@filename)
39
- end
40
+
40
41
  it 'should return an array of Addic7ed::Subtitle given valid episode and language' do
42
+ ['fr', 'en', 'it'].each do |lang|
43
+ lang_id = Addic7ed::LANGUAGES[lang][:id]
44
+ stub_request(:get, "http://www.addic7ed.com/serie/The_Walking_Dead/3/2/#{lang_id}")
45
+ .to_return File.new("spec/responses/walking-dead-3-2-#{lang_id}.http")
46
+ end
41
47
  @episode.subtitles('fr').size.should == 4
42
48
  @episode.subtitles('en').size.should == 3
43
49
  @episode.subtitles('it').size.should == 1
44
50
  end
51
+
45
52
  it 'should use French as default language' do
46
53
  @episode.subtitles.should == @episode.subtitles('fr')
47
54
  end
55
+
48
56
  it 'should raise LanguageNotSupported given an unsupported language code' do
49
57
  expect{
50
58
  @episode.subtitles('aa')
51
59
  }.to raise_error(Addic7ed::LanguageNotSupported)
52
60
  end
61
+
53
62
  it 'should raise EpisodeNotFound given not existing episode' do
63
+ stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/42/8')
64
+ .to_return File.new('spec/responses/walking-dead-3-42-8.http')
54
65
  expect{
55
66
  Addic7ed::Episode.new(@filename_episode_not_found).subtitles
56
67
  }.to raise_error(Addic7ed::EpisodeNotFound)
57
68
  end
69
+
58
70
  it 'should raise NoSubtitleFound given valid episode which has no subtitle on Addic7ed' do
71
+ stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/48')
72
+ .to_return File.new('spec/responses/walking-dead-3-2-48.http')
59
73
  expect{
60
- @episode.subtitles('es')
74
+ @episode.subtitles('az')
61
75
  }.to raise_error(Addic7ed::NoSubtitleFound)
62
76
  end
77
+
63
78
  it 'may raise a ParsingError, but I don\'t know how to test it :-('
64
- it 'may raise a WTFError, but it\'s unsure when, so it stays untested'
79
+
65
80
  end
66
81
 
67
82
  describe '#best_subtitle' do
68
- before :all do
69
- @filename = 'The.Walking.Dead.S03E03.720p.HDTV.x264-EVOLVE.mkv'
70
- @filename_compatible_group = 'The.Walking.Dead.S03E06.720p.HDTV.x264-IMMERSE.mkv'
71
- @episode = Addic7ed::Episode.new(@filename)
72
- end
83
+
73
84
  it 'should find the subtitle with status completed and same group name' do
74
- @episode.best_subtitle('fr').url.should == 'http://www.addic7ed.com/updated/8/68290/2'
85
+ stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/8')
86
+ .to_return File.new('spec/responses/walking-dead-3-2-8.http')
87
+ @episode.best_subtitle('fr').url.should == 'http://www.addic7ed.com/original/68018/4'
75
88
  end
89
+
76
90
  it 'should find the subtitle with status completed, compatible group name and as many downloads as possible' do
77
- @episode = Addic7ed::Episode.new(@filename_compatible_group)
78
- @episode.best_subtitle('fr').url.should == 'http://www.addic7ed.com/updated/8/68980/2'
91
+ stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/4/8')
92
+ .to_return File.new('spec/responses/walking-dead-3-4-8.http')
93
+ compatible_episode = Addic7ed::Episode.new(@filename_compatible_group)
94
+ compatible_episode.best_subtitle('fr').url.should == 'http://www.addic7ed.com/updated/8/68508/3'
79
95
  end
96
+
80
97
  it 'should use French as default language' do
81
98
  @episode.best_subtitle.should == @episode.best_subtitle('fr')
82
99
  end
100
+
83
101
  it 'should raise LanguageNotSupported given an unsupported language code' do
84
102
  expect{
85
103
  @episode.best_subtitle('aa')
86
104
  }.to raise_error(Addic7ed::LanguageNotSupported)
87
105
  end
88
- it 'should raise EpisodeNotFound given not existing episode' do
89
- expect{
90
- Addic7ed::Episode.new(@filename_episode_not_found).best_subtitle
91
- }.to raise_error(Addic7ed::EpisodeNotFound)
92
- end
106
+
93
107
  it 'should raise NoSubtitleFound given valid episode which has no subtitle on Addic7ed' do
108
+ stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/48')
109
+ .to_return File.new('spec/responses/walking-dead-3-2-48.http')
94
110
  expect{
95
- @episode.best_subtitle('es')
111
+ @episode.best_subtitle('az')
96
112
  }.to raise_error(Addic7ed::NoSubtitleFound)
97
113
  end
114
+
98
115
  end
99
116
 
100
117
  describe '#download_best_subtitle!' do
118
+
101
119
  it 'should be tested, but I\'m not sure how to do it properly'
120
+
102
121
  end
122
+
103
123
  end