FIX: media/funnyordie.lua: Stream URL pattern
[libquvi-scripts.git] / tests / subtitle / subtitle_youtube.c
blob48ac97b1b527300eb4b26da2d38c21f8d1650a79
1 /* libquvi-scripts
2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <string.h>
24 #include <glib.h>
25 #include <quvi.h>
27 #include "tests.h"
29 static const gchar URL[] = "http://youtube.com/watch?v=0QRO3gKj3qw";
31 static void test_subtitle_youtube_core()
33 struct qsub_test_opts_s o;
35 memset(&o, 0, sizeof(o));
37 /* type */
39 o.type.gt0.format = TRUE;
40 o.type.gt0.type = TRUE;
42 /* lang */
44 o.lang.s_len_gt0.translated = TRUE; /* cc only */
45 o.lang.s_len_gt0.original = TRUE; /* cc only */
46 o.lang.s_len_gt0.code = TRUE;
47 o.lang.s_len_gt0.url = TRUE;
48 o.lang.s_len_gt0.id = TRUE;
50 qsub_test(__func__, URL, &o);
53 static void _test_subrip(quvi_t q, quvi_subtitle_t qsub, const gchar *lang)
55 quvi_subtitle_export_t qse;
56 quvi_subtitle_lang_t qsl;
57 gchar *s;
59 qsl = quvi_subtitle_select(qsub, lang);
60 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
61 g_assert(qsl != NULL);
63 quvi_subtitle_lang_get(qsl, QUVI_SUBTITLE_LANG_PROPERTY_ID, &s);
64 g_test_message("lang_id=%s", s);
66 qse = quvi_subtitle_export_new(qsl, "srt");
67 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
68 g_assert(qse != NULL);
70 g_test_message("subrip_data=%s", quvi_subtitle_export_data(qse));
71 g_assert_cmpint(strlen(quvi_subtitle_export_data(qse)), >, 4096);
73 quvi_subtitle_export_free(qse);
76 static void test_subtitle_youtube_export()
78 quvi_subtitle_t qsub;
79 quvi_t q;
81 if (chk_skip(__func__) == TRUE)
82 return;
84 q = quvi_new();
85 g_assert(q != NULL);
86 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
88 chk_verbose(q);
90 qsub = quvi_subtitle_new(q, URL);
91 g_test_message("errmsg=%s", quvi_errmsg(q));
92 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
93 g_assert(qsub != NULL);
95 _test_subrip(q, qsub, "tts_en,croak");
96 _test_subrip(q, qsub, "cc_en,croak");
98 quvi_subtitle_free(qsub);
99 quvi_free(q);
102 gint main(gint argc, gchar **argv)
104 g_test_init(&argc, &argv, NULL);
106 g_test_add_func("/subtitle/youtube (core)",
107 test_subtitle_youtube_core);
109 g_test_add_func("/subtitle/youtube (export, subrip)",
110 test_subtitle_youtube_export);
112 return (g_test_run());
115 /* vim: set ts=2 sw=2 tw=72 expandtab: */