<commit_before>module Kappa
  class VideoBase
    include IdEquality

    def initialize(arg, connection)
      @connection = connection

      case arg
        when Hash
          parse(arg)
        when String
          json = @connection.get("videos/#{arg}")
          parse(json)
        else
          raise ArgumentError
      end
    end
  end
end

module Kappa::V2
  class Video < Kappa::VideoBase
    def initialize(arg)
      super(arg, Connection.instance)
    end

    def channel
      Channel.new(@conn.get("channels/#{@channel_name}"), @conn)
    end

    attr_reader :id
    attr_reader :title
    attr_reader :recorded_at
    attr_reader :url
    attr_reader :view_count
    attr_reader :description
    # TODO: Is this actually in seconds? Doesn't seem to match up with video length.
    attr_reader :length_sec
    attr_reader :game_name
    attr_reader :preview_url
    # TODO: Move this under "v.channel.name" and force the query if other attributes are requested.
    attr_reader :channel_name

  private
    def parse(hash)
      @conn = conn

      @id = hash['id']
      @title = hash['title']
      @recorded_at = DateTime.parse(hash['recorded_at'])
      @url = hash['url']
      @view_count = hash['views']
      @description = hash['description']
      @length_sec = hash['length']
      @game_name = hash['game']
      @preview_url = hash['preview']
      @channel_name = hash['channel']['name']
      # @channel_display_name = json['channel']['display_name']
    end
  end

  class Videos
    def self.top(params = {})
    end
  end
end<commit_msg>Removing old connection code from Video, initializing it like other objects.<commit_after>module Kappa
  class VideoBase
    include IdEquality

    def initialize(hash)
      parse(hash)
    end

    def self.get(id)
      json = connection.get("videos/#{id}")
      new(json)
    end
  end
end

module Kappa::V2
  class Video < Kappa::VideoBase
    include Connection

    def channel
      Channel.new(connection.get("channels/#{@channel_name}"))
    end

    attr_reader :id
    attr_reader :title
    attr_reader :recorded_at
    attr_reader :url
    attr_reader :view_count
    attr_reader :description
    # TODO: Is this actually in seconds? Doesn't seem to match up with video length.
    attr_reader :length_sec
    attr_reader :game_name
    attr_reader :preview_url
    # TODO: Move this under "v.channel.name" and force the query if other attributes are requested.
    attr_reader :channel_name

  private
    def parse(hash)
      @id = hash['id']
      @title = hash['title']
      @recorded_at = DateTime.parse(hash['recorded_at'])
      @url = hash['url']
      @view_count = hash['views']
      @description = hash['description']
      @length_sec = hash['length']
      @game_name = hash['game']
      @preview_url = hash['preview']
      @channel_name = hash['channel']['name']
      # @channel_display_name = json['channel']['display_name']
    end
  end

  class Videos
    def self.top(params = {})
    end
  end
end
{'fraction_non_alphanumeric': 0.10271703114645461, 'fraction_numerical': 0.0006626905235255136, 'mean_word_length': 2.7879548306148054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4779601', 'n_tokens_mistral': 922, 'n_tokens_neox': 896, 'n_words': 247}