Add misc/url.* with m_url_(un)escaped_form
[libquvi.git] / src / misc / match_subtitle_export_script.c
blobaf44cbf08fa4935000e66c20b8ce3a715e6049d3
1 /* libquvi
2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <glib/gi18n-lib.h>
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_subtitle_export_s.h"
30 #include "_quvi_subtitle_s.h"
31 #include "_quvi_script_s.h"
32 /* -- */
33 #include "misc/match_subtitle_export_script.h"
34 #include "misc/subtitle_export.h"
35 #include "lua/exec.h"
37 extern const gchar *show_script; /* m_scan_scripts */
39 QuviError
40 _match_format_to_subtitle_export_script(_quvi_subtitle_export_t qse,
41 GSList **curr)
43 *curr = qse->handle.quvi->scripts.subtitle_export;
44 while (*curr != NULL)
46 const QuviError rc = l_exec_subtitle_export_script_ident(qse, *curr);
48 if (rc == QUVI_OK)
49 return (rc);
51 *curr = g_slist_next(*curr);
53 return (QUVI_ERROR_NO_SUPPORT);
56 QuviError
57 m_match_subtitle_export_script(_quvi_t q, _quvi_subtitle_export_t *dst,
58 _quvi_subtitle_lang_t qsl,
59 const gchar *to_format)
61 QuviError rc;
62 GSList *s;
64 *dst = m_subtitle_export_new(q, qsl->url->str);
65 g_string_assign((*dst)->format.to, to_format);
66 (*dst)->format.from = qsl->format;
68 rc = _match_format_to_subtitle_export_script(*dst, &s);
69 if (rc == QUVI_ERROR_NO_SUPPORT)
71 g_string_printf(q->status.errmsg,
72 _("No support: Could not find a subtitle export "
73 "script for format `%s'"), to_format);
74 return (rc);
76 else if (rc != QUVI_OK)
77 return (rc);
79 if (show_script != NULL && strlen(show_script) >0)
81 const _quvi_script_t qs = (const _quvi_script_t) s->data;
83 g_message("[%s] libquvi: %s: input URL accepted",
84 __func__, qs->fpath->str);
86 return (l_exec_subtitle_export_script_export(*dst, s));
89 /* vim: set ts=2 sw=2 tw=72 expandtab: */