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/>.
23 #include <glib/gi18n-lib.h>
30 #include "_quvi_media_s.h"
31 #include "_quvi_net_s.h"
32 #include "_quvi_script_s.h"
34 #include "misc/match_media_script.h"
35 #include "misc/unescape.h"
36 #include "misc/resolve.h"
37 #include "misc/media.h"
38 #include "net/handle.h"
41 static gboolean
_chk_goto_url(_quvi_media_t qm
)
43 if (qm
->url
.redirect_to
->len
>0)
45 g_string_assign(qm
->url
.input
, qm
->url
.redirect_to
->str
);
46 g_string_assign(qm
->url
.redirect_to
, "");
52 extern QuviError
l_match_url_to_media_script(_quvi_media_t
, GSList
**);
53 extern const gchar
*show_script
; /* m_scan_scripts */
55 typedef QuviMatchMediaScriptMode _qm_mode
;
57 QuviError
m_match_media_script(_quvi_t q
, _quvi_media_t
*qm
,
58 const gchar
*url
, const _qm_mode mode
)
60 gboolean resolve_flag
;
64 resolve_flag
= (mode
!= QM_MATCH_MS_SUPPORTED_OFFLINE
)
69 *qm
= m_media_new(q
, url
);
71 if (resolve_flag
== TRUE
) /* Resolve URL redirection. */
73 m_resolve(q
, url
, (*qm
)->url
.input
);
74 if (quvi_ok(q
) == QUVI_FALSE
)
75 return (q
->status
.rc
);
78 m_unescape_url((*qm
)->url
.input
);
79 rc
= l_match_url_to_media_script(*qm
, &s
);
81 if (rc
== QUVI_ERROR_NO_SUPPORT
)
83 static const gchar
*_E
=
84 N_("No support: %s: Could not find a media script for URL");
86 g_string_printf(q
->status
.errmsg
, g_dgettext(GETTEXT_PACKAGE
, _E
), url
);
89 else if (rc
!= QUVI_OK
)
92 if (show_script
!= NULL
&& strlen(show_script
) >0)
94 const _quvi_script_t qs
= (const _quvi_script_t
) s
->data
;
96 g_message("[%s] libquvi: %s: input URL accepted",
97 __func__
, qs
->fpath
->str
);
102 case QM_MATCH_MS_PARSE
:
103 rc
= l_exec_media_script_parse(*qm
, s
);
106 /* Check if goto_url was set. */
107 if (_chk_goto_url(*qm
) == TRUE
)
108 return (m_match_media_script(q
, qm
, url
, mode
));
112 case QM_MATCH_MS_SUPPORTED_OFFLINE
:
113 case QM_MATCH_MS_SUPPORTED_ONLINE
:
119 /* vim: set ts=2 sw=2 tw=72 expandtab: */