<commit_before>/// \file flv2dtsc.cpp
/// Contains the code that will transform any valid FLV input into valid DTSC.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <mist/flv_tag.h>
#include <mist/dtsc.h>
#include <mist/json.h>
#include <mist/amf.h>
#include <mist/config.h>

///\brief Holds everything unique to converters.
namespace Converters {

  ///\brief Converts FLV from stdin to DTSC on stdout.
  ///\return The return code for the converter.
  int FLV2DTSC(std::ostream & output){
    FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
    JSON::Value meta_out; // Storage for outgoing header data.
    JSON::Value pack_out; // Storage for outgoing data.
    std::stringstream prebuffer; // Temporary buffer before sending real data
    bool sending = false;
    unsigned int counter = 0;

    while ( !feof(stdin)){
      if (FLV_in.FileLoader(stdin)){
        pack_out = FLV_in.toJSON(meta_out);
        if (pack_out.isNull()){
          continue;
        }
        if ( !sending){
          counter++;
          if (counter > 8){
            sending = true;
            meta_out["moreheader"] = 0LL;
            std::string packed_header = meta_out.toNetPacked();
            unsigned int size = htonl(packed_header.size());
            output << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
            output << prebuffer.rdbuf();
            prebuffer.str("");
            std::cerr << "Buffer done, starting real-time output..." << std::endl;
          }else{
            std::string packed_out = pack_out.toNetPacked();
            unsigned int size = htonl(packed_out.size());
            prebuffer << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
            continue; //don't also write
          }
        }
        //simply write
        std::string packed_out = pack_out.toNetPacked();
        unsigned int size = htonl(packed_out.size());
        output << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
      }
    }

    // if the FLV input is very short, do output it correctly...
    if ( !sending){
      std::cerr << "EOF - outputting buffer..." << std::endl;
      meta_out["moreheader"] = 0LL;
      std::string packed_header = meta_out.toNetPacked();
      unsigned int size = htonl(packed_header.size());
      output << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
      output << prebuffer.rdbuf();
    }
    std::cerr << "Done! If you output this data to a file, don't forget to run MistDTSCFix next." << std::endl;

    return 0;
  } //FLV2DTSC

}

///\brief Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC().
int main(int argc, char ** argv){
  Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
  conf.addOption("output",
      JSON::fromString(
          "{\"long\":\"output\", \"value\":[\"stdout\"], \"short\":\"o\", \"arg\":\"string\", \"help\":\"Name of the outputfile or stdout for standard output.\"}"));
  conf.parseArgs(argc, argv);
  if (conf.getString("output") == "stdout"){
    return Converters::FLV2DTSC(std::cout);
  }
  std::ofstream oFile(conf.getString("output").c_str());
  return Converters::FLV2DTSC(oFile);
} //main<commit_msg>Minor fixes in the FLV2DTSC Converter<commit_after>/// \file flv2dtsc.cpp
/// Contains the code that will transform any valid FLV input into valid DTSC.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <mist/flv_tag.h>
#include <mist/dtsc.h>
#include <mist/json.h>
#include <mist/amf.h>
#include <mist/config.h>

///\brief Holds everything unique to converters.
namespace Converters {

  ///\brief Converts FLV from stdin to DTSC on stdout.
  ///\return The return code for the converter.
  int FLV2DTSC(std::ostream & output){
    FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
    JSON::Value meta_out; // Storage for outgoing header data.
    JSON::Value pack_out; // Storage for outgoing data.
    std::stringstream prebuffer; // Temporary buffer before sending real data
    bool sending = false;
    unsigned int counter = 0;

    while ( !feof(stdin)){
      if (FLV_in.FileLoader(stdin)){
        pack_out = FLV_in.toJSON(meta_out);
        if (pack_out.isNull()){
          continue;
        }
        if ( !sending){
          counter++;
          if (counter > 8){
            sending = true;
            meta_out["moreheader"] = 0LL;
            output << meta_out.toNetPacked();
            prebuffer.str("");
            std::cerr << "Buffer done, starting real-time output..." << std::endl;
          }else{
            prebuffer << pack_out.toNetPacked();
            continue; //don't also write
          }
        }
        //simply write
        output << pack_out.toNetPacked();
      }
    }

    // if the FLV input is very short, do output it correctly...
    if ( !sending){
      std::cerr << "EOF - outputting buffer..." << std::endl;
      meta_out["moreheader"] = 0LL;
      output << meta_out.toNetPacked();
      output << prebuffer.rdbuf();
    }
    std::cerr << "Done! If you output this data to a file, don't forget to run MistDTSCFix next." << std::endl;

    return 0;
  } //FLV2DTSC

}

///\brief Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC().
int main(int argc, char ** argv){
  Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
  conf.addOption("output",
      JSON::fromString(
          "{\"long\":\"output\", \"value\":[\"stdout\"], \"short\":\"o\", \"arg\":\"string\", \"help\":\"Name of the outputfile or stdout for standard output.\"}"));
  conf.parseArgs(argc, argv);
  if (conf.getString("output") == "stdout"){
    return Converters::FLV2DTSC(std::cout);
  }
  std::ofstream oFile(conf.getString("output").c_str());
  return Converters::FLV2DTSC(oFile);
} //main
{'fraction_non_alphanumeric': 0.15783466492744172, 'fraction_numerical': 0.005706831893037665, 'mean_word_length': 2.83375, 'pattern_counts': {'":': 10, '<': 95, '<?xml version=': 0, '>': 35, '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': '4909905', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1968, 'n_words': 528}