input: fix possible crash in printing key combo names
[mplayer.git] / stream / quvi.c
blob1dde19258691d781849cde65701ab8d5dcfe5b0b
1 /*
2 * This file is part of mplayer2.
4 * mplayer2 is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * mplayer2 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with mplayer2. If not, see <http://www.gnu.org/licenses/>.
18 #include <quvi/quvi.h>
20 #include "talloc.h"
21 #include "mp_msg.h"
22 #include "options.h"
23 #include "stream.h"
25 struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
27 QUVIcode rc;
29 quvi_t q;
30 rc = quvi_init(&q);
31 if (rc != QUVI_OK)
32 return NULL;
34 // Don't try to use quvi on an URL that's not directly supported, since
35 // quvi will do a network access anyway in order to check for HTTP
36 // redirections etc.
37 // The documentation says this will fail on "shortened" URLs.
38 if (quvi_supported(q, (char *)url) != QUVI_OK) {
39 quvi_close(&q);
40 return NULL;
43 mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
45 // Can use quvi_query_formats() to get a list of formats like this:
46 // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p"
47 // (This example is youtube specific.)
48 // That call requires an extra net access. quvi_next_media_url() doesn't
49 // seem to do anything useful. So we can't really do anything useful
50 // except pass through the user's format setting.
51 quvi_setopt(q, QUVIOPT_FORMAT, opts->quvi_format);
53 quvi_media_t m;
54 rc = quvi_parse(q, (char *)url, &m);
55 if (rc != QUVI_OK) {
56 mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc));
57 quvi_close(&q);
58 return NULL;
61 struct mp_resolve_result *result =
62 talloc_zero(NULL, struct mp_resolve_result);
64 char *val;
66 if (quvi_getprop(m, QUVIPROP_MEDIAURL, &val) == QUVI_OK)
67 result->url = talloc_strdup(result, val);
69 if (quvi_getprop(m, QUVIPROP_PAGETITLE, &val) == QUVI_OK)
70 result->title = talloc_strdup(result, val);
72 quvi_parse_close(&m);
73 quvi_close(&q);
75 if (!result->url) {
76 talloc_free(result);
77 result = NULL;
80 return result;