mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2024-12-24 20:01:42 +00:00
clear up which function as api
This commit is contained in:
parent
84ce45b8f0
commit
913432232d
@ -7,72 +7,12 @@
|
||||
#include "../src/lib_ccx/ccx_mp4.h"
|
||||
#include "../src/lib_ccx/hardsubx.h"
|
||||
#include "../src/lib_ccx/ccx_share.h"
|
||||
#include "../src/ccextractor.h"
|
||||
#include "../src/wrappers/wrapper.h"
|
||||
#include "../src/ccextractor.h"
|
||||
#include "../src/wrappers/wrapper.h"
|
||||
%}
|
||||
void my_pythonapi(struct ccx_s_options *api_options, PyObject* func);
|
||||
%pythoncode %{
|
||||
def g608_grid_former(line,text,color,font):
|
||||
if "text[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
text.append(line)
|
||||
if "color[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
color.append(line)
|
||||
if "font[" in line:
|
||||
line = str(line.split(":", 1)[1])
|
||||
line = str(line.split("\n")[0])
|
||||
font.append(line)
|
||||
|
||||
def print_g608_grid(case,text,color,font):
|
||||
help_string = """
|
||||
Case is the value that would give the desired output.
|
||||
case = 0 --> print start_time,end_time,text,color,font
|
||||
case = 1 --> print start_time,end_time,text
|
||||
case = 2 --> print start_time,end_time,color
|
||||
case = 3 --> print start_time,end_time,font
|
||||
case = 4 --> print start_time,end_time,text,color
|
||||
case = 5 --> print start_time,end_time,text,font
|
||||
case = 6 --> print start_time,end_time,color,font
|
||||
"""
|
||||
if case==0:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
|
||||
elif case==1:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
elif case==2:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==3:
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==4:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
elif case==5:
|
||||
if text:
|
||||
print "\n".join(text)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
elif case==6:
|
||||
if color:
|
||||
print "\n".join(color)
|
||||
if font:
|
||||
print "\n".join(font)
|
||||
else:
|
||||
print help_string
|
||||
|
||||
%}
|
||||
%include "../src/lib_ccx/ccx_common_common.h"
|
||||
%include "../src/ccextractor.h"
|
||||
%include "../src//wrappers/wrapper.h"
|
||||
struct ccx_s_options* api_init_options();
|
||||
void check_configuration_file(struct ccx_s_options api_options);
|
||||
int compile_params(struct ccx_s_options *api_options,int argc);
|
||||
void api_add_param(struct ccx_s_options* api_options,char* arg);
|
||||
int api_start(struct ccx_s_options api_options);
|
||||
void my_pythonapi(struct ccx_s_options *api_options, PyObject *func);
|
||||
|
@ -496,20 +496,80 @@ int api_param_count(struct ccx_s_options* api_options)
|
||||
{
|
||||
return api_options->python_param_count;
|
||||
}
|
||||
#endif // PYTHON_API
|
||||
#endif
|
||||
|
||||
/*
|
||||
* asprintf alternative
|
||||
* Defined only in case of windows users.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
int vasprintf(char **strp, const char *fmt, va_list ap)
|
||||
{
|
||||
//_vscprintf tells you how big the buffer needs to be
|
||||
int len = _vscprintf(fmt, ap);
|
||||
if (len == -1) {
|
||||
return -1;
|
||||
}
|
||||
size_t size = (size_t)len + 1;
|
||||
char *str = malloc(size);
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
// _vsprintf_s is the "secure" version of vsprintf
|
||||
int r = vsprintf_s(str, len + 1, fmt, ap);
|
||||
if (r == -1) {
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
*strp = str;
|
||||
return r;
|
||||
}
|
||||
|
||||
int asprintf(char **strp, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int r = vasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
char* time_wrapper(char* fmt, unsigned h, unsigned m, unsigned s, unsigned ms)
|
||||
{
|
||||
char * time;
|
||||
asprintf(&time,fmt, h, m, s, ms);
|
||||
return time;
|
||||
}
|
||||
|
||||
#ifdef PYTHON_API
|
||||
void call_from_python_api(struct ccx_s_options *api_options)
|
||||
{
|
||||
int indicator = api_options->signal_python_api;
|
||||
if (indicator)
|
||||
signal_python_api=1;
|
||||
else
|
||||
signal_python_api=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
void run(PyObject * reporter, char * line, int encoding)
|
||||
{
|
||||
assert ( PyFunction_Check(reporter) );
|
||||
PyObject* args = Py_BuildValue("(si)",line,encoding);
|
||||
PyObject_CallObject((PyObject*)reporter, args);
|
||||
}
|
||||
#endif
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct ccx_s_options* api_options = api_init_options();
|
||||
check_configuration_file(*api_options);
|
||||
#ifdef PYTHON_API
|
||||
#ifdef ENABLE_PYTHON
|
||||
for(int i = 1; i < argc; i++)
|
||||
api_add_param(api_options,argv[i]);
|
||||
#endif
|
||||
|
||||
#ifdef PYTHON_API
|
||||
#ifdef ENABLE_PYTHON
|
||||
int compile_ret = compile_params(api_options,argc);
|
||||
#else
|
||||
int compile_ret = parse_parameters (api_options, argc, argv);
|
||||
|
@ -28,44 +28,27 @@ CURLcode res;
|
||||
#define LEPT_MSG_SEVERITY L_SEVERITY_NONE
|
||||
#endif
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
#ifdef PYTHON_API
|
||||
#include "Python.h"
|
||||
#include "funcobject.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PYTHON
|
||||
struct python_subs_modified{
|
||||
char *start_time;
|
||||
char* end_time;
|
||||
};
|
||||
|
||||
struct python_subs_array{
|
||||
#if defined(PYTHONAPI)
|
||||
PyObject* reporter;
|
||||
#endif
|
||||
int sub_count;
|
||||
struct python_subs_modified* subs;
|
||||
};
|
||||
void free_python_global_vars();
|
||||
PyObject* py_callback_func;
|
||||
void api_add_param(struct ccx_s_options* api_options,char* arg);
|
||||
int compile_params(struct ccx_s_options *api_options,int argc);
|
||||
void py_callback(char *line, int encoding);
|
||||
int api_param_count(struct ccx_s_options* api_options);
|
||||
char * api_param(struct ccx_s_options* api_options, int count);
|
||||
#endif
|
||||
|
||||
|
||||
struct ccx_s_options ccx_options;
|
||||
struct lib_ccx_ctx *signal_ctx;
|
||||
#ifdef ENABLE_PYTHON
|
||||
struct python_subs_array array;
|
||||
int signal_python_api; // 1 symbolises that python wrapper made the call.
|
||||
#endif
|
||||
//volatile int terminate_asap = 0;
|
||||
|
||||
struct ccx_s_options* api_init_options();
|
||||
void check_configuration_file(struct ccx_s_options api_options);
|
||||
int compile_params(struct ccx_s_options *api_options,int argc);
|
||||
void api_add_param(struct ccx_s_options* api_options,char* arg);
|
||||
int api_start(struct ccx_s_options api_options);
|
||||
|
||||
int api_param_count(struct ccx_s_options* api_options);
|
||||
char * api_param(struct ccx_s_options* api_options, int count);
|
||||
|
||||
void sigterm_handler(int sig);
|
||||
void sigint_handler(int sig);
|
||||
@ -73,12 +56,4 @@ void print_end_msg(void);
|
||||
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
#ifdef ENABLE_PYTHON
|
||||
void call_from_python_api(struct ccx_s_options *api_options);
|
||||
void free_python_global_vars();
|
||||
#endif
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
void run(PyObject * reporter, char * line, int encoding);
|
||||
#endif
|
||||
#endif //CCEXTRACTOR_H
|
||||
|
@ -173,7 +173,7 @@ void init_options (struct ccx_s_options *options)
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATLEAST, &options->enc_cfg.endcreditsforatleast);
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATMOST, &options->enc_cfg.endcreditsforatmost);
|
||||
|
||||
#ifdef ENABLE_PYTHON
|
||||
#ifdef PYTHON_API
|
||||
options->python_param_count = 0;
|
||||
options->python_params = malloc(options->python_param_count * sizeof *options->python_params);
|
||||
#endif
|
||||
|
@ -2,16 +2,10 @@
|
||||
#include "ccextractor.h"
|
||||
|
||||
#ifdef PYTHON_API
|
||||
void set_pythonapi(struct ccx_s_options *api_options){
|
||||
api_add_param(api_options,"-pythonapi");
|
||||
void my_pythonapi(struct ccx_s_options *api_options, PyObject *callback_func) {
|
||||
py_callback_func = callback_func;
|
||||
}
|
||||
#if defined(PYTHONAPI)
|
||||
void set_pythonapi_via_python(struct ccx_s_options *api_options, PyObject * func){
|
||||
//setting the user specified callback function as a array element which would be global in C
|
||||
array.reporter = func;
|
||||
api_add_param(api_options,"-pythonapi");
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
autoprogram wrapper
|
||||
*/
|
||||
|
@ -1,15 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include "ccextractor.h"
|
||||
|
||||
#if defined(PYTHONAPI)
|
||||
void set_pythonapi_via_python(struct ccx_s_options *api_options, PyObject * func);
|
||||
#define my_pythonapi(args, func) set_pythonapi_via_python(args, func)
|
||||
#else
|
||||
#define my_pythonapi(args, func) set_pythonapi(args)
|
||||
#endif
|
||||
|
||||
#ifdef PYTHON_API
|
||||
void set_pythonapi(struct ccx_s_options *api_options);
|
||||
void my_pythonapi(struct ccx_s_options *api_options, PyObject *callback_func);
|
||||
void setautoprogram(struct ccx_s_options *api_options);
|
||||
void setstdout(struct ccx_s_options *api_options);
|
||||
void setpesheader(struct ccx_s_options *api_options);
|
||||
|
Loading…
Reference in New Issue
Block a user