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>
37 Query::Query(const Query
& q
)
46 Query
& Query::operator=(const Query
& q
)
63 quvi_code
= quvi_init(&_quvi
);
65 if (quvi_code
!= QUVI_OK
)
67 const char *e
= quvi_strerror(_quvi
, static_cast<QUVIcode
>(quvi_code
));
68 throw std::runtime_error(e
);
71 quvi_getinfo(_quvi
, QUVIINFO_CURL
, &_curl
);
72 assert(_curl
!= NULL
);
79 assert(_quvi
== NULL
);
83 Media
Query::parse(const std::string
& url
, const Options
& opts
)
85 if ( !opts
.format
.empty() )
86 quvi_setopt(_quvi
, QUVIOPT_FORMAT
, opts
.format
.c_str() );
88 quvi_setopt(_quvi
, QUVIOPT_NOVERIFY
, !opts
.verify
? 1L:0L);
89 quvi_setopt(_quvi
, QUVIOPT_NORESOLVE
, !opts
.resolve
? 1L:0L);
91 quvi_setopt(_quvi
, QUVIOPT_CATEGORY
, opts
.category
);
93 if ( !opts
.user_agent
.empty() )
94 curl_easy_setopt(_curl
, CURLOPT_USERAGENT
, opts
.user_agent
.c_str());
96 if ( !opts
.http_proxy
.empty() )
97 curl_easy_setopt(_curl
, CURLOPT_PROXY
, opts
.http_proxy
.c_str() );
99 curl_easy_setopt(_curl
, CURLOPT_VERBOSE
, opts
.verbose_libcurl
? 1L:0L);
102 quvi_code
= quvi_parse(_quvi
, const_cast<char*>(url
.c_str()), &m
);
104 quvi_getinfo(_quvi
, QUVIINFO_HTTPCODE
, &resp_code
);
106 if (quvi_code
!= QUVI_OK
)
108 const char *e
= quvi_strerror(_quvi
, static_cast<QUVIcode
>(quvi_code
));
109 last_error
= std::string(e
);
116 int Query::next_website(std::string
& domain
, std::string
& formats
)
118 char *d
=NULL
, *f
=NULL
;
119 const QUVIcode rc
= quvi_next_supported_website(_quvi
, &d
, &f
);
127 return static_cast<int>(rc
);
130 int Query::supported(const std::string
& url
)
132 quvi_code
= quvi_supported(_quvi
, const_cast<char*>(url
.c_str()));
134 if (quvi_code
!= QUVI_OK
)
137 quvi_strerror(_quvi
, static_cast<QUVIcode
>(quvi_code
));
139 last_error
= std::string(e
);
142 return static_cast<int>(quvi_code
);
145 // vim: set ts=2 sw=2 tw=72 expandtab: