<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,8 @@
 #!/usr/bin/env ruby
 #  SubtitleIt
 #
-#  Created on 2008-9-4.
-#  Copyright (c) 2008. All rights reserved.
+#  Created on 2008-09-04.
+#  Copyleft (c) 2008. MIT License.
 #
 begin
   require 'rubygems'
@@ -31,7 +31,7 @@ Usage: #{File.basename($0)} [options] movie or file_in [file_out]
 BANNER
 
   opts.separator &quot; Options are:&quot;
-  
+
   opts.on(&quot;-l&quot;, &quot;--language [LANGUAGE]&quot;, String,
           &quot;Language to search subtitles for, try it empty to see the supported ones.&quot;) do |OPTIONS[:lang]|
     if OPTIONS[:lang].nil?
@@ -42,18 +42,18 @@ BANNER
 
   opts.on(&quot;-c&quot;, &quot;--convert=FORMAT&quot;, String,
           &quot;Format to convert to&quot;) { |OPTIONS[:format]| }
-          
+
   opts.on(&quot;-d&quot;, &quot;--delay=DELAY&quot;, Float,
           &quot;Delay to add/remove&quot;) { |OPTIONS[:delay]| }
-          
-  opts.on(&quot;-f&quot;, &quot;--force&quot;, &quot;Force overwrite&quot;) { OPTIONS[:force] = true }          
-          
+
+  opts.on(&quot;-f&quot;, &quot;--force&quot;, &quot;Force overwrite&quot;) { OPTIONS[:force] = true }
+
   opts.on(&quot;-h&quot;, &quot;--help&quot;,
-          &quot;Show this help message.&quot;) { puts opts; exit }          
-          
+          &quot;Show this help message.&quot;) { puts opts; exit }
+
   opts.on(&quot;-v&quot;, &quot;--version&quot;,
-          &quot;Show program version&quot;) {   puts &quot;SubtitleIt v#{SubtitleIt::VERSION::STRING}&quot;; exit }          
-          
+          &quot;Show program version&quot;) {   puts &quot;SubtitleIt v#{SubtitleIt::VERSION::STRING}&quot;; exit }
+
   opts.parse!(ARGV)
 
   if MANDATORY_OPTIONS &amp;&amp; MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
@@ -67,4 +67,3 @@ if ARGV.empty?
 else
   SubtitleIt::Bin.run! ARGV, OPTIONS[:lang], OPTIONS[:format], OPTIONS[:force], OPTIONS[:delay]
 end
-</diff>
      <filename>bin/subtitle_it</filename>
    </modified>
    <modified>
      <diff>@@ -1,36 +1,38 @@
 module SubtitleIt
-  #TODO: create a lang class?
-  # now I`m more lost.... opensubtitle uses a 3 chars like
+  #  opensubtitle uses a 3 chars like
   # Por =&gt; Portuguese
   # Cze =&gt; Czech ....
+  #
+  # LANGUAGE /  HUMAN NAME /  OPENSUBTITLE CODE
   LANGS = {
     :aa =&gt;  'Afar',
     :ab =&gt;  'Abkhazian',
     :af =&gt;  'Afrikaans',
     :ak =&gt;  'Akan',
+    :ay =&gt;  'Assyrian',
     :sq =&gt;  'Albanian',
     :am =&gt;  'Amharic',
     :ar =&gt;  'Arabic',
-    :pb =&gt;  'Brazilian Portuguese',
+    :br =&gt;  ['Brazilian', 'por'],
     :hy =&gt;  'Armenian',
     :bs =&gt;  'Bosnian',
     :bg =&gt;  'Bulgarian',
     :ca =&gt;  'Catalan',
-    :zh =&gt;  'Chinese',
     :cs =&gt;  'Czech',
     :da =&gt;  'Danish',
     :nl =&gt;  'Dutch',
+    :en =&gt;  ['English','eng'],
     :et =&gt;  'Estonian',
-    :fr =&gt;  'French',
+    :fr =&gt;  ['French', 'fra'],
     :de =&gt;  'German',
-    :gl =&gt;  'Galician',	
+    :gl =&gt;  'Galician',
     :el =&gt;  'Greek',
     :he =&gt;  'Hebrew',
     :hi =&gt;  'Hindi',
     :hr =&gt;  'Croatian',
     :hu =&gt;  'Hungarian',
     :is =&gt;  'Icelandic',
-    :id =&gt;  'Indonesian',	
+    :id =&gt;  'Indonesian',
     :it =&gt;  'Italian',
     :ja =&gt;  'Japanese',
     :kk =&gt;  'Kazakh',
@@ -54,14 +56,6 @@ module SubtitleIt
     :uk =&gt;  'Ukrainian',
     :vi =&gt;  'Vietnamese',
     :ro =&gt;  'Romanian',
-    :pb =&gt;  'Brazilian',
-    :ay =&gt;  'Assyrian',
-    :en =&gt;  'English'
-  }
-
-  OPSUB_LANGS = {
-    # TODO : add the other languages id
-    :fr =&gt; 'fra',
-    :en =&gt; 'eng'
+    :zh =&gt;  'Chinese'
   }
 end</diff>
      <filename>lib/subtitle_it/languages.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@ require 'stringio'
 
 require 'subtitle_it/version'
 require 'subtitle_it/subtitle'
+require 'subtitle_it/languages'
 
 module SubtitleIt
   class Subdown
@@ -38,10 +39,10 @@ module SubtitleIt
       call('ServerInfo')
     end
 
-    def search_subtitles(movie, lang='')
-      lang ||= &quot;&quot;
-      lang_id = Subdown.opsub_id(lang) unless lang == &quot;&quot;
-      puts &quot;Searching for &quot; + lang + &quot; =&gt; id: &quot; + lang_id.to_s unless lang == &quot;&quot;
+    def search_subtitles(movie, lang_id=nil)
+      lang_name, lang_id = LANGS[:lang_id]
+      STDOUT.print &quot;Searching for &quot;
+      STDOUT.puts lang_id ? lang_name : &quot;all languages.&quot;
       args = {
         'sublanguageid' =&gt; lang_id,
         'moviehash'     =&gt; movie.haxx,
@@ -58,7 +59,7 @@ module SubtitleIt
 
     def download_subtitle(sub)
       result = call('DownloadSubtitles', [sub.osdb_id])
-      sub.data = self.class.decode_and_unzip(result['data'][0]['data'])     
+      sub.data = self.class.decode_and_unzip(result['data'][0]['data'])
     end
 
     def upload_subtitle(movie, subs)
@@ -74,53 +75,50 @@ module SubtitleIt
       # TODO.. get the correct codes
 #    end
 #
-    def Subdown.opsub_id( language )		# Get the Opensubtitle.org language id from the language string (e.g. 'French' returns 'fra' )
-      ary = LANGS.find do |sym_lang| 
-        sym_lang if sym_lang[1].downcase == language.downcase 
-      end
-      OPSUB_LANGS[ ary[0] ]
-    end
-    
-    def Subdown.subtitle_languages
-      lang_ary = []
-      OPSUB_LANGS.each_key do |key| 
-        lang_ary.push( LANGS[key] )
-      end
-      lang_ary.sort.inject( &quot;&quot; ) do |str, lang|
-        str += lang + &quot; &quot;
-	str
-      end
-    end
+#    def Subdown.opsub_id( language )		# Get the Opensubtitle.org language id from the language string (e.g. 'French' returns 'fra' )
+#      ary = LANGS.find do |sym_lang|
+#        sym_lang if sym_lang[1].downcase == language.downcase
+#      end
+#      OPSUB_LANGS[ ary[0] ]
+#    end
+
+#    def Subdown.subtitle_languages
+#      lang_ary = []
+#      OPSUB_LANGS.each_key do |key|
+#        lang_ary.push( LANGS[key] )
+#      end
+#      lang_ary.sort.inject( &quot;&quot; ) { |str, lang| str &lt;&lt; lang + &quot; &quot; }
+#    end
 
     private
 
-      def call(method, *args)
-        unless NO_TOKEN.include? method
-          raise 'Need to be logged in for this.' unless logged_in?
-          args = [@token, *args]
-        end
+    def call(method, *args)
+      unless NO_TOKEN.include? method
+        raise 'Need to be logged in for this.' unless logged_in?
+        args = [@token, *args]
+      end
 
-        result = @client.call(method, *args)
+      result = @client.call(method, *args)
 #        $LOG.debug &quot;Client#call #{method}, #{args.inspect}: #{result.inspect}&quot;
-        
-        if !self.class.result_status_ok?(result)
-          raise XMLRPC::FaultException.new(result['status'].to_i, result['status'][4..-1]) # 'status' of the form 'XXX Message'
-        end
-        
-        result
-      end
-      
-      # Returns true if status is OK (ie. in range 200-299) or don't exists.
-      def self.result_status_ok?(result)
-        !result.key?('status') || (200...300) === result['status'].to_i
-      end
 
-      def prevent_session_expiration
-        call('NoOperation')
+      unless self.class.result_status_ok?(result)
+        raise XMLRPC::FaultException.new(result['status'].to_i, result['status'][4..-1]) # 'status' of the form 'XXX Message'
       end
 
-      def self.decode_and_unzip(data)
-        Zlib::GzipReader.new(StringIO.new(XMLRPC::Base64.decode(data))).read
-      end
+      result
+    end
+
+    # Returns true if status is OK (ie. in range 200-299) or don't exists.
+    def self.result_status_ok?(result)
+      !result.key?('status') || (200...300) === result['status'].to_i
+    end
+
+    def prevent_session_expiration
+      call('NoOperation')
+    end
+
+    def self.decode_and_unzip(data)
+      Zlib::GzipReader.new(StringIO.new(XMLRPC::Base64.decode(data))).read
+    end
   end
 end</diff>
      <filename>lib/subtitle_it/subdown.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,39 +3,43 @@
 module SubtitleIt
   class Subtime
     attr_accessor :hrs, :min, :sec, :ms
-        
-    def initialize(data) 
-      raise if data == nil          
+
+    def initialize(data)
+      raise if data == nil
       parse_data(data)
     end
-        
+
     # parses string like '00:00:00,000' or single number as ms.
     def parse_data(data)
       case data
-      when Numeric 
-        @sec, @ms = data.divmod(1000)
+      when Numeric
+        @sec, @ms  = data.divmod(1000)
         @min, @sec = @sec.divmod(60)
         @hrs, @min = @min.divmod(60)
-      when String 
+      when String
         time, float = data.split(/\.|\,/)
         time = time.split(/:/).map { |s| s.to_i }
         @ms =  ((&quot;0.%d&quot; % float.to_i).to_f * 1000).to_i if float
         @sec, @min, @hrs = time.reverse
       else raise &quot;Format unknown.&quot;
-      end 
+      end
       #FIXME: dunno what to do about this.. nil = problems with to_i
       @hrs ||= 0; @min ||= 0; @sec ||= 0;  @ms ||= 0
     end
 
     # to_s(separator) =&gt; to_s(&quot;,&quot;) =&gt; 00:00:00,000
-    def to_s(sep='.'); &quot;%02d:%02d:%02d#{sep}%03d&quot; % [@hrs, @min, @sec,  @ms];    end
-    
+    def to_s(sep='.')
+      &quot;%02d:%02d:%02d#{sep}%03d&quot; % [@hrs, @min, @sec,  @ms]
+    end
+
     # return time as a total in ms
-    def to_i;  ( @hrs * 3600 + @min * 60 + @sec ) * 1000 + @ms;    end
-    
-    def +(other);   Subtime.new(self.to_i + other.to_i);    end    
-    def -(other);   Subtime.new(self.to_i - other.to_i);    end    
+    def to_i
+      ( @hrs * 3600 + @min * 60 + @sec ) * 1000 + @ms
+    end
+
+    def +(other);   Subtime.new(self.to_i + other.to_i);    end
+    def -(other);   Subtime.new(self.to_i - other.to_i);    end
     def &lt;=&gt;(other);      self.to_i &lt;=&gt; other.to_i;    end
     include Comparable
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/subtitle_it/subtime.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,44 +2,44 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
 module SubdownHelper
   def mock_xmlrpc(stubs={})
-    @mock_xmlrpc ||= mock(XMLRPC::Client, stubs)#, @auth=nil, @parser=nil, @user=nil, @timeout=30, @cookie=nil, @http=#&lt;Net::HTTP www.opensubtitles.org:80 open=false&gt;, @use_ssl=false, @http_last_response=nil, @port=80, @host=&quot;www.opensubtitles.org&quot;, @path=&quot;/xml-rpc&quot;, @http_header_extra=nil, @create=nil, @password=nil, @proxy_port=nil, @proxy_host=nil&gt; 
+    @mock_xmlrpc ||= mock(XMLRPC::Client, stubs)#, @auth=nil, @parser=nil, @user=nil, @timeout=30, @cookie=nil, @http=#&lt;Net::HTTP www.opensubtitles.org:80 open=false&gt;, @use_ssl=false, @http_last_response=nil, @port=80, @host=&quot;www.opensubtitles.org&quot;, @path=&quot;/xml-rpc&quot;, @http_header_extra=nil, @create=nil, @password=nil, @proxy_port=nil, @proxy_host=nil&gt;
   end
   def mock_movie
-    @mock_movie = mock(Movie, :haxx =&gt; '09a2c497663259cb')
+    @mock_movie = mock(Movie, :haxx =&gt; '09a2c497663259cb', :size =&gt; 81401)
   end
 end
 
 
 describe Subdown do
   include SubdownHelper
-  
+
   before(:each) do
-    @sub = mock(Subtitle)    
+    @sub = mock(Subtitle)
   end
-  
+
   it &quot;should initialize nicely&quot; do
     XMLRPC::Client.should_receive(:new2)
-    @down = Subdown.new    
+    @down = Subdown.new
   end
-  
+
   it &quot;should log in!&quot; do
     XMLRPC::Client.should_receive(:new2).with('http://www.opensubtitles.org/xml-rpc').and_return(mock_xmlrpc)
     @mock_xmlrpc.should_receive(:call).with(&quot;LogIn&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;SubtitleIt #{SubtitleIt::VERSION::STRING}&quot;).and_return({
-      &quot;status&quot;=&gt;&quot;200 OK&quot;, 
-      &quot;seconds&quot;=&gt;0.004, 
+      &quot;status&quot;=&gt;&quot;200 OK&quot;,
+      &quot;seconds&quot;=&gt;0.004,
       &quot;token&quot;=&gt;&quot;shkuj98gcvu5gp1b5tlo8uq525&quot;
       })
     @down = Subdown.new
-    @down.should_not be_logged_in    
+    @down.should_not be_logged_in
     @down.log_in!
     @down.should be_logged_in
   end
-  
+
   it &quot;should raise if connection sux&quot; do
     XMLRPC::Client.should_receive(:new2).with('http://www.opensubtitles.org/xml-rpc').and_return(mock_xmlrpc)
     @mock_xmlrpc.should_receive(:call).with(&quot;LogIn&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;SubtitleIt #{SubtitleIt::VERSION::STRING}&quot;).and_return({
-      &quot;status&quot;=&gt;&quot;404 FAIL&quot;, 
-      &quot;seconds&quot;=&gt;0.004, 
+      &quot;status&quot;=&gt;&quot;404 FAIL&quot;,
+      &quot;seconds&quot;=&gt;0.004,
       &quot;token&quot;=&gt;&quot;&quot;
       })
     @down = Subdown.new
