| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License version 2 as |
| 5 |
# published by the Free Software Foundation. |
| 6 |
|
| 7 |
"""Extractors for https://www.xasiat.com""" |
| 8 |
|
| 9 |
from .common import Extractor, Message |
| 10 |
from .. import text, dt |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?xasiat\.com((?:/(fr|ja))?" |
| 13 |
|
| 14 |
|
| 15 |
class XasiatExtractor(Extractor): |
| 16 |
category = "xasiat" |
| 17 |
root = "https://www.xasiat.com" |
| 18 |
|
| 19 |
def items(self): |
| 20 |
data = {"_extractor": (XasiatAlbumExtractor if self.groups[2] else |
| 21 |
XasiatVideoExtractor)} |
| 22 |
for url in self.posts(): |
| 23 |
yield Message.Queue, url, data |
| 24 |
|
| 25 |
def posts(self): |
| 26 |
return self._pagination(*self.groups) |
| 27 |
|
| 28 |
def _end_marker(self, lang): |
| 29 |
next = ("Next" if lang is None else |
| 30 |
"次へ" if lang == "ja" else "En avant") |
| 31 |
return f"><span>{next}</span><" |
| 32 |
|
| 33 |
def _pagination(self, path, lang, type, pnum=1): |
| 34 |
url = f"{self.root}{path}/" |
| 35 |
type = "video" if type is None else "album" |
| 36 |
params = { |
| 37 |
"mode" : "async", |
| 38 |
"function": "get_block", |
| 39 |
"block_id": f"list_{type}s_common_{type}s_list", |
| 40 |
"sort_by" : "post_date", |
| 41 |
"from" : pnum, |
| 42 |
} |
| 43 |
headers = { |
| 44 |
"X-Requested-With": "XMLHttpRequest", |
| 45 |
} |
| 46 |
|
| 47 |
marker = self._end_marker(lang) |
| 48 |
find_posts = text.re(r'(?s)class="item ">\s*<a href="([^"]+)').findall |
| 49 |
while True: |
| 50 |
params["_"] = int(dt.time.time() * 1000) |
| 51 |
|
| 52 |
page = self.request(url, params=params, headers=headers).text |
| 53 |
yield from find_posts(page) |
| 54 |
|
| 55 |
if marker in page: |
| 56 |
break |
| 57 |
params["from"] += 1 |
| 58 |
|
| 59 |
|
| 60 |
class XasiatAlbumExtractor(XasiatExtractor): |
| 61 |
subcategory = "album" |
| 62 |
directory_fmt = ("{category}", "{title}") |
| 63 |
archive_fmt = "{album_url}_{num}" |
| 64 |
pattern = BASE_PATTERN + r"/albums/(\d+)/[^/?#]+)" |
| 65 |
example = "https://www.xasiat.com/albums/12345/TITLE/" |
| 66 |
|
| 67 |
def items(self): |
| 68 |
path, lang, album_id = self.groups |
| 69 |
url = f"{self.root}{path}/" |
| 70 |
response = self.request(url) |
| 71 |
extr = text.extract_from(response.text) |
| 72 |
|
| 73 |
title = extr("<h1>", "<") |
| 74 |
info = extr('class="info-content"', "</div>") |
| 75 |
images = extr('class="images"', "</div>") |
| 76 |
|
| 77 |
urls = list(text.extract_iter(images, 'href="', '"')) |
| 78 |
categories = text.re(r'categories/[^"]+\">\s*(.+)\s*</a').findall(info) |
| 79 |
data = { |
| 80 |
"title": text.unescape(title), |
| 81 |
"model": text.re( |
| 82 |
r'top_models1"></i>\s*(.+)\s*</span').findall(info), |
| 83 |
"tags": text.re( |
| 84 |
r'tags/[^"]+\">\s*(.+)\s*</a').findall(info), |
| 85 |
"album_category": categories[0] if categories else "", |
| 86 |
"album_url": response.url, |
| 87 |
"album_id": text.parse_int(album_id), |
| 88 |
"count": len(urls), |
| 89 |
"lang": "en" if lang is None else lang, |
| 90 |
} |
| 91 |
|
| 92 |
yield Message.Directory, "", data |
| 93 |
for data["num"], url in enumerate(urls, 1): |
| 94 |
text.nameext_from_name(url.rsplit("/", 2)[1], data) |
| 95 |
yield Message.Url, url, data |
| 96 |
|
| 97 |
|
| 98 |
class XasiatVideoExtractor(XasiatExtractor): |
| 99 |
subcategory = "video" |
| 100 |
directory_fmt = ("{category}",) |
| 101 |
filename_fmt = "{video_id} {title}.{extension}" |
| 102 |
archive_fmt = "{video_url}" |
| 103 |
pattern = BASE_PATTERN + r"/videos/(\d+)/[^/?#]+)" |
| 104 |
example = "https://www.xasiat.com/videos/12345/TITLE/" |
| 105 |
|
| 106 |
def items(self): |
| 107 |
path, lang, video_id = self.groups |
| 108 |
url = f"{self.root}{path}/" |
| 109 |
response = self.request(url) |
| 110 |
extr = text.extract_from(response.text) |
| 111 |
|
| 112 |
data = { |
| 113 |
"title": text.unescape(extr( |
| 114 |
'property="og:title" content="', '"')), |
| 115 |
"thumbnail": text.unescape(extr( |
| 116 |
'property="og:image" content="', '"')), |
| 117 |
"date": self.parse_datetime_iso(extr( |
| 118 |
'property="video:release_date" content="', '"')), |
| 119 |
"duration": text.parse_int(extr( |
| 120 |
'property="video:duration" content="', '"')), |
| 121 |
"views": text.parse_int(extr( |
| 122 |
'"userInteractionCount": "', '"')), |
| 123 |
"likes": text.parse_int(extr( |
| 124 |
'"userInteractionCount": "', '"')), |
| 125 |
"width": text.parse_int(extr( |
| 126 |
'property="og:video:width" content="', '"')), |
| 127 |
"height": text.parse_int(extr( |
| 128 |
'property="og:video:height" content="', '"')), |
| 129 |
"tags": extr('property="video:tag" content="', '"').split(", "), |
| 130 |
"video_url": response.url, |
| 131 |
"video_id": text.parse_int(video_id), |
| 132 |
"count": 1, |
| 133 |
"type": "video", |
| 134 |
"lang": "en" if lang is None else lang, |
| 135 |
} |
| 136 |
|
| 137 |
info = extr('class="info-content"', "</div>") |
| 138 |
|
| 139 |
if self.config("format") in {"SD", "sd", "480p"}: |
| 140 |
url = extr("video_url: '", "'") |
| 141 |
data["format"] = "SD" |
| 142 |
else: |
| 143 |
url = extr("video_alt_url: '", "'") |
| 144 |
data["format"] = "Best Quality" |
| 145 |
|
| 146 |
data["model"] = text.re( |
| 147 |
r'top_models1"></i>\s*(.+)\s*</span').findall(info) |
| 148 |
categories = text.re( |
| 149 |
r'categories/[^"]+\">\s*(.+)\s*</a').findall(info) |
| 150 |
data["video_category"] = categories[0] if categories else "" |
| 151 |
|
| 152 |
yield Message.Directory, "", data |
| 153 |
text.nameext_from_name(url.rsplit("/", 2)[1], data) |
| 154 |
yield Message.Url, url, data |
| 155 |
|
| 156 |
|
| 157 |
class XasiatTagExtractor(XasiatExtractor): |
| 158 |
subcategory = "tag" |
| 159 |
pattern = BASE_PATTERN + r"/(albums/)?tags/[^/?#]+)" |
| 160 |
example = "https://www.xasiat.com/albums/tags/TAG/" |
| 161 |
|
| 162 |
|
| 163 |
class XasiatCategoryExtractor(XasiatExtractor): |
| 164 |
subcategory = "category" |
| 165 |
pattern = BASE_PATTERN + r"/(albums/)?categories/[^/?#]+)" |
| 166 |
example = "https://www.xasiat.com/albums/categories/CATEGORY/" |
| 167 |
|
| 168 |
|
| 169 |
class XasiatModelExtractor(XasiatExtractor): |
| 170 |
subcategory = "model" |
| 171 |
pattern = BASE_PATTERN + r"/(albums/)?models/[^/?#]+)" |
| 172 |
example = "https://www.xasiat.com/albums/models/MODEL/" |
| 173 |
|
| 174 |
|
| 175 |
class XasiatSearchExtractor(XasiatExtractor): |
| 176 |
subcategory = "search" |
| 177 |
pattern = BASE_PATTERN + r"/(search/))([^/?#]+)" |
| 178 |
example = "https://www.xasiat.com/search/QUERY/" |
| 179 |
|
| 180 |
def _pagination(self, path, lang, type, query, pnum=1): |
| 181 |
url = f"{self.root}{path}{query}/" |
| 182 |
params = { |
| 183 |
"mode" : "async", |
| 184 |
"function": "get_block", |
| 185 |
"block_id": "list_albums_albums_list_search_result", |
| 186 |
"q" : text.unquote(query), |
| 187 |
"category_ids": "", |
| 188 |
"sort_by" : "", |
| 189 |
} |
| 190 |
headers = { |
| 191 |
"X-Requested-With": "XMLHttpRequest", |
| 192 |
} |
| 193 |
|
| 194 |
marker = self._end_marker(lang) |
| 195 |
find_posts = text.re(r'class="item ">\s*<a href="([^"]+)').findall |
| 196 |
while True: |
| 197 |
params["from_videos"] = pnum |
| 198 |
params["from_albums"] = pnum |
| 199 |
params["_"] = int(dt.time.time() * 1000), |
| 200 |
|
| 201 |
page = self.request(url, params=params, headers=headers).text |
| 202 |
yield from find_posts(page) |
| 203 |
|
| 204 |
if marker in page: |
| 205 |
break |
| 206 |
pnum += 1 |