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
20 /** @file playlist_get.c */
29 #include "_quvi_playlist_s.h"
31 /* Advances the current media pointer to the first media if undefined. */
32 static void _chk_curr_media(_quvi_playlist_t qp
, _quvi_playlist_media_t
*qpm
)
34 if (qp
->curr
.media
== NULL
)
35 quvi_playlist_media_next(qp
);
37 if (qp
->curr
.media
!= NULL
)
38 *qpm
= (_quvi_playlist_media_t
) qp
->curr
.media
->data
;
41 static const gchar empty
[] = "";
43 static QuviError
_playlist_get(_quvi_playlist_t qp
,
44 QuviPlaylistProperty n
, ...)
46 _quvi_playlist_media_t qpm
;
55 type
= QUVI_PLAYLIST_PROPERTY_TYPE_MASK
& (gint
) n
;
66 case QUVI_PLAYLIST_PROPERTY_TYPE_STRING
:
67 sp
= va_arg(arg
, gchar
**);
69 rc
= QUVI_ERROR_INVALID_ARG
;
71 case QUVI_PLAYLIST_PROPERTY_TYPE_LONG
:
72 lp
= va_arg(arg
, glong
*);
74 rc
= QUVI_ERROR_INVALID_ARG
;
76 case QUVI_PLAYLIST_PROPERTY_TYPE_DOUBLE
:
77 dp
= va_arg(arg
, gdouble
*);
79 rc
= QUVI_ERROR_INVALID_ARG
;
82 rc
= QUVI_ERROR_INVALID_ARG
;
92 case QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL
:
93 *sp
= qp
->url
.thumbnail
->str
;
96 case QUVI_PLAYLIST_PROPERTY_TITLE
:
100 case QUVI_PLAYLIST_PROPERTY_ID
:
101 *sp
= qp
->id
.playlist
->str
;
105 * (Playlist) Media properties.
107 * quvi_playlist_get is expected to return the property values for
108 * the first media the playlist script returned, just like
109 * quvi_media_get does with media scripts. We must mimic this
110 * behaviour by first attempting to move to the first item in the
111 * playlist media list.
113 * Unlike with quvi_media_get, playlist scripts are allowed to return
114 * nothing. Media scripts are expected to return at least one media
117 * This means that if the playlist script did not return any such
118 * properties (e.g. media URL):
119 * - returned strings must be set to empty ("")
120 * - returned numeric values must be set to 0
123 case QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE
:
124 _chk_curr_media(qp
, &qpm
);
125 *sp
= (qpm
!= NULL
) ? qpm
->title
->str
: (gchar
*) empty
;
128 case QUVI_PLAYLIST_MEDIA_PROPERTY_URL
:
129 _chk_curr_media(qp
, &qpm
);
130 *sp
= (qpm
!= NULL
) ? qpm
->url
->str
: (gchar
*) empty
;
133 case QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS
:
134 _chk_curr_media(qp
, &qpm
);
135 *dp
= (qpm
!= NULL
) ? qpm
->duration_ms
: 0;
139 rc
= QUVI_ERROR_INVALID_ARG
;
145 /** @brief Return a playlist property
146 @sa @ref parse_playlist
147 @ingroup playlistprop
149 void quvi_playlist_get(quvi_playlist_t handle
,
150 QuviPlaylistProperty property
, ...)
157 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
158 g_return_if_fail(handle
!= NULL
);
160 va_start(arg
, property
);
161 p
= va_arg(arg
, gpointer
);
164 qp
= (_quvi_playlist_t
) handle
;
167 q
->status
.rc
= _playlist_get(qp
, property
, p
);
170 /* vim: set ts=2 sw=2 tw=72 expandtab: */