@@ -48,47 +48,89 @@ describe Subdown do
   end
 
 
-  describe &quot;Instantiate&quot; do
+  describe &quot;Logged in&quot; do
     before(:each) do
-      @down = Subdown.new     
+      XMLRPC::Client.should_receive(:new2).
+        with('http://www.opensubtitles.org/xml-rpc').
+        and_return(mock_xmlrpc)
+
+      @mock_xmlrpc.should_receive(:call).with(&quot;LogIn&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;,
+        &quot;SubtitleIt #{SubtitleIt::VERSION::STRING}&quot;).and_return({
+          &quot;status&quot;=&gt;&quot;200 OK&quot;,
+          &quot;seconds&quot;=&gt;0.004,
+          &quot;token&quot;=&gt;&quot;shkuj98gcvu5gp1b5tlo8uq525&quot;
+      })
+      @down = Subdown.new
+      @down.log_in!
     end
-    
-    it &quot;should get subtitle languages&quot; do
-      @down.subtitle_languages.should be_instance_of(Array)
-      @down.subtitle_languages.length.should eql(51)
-      @down.subtitle_languages[0].should be_instance_of(String)
+
+    it &quot;should search for all languages&quot; do
+      @mock_xmlrpc.should_receive(:call).with(&quot;SearchSubtitles&quot;,
+        &quot;shkuj98gcvu5gp1b5tlo8uq525&quot;, [{
+          &quot;sublanguageid&quot;=&gt;nil,
+          &quot;moviebytesize&quot;=&gt;81401,
+          &quot;moviehash&quot;=&gt;&quot;09a2c497663259cb&quot;}]).and_return(
+            { :result =&gt; 200 }
+          )
+
+      STDOUT.should_receive(:print).with(&quot;Searching for &quot;)
+      STDOUT.should_receive(:puts).with(&quot;all languages.&quot;)
+      @down.search_subtitles(mock_movie).
+        should eql([])
     end
