Update NEWS for v0.9.4
[libquvi.git] / src / misc / match_media_script.c
blob0b489da8b491e4f251790eb7e4a4915fd2482348
1 /* libquvi
2 * Copyright (C) 2012,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>
25 #include <string.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_media_s.h"
31 #include "_quvi_net_s.h"
32 #include "_quvi_script_s.h"
33 /* -- */
34 #include "misc/match_media_script.h"
35 #include "misc/resolve.h"
36 #include "misc/media.h"
37 #include "net/handle.h"
38 #include "lua/exec.h"
40 static gboolean _chk_goto_url(_quvi_media_t qm)
42 if (qm->url.redirect_to->len >0)
44 g_string_assign(qm->url.input, qm->url.redirect_to->str);
45 g_string_assign(qm->url.redirect_to, "");
46 return (TRUE);
48 return (FALSE);
51 extern QuviError l_match_url_to_media_script(_quvi_media_t, GSList**);
52 extern const gchar *show_script; /* m_scan_scripts */
54 typedef QuviMatchMediaScriptMode _qm_mode;
56 QuviError m_match_media_script(_quvi_t q, _quvi_media_t *qm,
57 const gchar *url, const _qm_mode mode)
59 gboolean resolve_flag;
60 QuviError rc;
61 GSList *s;
63 resolve_flag = (mode != QM_MATCH_MS_SUPPORTED_OFFLINE)
64 ? TRUE
65 : FALSE;
67 if (*qm == NULL)
68 *qm = m_media_new(q, url);
70 if (resolve_flag == TRUE) /* Resolve URL redirection. */
72 m_resolve(q, (*qm)->url.input);
73 if (quvi_ok(q) == QUVI_FALSE)
74 return (q->status.rc);
77 rc = l_match_url_to_media_script(*qm, &s);
78 if (rc == QUVI_ERROR_NO_SUPPORT)
80 static const gchar *_E =
81 N_("No support: %s: Could not find a media script for URL");
83 g_string_printf(q->status.errmsg, g_dgettext(GETTEXT_PACKAGE, _E), url);
84 return (rc);
86 else if (rc != QUVI_OK)
87 return (rc);
89 if (show_script != NULL && strlen(show_script) >0)
91 const _quvi_script_t qs = (const _quvi_script_t) s->data;
93 g_message("[%s] libquvi: %s: input URL accepted",
94 __func__, qs->fpath->str);
97 switch (mode)
99 case QM_MATCH_MS_PARSE:
100 rc = l_exec_media_script_parse(*qm, s);
101 if (rc == QUVI_OK)
103 /* Check if goto_url was set. */
104 if (_chk_goto_url(*qm) == TRUE)
105 return (m_match_media_script(q, qm, url, mode));
107 break;
109 case QM_MATCH_MS_SUPPORTED_OFFLINE:
110 case QM_MATCH_MS_SUPPORTED_ONLINE:
111 break;
113 return (rc);
116 /* vim: set ts=2 sw=2 tw=72 expandtab: */