Add examples/file_ext.c
[libquvi.git] / src / misc / match_subtitle_script.c
blob74fdc0f0dfa103363993013ee819a6a529511155
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 <string.h>
24 #include <glib/gi18n-lib.h>
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_subtitle_s.h"
31 #include "_quvi_net_s.h"
32 #include "_quvi_script_s.h"
33 /* -- */
34 #include "misc/match_subtitle_script.h"
35 #include "misc/unescape.h"
36 #include "misc/resolve.h"
37 #include "misc/subtitle.h"
38 #include "net/handle.h"
39 #include "lua/exec.h"
41 extern QuviError l_match_url_to_subtitle_script(_quvi_subtitle_t, GSList**);
42 extern const gchar *show_script; /* m_scan_scripts */
44 typedef QuviMatchSubtitleScriptMode _qm_mode;
46 QuviError m_match_subtitle_script(_quvi_t q, _quvi_subtitle_t *qsub,
47 const gchar *url, const _qm_mode mode)
49 gboolean resolve_flag;
50 QuviError rc;
51 GSList *s;
53 resolve_flag = (mode != QM_MATCH_SUBS_SUPPORTED_OFFLINE)
54 ? TRUE
55 : FALSE;
57 *qsub = m_subtitle_new(q, url);
59 if (resolve_flag == TRUE) /* Resolve URL redirection. */
61 m_resolve(q, url, (*qsub)->url.input);
62 if (quvi_ok(q) == QUVI_FALSE)
63 return (q->status.rc);
66 m_unescape_url((*qsub)->url.input);
67 rc = l_match_url_to_subtitle_script(*qsub, &s);
69 if (rc == QUVI_ERROR_NO_SUPPORT)
71 g_string_printf(q->status.errmsg,
72 _("No support: %s: Could not find a subtitle "
73 "script for URL"), url);
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);
87 switch (mode)
89 case QM_MATCH_SUBS_PARSE:
90 rc = l_exec_subtitle_script_parse(*qsub, s);
91 break;
92 case QM_MATCH_SUBS_SUPPORTED_OFFLINE:
93 case QM_MATCH_SUBS_SUPPORTED_ONLINE:
94 break;
96 return (rc);
99 /* vim: set ts=2 sw=2 tw=72 expandtab: */