123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- $stream_context = [
- 'http' => [
- 'header' =>
- 'User-Agent: Mozilla/5.0' . PHP_EOL .
- 'Cookie: PHPSESSID=' . SESSION_ID,
- 'ignore_errors' => true
- ]
- ];
- if (HTTP_PROXY) {
- $stream_context['http']['proxy'] = 'tcp://' . HTTP_PROXY;
- }
- stream_context_set_default($stream_context);
- function get_lang_query() {
- if (function_exists('get_string')) {
- return 'lang=' . get_string('pixiv-lang');
- }
- return 'lang=en';
- }
- function get_json($url, $associative = false) {
- $response = file_get_contents($url);
- if (!isset($http_response_header)) {
- return [false, 'network-error'];
- }
- $response_code = substr($http_response_header[0], 9, 3);
- if ($response_code == '401') {
- return [false, 'unauthorized'];
- }
- return [json_decode($response, $associative), false];
- }
- function get_discovery() {
- return get_json(sprintf(
- 'https://www.pixiv.net/ajax/discovery/artworks?mode=%s&limit=%s&%s',
- get_closest_mode(), 100, get_lang_query()
- ));
- }
- function get_artwork_info($id) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/illust/%s?%s',
- $id, get_lang_query()
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'artwork.not-found'];
- return [$response, false];
- }
- function get_artwork_pages($id) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/illust/%s/pages',
- $id
- ), true);
- if ($error) return [false, $error];
- if (empty($response['body'])) return [false, 'artwork.not-found'];
- return [$response, false];
- }
- function get_artwork_comments($id, $offset, $limit) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/illusts/comments/roots?illust_id=%s&offset=%s&limit=%s',
- $id, $offset, $limit
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'artwork.not-found'];
- if (empty($response->body->comments)) return [false, 'artwork.no-comments'];
- return [$response, false];
- }
- function get_artwork_comment_replies($id, $page) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/illusts/comments/replies?comment_id=%s&page=%s',
- $id, $page
- ));
- if ($error) return [false, $error];
- if (empty($response->body->comments)) return [false, 'artwork.no-replies'];
- return [$response, false];
- }
- function get_artwork_related($id) {
- return get_json(sprintf(
- 'https://www.pixiv.net/ajax/illust/%s/recommend/init?limit=%s&%s',
- $id, 120, get_lang_query()
- ));
- }
- function get_search($query, $page) {
- return get_json(sprintf(
- 'https://www.pixiv.net/ajax/search/artworks/%s?mode=%s&p=%s&%s',
- urlencode($query), get_closest_mode(), $page, get_lang_query()
- ));
- }
- function get_tag_info($query) {
- return get_json(sprintf(
- 'https://www.pixiv.net/ajax/search/tags/%s',
- urlencode($query)
- ));
- }
- function get_user_info($id) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/user/%s?full=1',
- $id
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'user.not-found'];
- return [$response, false];
- }
- function get_user_bookmarks($id, $offset, $limit) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/user/%s/illusts/bookmarks?tag=&offset=%s&limit=%s&rest=show&%s',
- $id, $offset, $limit, get_lang_query()
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'user.not-found'];
- return [$response, false];
- }
- function get_user_artworks_with_tag($id, $category, $tag, $offset, $limit) {
- $request_path = [
- 'artworks' => 'illustmanga',
- 'illustrations' => 'illusts',
- 'manga' => 'manga'
- ][$category];
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/user/%s/%s/tag?tag=%s&offset=%s&limit=%s&%s',
- $id, $request_path, urlencode($tag), $offset, $limit, get_lang_query()
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'user.not-found'];
- return [$response, false];
- }
- function get_user_artworks_list($id) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/user/%s/profile/all',
- $id
- ), true);
- if ($error) return [false, $error];
- if (empty($response['body'])) return [false, 'user.not-found'];
- return [$response, false];
- }
- function get_user_artworks($user_id, $artwork_ids) {
- list($response, $error) = get_json(sprintf(
- 'https://www.pixiv.net/ajax/user/%s/profile/illusts?work_category=illustManga&is_first_page=0&%s&%s',
- $user_id, get_lang_query(), http_build_query(['ids' => $artwork_ids])
- ));
- if ($error) return [false, $error];
- if (empty($response->body)) return [false, 'user.not-found'];
- return [$response, false];
- }
- function get_frequent_tags($artwork_ids) {
- return get_json(sprintf(
- 'https://www.pixiv.net/ajax/tags/frequent/illust?%s&%s',
- get_lang_query(), http_build_query(['ids' => $artwork_ids])
- ));
- }
|