<commit_before>#include <ffmpeg/avformat.h>
#include <stdlib.h>
#include <string.h>

#include "libsjindex/indexer.h"
#include "libsjindex/sj_search_index.h"

int main(int argc, char **argv)
{
    SJ_IndexContext sj_ic;
    Index read_idx;
    Index key_frame;
    uint64_t search_val;
    
    memset(&key_frame, 0, sizeof(key_frame));
    memset(&read_idx, 0, sizeof(read_idx));
    if (argc < 4) {
        printf("usage: search_idx <parameter type> <index file> <hhmmssff>\n");
        printf("parameters types are :\n\t1\ttimecode\n\t2\tpts\n\t4\tdts\n");
        return 1;
    }

    int len = strlen(argv[3]);
    for (int i = 0; i < len; i++){
        if (argv[3][i] < '0' || argv[3][i] > '9'){
            printf("search value must be integer\n");
            return 0;
        }
    }
    
    int load_res = sj_index_load(argv[2], &sj_ic);
    if (load_res == -1) {
        printf("File could not be open\n");
        return 0;
    }

    if (load_res == -2) {
        printf("File is not a index file\n");
        return 0;
    }
    
    if (load_res == -4) {
        printf("Index is empty\n");
        return 0;
    }
    printf("Index size : %lld\n", sj_ic.size);
    search_val = atoll(argv[3]);
    uint64_t flags = atoll(argv[1]);
    int res = sj_index_search(&sj_ic, search_val, &read_idx, &key_frame, flags);

    if (res == -1){
        printf("Frame could not be found, check input data\n");
        return -2;
    } 

    if (res == -4) {
        printf("Invalid search mode\n");
        return -4;
    }

/*    if (res == -1) {
        printf("Video starts at\ntimecode\t%02d:%02d:%02d:%02d\nPTS\t\t%lld\nDTS\t\t%lld\n", sj_ic.indexes[0].timecode.hours, sj_ic.indexes[0].timecode.minutes, sj_ic.indexes[0].timecode.seconds, sj_ic.indexes[0].timecode.frames, sj_ic.indexes[0].pts, sj_ic.indexes[0].dts);
        return -1;
    }*/
    
    printf("Frame %c : \t\ntimecode\t%02d:%02d:%02d:%02d\nPTS\t\t%lld\nDTS\t\t%lld\nPES-OFFSET\t\t%lld\n", sj_index_get_frame_type(read_idx) ,read_idx.timecode.hours, read_idx.timecode.minutes, read_idx.timecode.seconds, read_idx.timecode.frames, read_idx.pts, read_idx.dts, read_idx.pes_offset);
    printf("Related key-frame : \t\ntimecode\t%02d:%02d:%02d:%02d\nPTS\t\t%lld\nDTS\t\t%lld\nPES-OFFSET\t\t%lld\n", key_frame.timecode.hours,key_frame.timecode.minutes, key_frame.timecode.seconds, key_frame.timecode.frames, key_frame.pts, key_frame.dts, key_frame.pes_offset);
    sj_index_unload(&sj_ic);
    return 0;
}<commit_msg>clean-up<commit_after>#include <ffmpeg/avformat.h>
#include <stdlib.h>
#include <string.h>

#include "libsjindex/indexer.h"
#include "libsjindex/sj_search_index.h"

int main(int argc, char **argv)
{
    SJ_IndexContext sj_ic;
    Index read_idx;
    Index key_frame;
    uint64_t search_val;

    memset(&key_frame, 0, sizeof(key_frame));
    memset(&read_idx, 0, sizeof(read_idx));
    if (argc < 4) {
        printf("usage: search_idx <parameter type> <index file> <hhmmssff>\n");
        printf("parameters types are :\n\t1\ttimecode\n\t2\tpts\n\t4\tdts\n");
        return 1;
    }

    int len = strlen(argv[3]);
    for (int i = 0; i < len; i++){
        if (argv[3][i] < '0' || argv[3][i] > '9'){
            printf("search value must be integer\n");
            return 0;
        }
    }

    // Index file loading and checks 
    int load_res = sj_index_load(argv[2], &sj_ic);
    if (load_res == -1) {
        printf("File could not be open\n");
        return 0;
    }

    if (load_res == -2) {
        printf("File is not a index file\n");
        return 0;
    }
    
    if (load_res == -4) {
        printf("Index is empty\n");
        return 0;
    }
    printf("Index size : %lld\n", sj_ic.size);
    search_val = atoll(argv[3]);
    uint64_t flags = atoll(argv[1]);

    // Search
    int res = sj_index_search(&sj_ic, search_val, &read_idx, &key_frame, flags);
    
    // Check search result
    if (res == -1){
        printf("Frame could not be found, check input data\n");
        return -2;
    } 

    if (res == -4) {
        printf("Invalid search mode\n");
        return -4;
    }

    printf("Frame %c : \t\ntimecode\t%02d:%02d:%02d:%02d\nPTS\t\t%lld\nDTS\t\t%lld\nPES-OFFSET\t\t%lld\n", sj_index_get_frame_type(read_idx) ,read_idx.timecode.hours, read_idx.timecode.minutes, read_idx.timecode.seconds, read_idx.timecode.frames, read_idx.pts, read_idx.dts, read_idx.pes_offset);
    printf("Related key-frame : \t\ntimecode\t%02d:%02d:%02d:%02d\nPTS\t\t%lld\nDTS\t\t%lld\nPES-OFFSET\t\t%lld\n", key_frame.timecode.hours,key_frame.timecode.minutes, key_frame.timecode.seconds, key_frame.timecode.frames, key_frame.pts, key_frame.dts, key_frame.pes_offset);
    sj_index_unload(&sj_ic);
    
    return 0;
}
{'fraction_non_alphanumeric': 0.1649026248941575, 'fraction_numerical': 0.023708721422523286, 'mean_word_length': 2.810483870967742, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '387038', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1876, 'n_words': 343}