mirror of
https://github.com/mpv-player/mpv.git
synced 2026-10-16 22:40:53 +08:00
stream: add effective_url, the url after redirects
stream_lavf takes it from the location option of the protocol and stream_curl from CURLINFO_EFFECTIVE_URL.
This commit is contained in:
@@ -243,6 +243,7 @@ typedef struct stream {
|
||||
void *priv; // used for DVD, TV, RTSP etc
|
||||
char *url; // filename/url (possibly including protocol prefix)
|
||||
char *path; // filename (url without protocol prefix)
|
||||
char *effective_url; // url after redirects, if known
|
||||
char *mime_type; // when HTTP streaming is used
|
||||
char *server_filename; // file name reported by the server, if any
|
||||
char *demuxer; // request demuxer to be used
|
||||
|
||||
@@ -167,7 +167,6 @@ struct priv {
|
||||
CURL *curl;
|
||||
struct curl_slist *headers;
|
||||
char *url;
|
||||
const char *effective_url;
|
||||
const struct curl_scheme *scheme;
|
||||
|
||||
// Stream parameters
|
||||
@@ -1191,7 +1190,7 @@ static int curl_open(stream_t *s, const struct stream_open_args *args)
|
||||
|
||||
const char *effective_url = NULL;
|
||||
curl_easy_getinfo(p->curl, CURLINFO_EFFECTIVE_URL, &effective_url);
|
||||
p->effective_url = effective_url ? effective_url : p->url;
|
||||
s->effective_url = talloc_strdup(s, effective_url);
|
||||
|
||||
s->seekable = p->seekable;
|
||||
s->is_network = true;
|
||||
@@ -1387,7 +1386,7 @@ static int open_curl_transport(struct demuxer *demuxer, AVIOContext **pb_out,
|
||||
c->av_class = &curl_avio_cookie_class;
|
||||
c->stream = s;
|
||||
c->cancel = cancel;
|
||||
c->location = ((struct priv *)s->priv)->effective_url;
|
||||
c->location = s->effective_url ? s->effective_url : s->url;
|
||||
|
||||
void *buffer = av_malloc(64 * 1024);
|
||||
if (!buffer) {
|
||||
|
||||
@@ -411,6 +411,12 @@ static int open_f(stream_t *stream)
|
||||
stream->mime_type = talloc_strdup(stream, mt);
|
||||
av_free(mt);
|
||||
}
|
||||
uint8_t *location = NULL;
|
||||
if (av_opt_get(avio, "location", AV_OPT_SEARCH_CHILDREN, &location) >= 0) {
|
||||
if (*location)
|
||||
stream->effective_url = talloc_strdup(stream, location);
|
||||
av_free(location);
|
||||
}
|
||||
}
|
||||
|
||||
stream->priv = avio;
|
||||
|
||||
Reference in New Issue
Block a user