Class: YoutubeDL::OutputParser
- Inherits:
-
Object
- Object
- YoutubeDL::OutputParser
- Defined in:
- lib/youtube_dl/output_parser.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize ⇒ OutputParser
constructor
A new instance of OutputParser.
- #process(line) ⇒ Object
Constructor Details
#initialize ⇒ OutputParser
Returns a new instance of OutputParser.
7 8 9 |
# File 'lib/youtube_dl/output_parser.rb', line 7 def initialize @state = State.new end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/youtube_dl/output_parser.rb', line 11 def state @state end |
Instance Method Details
#process(line) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 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 |
# File 'lib/youtube_dl/output_parser.rb', line 13 def process(line) line = line.strip m = regex.match(line) return :unparsable if m.nil? if m[:destination] state.destination = Pathname(m[:destination]) return :destination end if m[:merger] state.destination = Pathname(m[:merger]) return :merger end if m[:deleting] return :deleting end if m[:info_json] state.info_json = Pathname(m[:info_json]) if m[:info_json] return :info_json end if m[:progress] if m[:progress] if m[:progress] == '100' state.progress = 100 else state.progress = m[:progress].to_f end end state.total_size = Filesize.from("#{m[:total_size]} #{m[:total_size_unit]}") if m[:total_size] state.speed = Filesize.from("#{m[:speed]} #{m[:speed_unit]}") if m[:speed] return :progress end if m[:error] state.error = m[:error] if m[:error] return :error end raise 'Not sure how I got here...' end |