docs: document --quvi-format
[mplayer.git] / stream / open.c
blob16d0dc35fc06c12d252bc703493b78eacfb36395
1 /*
2 * This file is part of MPlayer.
4 * MPlayer 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 * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <ctype.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <string.h>
27 #include "config.h"
28 #include "mp_msg.h"
29 #include "talloc.h"
31 #ifdef __FreeBSD__
32 #include <sys/cdrio.h>
33 #endif
35 #include "m_option.h"
36 #include "options.h"
37 #include "stream.h"
38 #include "libmpdemux/demuxer.h"
41 /// We keep these 2 for the gui atm, but they will be removed.
42 int vcd_track=0;
43 char* cdrom_device=NULL;
44 char* dvd_device=NULL;
45 int dvd_title=0;
47 #ifdef CONFIG_LIBQUVI
49 #include <quvi/quvi.h>
51 static const char *resolve_quvi(const char *url, struct MPOpts *opts)
53 char *media_title, *media_url;
54 quvi_media_t m;
55 QUVIcode rc;
56 quvi_t q;
58 rc = quvi_init(&q);
59 if (rc != QUVI_OK)
60 return NULL;
62 // Don't try to use quvi on an URL that's not directly supported, since
63 // quvi will do a network access anyway in order to check for HTTP
64 // redirections etc.
65 // The documentation says this will fail on "shortened" URLs.
66 if (quvi_supported(q, (char *)url) != QUVI_OK) {
67 quvi_close(&q);
68 return NULL;
71 mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
73 // Can use quvi_query_formats() to get a list of formats like this:
74 // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p"
75 // (This example is youtube specific.)
76 // That call requires an extra net access. quvi_next_media_url() doesn't
77 // seem to do anything useful. So we can't really do anything useful
78 // except pass through the user's format setting.
79 quvi_setopt(q, QUVIOPT_FORMAT, opts->quvi_format);
81 rc = quvi_parse(q, (char *)url, &m);
82 if (rc != QUVI_OK) {
83 mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc));
84 quvi_close(&q);
85 return NULL;
88 quvi_getprop(m, QUVIPROP_PAGETITLE, &media_title);
89 quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
91 mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Site media title: '%s'\n",
92 media_title);
93 media_url = talloc_strdup(NULL, media_url);
95 quvi_parse_close(&m);
96 quvi_close(&q);
98 return media_url;
100 #endif
102 // Open a new stream (stdin/file/vcd/url)
104 stream_t* open_stream(const char *filename, struct MPOpts *options,
105 int *file_format)
107 if (!file_format)
108 file_format = &(int){DEMUXER_TYPE_UNKNOWN};
109 // Check if playlist or unknown
110 if (*file_format != DEMUXER_TYPE_PLAYLIST){
111 *file_format=DEMUXER_TYPE_UNKNOWN;
114 if(!filename) {
115 mp_msg(MSGT_OPEN,MSGL_ERR,"NULL filename, report this bug\n");
116 return NULL;
119 const char *resolved = NULL;
121 #ifdef CONFIG_LIBQUVI
122 resolved = resolve_quvi(filename, options);
123 #endif
125 if (resolved)
126 filename = resolved;
128 stream_t *res = open_stream_full(filename,STREAM_READ,options,file_format);
129 talloc_free((void *)resolved);
130 return res;