From 793f85945fc07db905e54390c065ae51b9eeef9b Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 Dec 2013 01:40:26 +0100 Subject: Move libquvi stuff to stream/resolve/ --- mpvcore/resolve.h | 53 -------------- mpvcore/resolve_quvi.c | 111 ----------------------------- mpvcore/resolve_quvi9.c | 157 ----------------------------------------- old-makefile | 4 +- player/command.c | 2 +- player/loadfile.c | 2 +- player/main.c | 1 - player/misc.c | 1 - stream/resolve/resolve.h | 53 ++++++++++++++ stream/resolve/resolve_quvi.c | 111 +++++++++++++++++++++++++++++ stream/resolve/resolve_quvi9.c | 157 +++++++++++++++++++++++++++++++++++++++++ wscript_build.py | 4 +- 12 files changed, 327 insertions(+), 329 deletions(-) delete mode 100644 mpvcore/resolve.h delete mode 100644 mpvcore/resolve_quvi.c delete mode 100644 mpvcore/resolve_quvi9.c create mode 100644 stream/resolve/resolve.h create mode 100644 stream/resolve/resolve_quvi.c create mode 100644 stream/resolve/resolve_quvi9.c diff --git a/mpvcore/resolve.h b/mpvcore/resolve.h deleted file mode 100644 index 7a60b29114..0000000000 --- a/mpvcore/resolve.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MP_RESOLVE_H -#define MP_RESOLVE_H - -struct MPContext; -struct MPOpts; - -struct mp_resolve_result { - char *url; - char *title; - - struct mp_resolve_src **srcs; - int num_srcs; - - double start_time; - - struct mp_resolve_sub **subs; - int num_subs; - - struct playlist *playlist; -}; - -struct mp_resolve_src { - char *url; // can be NULL; otherwise it's the exact video URL - char *encid; // indicates quality level, contents are libquvi specific -}; - -struct mp_resolve_sub { - char *url; - char *data; - char *lang; -}; - -struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts); - -#endif diff --git a/mpvcore/resolve_quvi.c b/mpvcore/resolve_quvi.c deleted file mode 100644 index 00279c568f..0000000000 --- a/mpvcore/resolve_quvi.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with mpv; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include - -#include "talloc.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/options.h" -#include "resolve.h" - -static void add_source(struct mp_resolve_result *res, const char *url, - const char *encid) -{ - struct mp_resolve_src *src = talloc_ptrtype(res, src); - *src = (struct mp_resolve_src) { - .url = talloc_strdup(src, url), - .encid = talloc_strdup(src, encid), - }; - MP_TARRAY_APPEND(res, res->srcs, res->num_srcs, src); -} - -struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts) -{ - QUVIcode rc; - bool mp_url = false; - - quvi_t q; - rc = quvi_init(&q); - if (rc != QUVI_OK) - return NULL; - - if (!strncmp(url, "mp_", 3)) { - url += 3; - mp_url = true; - } - - // Don't try to use quvi on an URL that's not directly supported, since - // quvi will do a network access anyway in order to check for HTTP - // redirections etc. - // The documentation says this will fail on "shortened" URLs. - if (quvi_supported(q, (char *)url) != QUVI_OK) { - quvi_close(&q); - return NULL; - } - - mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n"); - - const char *req_format = opts->quvi_format ? opts->quvi_format : "best"; - - // Can use quvi_query_formats() to get a list of formats like this: - // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p" - // (This example is youtube specific.) - // That call requires an extra net access. quvi_next_media_url() doesn't - // seem to do anything useful. So we can't really do anything useful - // except pass through the user's format setting. - quvi_setopt(q, QUVIOPT_FORMAT, req_format); - - quvi_media_t m; - rc = quvi_parse(q, (char *)url, &m); - if (rc != QUVI_OK) { - mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc)); - quvi_close(&q); - return NULL; - } - - struct mp_resolve_result *result - = talloc_zero(NULL, struct mp_resolve_result); - - char *val; - - if (quvi_getprop(m, QUVIPROP_MEDIAURL, &val) == QUVI_OK) { - if (mp_url) - result->url = talloc_asprintf(result, "mp_%s", val); - else - result->url = talloc_strdup(result, val); - } - - if (quvi_getprop(m, QUVIPROP_PAGETITLE, &val) == QUVI_OK) - result->title = talloc_strdup(result, val); - - quvi_parse_close(&m); - quvi_close(&q); - - if (!result->url) { - talloc_free(result); - result = NULL; - } - - // Useful for quvi-format cycling - add_source(result, NULL, "default"); - add_source(result, NULL, "best"); - if (strcmp(req_format, "best") != 0 && strcmp(req_format, "default") != 0) - add_source(result, NULL, req_format); - - return result; -} diff --git a/mpvcore/resolve_quvi9.c b/mpvcore/resolve_quvi9.c deleted file mode 100644 index ea96f521e3..0000000000 --- a/mpvcore/resolve_quvi9.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with mpv. If not, see . - */ - -#include -#include -#include - -#include - -#include "talloc.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/options.h" -#include "mpvcore/playlist.h" -#include "resolve.h" - -static bool mp_quvi_ok(quvi_t q) -{ - if (!quvi_ok(q)) { - mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); - return false; - } - return true; -} - -struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts) -{ - int mode = QUVI_SUPPORTS_MODE_OFFLINE; - - quvi_t q = quvi_new(); - if (!quvi_ok(q)) { - mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); - - quvi_free(q); - return NULL; - } - - struct mp_resolve_result *res = talloc_zero(NULL, struct mp_resolve_result); - - if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_PLAYLIST)) { - mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking playlist...\n"); - quvi_playlist_t qp = quvi_playlist_new(q, url); - if (mp_quvi_ok(q)) { - res->playlist = talloc_zero(res, struct playlist); - while (quvi_playlist_media_next(qp)) { - char *entry = NULL; - quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &entry); - if (entry) - playlist_add_file(res->playlist, entry); - } - } - quvi_playlist_free(qp); - } - - if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_MEDIA)) { - mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n"); - quvi_media_t media = quvi_media_new(q, url); - if (mp_quvi_ok(q)) { - char *format = opts->quvi_format ? opts->quvi_format : "best"; - bool use_default = strcmp(format, "default") == 0; - if (!use_default) - quvi_media_stream_select(media, format); - - char *val = NULL; - quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_URL, &val); - res->url = talloc_strdup(res, val); - - val = NULL; - quvi_media_get(media, QUVI_MEDIA_PROPERTY_TITLE, &val); - res->title = talloc_strdup(res, val); - - double start = 0; - quvi_media_get(media, QUVI_MEDIA_PROPERTY_START_TIME_MS, &start); - res->start_time = start / 1000.0; - - quvi_media_stream_reset(media); - while (quvi_media_stream_next(media)) { - char *entry = NULL, *id = NULL; - quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_URL, &entry); - quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_ID, &id); - if (entry) { - struct mp_resolve_src *src = talloc_ptrtype(res, src); - *src = (struct mp_resolve_src) { - .url = talloc_strdup(src, entry), - .encid = talloc_strdup(src, id), - }; - MP_TARRAY_APPEND(res, res->srcs, res->num_srcs, src); - talloc_steal(res->srcs, src); - } - } - - } - quvi_media_free(media); - } - - if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_SUBTITLE)) { - mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Getting subtitles...\n"); - quvi_subtitle_t qsub = quvi_subtitle_new(q, url); - if (mp_quvi_ok(q)) { - while (1) { - quvi_subtitle_type_t qst = quvi_subtitle_type_next(qsub); - if (!qst) - break; - while (1) { - quvi_subtitle_lang_t qsl = quvi_subtitle_lang_next(qst); - if (!qsl) - break; - char *lang; - quvi_subtitle_lang_get(qsl, QUVI_SUBTITLE_LANG_PROPERTY_ID, - &lang); - // Let quvi convert the subtitle to SRT. - quvi_subtitle_export_t qse = - quvi_subtitle_export_new(qsl, "srt"); - if (mp_quvi_ok(q)) { - const char *subdata = quvi_subtitle_export_data(qse); - struct mp_resolve_sub *sub = talloc_ptrtype(res, sub); - *sub = (struct mp_resolve_sub) { - .lang = talloc_strdup(sub, lang), - .data = talloc_strdup(sub, subdata), - }; - MP_TARRAY_APPEND(res, res->subs, res->num_subs, sub); - talloc_steal(res->subs, sub); - } - quvi_subtitle_export_free(qse); - } - } - } - quvi_subtitle_free(qsub); - } - - quvi_free(q); - - if (!res->url && (!res->playlist || !res->playlist->first)) { - talloc_free(res); - res = NULL; - } - - // libkdecore calls setlocale(LC_ALL, ""), which breaks basic C string - // processing functions. libkdecore can be loaded by libproxy, which is - // used by libquvi9. This is a rather dirty workaround to reset locales. - setlocale(LC_ALL, "C"); - - return res; -} diff --git a/old-makefile b/old-makefile index 29ce5e19f3..01a6a2e0b6 100644 --- a/old-makefile +++ b/old-makefile @@ -105,8 +105,8 @@ SOURCES-$(GL_WAYLAND) += video/out/wayland_common.c \ SOURCES-$(JACK) += audio/out/ao_jack.c SOURCES-$(JOYSTICK) += input/joystick.c -SOURCES-$(LIBQUVI) += mpvcore/resolve_quvi.c -SOURCES-$(LIBQUVI9) += mpvcore/resolve_quvi9.c +SOURCES-$(LIBQUVI) += stream/resolve/resolve_quvi.c +SOURCES-$(LIBQUVI9) += stream/resolve/resolve_quvi9.c SOURCES-$(LIRC) += input/lirc.c SOURCES-$(OPENAL) += audio/out/ao_openal.c SOURCES-$(OSS) += audio/out/ao_oss.c diff --git a/player/command.c b/player/command.c index d626e0c4a3..258251e948 100644 --- a/player/command.c +++ b/player/command.c @@ -37,7 +37,7 @@ #include "stream/stream.h" #include "demux/demux.h" #include "demux/stheader.h" -#include "mpvcore/resolve.h" +#include "stream/resolve/resolve.h" #include "mpvcore/playlist.h" #include "mpvcore/playlist_parser.h" #include "sub/osd.h" diff --git a/player/loadfile.c b/player/loadfile.c index 603d48b988..b1e41a08b8 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -38,7 +38,6 @@ #include "mpvcore/options.h" #include "mpvcore/m_property.h" #include "mpvcore/mp_common.h" -#include "mpvcore/resolve.h" #include "mpvcore/encode.h" #include "input/input.h" @@ -49,6 +48,7 @@ #include "audio/out/ao.h" #include "demux/demux.h" #include "stream/stream.h" +#include "stream/resolve/resolve.h" #include "sub/ass_mp.h" #include "sub/dec_sub.h" #include "sub/find_subfiles.h" diff --git a/player/main.c b/player/main.c index d2b7d9dd61..cfaf6f47d5 100644 --- a/player/main.c +++ b/player/main.c @@ -42,7 +42,6 @@ #include "mpvcore/mp_common.h" #include "mpvcore/mp_msg.h" #include "mpvcore/mpv_global.h" -#include "mpvcore/resolve.h" #include "mpvcore/parser-cfg.h" #include "mpvcore/parser-mpcmd.h" #include "mpvcore/playlist.h" diff --git a/player/misc.c b/player/misc.c index 68728295d4..928b56f88c 100644 --- a/player/misc.c +++ b/player/misc.c @@ -30,7 +30,6 @@ #include "mpvcore/options.h" #include "mpvcore/m_property.h" #include "mpvcore/mp_common.h" -#include "mpvcore/resolve.h" #include "mpvcore/encode.h" #include "mpvcore/playlist.h" #include "input/input.h" diff --git a/stream/resolve/resolve.h b/stream/resolve/resolve.h new file mode 100644 index 0000000000..7a60b29114 --- /dev/null +++ b/stream/resolve/resolve.h @@ -0,0 +1,53 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MP_RESOLVE_H +#define MP_RESOLVE_H + +struct MPContext; +struct MPOpts; + +struct mp_resolve_result { + char *url; + char *title; + + struct mp_resolve_src **srcs; + int num_srcs; + + double start_time; + + struct mp_resolve_sub **subs; + int num_subs; + + struct playlist *playlist; +}; + +struct mp_resolve_src { + char *url; // can be NULL; otherwise it's the exact video URL + char *encid; // indicates quality level, contents are libquvi specific +}; + +struct mp_resolve_sub { + char *url; + char *data; + char *lang; +}; + +struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts); + +#endif diff --git a/stream/resolve/resolve_quvi.c b/stream/resolve/resolve_quvi.c new file mode 100644 index 0000000000..00279c568f --- /dev/null +++ b/stream/resolve/resolve_quvi.c @@ -0,0 +1,111 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include "talloc.h" +#include "mpvcore/mp_msg.h" +#include "mpvcore/options.h" +#include "resolve.h" + +static void add_source(struct mp_resolve_result *res, const char *url, + const char *encid) +{ + struct mp_resolve_src *src = talloc_ptrtype(res, src); + *src = (struct mp_resolve_src) { + .url = talloc_strdup(src, url), + .encid = talloc_strdup(src, encid), + }; + MP_TARRAY_APPEND(res, res->srcs, res->num_srcs, src); +} + +struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts) +{ + QUVIcode rc; + bool mp_url = false; + + quvi_t q; + rc = quvi_init(&q); + if (rc != QUVI_OK) + return NULL; + + if (!strncmp(url, "mp_", 3)) { + url += 3; + mp_url = true; + } + + // Don't try to use quvi on an URL that's not directly supported, since + // quvi will do a network access anyway in order to check for HTTP + // redirections etc. + // The documentation says this will fail on "shortened" URLs. + if (quvi_supported(q, (char *)url) != QUVI_OK) { + quvi_close(&q); + return NULL; + } + + mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n"); + + const char *req_format = opts->quvi_format ? opts->quvi_format : "best"; + + // Can use quvi_query_formats() to get a list of formats like this: + // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p" + // (This example is youtube specific.) + // That call requires an extra net access. quvi_next_media_url() doesn't + // seem to do anything useful. So we can't really do anything useful + // except pass through the user's format setting. + quvi_setopt(q, QUVIOPT_FORMAT, req_format); + + quvi_media_t m; + rc = quvi_parse(q, (char *)url, &m); + if (rc != QUVI_OK) { + mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc)); + quvi_close(&q); + return NULL; + } + + struct mp_resolve_result *result + = talloc_zero(NULL, struct mp_resolve_result); + + char *val; + + if (quvi_getprop(m, QUVIPROP_MEDIAURL, &val) == QUVI_OK) { + if (mp_url) + result->url = talloc_asprintf(result, "mp_%s", val); + else + result->url = talloc_strdup(result, val); + } + + if (quvi_getprop(m, QUVIPROP_PAGETITLE, &val) == QUVI_OK) + result->title = talloc_strdup(result, val); + + quvi_parse_close(&m); + quvi_close(&q); + + if (!result->url) { + talloc_free(result); + result = NULL; + } + + // Useful for quvi-format cycling + add_source(result, NULL, "default"); + add_source(result, NULL, "best"); + if (strcmp(req_format, "best") != 0 && strcmp(req_format, "default") != 0) + add_source(result, NULL, req_format); + + return result; +} diff --git a/stream/resolve/resolve_quvi9.c b/stream/resolve/resolve_quvi9.c new file mode 100644 index 0000000000..ea96f521e3 --- /dev/null +++ b/stream/resolve/resolve_quvi9.c @@ -0,0 +1,157 @@ +/* + * This file is part of mpv. + * + * mpv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mpv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see . + */ + +#include +#include +#include + +#include + +#include "talloc.h" +#include "mpvcore/mp_msg.h" +#include "mpvcore/options.h" +#include "mpvcore/playlist.h" +#include "resolve.h" + +static bool mp_quvi_ok(quvi_t q) +{ + if (!quvi_ok(q)) { + mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); + return false; + } + return true; +} + +struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts) +{ + int mode = QUVI_SUPPORTS_MODE_OFFLINE; + + quvi_t q = quvi_new(); + if (!quvi_ok(q)) { + mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); + + quvi_free(q); + return NULL; + } + + struct mp_resolve_result *res = talloc_zero(NULL, struct mp_resolve_result); + + if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_PLAYLIST)) { + mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking playlist...\n"); + quvi_playlist_t qp = quvi_playlist_new(q, url); + if (mp_quvi_ok(q)) { + res->playlist = talloc_zero(res, struct playlist); + while (quvi_playlist_media_next(qp)) { + char *entry = NULL; + quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &entry); + if (entry) + playlist_add_file(res->playlist, entry); + } + } + quvi_playlist_free(qp); + } + + if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_MEDIA)) { + mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n"); + quvi_media_t media = quvi_media_new(q, url); + if (mp_quvi_ok(q)) { + char *format = opts->quvi_format ? opts->quvi_format : "best"; + bool use_default = strcmp(format, "default") == 0; + if (!use_default) + quvi_media_stream_select(media, format); + + char *val = NULL; + quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_URL, &val); + res->url = talloc_strdup(res, val); + + val = NULL; + quvi_media_get(media, QUVI_MEDIA_PROPERTY_TITLE, &val); + res->title = talloc_strdup(res, val); + + double start = 0; + quvi_media_get(media, QUVI_MEDIA_PROPERTY_START_TIME_MS, &start); + res->start_time = start / 1000.0; + + quvi_media_stream_reset(media); + while (quvi_media_stream_next(media)) { + char *entry = NULL, *id = NULL; + quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_URL, &entry); + quvi_media_get(media, QUVI_MEDIA_STREAM_PROPERTY_ID, &id); + if (entry) { + struct mp_resolve_src *src = talloc_ptrtype(res, src); + *src = (struct mp_resolve_src) { + .url = talloc_strdup(src, entry), + .encid = talloc_strdup(src, id), + }; + MP_TARRAY_APPEND(res, res->srcs, res->num_srcs, src); + talloc_steal(res->srcs, src); + } + } + + } + quvi_media_free(media); + } + + if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_SUBTITLE)) { + mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Getting subtitles...\n"); + quvi_subtitle_t qsub = quvi_subtitle_new(q, url); + if (mp_quvi_ok(q)) { + while (1) { + quvi_subtitle_type_t qst = quvi_subtitle_type_next(qsub); + if (!qst) + break; + while (1) { + quvi_subtitle_lang_t qsl = quvi_subtitle_lang_next(qst); + if (!qsl) + break; + char *lang; + quvi_subtitle_lang_get(qsl, QUVI_SUBTITLE_LANG_PROPERTY_ID, + &lang); + // Let quvi convert the subtitle to SRT. + quvi_subtitle_export_t qse = + quvi_subtitle_export_new(qsl, "srt"); + if (mp_quvi_ok(q)) { + const char *subdata = quvi_subtitle_export_data(qse); + struct mp_resolve_sub *sub = talloc_ptrtype(res, sub); + *sub = (struct mp_resolve_sub) { + .lang = talloc_strdup(sub, lang), + .data = talloc_strdup(sub, subdata), + }; + MP_TARRAY_APPEND(res, res->subs, res->num_subs, sub); + talloc_steal(res->subs, sub); + } + quvi_subtitle_export_free(qse); + } + } + } + quvi_subtitle_free(qsub); + } + + quvi_free(q); + + if (!res->url && (!res->playlist || !res->playlist->first)) { + talloc_free(res); + res = NULL; + } + + // libkdecore calls setlocale(LC_ALL, ""), which breaks basic C string + // processing functions. libkdecore can be loaded by libproxy, which is + // used by libquvi9. This is a rather dirty workaround to reset locales. + setlocale(LC_ALL, "C"); + + return res; +} diff --git a/wscript_build.py b/wscript_build.py index 8142ff87c5..66a96d834e 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -184,8 +184,6 @@ def build(ctx): ( "mpvcore/path.c" ), ( "mpvcore/playlist.c" ), ( "mpvcore/playlist_parser.c" ), - ( "mpvcore/resolve_quvi.c", "libquvi4" ), - ( "mpvcore/resolve_quvi9.c", "libquvi9" ), ( "mpvcore/version.c" ), ## Demuxers @@ -260,6 +258,8 @@ def build(ctx): ( "stream/tv.c", "tv" ), ( "stream/tvi_dummy.c", "tv" ), ( "stream/tvi_v4l2.c", "tv-v4l2"), + ( "stream/resolve/resolve_quvi.c", "libquvi4" ), + ( "stream/resolve/resolve_quvi9.c", "libquvi9" ), ## Subtitles ( "sub/ass_mp.c", "libass"), -- cgit v1.2.3