<commit_before>#include "MusicReader.h"

struct music_metadata* read_metadata(char* filename)
{
    
}<commit_msg>basics of album info complete, next do audio properties<commit_after>#include "MusicReader.h"

#include <taglib/tag.h> //Taglib
#include <taglib/fileref.h> //Taglib
#include <cstdlib>
#include <string>
#include <algorithm> //std::copy

/**
 * copy a C++ string into a new c string
 * std::string.c_str() is not sufficient because it only has the lifetime
 * of the C++ string object
 *
 * if the C++ string is empty it will return a C string containing only a null terminator
 *
 * WARNING: DOES *NOT* SUPPORT UNICODE
 */
char* copy_to_cstr(TagLib::String taglib_string)
{
    std::string cpp_string = taglib_string.to8Bit(false);

    //use malloc, not new
    //leave 1 extra place for the null terminator
    char* str = (char*) malloc(sizeof(char) * cpp_string.length() + 1);
    std::copy(cpp_string.begin(), cpp_string.end(), str);
    str[cpp_string.size()] = '\0';

    return str;
}

/**
 * WARNING: THIS FUNCTION DOES NO ERROR CHECKING
 */
struct music_metadata* read_metadata(char* filename)
{
    //allocate with malloc instead of new so Haskell can deallocate with
    //free (C standard library functions are much easier to call from Haskell
    //than C++)
    music_metadata* metadata = (music_metadata*) malloc(sizeof(music_metadata));
       
   try
   {    
    TagLib::FileRef fileRef(filename);
    TagLib::Tag* tag = fileRef.tag();
    metadata->title = copy_to_cstr(tag->title());
    metadata->artist = copy_to_cstr(fileRef.tag()->artist());
    metadata->album = copy_to_cstr(fileRef.tag()->album());
    metadata->comment = copy_to_cstr(fileRef.tag()->comment());
    metadata->genre = copy_to_cstr(fileRef.tag()->genre());

    //next handle audio properties
    return metadata;
   }
   catch(...)
   {
     return NULL;
   } 
}

int main() { }
{'fraction_non_alphanumeric': 0.13626723223753975, 'fraction_numerical': 0.0021208907741251328, 'mean_word_length': 3.7175, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, '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': '5749781', 'n_tokens_mistral': 622, 'n_tokens_neox': 600, 'n_words': 173}