Class: BtjunkieContainer::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/btjunkie/torrent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Torrent

Returns a new instance of Torrent.



6
7
8
9
# File 'lib/btjunkie/torrent.rb', line 6

def initialize(args)
  @_subtitle = {}
  args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
end

Instance Attribute Details

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/btjunkie/torrent.rb', line 5

def title
  @title
end

#torrentObject

Returns the value of attribute torrent.



5
6
7
# File 'lib/btjunkie/torrent.rb', line 5

def torrent
  @torrent
end

Instance Method Details

#dead?Boolean

Is the torrent dead? The definition of dead is; no seeders Returns a boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/btjunkie/torrent.rb', line 14

def dead?
  seeders <= 0
end

#detailsObject



59
60
61
# File 'lib/btjunkie/torrent.rb', line 59

def details
  @_details ||= "http://#{domain}#{@details}"
end

#domainObject

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



29
30
31
# File 'lib/btjunkie/torrent.rb', line 29

def domain
  "btjunkie.org"
end

#idObject Also known as: torrent_id

Generates an id using the details url



23
24
25
# File 'lib/btjunkie/torrent.rb', line 23

def id
  @_id ||= torrent.to_s.match(/(\w+)\/download\.torrent$/).to_a[1]
end

#imdb_idObject



70
# File 'lib/btjunkie/torrent.rb', line 70

def imdb_id; nil; end

#movieObject

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



46
47
48
49
50
# File 'lib/btjunkie/torrent.rb', line 46

def movie
  @_movie ||= MovieSearcher.find_by_release_name(title, :options => {
    :details => true
  })
end

#seedersObject



18
19
20
# File 'lib/btjunkie/torrent.rb', line 18

def seeders
  @_seeders ||= @seeders.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



55
56
57
# File 'lib/btjunkie/torrent.rb', line 55

def subtitle(option = :english)
  @_subtitle[option] ||= Undertexter.find(movie.imdb_id, :language => option).based_on(title)
end

#tidObject

Returns a unique id for the torrent based on the domain and the id of the torrent



34
35
36
# File 'lib/btjunkie/torrent.rb', line 34

def tid
  @_tid ||= Digest::MD5.hexdigest("#{domain}#{id}")
end

#valid?Boolean

The torrent is only valid if it has an id

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/btjunkie/torrent.rb', line 64

def valid?
  ! id.nil? and 
  @seeders.match(/^\d+$/) and not 
  @title.to_s.empty?
end