2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <http://quvi.sourceforge.net/>.
6 * This program 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 program 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 program. If not, see
18 * <http://www.gnu.org/licenses/>.
22 * An URI list conforming to the text/uri-list mime type defined in
23 * RFC2483 into individual URIs.
25 * media: default/selected stream URL only
26 * streams: all media stream URLs
27 * scan: embedded media URLs only
28 * subtitle: language URLs only
29 * playlist: media URLs only
31 * This module prints directory to std{out,err}, and reuses the
32 * lprint_enum_errmsg function from the enum module.
38 #include <glib/gprintf.h>
39 #include <glib/gi18n.h>
51 typedef struct rfc2483_s
*rfc2483_t
;
53 static gint
_rfc2483_handle_new(quvi_t q
, quvi_media_t qm
, gpointer
*dst
)
57 g_assert(dst
!= NULL
);
59 n
= g_new0(struct rfc2483_s
, 1);
64 return (EXIT_SUCCESS
);
67 static gint
_rfc2483_handle_free(gpointer data
, const gint r
)
73 static gint
_print(const rfc2483_t p
, const lutilPropertyType pt
,
74 const gchar
*n
, const gchar
*s
, const gdouble d
,
75 const gboolean comment_out
, const gboolean escape
)
80 r
= lutil_chk_property_ok(p
->q
, pt
, n
, lprint_enum_errmsg
);
81 if (r
!= EXIT_SUCCESS
) /* Reuse the lprint_enum_errmsg. */
82 return (EXIT_FAILURE
);
84 h
= (comment_out
== TRUE
) ? "# ":"";
90 gchar
*e
= g_uri_escape_string(s
, NULL
, TRUE
);
91 g_print("%s%s\n", h
, e
);
95 g_print("%s%s\n", h
, s
);
98 g_print("%s%.0f\n", h
, d
);
100 return (EXIT_SUCCESS
);
105 gint
lprint_rfc2483_media_new(quvi_t q
, quvi_media_t qm
, gpointer
*dst
)
107 return (_rfc2483_handle_new(q
, qm
, dst
));
110 void lprint_rfc2483_media_free(gpointer data
)
112 _rfc2483_handle_free(data
, -1);
115 gint
lprint_rfc2483_media_print_buffer(gpointer data
)
117 /* Nothing to buffer: everything gets printed to stdout immediately */
118 return (EXIT_SUCCESS
);
121 typedef lprint_cb_errmsg cem
;
123 static gint
_mp_s(const rfc2483_t p
, const QuviMediaProperty qmp
,
124 const gchar
*n
, const gboolean c
, const gboolean e
)
127 quvi_media_get(p
->qm
, qmp
, &s
);
128 return (_print(p
, UTIL_PROPERTY_TYPE_MEDIA
, n
, s
, -1, c
, e
));
131 #define _print_mp_s(n,c,e) /* c=commented-out, e=escaped */ \
133 if (_mp_s(p, n, #n, c, e) != EXIT_SUCCESS)\
134 return (EXIT_FAILURE);\
138 lprint_rfc2483_media_stream_properties(quvi_http_metainfo_t qmi
,
141 rfc2483_t p
= (rfc2483_t
) data
;
143 g_assert(data
!= NULL
);
145 _print_mp_s(QUVI_MEDIA_STREAM_PROPERTY_ID
, TRUE
, FALSE
);
146 _print_mp_s(QUVI_MEDIA_STREAM_PROPERTY_URL
, FALSE
, TRUE
);
148 return (EXIT_SUCCESS
);
151 gint
lprint_rfc2483_media_streams_available(quvi_t q
, quvi_media_t qm
)
156 if (_rfc2483_handle_new(q
, qm
, (gpointer
*) &p
) != EXIT_SUCCESS
)
157 return (EXIT_FAILURE
);
159 g_print(_("# Media streams\n#\n"));
162 while (quvi_media_stream_next(qm
) == QUVI_TRUE
&& r
==EXIT_SUCCESS
)
163 r
= lprint_rfc2483_media_stream_properties(NULL
, p
);
165 return (_rfc2483_handle_free(p
, r
));
170 gint
lprint_rfc2483_media_properties(gpointer data
)
172 return (EXIT_SUCCESS
);
177 gint
lprint_rfc2483_playlist_new(quvi_t q
, gpointer
*dst
)
179 return (_rfc2483_handle_new(q
, NULL
, dst
));
182 void lprint_rfc2483_playlist_free(gpointer data
)
184 /* Nothing to release. */
187 gint
lprint_rfc2483_playlist_print_buffer(gpointer data
)
189 /* Nothing to buffer: everything gets printed to stdout immediately */
190 return (EXIT_SUCCESS
);
193 static gint
_pp_s(const rfc2483_t p
, const quvi_playlist_t qp
,
194 const QuviPlaylistProperty qpp
, const gchar
*n
,
195 const gboolean c
, const gboolean e
)
198 quvi_playlist_get(qp
, qpp
, &s
);
199 return (_print(p
, UTIL_PROPERTY_TYPE_PLAYLIST
, n
, s
, -1, c
, e
));
202 #define _print_pp_s(n,c,e) /* c=commented-out, e=escaped */ \
204 if (_pp_s(p, qp, n, #n, c, e) != EXIT_SUCCESS)\
205 return (EXIT_FAILURE);\
208 static gint
_pp_d(const rfc2483_t p
, const quvi_playlist_t qp
,
209 const QuviPlaylistProperty qpp
, const gchar
*n
,
213 quvi_playlist_get(qp
, qpp
, &d
);
214 return (_print(p
, UTIL_PROPERTY_TYPE_PLAYLIST
, n
, NULL
, d
, c
, FALSE
));
217 #define _print_pp_d(n,c) /* c=commented-out */ \
219 if (_pp_d(p, qp, n, #n, c) != EXIT_SUCCESS)\
220 return (EXIT_FAILURE);\
223 gint
lprint_rfc2483_playlist_properties(quvi_playlist_t qp
, gpointer data
)
225 rfc2483_t p
= (rfc2483_t
) data
;
227 g_assert(data
!= NULL
);
228 g_assert(qp
!= NULL
);
230 g_print(_("# Playlist media URLs\n#\n"));
232 _print_pp_s(QUVI_PLAYLIST_PROPERTY_TITLE
, TRUE
, FALSE
);
233 _print_pp_s(QUVI_PLAYLIST_PROPERTY_ID
, TRUE
, FALSE
);
234 _print_pp_s(QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL
, TRUE
, FALSE
);
238 while (quvi_playlist_media_next(qp
) == QUVI_TRUE
)
240 _print_pp_s(QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE
, TRUE
, FALSE
);
241 _print_pp_d(QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS
, TRUE
);
242 _print_pp_s(QUVI_PLAYLIST_MEDIA_PROPERTY_URL
, FALSE
, TRUE
);
244 return (EXIT_SUCCESS
);
251 gint
lprint_rfc2483_scan_new(quvi_t q
, gpointer
*dst
)
253 return (_rfc2483_handle_new(q
, NULL
, dst
));
256 void lprint_rfc2483_scan_free(gpointer data
)
258 _rfc2483_handle_free(data
, -1);
261 gint
lprint_rfc2483_scan_print_buffer(gpointer data
)
263 /* Nothing to buffer: everything gets printed to stdout immediately */
264 return (EXIT_SUCCESS
);
267 gint
lprint_rfc2483_scan_properties(quvi_scan_t qs
, gpointer data
)
271 g_assert(qs
!= NULL
);
273 /* 'scan' interface does not have any properties. */
275 g_print(_("# Embedded media URLs\n#\n"));
276 while ( (s
= quvi_scan_next_media_url(qs
)) != NULL
)
278 gchar
*e
= g_uri_escape_string(s
, NULL
, TRUE
);
282 return (EXIT_SUCCESS
);
287 gint
lprint_rfc2483_subtitle_new(quvi_t q
, gpointer
*dst
)
289 return (_rfc2483_handle_new(q
, NULL
, dst
));
292 void lprint_rfc2483_subtitle_free(gpointer data
)
294 _rfc2483_handle_free(data
, -1);
297 gint
lprint_rfc2483_subtitle_print_buffer(gpointer data
)
299 /* Nothing to buffer: everything gets printed to stdout immediately */
300 return (EXIT_SUCCESS
);
303 static gint
_slp_s(const rfc2483_t p
, const quvi_subtitle_lang_t qsl
,
304 const QuviSubtitleLangProperty qslp
, const gchar
*n
,
305 const gboolean c
, const gboolean e
)
308 quvi_subtitle_lang_get(qsl
, qslp
, &s
);
309 return (_print(p
, UTIL_PROPERTY_TYPE_SUBTITLE_LANGUAGE
, n
, s
, -1, c
, e
));
312 #define _print_slp_s(n,c,e) /* c=commented-out, e=escaped */ \
314 if (_slp_s(p, l, n, #n, c, e) != EXIT_SUCCESS)\
315 return (EXIT_FAILURE);\
319 lprint_rfc2483_subtitle_lang_properties(quvi_subtitle_lang_t l
,
324 g_assert(data
!= NULL
);
325 p
= (rfc2483_t
) data
;
327 _print_slp_s(QUVI_SUBTITLE_LANG_PROPERTY_ID
, TRUE
, FALSE
);
328 _print_slp_s(QUVI_SUBTITLE_LANG_PROPERTY_URL
, FALSE
, TRUE
);
330 return (EXIT_SUCCESS
);
333 gint
lprint_rfc2483_subtitles_available(quvi_t q
, quvi_subtitle_t qsub
)
335 quvi_subtitle_type_t t
;
336 quvi_subtitle_lang_t l
;
340 if (_rfc2483_handle_new(q
, NULL
, (gpointer
*) &p
) != EXIT_SUCCESS
)
341 return (EXIT_FAILURE
);
343 g_print(_("# Subtitles\n#\n"));
346 while ( (t
= quvi_subtitle_type_next(qsub
)) != NULL
&& r
==EXIT_SUCCESS
)
348 while ( (l
= quvi_subtitle_lang_next(t
)) != NULL
&& r
==EXIT_SUCCESS
)
349 r
= lprint_rfc2483_subtitle_lang_properties(l
, p
);
351 return (_rfc2483_handle_free(p
, r
));
356 /* vim: set ts=2 sw=2 tw=72 expandtab: */