Sha256: 9811fffa2edbf32c631e4b7e2c4a08ec2d1c716a009541ed214e03e5d127e716

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module YoutubeVideo
  # Executable code for file(s) in bin/ folder
  class Runner
    def self.run!(args)
      video_id = args[0] || ENV['YT_VIDEO_ID']
      unless video_id
        puts 'USAGE: YPBT [video_id]'
        exit(1)
      end

      video = YoutubeVideo::Video.find(video_id: video_id)

      output_info(video)
    end

    def self.output_info(video)
      return 'Nothing found. (Invalid video id or api-key)' if video.nil?
      title = video.title
      separator = Array.new(video.title.length) { '-' }.join
      video_info =
        video.comments.map.with_index do |comment, index|
          comment_info(comment, index)
        end.join

      [title, separator, video_info].join("\n")
    end

    def self.comment_info(comment, index)
      "#{index + 1}:\n"\
      "  Author: #{comment.author.author_name}\n"\
      "  Comment: #{comment.text_display}\n"\
      "  LIKE: #{comment.author.like_count}\n"\
      "  AuthorChannelUrl: #{comment.author.author_channel_url}\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
YPBT-0.2.12 lib/YPBT/runner.rb
YPBT-0.2.11 lib/YPBT/runner.rb
YPBT-0.2.10 lib/YPBT/runner.rb