|
Packit |
3ff1e7 |
/* libquvi
|
|
Packit |
3ff1e7 |
* Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
|
|
Packit |
3ff1e7 |
*
|
|
Packit |
3ff1e7 |
* This file is part of libquvi <http://quvi.sourceforge.net/>.
|
|
Packit |
3ff1e7 |
*
|
|
Packit |
3ff1e7 |
* This program is free software: you can redistribute it and/or
|
|
Packit |
3ff1e7 |
* modify it under the terms of the GNU Affero General Public
|
|
Packit |
3ff1e7 |
* License as published by the Free Software Foundation, either
|
|
Packit |
3ff1e7 |
* version 3 of the License, or (at your option) any later version.
|
|
Packit |
3ff1e7 |
*
|
|
Packit |
3ff1e7 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
3ff1e7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
3ff1e7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
3ff1e7 |
* GNU Affero General Public License for more details.
|
|
Packit |
3ff1e7 |
*
|
|
Packit |
3ff1e7 |
* You should have received a copy of the GNU Affero General
|
|
Packit |
3ff1e7 |
* Public License along with this program. If not, see
|
|
Packit |
3ff1e7 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
3ff1e7 |
*/
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
#include "config.h"
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
#include <locale.h>
|
|
Packit |
3ff1e7 |
#include <stdlib.h>
|
|
Packit |
3ff1e7 |
#include <string.h>
|
|
Packit |
3ff1e7 |
#include <glib.h>
|
|
Packit |
3ff1e7 |
#include <quvi.h>
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
#include "examples.h"
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
struct _opts_s
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar **property;
|
|
Packit |
3ff1e7 |
gchar *type;
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static struct _opts_s opts;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static const GOptionEntry entries[] =
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
"property", 'p', 0, G_OPTION_ARG_STRING_ARRAY, &opts.property,
|
|
Packit |
3ff1e7 |
"Script property to output", "PROPERTY"
|
|
Packit |
3ff1e7 |
},
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
"type", 't', 0, G_OPTION_ARG_STRING, &opts.type,
|
|
Packit |
3ff1e7 |
"Script type", "TYPE"
|
|
Packit |
3ff1e7 |
},
|
|
Packit |
3ff1e7 |
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
struct _property_lookup_s
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
QuviScriptProperty to;
|
|
Packit |
3ff1e7 |
const gchar *from;
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static const struct _property_lookup_s property_conv[] =
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_PROPERTY_EXPORT_FORMAT, "export.format"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_PROPERTY_FILEPATH, "filepath"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_PROPERTY_FILENAME, "filename"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_PROPERTY_DOMAINS, "domains"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_PROPERTY_SHA1, "sha1"},
|
|
Packit |
3ff1e7 |
{0, NULL}
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static void dump_script(QuviScriptType type)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
QuviScriptProperty qsp;
|
|
Packit |
3ff1e7 |
gchar *s;
|
|
Packit |
3ff1e7 |
gint i,j;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
for (i=0; opts.property[i] != NULL; ++i)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
const gchar *p = opts.property[i];
|
|
Packit |
3ff1e7 |
for (j=0; property_conv[j].from != NULL; ++j)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
if (g_strcmp0(p, property_conv[j].from) == 0)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
qsp = property_conv[j].to;
|
|
Packit |
3ff1e7 |
break;
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
quvi_script_get(q, type, qsp, &s);
|
|
Packit |
3ff1e7 |
if (i == 0)
|
|
Packit |
3ff1e7 |
g_print("[%s]\n", __func__);
|
|
Packit |
3ff1e7 |
g_print(" %s=%s\n", p, s);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static gchar **property_sv()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar **r;
|
|
Packit |
3ff1e7 |
gint i,j;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
i=0;
|
|
Packit |
3ff1e7 |
while (property_conv[i].from != NULL) ++i;
|
|
Packit |
3ff1e7 |
r = g_new(gchar*, i+1);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
i=j=0;
|
|
Packit |
3ff1e7 |
while (property_conv[j].from != NULL)
|
|
Packit |
3ff1e7 |
r[i++] = g_strdup(property_conv[j++].from);
|
|
Packit |
3ff1e7 |
r[i] = NULL;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static gboolean chk_property_values()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar **v, *s;
|
|
Packit |
3ff1e7 |
gboolean r;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
v = property_sv();
|
|
Packit |
3ff1e7 |
r = examples_chk_val_sv(opts.property, v, &s);
|
|
Packit |
3ff1e7 |
if (r == FALSE)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
g_printerr(
|
|
Packit |
3ff1e7 |
"error: invalid value (`%s') for the option `--property'\n", s);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
g_strfreev(v);
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
struct _type_lookup_s
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
QuviScriptType to;
|
|
Packit |
3ff1e7 |
const gchar *from;
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static const struct _type_lookup_s type_conv[] =
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_TYPE_SUBTITLE_EXPORT, "subtitle.export"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_TYPE_SUBTITLE, "subtitle"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_TYPE_PLAYLIST, "playlist"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_TYPE_MEDIA, "media"},
|
|
Packit |
3ff1e7 |
{QUVI_SCRIPT_TYPE_SCAN, "scan"},
|
|
Packit |
3ff1e7 |
{0, NULL}
|
|
Packit |
3ff1e7 |
};
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static gchar **type_sv()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar **r;
|
|
Packit |
3ff1e7 |
gint i,j;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
i=0;
|
|
Packit |
3ff1e7 |
while (type_conv[i].from != NULL) ++i;
|
|
Packit |
3ff1e7 |
r = g_new(gchar*, i+1);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
i=j=0;
|
|
Packit |
3ff1e7 |
while (type_conv[j].from != NULL)
|
|
Packit |
3ff1e7 |
r[i++] = g_strdup(type_conv[j++].from);
|
|
Packit |
3ff1e7 |
r[i] = NULL;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static gboolean chk_type_values()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar **v, *s;
|
|
Packit |
3ff1e7 |
gboolean r;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
v = type_sv();
|
|
Packit |
3ff1e7 |
r = examples_chk_val_s(opts.type, v, &s);
|
|
Packit |
3ff1e7 |
if (r == FALSE)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
g_printerr(
|
|
Packit |
3ff1e7 |
"error: invalid value (`%s') for the option `--type'\n", s);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
g_strfreev(v);
|
|
Packit |
3ff1e7 |
v = NULL;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static QuviScriptType type_n()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gint i;
|
|
Packit |
3ff1e7 |
for (i=0; type_conv[i].from != NULL; ++i)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
if (g_strcmp0(opts.type, type_conv[i].from) == 0)
|
|
Packit |
3ff1e7 |
return (type_conv[i].to);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
return (QUVI_SCRIPT_TYPE_MEDIA);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static gint opts_new(gint argc, gchar **argv)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
GOptionContext *c;
|
|
Packit |
3ff1e7 |
GError *e;
|
|
Packit |
3ff1e7 |
gint r;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
c = g_option_context_new(NULL);
|
|
Packit |
3ff1e7 |
r = EXIT_SUCCESS;
|
|
Packit |
3ff1e7 |
e = NULL;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
g_option_context_set_help_enabled(c, TRUE);
|
|
Packit |
3ff1e7 |
g_option_context_add_main_entries(c, entries, NULL);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
if (g_option_context_parse(c, &argc, &argv, &e) == FALSE)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
g_printerr("error: %s\n", e->message);
|
|
Packit |
3ff1e7 |
g_error_free(e);
|
|
Packit |
3ff1e7 |
r = EXIT_FAILURE;
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
g_option_context_free(c);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
/* Set the defaults. */
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
if (opts.property == NULL)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar *v[] = {"filename", "domains", NULL};
|
|
Packit |
3ff1e7 |
opts.property = g_strdupv(v);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
if (opts.type == NULL)
|
|
Packit |
3ff1e7 |
opts.type = g_strdup("media");
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
/* Check input. */
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
if (chk_property_values() == FALSE)
|
|
Packit |
3ff1e7 |
return (EXIT_FAILURE);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
if (chk_type_values() == FALSE)
|
|
Packit |
3ff1e7 |
return (EXIT_FAILURE);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
static void opts_free()
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
g_strfreev(opts.property);
|
|
Packit |
3ff1e7 |
opts.property = NULL;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
g_free(opts.type);
|
|
Packit |
3ff1e7 |
opts.type = NULL;
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
gint main(gint argc, gchar **argv)
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
QuviScriptType type;
|
|
Packit |
3ff1e7 |
gint r;
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
setlocale(LC_ALL, "");
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
memset(&opts, 0, sizeof(struct _opts_s));
|
|
Packit |
3ff1e7 |
g_assert(q == NULL);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
r = opts_new(argc, argv);
|
|
Packit |
3ff1e7 |
if (r != EXIT_SUCCESS)
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
q = quvi_new();
|
|
Packit |
3ff1e7 |
examples_exit_if_error();
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
type = type_n();
|
|
Packit |
3ff1e7 |
{
|
|
Packit |
3ff1e7 |
gchar *p = g_strjoinv(",", opts.property);
|
|
Packit |
3ff1e7 |
g_printerr("[%s] type=%s (0x%x), property=%s\n",
|
|
Packit |
3ff1e7 |
__func__, opts.type, type, p);
|
|
Packit |
3ff1e7 |
g_free(p);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
while (quvi_script_next(q, type) == QUVI_TRUE)
|
|
Packit |
3ff1e7 |
dump_script(type);
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
examples_cleanup();
|
|
Packit |
3ff1e7 |
opts_free();
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
g_assert(q == NULL);
|
|
Packit |
3ff1e7 |
return (r);
|
|
Packit |
3ff1e7 |
}
|
|
Packit |
3ff1e7 |
|
|
Packit |
3ff1e7 |
/* vim: set ts=2 sw=2 tw=72 expandtab: */
|