suby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,13 +71,21 @@ module Suby
71
71
  extract download_url
72
72
  end
73
73
 
74
- def extract(url)
75
- contents = get(url)
74
+ def subtitles(url_or_response = download_url)
75
+ if Net::HTTPSuccess === url_or_response
76
+ url_or_response.body
77
+ else
78
+ get(url_or_response)
79
+ end
80
+ end
81
+
82
+ def extract(url_or_response)
83
+ contents = subtitles(url_or_response)
76
84
  http.finish
77
85
  format = self.class::FORMAT
78
86
  case format
79
87
  when :file
80
- open(sub_name(url), 'wb') { |f| f.write contents }
88
+ open(sub_name(contents), 'wb') { |f| f.write contents }
81
89
  when :zip
82
90
  open(TEMP_ARCHIVE_NAME, 'wb') { |f| f.write contents }
83
91
  Suby.extract_sub_from_archive(TEMP_ARCHIVE_NAME, format, basename)
@@ -90,8 +98,16 @@ module Suby
90
98
  File.basename(file, File.extname(file))
91
99
  end
92
100
 
93
- def sub_name(sub)
94
- basename + File.extname(sub)
101
+ def sub_name(contents)
102
+ basename + sub_extension(contents)
103
+ end
104
+
105
+ def sub_extension(contents)
106
+ if contents[0..10] =~ /1\r?\n/
107
+ '.srt'
108
+ else
109
+ '.sub'
110
+ end
95
111
  end
96
112
  end
97
113
  end
@@ -36,11 +36,17 @@ module Suby
36
36
 
37
37
  def redirected_url download_url
38
38
  header = { 'Referer' => "http://#{SITE}#{subtitles_url}" }
39
- location = get_redirection download_url, header # They check Referer
40
- if location == '/downloadexceeded.php'
41
- raise NotFoundError, "download exceeded"
39
+ response = get download_url, header, false
40
+ case response
41
+ when Net::HTTPSuccess
42
+ response
43
+ when Net::HTTPFound
44
+ location = response['Location']
45
+ if location == '/downloadexceeded.php'
46
+ raise NotFoundError, "download exceeded"
47
+ end
48
+ URI.escape location
42
49
  end
43
- URI.escape location
44
50
  end
45
51
 
46
52
  def download_url
data/suby.gemspec CHANGED
@@ -14,5 +14,5 @@ Gem::Specification.new do |s|
14
14
  s.add_dependency 'rubyzip2'
15
15
  s.add_dependency 'term-ansicolor'
16
16
 
17
- s.version = '0.1.1'
17
+ s.version = '0.1.2'
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-21 00:00:00.000000000 Z
12
+ date: 2011-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2156836860 !ruby/object:Gem::Requirement
16
+ requirement: &2153922380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156836860
24
+ version_requirements: *2153922380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rubyzip2
27
- requirement: &2156836400 !ruby/object:Gem::Requirement
27
+ requirement: &2153921780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156836400
35
+ version_requirements: *2153921780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: term-ansicolor
38
- requirement: &2156835980 !ruby/object:Gem::Requirement
38
+ requirement: &2153920880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156835980
46
+ version_requirements: *2153920880
47
47
  description: Find and download subtitles
48
48
  email: eregontp@gmail.com
49
49
  executables:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  requirements: []
85
85
  rubyforge_project:
86
- rubygems_version: 1.8.6.1
86
+ rubygems_version: 1.8.10
87
87
  signing_key:
88
88
  specification_version: 3
89
89
  summary: Subtitles' downloader