1
mirror of https://github.com/mpv-player/mpv synced 2024-11-03 03:19:24 +01:00

quvi: mp_msg conversions

This commit is contained in:
wm4 2013-12-21 20:38:42 +01:00
parent 33c8fd789d
commit d9b5652cac
4 changed files with 33 additions and 20 deletions

View File

@ -851,12 +851,12 @@ static void init_sub_renderer(struct MPContext *mpctx)
}
static struct mp_resolve_result *resolve_url(const char *filename,
struct MPOpts *opts)
struct mpv_global *global)
{
if (!mp_is_url(bstr0(filename)))
return NULL;
#if HAVE_LIBQUVI
return mp_resolve_quvi(filename, opts);
return mp_resolve_quvi(filename, global);
#else
return NULL;
#endif
@ -1037,7 +1037,7 @@ static void play_current_file(struct MPContext *mpctx)
assert(mpctx->d_sub == NULL);
char *stream_filename = mpctx->filename;
mpctx->resolve_result = resolve_url(stream_filename, opts);
mpctx->resolve_result = resolve_url(stream_filename, mpctx->global);
if (mpctx->resolve_result) {
print_resolve_contents(mpctx->log, mpctx->resolve_result);
if (mpctx->resolve_result->playlist) {

View File

@ -19,8 +19,7 @@
#ifndef MP_RESOLVE_H
#define MP_RESOLVE_H
struct MPContext;
struct MPOpts;
struct mpv_global;
struct mp_resolve_result {
char *url;
@ -48,6 +47,7 @@ struct mp_resolve_sub {
char *lang;
};
struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts);
struct mp_resolve_result *mp_resolve_quvi(const char *url,
struct mpv_global *global);
#endif

View File

@ -19,6 +19,7 @@
#include <quvi/quvi.h>
#include "talloc.h"
#include "common/global.h"
#include "common/msg.h"
#include "options/options.h"
#include "resolve.h"
@ -34,7 +35,8 @@ static void add_source(struct mp_resolve_result *res, const char *url,
MP_TARRAY_APPEND(res, res->srcs, res->num_srcs, src);
}
struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
struct mp_resolve_result *mp_resolve_quvi(const char *url,
struct mpv_global *global)
{
QUVIcode rc;
bool mp_url = false;
@ -58,7 +60,10 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
return NULL;
}
mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
struct MPOpts *opts = global->opts;
struct mp_log *log = mp_log_new(NULL, global->log, "quvi");
mp_info(log, "Checking URL...\n");
const char *req_format = opts->quvi_format ? opts->quvi_format : "best";
@ -73,8 +78,9 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
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));
mp_err(log, "%s\n", quvi_strerror(q, rc));
quvi_close(&q);
talloc_free(log);
return NULL;
}
@ -107,5 +113,6 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
if (strcmp(req_format, "best") != 0 && strcmp(req_format, "default") != 0)
add_source(result, NULL, req_format);
talloc_free(log);
return result;
}

View File

@ -22,38 +22,43 @@
#include <quvi.h>
#include "talloc.h"
#include "common/global.h"
#include "common/msg.h"
#include "options/options.h"
#include "common/playlist.h"
#include "resolve.h"
static bool mp_quvi_ok(quvi_t q)
static bool mp_quvi_ok(quvi_t q, struct mp_log *log)
{
if (!quvi_ok(q)) {
mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q));
mp_err(log, "%s\n", quvi_errmsg(q));
return false;
}
return true;
}
struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
struct mp_resolve_result *mp_resolve_quvi(const char *url,
struct mpv_global *global)
{
struct mp_log *log = mp_log_new(NULL, global->log, "quvi");
struct MPOpts *opts = global->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));
mp_err(log, "%s\n", quvi_errmsg(q));
quvi_free(q);
talloc_free(log);
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");
mp_info(log, "Checking playlist...\n");
quvi_playlist_t qp = quvi_playlist_new(q, url);
if (mp_quvi_ok(q)) {
if (mp_quvi_ok(q, log)) {
res->playlist = talloc_zero(res, struct playlist);
while (quvi_playlist_media_next(qp)) {
char *entry = NULL;
@ -66,9 +71,9 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
}
if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_MEDIA)) {
mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
mp_info(log, "Checking URL...\n");
quvi_media_t media = quvi_media_new(q, url);
if (mp_quvi_ok(q)) {
if (mp_quvi_ok(q, log)) {
char *format = opts->quvi_format ? opts->quvi_format : "best";
bool use_default = strcmp(format, "default") == 0;
if (!use_default)
@ -107,9 +112,9 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
}
if (quvi_supports(q, url, mode, QUVI_SUPPORTS_TYPE_SUBTITLE)) {
mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Getting subtitles...\n");
mp_info(log, "Getting subtitles...\n");
quvi_subtitle_t qsub = quvi_subtitle_new(q, url);
if (mp_quvi_ok(q)) {
if (mp_quvi_ok(q, log)) {
while (1) {
quvi_subtitle_type_t qst = quvi_subtitle_type_next(qsub);
if (!qst)
@ -124,7 +129,7 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
// Let quvi convert the subtitle to SRT.
quvi_subtitle_export_t qse =
quvi_subtitle_export_new(qsl, "srt");
if (mp_quvi_ok(q)) {
if (mp_quvi_ok(q, log)) {
const char *subdata = quvi_subtitle_export_data(qse);
struct mp_resolve_sub *sub = talloc_ptrtype(res, sub);
*sub = (struct mp_resolve_sub) {
@ -142,6 +147,7 @@ struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
}
quvi_free(q);
talloc_free(log);
if (!res->url && (!res->playlist || !res->playlist->first)) {
talloc_free(res);