src/api/: Use intended license header
[libquvi.git] / src / api / supports.c
blobe7f6414ae88b66ae7f5dd081ccab58ab98585688
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
20 /** @file supports.c */
22 #include "config.h"
24 #include <glib.h>
26 #include "quvi.h"
27 /* -- */
28 #include "_quvi_s.h"
29 #include "_quvi_media_s.h"
30 #include "_quvi_playlist_s.h"
31 /* -- */
32 #include "misc/match_playlist_script.h"
33 #include "misc/match_media_script.h"
35 static QuviBoolean _supports_playlist(_quvi_t q, const gchar *url,
36 const QuviSupportsMode mode)
38 _quvi_playlist_t qp = NULL;
40 q->status.rc = m_match_playlist_script(q, &qp, url,
41 (mode == QUVI_SUPPORTS_MODE_OFFLINE)
42 ? QM_MATCH_PS_SUPPORTED_OFFLINE
43 : QM_MATCH_PS_SUPPORTED_ONLINE,
44 NULL);
45 if (qp != NULL)
47 quvi_playlist_free((quvi_playlist_t) qp);
48 qp = NULL;
50 return (quvi_ok(q));
53 static QuviBoolean _supports_media(_quvi_t q, const gchar *url,
54 const QuviSupportsMode mode)
56 _quvi_media_t qm = NULL;
58 q->status.rc = m_match_media_script(q, &qm, url,
59 (mode == QUVI_SUPPORTS_MODE_OFFLINE)
60 ? QM_MATCH_MS_SUPPORTED_OFFLINE
61 : QM_MATCH_MS_SUPPORTED_ONLINE,
62 NULL);
63 if (qm != NULL)
65 quvi_media_free((quvi_media_t) qm);
66 qm = NULL;
68 return (quvi_ok(q));
71 /** @brief Check whether the URL is supported
73 Check if any of the scripts accepts the URL. Both offline and online
74 checking is supported.
76 @note
77 - Offline check will fail with most @ref sh_url
78 - Online check will resolve @ref sh_url
80 Type may be a combination.
82 @code
83 quvi_supports(q, URL, QUVI_SUPPORTS_OFFLINE,
84 QUVI_SUPPORTS_TYPE_PLAYLIST | QUVI_SUPPORTS_TYPE_MEDIA);
85 @endcode
87 @ingroup convenience
89 QuviBoolean quvi_supports(quvi_t handle, const char *url,
90 QuviSupportsMode mode, QuviSupportsType type)
92 QuviBoolean found;
93 _quvi_t q;
95 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
96 g_return_val_if_fail(handle != NULL, QUVI_FALSE);
97 g_return_val_if_fail(url != NULL, QUVI_FALSE);
99 q = (_quvi_t) handle;
100 q->status.rc = QUVI_OK;
101 found = QUVI_FALSE;
103 if (type & QUVI_SUPPORTS_TYPE_PLAYLIST)
104 found = _supports_playlist(q, url, mode);
106 if (q->status.rc == QUVI_OK || q->status.rc == QUVI_ERROR_NO_SUPPORT)
108 if (type & QUVI_SUPPORTS_TYPE_MEDIA)
109 found = _supports_media(q, url, mode);
111 return (found);
114 /* vim: set ts=2 sw=2 tw=72 expandtab: */