-        
+
+    it &quot;should search for one languages&quot; do
+      @mock_xmlrpc.should_receive(:call).with(&quot;SearchSubtitles&quot;,
+        &quot;shkuj98gcvu5gp1b5tlo8uq525&quot;, [{
+          &quot;sublanguageid&quot;=&gt;nil,
+          &quot;moviebytesize&quot;=&gt;81401,
+          &quot;moviehash&quot;=&gt;&quot;09a2c497663259cb&quot;}]).and_return(
+            { :result =&gt; 200 }
+          )
+
+      STDOUT.should_receive(:print).with(&quot;Searching for &quot;)
+      STDOUT.should_receive(:puts).with(&quot;portuguese.&quot;)
+      @down.search_subtitles(mock_movie, &quot;por&quot;).
+        should eql([])
+    end
+
+#    it &quot;should get subtitle languages&quot; do
+#      @down.subtitle_languages.should be_instance_of(Array)
+#      @down.subtitle_languages.length.should eql(51)
+#      @down.subtitle_languages[0].should be_instance_of(String)
+#    end
+
   end
 end
 
-#  REAL TESTS THAT USES THE INTERNET... DUNNO BETTER PRACTICE FOR THIS
-#   Mock is nice, but I would like to keep this here, who knows if
+#  REAL TESTS THAT USES THE WIRE... DUNNO BETTER PRACTICE FOR THIS
+#
+#   Mock is above, but I`ll keep this here, who knows if
 #   Opensubtitle API changes.... any suggestions?
