m_media_new: Store input URL in unescaped form
[libquvi.git] / src / misc / media.c
blob96ee8d70f4700f071059b6ff2c9307e32f9c5c65
1 /* libquvi
2 * Copyright (C) 2012,2013 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"
31 #include "misc/slst.h"
32 #include "misc/url.h"
34 gpointer m_media_new(_quvi_t q, const gchar *url)
36 _quvi_media_t qm;
37 gchar *u;
39 qm = g_new0(struct _quvi_media_s, 1);
41 qm->url.redirect_to = g_string_new(NULL);
42 qm->url.thumbnail = g_string_new(NULL);
45 * Store the input URL in the unescaped form which is what the `ident'
46 * functions of the scripts expect when the support check is run
47 * offline.
49 u = m_url_unescaped_form(url);
50 qm->url.input = g_string_new(u);
51 g_free(u);
53 qm->title = g_string_new(NULL);
54 qm->id = g_string_new(NULL);
55 qm->handle.quvi = q;
57 return (qm);
60 static void _stream_free(gpointer p, gpointer userdata)
62 _quvi_media_stream_t qms = (_quvi_media_stream_t) p;
64 if (p == NULL)
65 return;
67 g_string_free(qms->container, TRUE);
68 qms->container = NULL;
70 g_string_free(qms->url, TRUE);
71 qms->url = NULL;
73 g_string_free(qms->id, TRUE);
74 qms->id = NULL;
76 g_string_free(qms->video.encoding, TRUE);
77 qms->video.encoding = NULL;
79 g_string_free(qms->audio.encoding, TRUE);
80 qms->audio.encoding = NULL;
82 g_free(qms);
83 qms = NULL;
86 void m_media_free(_quvi_media_t qm)
88 if (qm == NULL)
89 return;
91 /* Streams */
93 m_slist_free_full(qm->streams, _stream_free);
94 qm->streams = NULL;
96 /* URLs */
98 g_string_free(qm->url.redirect_to, TRUE);
99 qm->url.redirect_to = NULL;
101 g_string_free(qm->url.thumbnail, TRUE);
102 qm->url.thumbnail = NULL;
104 g_string_free(qm->url.input, TRUE);
105 qm->url.input = NULL;
107 /* Other */
109 g_string_free(qm->title, TRUE);
110 qm->title = NULL;
112 g_string_free(qm->id, TRUE);
113 qm->id = NULL;
115 g_free(qm);
116 qm = NULL;
119 /* vim: set ts=2 sw=2 tw=72 expandtab: */