FIX: examples/supports.c: type_n: Return correct type
[libquvi.git] / src / misc / match_playlist_script.c
blob515516523f215acd1e2822bd340faaa4308732a3
1 /* libquvi
2 * Copyright (C) 2012 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_playlist_s.h"
31 #include "_quvi_net_s.h"
32 #include "_quvi_script_s.h"
33 /* -- */
34 #include "misc/match_playlist_script.h"
35 #include "misc/playlist.h"
36 #include "misc/unescape.h"
37 #include "misc/resolve.h"
38 #include "net/handle.h"
39 #include "lua/exec.h"
41 extern QuviError l_match_url_to_playlist_script(_quvi_playlist_t, GSList**);
42 extern const gchar *show_script; /* m_scan_scripts */
44 typedef QuviMatchPlaylistScriptMode _qm_mode;
46 QuviError m_match_playlist_script(_quvi_t q, _quvi_playlist_t *p,
47 const gchar *url, const _qm_mode mode)
49 gboolean resolve_flag;
50 QuviError rc;
51 GSList *s;
53 resolve_flag = (mode != QM_MATCH_PS_SUPPORTED_OFFLINE)
54 ? TRUE
55 : FALSE;
57 *p = m_playlist_new(q, url);
59 if (resolve_flag == TRUE) /* Resolve URL redirection. */
61 m_resolve(q, url, (*p)->url.input);
62 if (quvi_ok(q) == QUVI_FALSE)
63 return (q->status.rc);
66 m_unescape_url((*p)->url.input);
67 rc = l_match_url_to_playlist_script(*p, &s);
69 if (rc == QUVI_ERROR_NO_SUPPORT)
71 static const gchar *_E =
72 N_("No support: %s: Could not find a playlist script for URL");
74 g_string_printf((*p)->handle.quvi->status.errmsg,
75 g_dgettext(GETTEXT_PACKAGE, _E), url);
76 return (rc);
78 else if (rc != QUVI_OK)
79 return (rc);
81 if (show_script != NULL && strlen(show_script) >0)
83 const _quvi_script_t qs = (const _quvi_script_t) s->data;
85 g_message("[%s] libquvi: %s: input URL accepted",
86 __func__, qs->fpath->str);
89 switch (mode)
91 case QM_MATCH_PS_PARSE:
92 rc = l_exec_playlist_script_parse(*p, s);
93 break;
94 case QM_MATCH_PS_SUPPORTED_OFFLINE:
95 case QM_MATCH_PS_SUPPORTED_ONLINE:
96 break;
98 return (rc);
101 /* vim: set ts=2 sw=2 tw=72 expandtab: */