2 * Copyright (C) 2010-2011 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <curl/curl.h>
41 Query::Query(const Query
& q
)
49 Query
& Query::operator=(const Query
& q
)
66 quvi_code
= quvi_init(&_quvi
);
68 if (quvi_code
!= QUVI_OK
)
70 const char *e
= quvi_strerror(_quvi
, static_cast<QUVIcode
>(quvi_code
));
71 throw std::runtime_error(e
);
74 quvi_getinfo(_quvi
, QUVIINFO_CURL
, &_curl
);
75 assert(_curl
!= NULL
);
84 assert(_quvi
== NULL
);
88 void Query::set_opts(const Options
& opts
)
90 if ( !opts
.format
.empty() )
91 quvi_setopt(_quvi
, QUVIOPT_FORMAT
, opts
.format
.c_str() );
93 quvi_setopt(_quvi
, QUVIOPT_NOVERIFY
, !opts
.verify
? 1L:0L);
94 quvi_setopt(_quvi
, QUVIOPT_NORESOLVE
, !opts
.resolve
? 1L:0L);
96 quvi_setopt(_quvi
, QUVIOPT_CATEGORY
, opts
.category
);
98 if ( !opts
.user_agent
.empty() )
99 curl_easy_setopt(_curl
, CURLOPT_USERAGENT
, opts
.user_agent
.c_str());
101 if ( !opts
.http_proxy
.empty() )
102 curl_easy_setopt(_curl
, CURLOPT_PROXY
, opts
.http_proxy
.c_str());
104 curl_easy_setopt(_curl
, CURLOPT_VERBOSE
, opts
.verbose_libcurl
? 1L:0L);
107 Media
Query::parse(const std::string
& url
)
110 quvi_code
= quvi_parse(_quvi
, const_cast<char*>(url
.c_str()), &m
);
112 quvi_getinfo(_quvi
, QUVIINFO_HTTPCODE
, &resp_code
);
116 if (quvi_code
!= QUVI_OK
)
127 void Query::next_website(std::string
& domain
,
128 std::string
& formats
)
130 char *d
=NULL
, *f
=NULL
;
131 quvi_code
= quvi_next_supported_website(_quvi
, &d
, &f
);
133 if (quvi_code
== QUVI_OK
)
145 void Query::_format_error()
147 const char *e
= quvi_strerror(_quvi
, static_cast<QUVIcode
>(quvi_code
));
148 errmsg
= std::string(e
);
152 int Query::supported(const std::string
& url
)
154 quvi_code
= quvi_supported(_quvi
, const_cast<char*>(url
.c_str()));
156 if (quvi_code
!= QUVI_OK
)
159 return static_cast<int>(quvi_code
);
162 std::string
Query::formats(const std::string
& url
)
167 quvi_query_formats(_quvi
, const_cast<char*>(url
.c_str()), &s
);
169 quvi_getinfo(_quvi
, QUVIINFO_HTTPCODE
, &resp_code
);
173 if (quvi_code
!= QUVI_OK
)
185 // vim: set ts=2 sw=2 tw=72 expandtab: