Class: Saber::Tracker2::Base
- Inherits:
-
Object
- Object
- Saber::Tracker2::Base
- Defined in:
- lib/saber/tracker2/base.rb
Constant Summary collapse
- BASE_URL =
Implement
""
- TYPES =
{}
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #upload(format, filemap, o = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
16 17 18 |
# File 'lib/saber/tracker2/base.rb', line 16 def agent @agent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/saber/tracker2/base.rb', line 16 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/saber/tracker2/base.rb', line 16 def @options end |
Class Method Details
Instance Method Details
#upload(format, filemap, o = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/saber/tracker2/base.rb', line 25 def upload(format, filemap, o={}) failed_counts = 0 filemap.each {|file, torrent_file| yaml_file = "#{file}.yml" info0 = YAML.load_file(yaml_file) is_archived = torrent_file.to_s.start_with?("#{name}/") # current release only support ebook type. Saber.ui.error "Current doesn't support this upload_type -- #{info0['upload_type']}." unless %w[ebook magazine journal newspaper manual article comic].include? info0["upload_type"] info = {} # convert {"tracker.tags" => x} to {"trackers" => {"tags" => x}} info0.each {|k, v| if k.include?(".") tracker, key = k.split(".") info[tracker] ||= {} info[tracker][key] = v elsif Hash === info[k] and Hash === v info[k].merge!(v) else info[k] = v end } info.deep_symbolize_keys! info[:format] = format.upcase info[:upload_type2] = self.class::TYPES[info[:upload_type]] info[:torrent_file] = Pa.absolute2(torrent_file) info.merge! info.delete(name.to_sym){ {} } # skip empty description. if info[:description].empty? Saber.ui.error "SKIP: Empty description -- yaml_file" next end # check exists? if Tracker[name].respond_to?(:exists?) tracker = Tracker[name].new tracker.login if tracker.exists?(isbn: info[:isbn]) Saber.ui.say "SKIP: File existing in #{name} site. -- (#{info[:isbn]}) #{info[:title]}" next end end process_info!(info) upload_method = o[:add] ? :add_format : :new_upload if send(upload_method, info) Saber.ui.say "Upload Complete: #{file}" # archive if !is_archived and Rc._has_key?("upload.archive") archive = case (archive=Rc.upload.archive) when Proc archive.call(info[:upload_type]) else archive end Pa.mv yaml_file, archive, mkdir: true Pa.mv torrent_file, "#{archive}/#{name}", mkdir: true end else failed_counts += 1 Saber.ui.error "SKIP: Upload failed -- #{file}" end } agent.quit unless failed_counts > 0 end |