Module: Subscene

Extended by:
Subscene
Included in:
Subscene
Defined in:
lib/subscene.rb,
lib/subscene/error.rb,
lib/subscene/version.rb,
lib/subscene/response.rb,
lib/subscene/response/html.rb,
lib/subscene/response/raise_error.rb

Defined Under Namespace

Classes: Response, SearchNotSupported, Subtitle, SubtitleResult, SubtitleResultSet

Constant Summary collapse

ENDPOINT =
"http://subscene.com"
RELEASE_PATH =
"subtitles/release.aspx"
VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ Object

Public: Find a subtitle by id.

id - The id of the subtitle.

Examples

Subscene.find(136037)
# => TODO: display example result

Returns the complete information of the Subtitle.



72
73
74
75
76
77
78
79
# File 'lib/subscene.rb', line 72

def find(id)
  response = connection.get(id.to_s)
  html     = response.body

  subtitle = Subtitle.build(html)
  subtitle.id = id
  subtitle
end

#language=(lang_id) ⇒ Object

Public: Set the language id for the search filter.

lang_id - The id of the language. Maximum 3, comma separated.

Ids can be found at http://subscene.com/filter

Examples

Subscene.language = 13 # English
Subscene.search("...") # Results will be only English subtitles
Subscene.language = "13,38" # English, Spanish
...


93
94
95
# File 'lib/subscene.rb', line 93

def language=(lang_id)
  @lang_id = lang_id
end

#search(query = nil) ⇒ Object

Public: Search for a particular release.

query - The String to be found.

Examples

Subscene.search('The Big Bang Theory s01e01')
# => [#<Subscene::SubtitleResult:0x007feb7c9473b0
  @attributes={:id=>"136037", :name=>"The.Big.Bang.Theory.."]

Returns the Subtitles found.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/subscene.rb', line 49

def search(query=nil)
  params = { q: query } unless query.nil?
  params ||= {}

  response = connection.get do |req|
    req.url RELEASE_PATH, params
    req.headers['Cookie'] = "LanguageFilter=#{@lang_id};" if @lang_id
  end

  html = response.body
  SubtitleResultSet.build(html).instances
end