Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

encode in UTF-8 if latin1 for french subtitles

* Fix #5
  • Loading branch information...
commit 7b27c1a236e46616ef3b0ca8def537f25c959cda 1 parent 999d674
@eregon authored
Showing with 23 additions and 4 deletions.
  1. +23 −4 lib/suby/downloader.rb
View
27 lib/suby/downloader.rb
@@ -106,7 +106,7 @@ def extract(url_or_response)
else
raise "unknown subtitles format: #{format}"
end
- sub_name(contents).write contents
+ sub_name(contents).write encode contents
end
def sub_name(contents)
@@ -124,7 +124,7 @@ def sub_extension(contents)
def imdbid
@imdbid ||= begin
nfo_file = find_nfo_file
- convert_to_utf8(nfo_file.read)[%r!imdb\.[^/]+/title/tt(\d+)!i, 1] if nfo_file
+ convert_to_utf8_from_latin1(nfo_file.read)[%r!imdb\.[^/]+/title/tt(\d+)!i, 1] if nfo_file
end
end
@@ -132,17 +132,36 @@ def find_nfo_file
@file.dir.children.find { |file| file.ext == "nfo" }
end
- def convert_to_utf8(content)
+ def convert_to_utf8_from_latin1(content)
if content.valid_encoding?
content
else
- content.encode("UTF-8", "ISO-8859-1")
+ enc = content.encoding
+ if content.force_encoding("ISO-8859-1").valid_encoding?
+ yield if block_given?
+ content.encode("UTF-8")
+ else
+ # restore original encoding
+ subtitles.force_encoding(enc)
+ end
end
end
def success_message
"Found"
end
+
+ def encode(subtitles)
+ if @lang == :fr
+ convert_to_utf8_from_latin1(subtitles) do
+ def self.success_message
+ "#{super} (transcoded from ISO-8859-1)"
+ end
+ end
+ else
+ subtitles
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.