-# 
-# # 
+#
+# #
 # describe Subdown, &quot; - Wired tests&quot; do
 #   before(:each) do
 #     @down = Subdown.new
 #     @movie = mock(Movie, :haxx =&gt; '09a2c497663259cb')
 #     @down.log_in!
 #   end
-# 
+#
 #   it &quot;should get imdb info&quot; do
-#     @movie.should_receive('info=').with({&quot;MovieYear&quot;=&gt;&quot;2004&quot;, 
-#       &quot;MovieImdbID&quot;=&gt;&quot;403358&quot;, 
-#       &quot;MovieName&quot;=&gt;&quot;Nochnoy dozor&quot;, 
+#     @movie.should_receive('info=').with({&quot;MovieYear&quot;=&gt;&quot;2004&quot;,
+#       &quot;MovieImdbID&quot;=&gt;&quot;403358&quot;,
+#       &quot;MovieName&quot;=&gt;&quot;Nochnoy dozor&quot;,
 #       &quot;MovieHash&quot;=&gt;&quot;09a2c497663259cb&quot;})
 #     @down.imdb_info(@movie)
 #   end
-#   
+#
 #   it &quot;should search subs info&quot; do
-# 
+#
 #     @movie.stub!(:size).and_return(733589504)
 #     res = @down.search_subtitles(@movie, 'pt')
 #     res.should be_instance_of(Array)
-#     res.each do |r| 
+#     res.each do |r|
 #       r.should be_instance_of(Subtitle)
 #     end
 #   end
-# end
\ No newline at end of file
+# end</diff>
      <filename>spec/subtitle_it/subdown_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>.autotest</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>a586aa7c46b2c8004115de7bf5e891b858ad3904</id>
    </parent>
  </parents>
  <author>
    <name>Marcos Augusto</name>
    <email>x@nofxx.com</email>
  </author>
  <url>http://github.com/nofxx/subtitle_it/commit/ed8c72e37337689e4da162336bb217b87efdb6a2</url>
  <id>ed8c72e37337689e4da162336bb217b87efdb6a2</id>
  <committed-date>2008-10-28T08:57:44-07:00</committed-date>
  <authored-date>2008-10-28T08:57:44-07:00</authored-date>
  <message>specs works again...langs soon</message>
  <tree>1e19871bcabcdd6e6bd7ee71b643838f945af599</tree>
  <committer>
    <name>Marcos Augusto</name>
    <email>x@nofxx.com</email>
  </committer>
</commit>
