Class: Container::Torrent
Instance Attribute Summary collapse
-
#details ⇒ Object
Returns the value of attribute details.
Instance Method Summary collapse
-
#content ⇒ Object
Downloads the detailed view for this torrent Returns an Nokogiri object.
-
#dead? ⇒ Boolean
Is the torrent dead? The definition of dead is; no seeders Returns a boolean.
-
#domain ⇒ Object
Returns the domain for the torrent, without http or www If the domain for some reason isn’t found, it will use an empty string.
-
#id ⇒ Object
Generates an id using the details url.
-
#imdb ⇒ Object
Returns the full url to the related imdb page The link is parsed from the details view Example: www.imdb.com/title/tt0066026 Return type: String or nil.
-
#imdb_id ⇒ Object
Returns the imdb id for the torrent, including the tt at the beginning Example: tt0066026 Return type: String or nil.
-
#initialize(args) ⇒ Torrent
constructor
A new instance of Torrent.
-
#movie ⇒ Object
Returns an movie_searcher object based on the imdb_id, if it exists, otherwise the torrent title Read more about it here: github.com/oleander/MovieSearcher Return type: A MovieSearcher object or nil.
-
#seeders ⇒ Object
Returns the amount of seeders for the current torrent If the seeder-tag isn’t found, the value one (1) will be returned.
-
#subtitle(option = :english) ⇒ Object
Returns a Undertexter object, if we found a imdb_id, otherwise nil Read more about it here: github.com/oleander/Undertexter Return type: A single Undertexter object or nil.
-
#tid ⇒ Object
Returns a unique id for the torrent based on the domain and the id of the torrent.
-
#title ⇒ Object
Returns the title for the torrent If the title has’t been set from the Torrents class, we will download the details page try to find it there.
-
#torrent ⇒ Object
Returns the torrent for the torrent If the torrent has’t been set from the Torrents class, we will download the details page try to find it there.
-
#torrent_id ⇒ Object
Just a mirror method for #tid, just in case someone don’t like the method name tid.
-
#valid? ⇒ Boolean
Is the torrent valid? The definition of valid: Non of the accessors => is nil => contains htmltags => starts or ends with whitespace It must also stand up to the following requirements => The details and torrent url must be valid => The id for the torrent must only contain integers.
-
#valid_torrent?(torrent) ⇒ Boolean
Check to see if the ingoing param is a valid torrent url or not The url has to be a valid url and has to end with .torrent.
-
#valid_url?(url) ⇒ Boolean
Check to see if the ingoing param is a valid url or not.
Methods inherited from Shared
#default_values, #download, #error, #inner_call, #load, #url_cleaner, #valid_option?
Constructor Details
#initialize(args) ⇒ Torrent
Returns a new instance of Torrent.
118 119 120 121 122 |
# File 'lib/torrents/container.rb', line 118 def initialize(args) args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] } @errors = [] unless @errors @debug = false unless @debug end |
Instance Attribute Details
#details ⇒ Object
Returns the value of attribute details.
116 117 118 |
# File 'lib/torrents/container.rb', line 116 def details @details end |
Instance Method Details
#content ⇒ Object
Downloads the detailed view for this torrent Returns an Nokogiri object
166 167 168 |
# File 'lib/torrents/container.rb', line 166 def content @content ||= Nokogiri::HTML self.download(@details) end |
#dead? ⇒ Boolean
Is the torrent dead? The definition of dead is; no seeders Returns a boolean
127 128 129 |
# File 'lib/torrents/container.rb', line 127 def dead? self.seeders <= 0 end |
#domain ⇒ Object
Returns the domain for the torrent, without http or www If the domain for some reason isn’t found, it will use an empty string
188 189 190 |
# File 'lib/torrents/container.rb', line 188 def domain @domain ||= self.details.match(/(ftp|http|https):\/\/([w]+\.)?(.+?\.[a-z]{2,3})/i).to_a[3] || "" end |
#id ⇒ Object
Generates an id using the details url
182 183 184 |
# File 'lib/torrents/container.rb', line 182 def id @id ||= self.inner_call(:id, self.details).to_i end |
#imdb ⇒ Object
Returns the full url to the related imdb page The link is parsed from the details view Example: www.imdb.com/title/tt0066026 Return type: String or nil
206 207 208 |
# File 'lib/torrents/container.rb', line 206 def imdb @imdb ||= self.content.to_s.match(/((http:\/\/)?([w]{3}\.)?imdb.com\/title\/tt\d+)/i).to_a[1] end |
#imdb_id ⇒ Object
Returns the imdb id for the torrent, including the tt at the beginning Example: tt0066026 Return type: String or nil
213 214 215 |
# File 'lib/torrents/container.rb', line 213 def imdb_id @imdb_id ||= self.imdb.to_s.match(/(tt\d+)/).to_a[1] end |
#movie ⇒ Object
Returns an movie_searcher object based on the imdb_id, if it exists, otherwise the torrent title Read more about it here: github.com/oleander/MovieSearcher Return type: A MovieSearcher object or nil
220 221 222 |
# File 'lib/torrents/container.rb', line 220 def movie self.imdb_id.nil? ? MovieSearcher.find_by_release_name(self.title, :options => {:details => true}) : MovieSearcher.find_movie_by_id(self.imdb_id) end |
#seeders ⇒ Object
Returns the amount of seeders for the current torrent If the seeder-tag isn’t found, the value one (1) will be returned. Returns an integer from 0 to inf
134 135 136 |
# File 'lib/torrents/container.rb', line 134 def seeders @seeders ||= self.inner_call(:seeders, self.content).to_i end |
#subtitle(option = :english) ⇒ Object
Returns a Undertexter object, if we found a imdb_id, otherwise nil Read more about it here: github.com/oleander/Undertexter Return type: A single Undertexter object or nil
235 236 237 238 |
# File 'lib/torrents/container.rb', line 235 def subtitle(option = :english) @subtitle = {} unless @subtitle @subtitle[option] ||= Undertexter.find(self.imdb_id, language: option).based_on(self.title) end |
#tid ⇒ Object
Returns a unique id for the torrent based on the domain and the id of the torrent
193 194 195 |
# File 'lib/torrents/container.rb', line 193 def tid @tid ||= Digest::MD5.hexdigest("#{domain}#{id}") end |
#title ⇒ Object
Returns the title for the torrent If the title has’t been set from the Torrents class, we will download the details page try to find it there. Return type: String or nil
227 228 229 230 |
# File 'lib/torrents/container.rb', line 227 def title @title ||= self.inner_call(:details_title, self.content) @title = @title.strip unless @title.nil? end |
#torrent ⇒ Object
Returns the torrent for the torrent If the torrent has’t been set from the Torrents class, we will download the details page try to find it there. Return type: String or nil
243 244 245 |
# File 'lib/torrents/container.rb', line 243 def torrent @torrent ||= self.inner_call(:details_torrent, self.content) end |
#torrent_id ⇒ Object
Just a mirror method for #tid, just in case someone don’t like the method name tid
198 199 200 |
# File 'lib/torrents/container.rb', line 198 def torrent_id @torrent_id ||= self.tid end |
#valid? ⇒ Boolean
Is the torrent valid? The definition of valid:
Non of the accessors
=> is nil
=> contains htmltags
=> starts or ends with whitespace
It must also stand up to the following requirements
=> The details and torrent url must be valid
=> The id for the torrent must only contain integers.
Returns true or false
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/torrents/container.rb', line 148 def valid? [:details, :torrent, :title, :id].each do |method| data = self.send(method) return false if self.send(method).nil? or data.to_s.empty? or data.to_s.match(/<\/?[^>]*>/) or data.to_s.strip != data.to_s end return [ !! self.valid_url?(self.details), !! self.valid_torrent?(self.torrent), !! self.inner_call(:id, self.details).to_s.match(/^\d+$/) ].all? end |
#valid_torrent?(torrent) ⇒ Boolean
Check to see if the ingoing param is a valid torrent url or not The url has to be a valid url and has to end with .torrent
177 178 179 |
# File 'lib/torrents/container.rb', line 177 def valid_torrent?(torrent) torrent.match(/\.torrent$/) and self.valid_url?(torrent) end |
#valid_url?(url) ⇒ Boolean
Check to see if the ingoing param is a valid url or not
171 172 173 |
# File 'lib/torrents/container.rb', line 171 def valid_url?(url) !! url.match(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i) end |