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 */
30 #include "_quvi_media_s.h"
31 #include "_quvi_playlist_s.h"
32 #include "_quvi_subtitle_s.h"
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
);
49 quvi_playlist_free((quvi_playlist_t
) qp
);
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
);
67 quvi_subtitle_free((quvi_subtitle_t
) qsub
);
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
);
84 quvi_media_free((quvi_media_t
) qm
);
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.
96 - Offline check will fail with most @ref sh_url
97 - Online check will resolve @ref sh_url
99 Type may be a combination.
102 quvi_supports(q, URL, QUVI_SUPPORTS_OFFLINE,
103 QUVI_SUPPORTS_TYPE_PLAYLIST | QUVI_SUPPORTS_TYPE_MEDIA);
108 QuviBoolean
quvi_supports(quvi_t handle
, const char *url
,
109 QuviSupportsMode mode
, QuviSupportsType type
)
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
;
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
);
139 /* vim: set ts=2 sw=2 tw=72 expandtab: */