Class: SubtitleIt::Subdown

Inherits:
Object
  • Object
show all
Defined in:
lib/subtitle_it/subdown.rb

Constant Summary collapse

@@host =
"http://www.opensubtitles.org/xml-rpc"
@@host_dev =
"http://dev.opensubtitles.org/xml-rpc"
@@user_agent =
"SubtitleIt #{SubtitleIt::VERSION}"
@@no_token =
%w(ServerInfo LogIn)

Instance Method Summary collapse

Constructor Details

#initialize(host = @@host) ⇒ Subdown

Returns a new instance of Subdown.



18
19
20
21
# File 'lib/subtitle_it/subdown.rb', line 18

def initialize(host = @@host)
  @client = XMLRPC::Client.new2(host)
  @token = nil
end

Instance Method Details

#download_subtitle(sub) ⇒ Object



56
57
58
59
60
# File 'lib/subtitle_it/subdown.rb', line 56

def download_subtitle(sub)
  result = call('DownloadSubtitles', [sub.id])
  sub.data = self.class.decode_and_unzip(result['data'][0]['data'])
  
end

#imdb_info(movie) ⇒ Object



65
66
67
68
# File 'lib/subtitle_it/subdown.rb', line 65

def imdb_info(movie)
  result = call('CheckMovieHash', [movie.haxx])
  movie.info = result['data'][movie.haxx] # TODO: Handle if no result for movie
end

#log_in!Object



23
24
25
26
# File 'lib/subtitle_it/subdown.rb', line 23

def log_in!
  result = call('LogIn', '', '', '', @@user_agent)
  @token = result['token'].to_s
end

#log_out!Object



32
33
34
35
# File 'lib/subtitle_it/subdown.rb', line 32

def log_out!
  call('LogOut')
  @token = nil
end

#logged_in?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/subtitle_it/subdown.rb', line 28

def logged_in?
  !@token.nil? && !@token.empty?
end

#search_subtitles(movie) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/subtitle_it/subdown.rb', line 41

def search_subtitles(movie)
  args = {
    'sublanguageid' => '',
    'moviehash'     => movie.haxx,
    'moviebytesize' => movie.size
  }

  result = call('SearchSubtitles', [args])
  return [] unless result['data'] # if no results result['data'] == false
  result['data'].inject([]) do |subs, sub_info|
    subs << Subtitle.new(nil,nil,sub_info)
    subs
  end
end

#server_infoObject



37
38
39
# File 'lib/subtitle_it/subdown.rb', line 37

def server_info
  call('ServerInfo')
end

#subtitle_languagesObject



70
71
# File 'lib/subtitle_it/subdown.rb', line 70

def subtitle_languages
end

#upload_subtitle(movie, subs) ⇒ Object



62
63
# File 'lib/subtitle_it/subdown.rb', line 62

def upload_subtitle(movie, subs)
end