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/>.
21 /** @file playlist_get.c */
30 #include "_quvi_playlist_s.h"
32 /* Advances the current media pointer to the first media if undefined. */
33 static void _chk_curr_media(_quvi_playlist_t qp
, _quvi_playlist_media_t
*qpm
)
35 if (qp
->curr
.media
== NULL
)
36 quvi_playlist_media_next(qp
);
38 if (qp
->curr
.media
!= NULL
)
39 *qpm
= (_quvi_playlist_media_t
) qp
->curr
.media
->data
;
42 static const gchar empty
[] = "";
44 static QuviError
_playlist_get(_quvi_playlist_t qp
,
45 QuviPlaylistProperty n
, ...)
47 _quvi_playlist_media_t qpm
;
56 type
= QUVI_PLAYLIST_PROPERTY_TYPE_MASK
& (gint
) n
;
67 case QUVI_PLAYLIST_PROPERTY_TYPE_STRING
:
68 sp
= va_arg(arg
, gchar
**);
70 rc
= QUVI_ERROR_INVALID_ARG
;
72 case QUVI_PLAYLIST_PROPERTY_TYPE_LONG
:
73 lp
= va_arg(arg
, glong
*);
75 rc
= QUVI_ERROR_INVALID_ARG
;
77 case QUVI_PLAYLIST_PROPERTY_TYPE_DOUBLE
:
78 dp
= va_arg(arg
, gdouble
*);
80 rc
= QUVI_ERROR_INVALID_ARG
;
83 rc
= QUVI_ERROR_INVALID_ARG
;
93 case QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL
:
94 *sp
= qp
->url
.thumbnail
->str
;
97 case QUVI_PLAYLIST_PROPERTY_TITLE
:
101 case QUVI_PLAYLIST_PROPERTY_ID
:
102 *sp
= qp
->id
.playlist
->str
;
106 * (Playlist) Media properties.
108 * quvi_playlist_get is expected to return the property values for
109 * the first media the playlist script returned, just like
110 * quvi_media_get does with media scripts. We must mimic this
111 * behaviour by first attempting to move to the first item in the
112 * playlist media list.
114 * Unlike with quvi_media_get, playlist scripts are allowed to return
115 * nothing. Media scripts are expected to return at least one media
118 * This means that if the playlist script did not return any such
119 * properties (e.g. media URL):
120 * - returned strings must be set to empty ("")
121 * - returned numeric values must be set to 0
124 case QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE
:
125 _chk_curr_media(qp
, &qpm
);
126 *sp
= (qpm
!= NULL
) ? qpm
->title
->str
: (gchar
*) empty
;
129 case QUVI_PLAYLIST_MEDIA_PROPERTY_URL
:
130 _chk_curr_media(qp
, &qpm
);
131 *sp
= (qpm
!= NULL
) ? qpm
->url
->str
: (gchar
*) empty
;
134 case QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS
:
135 _chk_curr_media(qp
, &qpm
);
136 *dp
= (qpm
!= NULL
) ? qpm
->duration_ms
: 0;
140 rc
= QUVI_ERROR_INVALID_ARG
;
146 /** @brief Return a playlist property
147 @sa @ref parse_playlist
148 @ingroup playlistprop
149 @note URLs will be returned in the escaped form
151 void quvi_playlist_get(quvi_playlist_t handle
,
152 QuviPlaylistProperty property
, ...)
159 /* If G_DISABLE_CHECKS is defined then the check is not performed. */
160 g_return_if_fail(handle
!= NULL
);
162 va_start(arg
, property
);
163 p
= va_arg(arg
, gpointer
);
166 qp
= (_quvi_playlist_t
) handle
;
169 q
->status
.rc
= _playlist_get(qp
, property
, p
);
172 /* vim: set ts=2 sw=2 tw=72 expandtab: */