2 * Copyright (C) 2012,2013 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/>.
41 static struct _opts_s opts
;
43 static const GOptionEntry entries
[] =
46 "stream", 's', 0, G_OPTION_ARG_STRING
, &opts
.stream
,
47 "Select stream ID, or a comma-separated list of IDs", "ID"
50 "best", 'b', 0, G_OPTION_ARG_NONE
, &opts
.best
,
51 "Choose the best available stream, negates --stream", NULL
54 "autoproxy", 'a', 0, G_OPTION_ARG_NONE
, &opts
.autoproxy
,
55 "Enable the autoproxy feature", NULL
58 "verbose", 'v', 0, G_OPTION_ARG_NONE
, &opts
.verbose
,
59 "Verbose libcurl output", NULL
62 "cookies", 'c', 0, G_OPTION_ARG_NONE
, &opts
.cookies
,
63 "Parse and use HTTP cookies", NULL
66 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_STRING_ARRAY
, &opts
.url
, "URL"
68 {NULL
, 0, 0, 0, NULL
, NULL
, NULL
}
71 static void dump_stream()
75 quvi_media_get(qm
, QUVI_MEDIA_STREAM_PROPERTY_URL
, &url
);
76 quvi_media_get(qm
, QUVI_MEDIA_STREAM_PROPERTY_ID
, &id
);
78 g_print(" id='%s', url='%s'\n", id
, url
);
81 static void dump_streams()
83 while (quvi_media_stream_next(qm
) == QUVI_TRUE
)
87 static gint
opts_new(gint argc
, gchar
**argv
)
93 c
= g_option_context_new("URL");
97 g_option_context_set_help_enabled(c
, TRUE
);
98 g_option_context_add_main_entries(c
, entries
, NULL
);
100 if (g_option_context_parse(c
, &argc
, &argv
, &e
) == FALSE
)
102 g_printerr("error: %s\n", e
->message
);
108 g_option_context_free(c
);
113 if (opts
.url
== NULL
)
115 g_printerr("error: no input URL\n");
116 return (EXIT_FAILURE
);
122 static void opts_free()
127 g_strfreev(opts
.url
);
131 typedef quvi_callback_status qcs
;
133 gint
main(gint argc
, gchar
**argv
)
138 g_assert(qm
== NULL
);
141 memset(&opts
, 0, sizeof(struct _opts_s
));
142 setlocale(LC_ALL
, "");
144 r
= opts_new(argc
, argv
);
145 if (r
!= EXIT_SUCCESS
)
149 examples_exit_if_error();
151 if (opts
.autoproxy
== TRUE
)
152 examples_enable_autoproxy();
154 if (opts
.cookies
== TRUE
)
155 examples_enable_cookies();
157 if (opts
.verbose
== TRUE
)
158 examples_enable_verbose();
160 quvi_set(q
, QUVI_OPTION_CALLBACK_STATUS
, (qcs
) examples_status
);
162 for (i
=0; opts
.url
[i
] != NULL
; ++i
)
164 qm
= quvi_media_new(q
, opts
.url
[i
]);
165 examples_exit_if_error();
167 quvi_media_get(qm
, QUVI_MEDIA_PROPERTY_TITLE
, &s
);
168 g_print("[%s]\n title='%s'\n", __func__
, s
);
170 if (opts
.best
== TRUE
)
172 quvi_media_stream_choose_best(qm
);
175 else if (opts
.stream
!= NULL
)
177 quvi_media_stream_select(qm
, opts
.stream
);
178 examples_exit_if_error();
191 g_assert(qm
== NULL
);
197 /* vim: set ts=2 sw=2 tw=72 expandtab: */