FIX: examples/supports.c: type_n: Return correct type
[libquvi.git] / src / misc / media.c
blob581122e1c110d730f6cc54d8e2132dbc78a5dcb3
1 /* libquvi
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 #include "config.h"
23 #include <glib.h>
25 #include "quvi.h"
26 /* -- */
27 #include "_quvi_s.h"
28 #include "_quvi_media_s.h"
29 /* -- */
30 #include "misc/media.h"
32 gpointer m_media_new(_quvi_t q, const gchar *url)
34 _quvi_media_t qm = g_new0(struct _quvi_media_s, 1);
35 /* URL */
36 qm->url.redirect_to = g_string_new(NULL);
37 qm->url.thumbnail = g_string_new(NULL);
38 qm->url.input = g_string_new(url);
39 /* Handle */
40 qm->handle.quvi = q;
41 /* Other */
42 qm->title = g_string_new(NULL);
43 qm->id = g_string_new(NULL);
44 return (qm);
47 static void _stream_free(gpointer p, gpointer userdata)
49 _quvi_media_stream_t qms = (_quvi_media_stream_t) p;
51 if (p == NULL)
52 return;
54 g_string_free(qms->container, TRUE);
55 qms->container = NULL;
57 g_string_free(qms->url, TRUE);
58 qms->url = NULL;
60 g_string_free(qms->id, TRUE);
61 qms->id = NULL;
63 g_string_free(qms->video.encoding, TRUE);
64 qms->video.encoding = NULL;
66 g_string_free(qms->audio.encoding, TRUE);
67 qms->audio.encoding = NULL;
69 g_free(qms);
70 qms = NULL;
73 void m_media_free(_quvi_media_t qm)
75 if (qm == NULL)
76 return;
78 /* Streams */
80 #ifdef HAVE_GLIB_2_28
81 g_slist_free_full(qm->streams, _stream_free);
82 #else
83 g_slist_foreach(qm->streams, _stream_free, NULL);
84 g_slist_free(qm->streams);
85 #endif
86 qm->streams = NULL;
88 /* URLs */
90 g_string_free(qm->url.redirect_to, TRUE);
91 qm->url.redirect_to = NULL;
93 g_string_free(qm->url.thumbnail, TRUE);
94 qm->url.thumbnail = NULL;
96 g_string_free(qm->url.input, TRUE);
97 qm->url.input = NULL;
99 /* Other */
101 g_string_free(qm->title, TRUE);
102 qm->title = NULL;
104 g_string_free(qm->id, TRUE);
105 qm->id = NULL;
107 g_free(qm);
108 qm = NULL;
111 /* vim: set ts=2 sw=2 tw=72 expandtab: */