<commit_before>#!/usr/bin/env ruby

require 'rev'

class Connection
  def initialize(s, ch, icy)
    @sck         = s;
    @icyInterval = 0;
    @ch          = ch;
    if(icy == "1")
      @icyInterval = 4096;
    end
    @icyRemaining = @icyInterval;
  end

  def write(data)
    while(data.bytesize() != 0)
      if(@icyRemaining > data.bytesize())
        @sck.write(data);
        @icyRemaining -= data.bytesize();
        data     = "";
      else
        @sck.write(data[0..@icyRemaining-1]);
        data     = data[@icyRemaining..-1];
        generateIcyMetaData();
        @icyRemaining = @icyInterval;
      end
    end
  end

  def metaint()
    @icyInterval;
  end

  private
  def generateIcyMetaData
    str  = "";
    meta = @ch.meta();

    if(meta && @meta != meta)
      str = "StreamTitle='#{meta[3].gsub("\'", " ")} - #{meta[4].gsub("\'", " ")} - #{meta[5].gsub("\'", " ")}'"
      @meta = meta;
    end
    
    padding = str.bytesize() % 16;
    padding = 16 - padding  if(padding != 0)
    str += "\x00" * padding;
    @sck.write((str.bytesize()/16).chr);
    @sck.write(str);
  end
end<commit_msg>tag: add ; on the end of icy metadata<commit_after>#!/usr/bin/env ruby

require 'rev'

class Connection
  def initialize(s, ch, icy)
    @sck         = s;
    @icyInterval = 0;
    @ch          = ch;
    if(icy == "1")
      @icyInterval = 4096;
    end
    @icyRemaining = @icyInterval;
  end

  def write(data)
    while(data.bytesize() != 0)
      if(@icyRemaining > data.bytesize())
        @sck.write(data);
        @icyRemaining -= data.bytesize();
        data     = "";
      else
        @sck.write(data[0..@icyRemaining-1]);
        data     = data[@icyRemaining..-1];
        generateIcyMetaData();
        @icyRemaining = @icyInterval;
      end
    end
  end

  def metaint()
    @icyInterval;
  end

  private
  def generateIcyMetaData
    str  = "";
    meta = @ch.meta();

    if(meta && @meta != meta)
      str = "StreamTitle='#{meta[3].gsub("\'", " ")} - #{meta[4].gsub("\'", " ")} - #{meta[5].gsub("\'", " ")}';"
      @meta = meta;
    end
    
    padding = str.bytesize() % 16;
    padding = 16 - padding  if(padding != 0)
    str += "\x00" * padding;
    @sck.write((str.bytesize()/16).chr);
    @sck.write(str);
  end
end
{'fraction_non_alphanumeric': 0.1839435377150419, 'fraction_numerical': 0.01940891045434495, 'mean_word_length': 2.0690121786197566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2428919', 'n_tokens_mistral': 850, 'n_tokens_neox': 822, 'n_words': 164}