| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2017-2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://www.xvideos.com/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor, Extractor, Message |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = (r"(?:https?://)?(?:www\.)?xvideos\.com" |
| 15 |
r"/(?:profiles|(?:amateur-|model-)?channels)") |
| 16 |
|
| 17 |
|
| 18 |
class XvideosBase(): |
| 19 |
"""Base class for xvideos extractors""" |
| 20 |
category = "xvideos" |
| 21 |
root = "https://www.xvideos.com" |
| 22 |
|
| 23 |
|
| 24 |
class XvideosGalleryExtractor(XvideosBase, GalleryExtractor): |
| 25 |
"""Extractor for user profile galleries on xvideos.com""" |
| 26 |
subcategory = "gallery" |
| 27 |
directory_fmt = ("{category}", "{user[name]}", |
| 28 |
"{gallery[id]} {gallery[title]}") |
| 29 |
filename_fmt = "{category}_{gallery[id]}_{num:>03}.{extension}" |
| 30 |
archive_fmt = "{gallery[id]}_{num}" |
| 31 |
pattern = BASE_PATTERN + r"/([^/?#]+)/photos/(\d+)" |
| 32 |
example = "https://www.xvideos.com/profiles/USER/photos/12345" |
| 33 |
|
| 34 |
def __init__(self, match): |
| 35 |
self.user, self.gallery_id = match.groups() |
| 36 |
url = f"{self.root}/profiles/{self.user}/photos/{self.gallery_id}" |
| 37 |
GalleryExtractor.__init__(self, match, url) |
| 38 |
|
| 39 |
def metadata(self, page): |
| 40 |
extr = text.extract_from(page) |
| 41 |
user = { |
| 42 |
"id" : text.parse_int(extr('"id_user":', ',')), |
| 43 |
"display": extr('"display":"', '"'), |
| 44 |
"sex" : extr('"sex":"', '"'), |
| 45 |
"name" : self.user, |
| 46 |
} |
| 47 |
title = extr('"title":"', '"') |
| 48 |
user["description"] = extr( |
| 49 |
'<small class="mobile-hide">', '</small>').strip() |
| 50 |
tags = extr('<em>Tagged:</em>', '<').strip() |
| 51 |
|
| 52 |
return { |
| 53 |
"user": user, |
| 54 |
"gallery": { |
| 55 |
"id" : text.parse_int(self.gallery_id), |
| 56 |
"title": text.unescape(title), |
| 57 |
"tags" : text.unescape(tags).split(", ") if tags else [], |
| 58 |
}, |
| 59 |
} |
| 60 |
|
| 61 |
def images(self, page): |
| 62 |
results = [ |
| 63 |
(url, None) |
| 64 |
for url in text.extract_iter( |
| 65 |
page, '<a class="embed-responsive-item" href="', '"') |
| 66 |
] |
| 67 |
|
| 68 |
if not results: |
| 69 |
return |
| 70 |
|
| 71 |
while len(results) % 500 == 0: |
| 72 |
path = text.rextr(page, ' href="', '"', page.find(">Next</")) |
| 73 |
if not path: |
| 74 |
break |
| 75 |
page = self.request(self.root + path).text |
| 76 |
results.extend( |
| 77 |
(url, None) |
| 78 |
for url in text.extract_iter( |
| 79 |
page, '<a class="embed-responsive-item" href="', '"') |
| 80 |
) |
| 81 |
|
| 82 |
return results |
| 83 |
|
| 84 |
|
| 85 |
class XvideosUserExtractor(XvideosBase, Extractor): |
| 86 |
"""Extractor for user profiles on xvideos.com""" |
| 87 |
subcategory = "user" |
| 88 |
categorytransfer = True |
| 89 |
pattern = BASE_PATTERN + r"/([^/?#]+)/?(?:#.*)?$" |
| 90 |
example = "https://www.xvideos.com/profiles/USER" |
| 91 |
|
| 92 |
def __init__(self, match): |
| 93 |
Extractor.__init__(self, match) |
| 94 |
self.user = match[1] |
| 95 |
|
| 96 |
def items(self): |
| 97 |
url = f"{self.root}/profiles/{self.user}" |
| 98 |
page = self.request(url, notfound=self.subcategory).text |
| 99 |
data = util.json_loads(text.extr( |
| 100 |
page, "xv.conf=", ";</script>"))["data"] |
| 101 |
|
| 102 |
if not isinstance(data["galleries"], dict): |
| 103 |
return |
| 104 |
if "0" in data["galleries"]: |
| 105 |
del data["galleries"]["0"] |
| 106 |
|
| 107 |
galleries = [ |
| 108 |
{ |
| 109 |
"id" : text.parse_int(gid), |
| 110 |
"title": text.unescape(gdata["title"]), |
| 111 |
"count": gdata["nb_pics"], |
| 112 |
"_extractor": XvideosGalleryExtractor, |
| 113 |
} |
| 114 |
for gid, gdata in data["galleries"].items() |
| 115 |
] |
| 116 |
galleries.sort(key=lambda x: x["id"]) |
| 117 |
|
| 118 |
base = f"{self.root}/profiles/{self.user}/photos/" |
| 119 |
for gallery in galleries: |
| 120 |
url = base + str(gallery["id"]) |
| 121 |
yield Message.Queue, url, gallery |