Add misc/url.* with m_url_(un)escaped_form
[libquvi.git] / src / misc / match_playlist_script.c
blob85d72a79a1514c9504088375180cc35832e51a96
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_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/resolve.h"
37 #include "net/handle.h"
38 #include "lua/exec.h"
40 extern QuviError l_match_url_to_playlist_script(_quvi_playlist_t, GSList**);
41 extern const gchar *show_script; /* m_scan_scripts */
43 typedef QuviMatchPlaylistScriptMode _qm_mode;
45 QuviError m_match_playlist_script(_quvi_t q, _quvi_playlist_t *p,
46 const gchar *url, const _qm_mode mode)
48 gboolean resolve_flag;
49 QuviError rc;
50 GSList *s;
52 resolve_flag = (mode != QM_MATCH_PS_SUPPORTED_OFFLINE)
53 ? TRUE
54 : FALSE;
56 *p = m_playlist_new(q, url);
58 if (resolve_flag == TRUE) /* Resolve URL redirection. */
60 m_resolve(q, (*p)->url.input);
61 if (quvi_ok(q) == QUVI_FALSE)
62 return (q->status.rc);
65 rc = l_match_url_to_playlist_script(*p, &s);
66 if (rc == QUVI_ERROR_NO_SUPPORT)
68 static const gchar *_E =
69 N_("No support: %s: Could not find a playlist script for URL");
71 g_string_printf((*p)->handle.quvi->status.errmsg,
72 g_dgettext(GETTEXT_PACKAGE, _E), url);
73 return (rc);
75 else if (rc != QUVI_OK)
76 return (rc);
78 if (show_script != NULL && strlen(show_script) >0)
80 const _quvi_script_t qs = (const _quvi_script_t) s->data;
82 g_message("[%s] libquvi: %s: input URL accepted",
83 __func__, qs->fpath->str);
86 switch (mode)
88 case QM_MATCH_PS_PARSE:
89 rc = l_exec_playlist_script_parse(*p, s);
90 break;
91 case QM_MATCH_PS_SUPPORTED_OFFLINE:
92 case QM_MATCH_PS_SUPPORTED_ONLINE:
93 break;
95 return (rc);
98 /* vim: set ts=2 sw=2 tw=72 expandtab: */