Pass lua_State arg to l_quvi_object_opts_croak_if_error
[libquvi.git] / src / api / supports.c
blobf58e0c32f1927ab9b26c6f860ee5d47a55e6d1e5
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 /** @file supports.c */
23 #include "config.h"
25 #include <glib.h>
27 #include "quvi.h"
28 /* -- */
29 #include "_quvi_s.h"
30 #include "_quvi_media_s.h"
31 #include "_quvi_playlist_s.h"
32 #include "_quvi_subtitle_s.h"
33 /* -- */
34 #include "misc/match_playlist_script.h"
35 #include "misc/match_subtitle_script.h"
36 #include "misc/match_media_script.h"
38 static QuviBoolean _supports_playlist(_quvi_t q, const gchar *url,
39 const QuviSupportsMode mode)
41 _quvi_playlist_t qp = NULL;
43 q->status.rc = m_match_playlist_script(q, &qp, url,
44 (mode == QUVI_SUPPORTS_MODE_OFFLINE)
45 ? QM_MATCH_PS_SUPPORTED_OFFLINE
46 : QM_MATCH_PS_SUPPORTED_ONLINE);
47 if (qp != NULL)
49 quvi_playlist_free((quvi_playlist_t) qp);
50 qp = NULL;
52 return (quvi_ok(q));
55 static QuviBoolean _supports_subtitle(_quvi_t q, const gchar *url,
56 const QuviSupportsMode mode)
58 _quvi_subtitle_t qsub = NULL;
60 q->status.rc = m_match_subtitle_script(q, &qsub, url,
61 (mode == QUVI_SUPPORTS_MODE_OFFLINE)
62 ? QM_MATCH_SUBS_SUPPORTED_OFFLINE
63 : QM_MATCH_SUBS_SUPPORTED_ONLINE);
65 if (qsub != NULL)
67 quvi_subtitle_free((quvi_subtitle_t) qsub);
68 qsub = NULL;
70 return (quvi_ok(q));
73 static QuviBoolean _supports_media(_quvi_t q, const gchar *url,
74 const QuviSupportsMode mode)
76 _quvi_media_t qm = NULL;
78 q->status.rc = m_match_media_script(q, &qm, url,
79 (mode == QUVI_SUPPORTS_MODE_OFFLINE)
80 ? QM_MATCH_MS_SUPPORTED_OFFLINE
81 : QM_MATCH_MS_SUPPORTED_ONLINE);
82 if (qm != NULL)
84 quvi_media_free((quvi_media_t) qm);
85 qm = NULL;
87 return (quvi_ok(q));
90 /** @brief Check whether the URL is supported
92 Check if any of the scripts accepts the URL. Both offline and online
93 checking is supported.
95 @note
96 - Offline check will fail with most @ref sh_url
97 - Online check will resolve @ref sh_url
99 Type may be a combination.
101 @code
102 quvi_supports(q, URL, QUVI_SUPPORTS_OFFLINE,
103 QUVI_SUPPORTS_TYPE_PLAYLIST | QUVI_SUPPORTS_TYPE_MEDIA);
104 @endcode
106 @ingroup convenience
108 QuviBoolean quvi_supports(quvi_t handle, const char *url,
109 QuviSupportsMode mode, QuviSupportsType type)
111 QuviBoolean found;
112 _quvi_t q;
114 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
115 g_return_val_if_fail(handle != NULL, QUVI_FALSE);
116 g_return_val_if_fail(url != NULL, QUVI_FALSE);
118 q = (_quvi_t) handle;
119 q->status.rc = QUVI_OK;
120 found = QUVI_FALSE;
122 if (type & QUVI_SUPPORTS_TYPE_PLAYLIST)
123 found = _supports_playlist(q, url, mode);
125 if (q->status.rc == QUVI_OK || q->status.rc == QUVI_ERROR_NO_SUPPORT)
127 if (type & QUVI_SUPPORTS_TYPE_SUBTITLE)
128 found = _supports_subtitle(q, url, mode);
131 if (q->status.rc == QUVI_OK || q->status.rc == QUVI_ERROR_NO_SUPPORT)
133 if (type & QUVI_SUPPORTS_TYPE_MEDIA)
134 found = _supports_media(q, url, mode);
136 return (found);
139 /* vim: set ts=2 sw=2 tw=72 expandtab: */