Class: Subscene::Subtitle
- Inherits:
-
Object
- Object
- Subscene::Subtitle
- Defined in:
- lib/subscene/subtitle.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#download_url ⇒ Object
Returns the value of attribute download_url.
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#framerate ⇒ Object
Returns the value of attribute framerate.
-
#hearing_impaired ⇒ Object
Returns the value of attribute hearing_impaired.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#user ⇒ Object
Returns the value of attribute user.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#download ⇒ Object
Public: Download a Subtitle file.
-
#initialize(attributes = {}) ⇒ Subtitle
constructor
A new instance of Subtitle.
Constructor Details
#initialize(attributes = {}) ⇒ Subtitle
Returns a new instance of Subtitle.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/subscene/subtitle.rb', line 6 def initialize(attributes = {}) @attributes = attributes @id = @attributes[:id] @name = @attributes[:name] @lang = @attributes[:lang] @user = @attributes[:user] @user_id = @attributes[:user_id] @comment = @attributes[:comment] @rating = @attributes[:rating] @downloads = @attributes[:downloads] @framerate = @attributes[:framerate] @created_at = @attributes[:created_at] @download_url = @attributes[:download_url] @hearing_impaired = @attributes[:hearing_impaired] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def attributes @attributes end |
#comment ⇒ Object
Returns the value of attribute comment.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def comment @comment end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def created_at @created_at end |
#download_url ⇒ Object
Returns the value of attribute download_url.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def download_url @download_url end |
#downloads ⇒ Object
Returns the value of attribute downloads.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def downloads @downloads end |
#framerate ⇒ Object
Returns the value of attribute framerate.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def framerate @framerate end |
#hearing_impaired ⇒ Object
Returns the value of attribute hearing_impaired.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def hearing_impaired @hearing_impaired end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def id @id end |
#lang ⇒ Object
Returns the value of attribute lang.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def lang @lang end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def name @name end |
#rating ⇒ Object
Returns the value of attribute rating.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def @rating end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def user @user end |
#user_id ⇒ Object
Returns the value of attribute user_id.
3 4 5 |
# File 'lib/subscene/subtitle.rb', line 3 def user_id @user_id end |
Class Method Details
.build(html) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/subscene/subtitle.rb', line 40 def self.build(html) new({ id: (html.css("nav.comment-sub a").to_s.match(/subtitleId=(\d+)/)[1] rescue nil), name: (html.css("li.release").children.last.text.strip rescue nil), lang: (html.css("a#downloadButton").text.match(/Download (.*)\n/)[1] rescue nil), user: (html.css("li.author").text.strip rescue nil), user_id: (html.css("li.author a").attribute("href").value.match(/\d+/).to_s rescue nil), comment: (html.css("div.comment").text.strip rescue nil), rating: (html.css("div.rating").text.strip rescue nil), downloads: (html.css("div.details li[contains('Downloads')]").children.last.text.strip rescue nil), framerate: (html.css("div.details li[contains('Framerate')]").children.last.text.strip rescue nil), created_at: (html.css("div.details li[contains('Online')]").children.last.text.strip rescue nil), download_url: (html.css("a#downloadButton").attr("href").value rescue nil), hearing_impaired: (html.css("div.details li[contains('Hearing')]").children.last.text.strip != "No" rescue nil) }) end |
Instance Method Details
#download ⇒ Object
Public: Download a Subtitle file.
Examples
Subscene.find(136037).download
# => #<Faraday::Response #@env={:body=>"PK\u00...",
:response_headers=>{"content-type"=>"application/x-zip-compressed"} [..]>
Returns a Faraday::Response instance.
32 33 34 35 36 37 38 |
# File 'lib/subscene/subtitle.rb', line 32 def download conn = Faraday.new(url: Subscene::ENDPOINT) conn.post do |req| req.url download_url req.headers['Referer'] = "#{Subscene::ENDPOINT}/#{id}" end end |