2013-06-27 16:21:07 +00:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
libquvi9: work around insane interaction between libquvi and libkdecore
The primary effect of this commit is that it fixes playback resume if
libquvi 0.9 and German locale are used, and libkdecore is on the system.
(See github issue #279.)
libquvi uses libproxy to determine system-wide proxy settings. libproxy
in turn loads libkdecore (if present) to determine KDE proxy settings.
libkdecore has a global constructor, which calls setlocale(LC_ALL, ""),
switching the current locale from "C" to what the user's settings. This
breaks some basic C string processing functions. Note that the locale
won't be set on program start, but only when libproxy calls dlopen() on
its config_kde module, which actually causes libkdecore to be loaded and
initialized.
In particular, with German locale, snprintf() would use "," instead of
"." when formatting float values, which in combination with playback
resume, would lead to parse errors the next time mpv was started, which
is how this issue was found.
I'd consider this a bug with libkdecore or at least libproxy. No library
should ever even touch locale: it might break basic expectations on C
string handling functions, might override program settings, and it's not
thread-safe. But this is so nasty and severe, that a quick hack to fix
it hurts less.
See github issue #279 and KDE bug #325902.
2013-10-12 14:51:41 +00:00
|
|
|
#include <locale.h>
|
2013-06-27 16:21:07 +00:00
|
|
|
|
|
|
|
#include <quvi.h>
|
|
|
|
|
|
|
|
#include "talloc.h"
|
2013-12-21 19:38:42 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/playlist.h"
|
2013-06-27 16:21:07 +00:00
|
|
|
#include "resolve.h"
|
|
|
|
|
2013-12-21 19:38:42 +00:00
|
|
|
static bool mp_quvi_ok(quvi_t q, struct mp_log *log)
|
2013-06-27 16:21:07 +00:00
|
|
|
{
|
|
|
|
if (!quvi_ok(q)) {
|
2013-12-21 19:38:42 +00:00
|
|
|
mp_err(log, "%s\n", quvi_errmsg(q));
|
2013-06-27 16:21:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:38:42 +00:00
|
|
|
struct mp_resolve_result *mp_resolve_quvi(const char *url,
|
|
|
|
struct mpv_global *global)
|
2013-06-27 16:21:07 +00:00
|
|
|
{
|
2013-12-21 19:38:42 +00:00
|
|
|
struct mp_log *log = mp_log_new(NULL, global->log, "quvi");
|
|
|
|
struct MPOpts *opts = global->opts;
|
2013-06-27 16:21:07 +00:00
|
|
|
int mode = QUVI_SUPPORTS_MODE_OFFLINE;
|
|
|
|
|
|
|
|
quvi_t q = quvi_new();
|
|
|
|
if (!quvi_ok(q)) {
|
2013-12-21 19:38:42 +00:00
|
|
|
mp_err(log, "%s\n", quvi_errmsg(q));
|
2013-06-27 16:21:07 +00:00
|
|
|
|
|
|
|
quvi_free(q);
|
2013-12-21 19:38:42 +00:00
|
|
|
talloc_free(log);
|
2013-06-27 16:21:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mp_resolve_result *res = talloc_zero(NULL, struct mp_resolve_result);
|
|
|
|
|
|
|
|
if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_PLAYLIST)) {
|
2013-12-21 19:38:42 +00:00
|
|
|
mp_info(log, "Checking playlist...\n");
|
2013-06-27 16:21:07 +00:00
|
|
|
quvi_playlist_t qp = quvi_playlist_new(q, url);
|
2013-12-21 19:38:42 +00:00
|
|
|
if (mp_quvi_ok(q, log)) {
|
2013-06-27 16:21:07 +00:00
|
|
|
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)) {
|
2013-12-21 19:38:42 +00:00
|
|
|
mp_info(log, "Checking URL...\n");
|
2013-06-27 16:21:07 +00:00
|
|
|
quvi_media_t media = quvi_media_new(q, url);
|
2013-12-21 19:38:42 +00:00
|
|
|
if (mp_quvi_ok(q, log)) {
|
2013-06-27 16:21:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-05 21:21:08 +00:00
|
|
|
if (opts->quvi_fetch_subtitles && quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_SUBTITLE)) {
|
2013-12-21 19:38:42 +00:00
|
|
|
mp_info(log, "Getting subtitles...\n");
|
2013-06-27 16:21:07 +00:00
|
|
|
quvi_subtitle_t qsub = quvi_subtitle_new(q, url);
|
2013-12-21 19:38:42 +00:00
|
|
|
if (mp_quvi_ok(q, log)) {
|
2013-06-27 16:21:07 +00:00
|
|
|
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");
|
2013-12-21 19:38:42 +00:00
|
|
|
if (mp_quvi_ok(q, log)) {
|
2013-06-27 16:21:07 +00:00
|
|
|
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);
|
2013-12-21 19:38:42 +00:00
|
|
|
talloc_free(log);
|
2013-06-27 16:21:07 +00:00
|
|
|
|
|
|
|
if (!res->url && (!res->playlist || !res->playlist->first)) {
|
|
|
|
talloc_free(res);
|
|
|
|
res = NULL;
|
|
|
|
}
|
libquvi9: work around insane interaction between libquvi and libkdecore
The primary effect of this commit is that it fixes playback resume if
libquvi 0.9 and German locale are used, and libkdecore is on the system.
(See github issue #279.)
libquvi uses libproxy to determine system-wide proxy settings. libproxy
in turn loads libkdecore (if present) to determine KDE proxy settings.
libkdecore has a global constructor, which calls setlocale(LC_ALL, ""),
switching the current locale from "C" to what the user's settings. This
breaks some basic C string processing functions. Note that the locale
won't be set on program start, but only when libproxy calls dlopen() on
its config_kde module, which actually causes libkdecore to be loaded and
initialized.
In particular, with German locale, snprintf() would use "," instead of
"." when formatting float values, which in combination with playback
resume, would lead to parse errors the next time mpv was started, which
is how this issue was found.
I'd consider this a bug with libkdecore or at least libproxy. No library
should ever even touch locale: it might break basic expectations on C
string handling functions, might override program settings, and it's not
thread-safe. But this is so nasty and severe, that a quick hack to fix
it hurts less.
See github issue #279 and KDE bug #325902.
2013-10-12 14:51:41 +00:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
2013-06-27 16:21:07 +00:00
|
|
|
return res;
|
|
|
|
}
|