2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <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/>.
40 static struct _opts_s opts
;
42 static const GOptionEntry entries
[] =
45 "stream", 's', 0, G_OPTION_ARG_STRING
, &opts
.stream
,
46 "Select stream ID, or a comma-separated list of IDs", "ID"
49 "best", 'b', 0, G_OPTION_ARG_NONE
, &opts
.best
,
50 "Choose the best available stream, negates --stream", NULL
53 "autoproxy", 'a', 0, G_OPTION_ARG_NONE
, &opts
.autoproxy
,
54 "Enable the autoproxy feature", NULL
57 "verbose", 'v', 0, G_OPTION_ARG_NONE
, &opts
.verbose
,
58 "Verbose libcurl output", NULL
61 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_STRING_ARRAY
, &opts
.url
, "URL"
63 {NULL
, 0, 0, 0, NULL
, NULL
, NULL
}
66 static void dump_stream()
70 quvi_media_get(qm
, QUVI_MEDIA_STREAM_PROPERTY_URL
, &url
);
71 quvi_media_get(qm
, QUVI_MEDIA_STREAM_PROPERTY_ID
, &id
);
73 g_print(" id='%s', url='%s'\n", id
, url
);
76 static void dump_streams()
78 while (quvi_media_stream_next(qm
) == QUVI_TRUE
)
82 static gint
opts_new(gint argc
, gchar
**argv
)
88 c
= g_option_context_new("URL");
92 g_option_context_set_help_enabled(c
, TRUE
);
93 g_option_context_add_main_entries(c
, entries
, NULL
);
95 if (g_option_context_parse(c
, &argc
, &argv
, &e
) == FALSE
)
97 g_printerr("error: %s\n", e
->message
);
103 g_option_context_free(c
);
108 if (opts
.url
== NULL
)
110 g_printerr("error: no input URL\n");
111 return (EXIT_FAILURE
);
117 static void opts_free()
122 g_strfreev(opts
.url
);
126 typedef quvi_callback_status qcs
;
128 gint
main(gint argc
, gchar
**argv
)
133 g_assert(qm
== NULL
);
136 memset(&opts
, 0, sizeof(struct _opts_s
));
137 setlocale(LC_ALL
, "");
139 r
= opts_new(argc
, argv
);
140 if (r
!= EXIT_SUCCESS
)
144 examples_exit_if_error();
146 if (opts
.autoproxy
== TRUE
)
147 examples_enable_autoproxy();
149 if (opts
.verbose
== TRUE
)
150 examples_enable_verbose();
152 quvi_set(q
, QUVI_OPTION_CALLBACK_STATUS
, (qcs
) examples_status
);
154 for (i
=0; opts
.url
[i
] != NULL
; ++i
)
156 qm
= quvi_media_new(q
, opts
.url
[i
]);
157 examples_exit_if_error();
159 quvi_media_get(qm
, QUVI_MEDIA_PROPERTY_TITLE
, &s
);
160 g_print("[%s]\n title='%s'\n", __func__
, s
);
162 if (opts
.best
== TRUE
)
164 quvi_media_stream_choose_best(qm
);
167 else if (opts
.stream
!= NULL
)
169 quvi_media_stream_select(qm
, opts
.stream
);
170 examples_exit_if_error();
183 g_assert(qm
== NULL
);
189 /* vim: set ts=2 sw=2 tw=72 expandtab: */