[xvideos] improve
- derive from GalleryExtractor - match '…-channels' URLs - "better" metadata structure
This commit is contained in:
@@ -6,86 +6,91 @@
|
|||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
"""Extract images from https://www.xvideos.com/"""
|
"""Extractors for https://www.xvideos.com/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import GalleryExtractor, Extractor, Message
|
||||||
from .. import text, exception
|
from .. import text
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
class XvideosExtractor(Extractor):
|
class XvideosBase():
|
||||||
"""Base class for xvideos extractors"""
|
"""Base class for xvideos extractors"""
|
||||||
category = "xvideos"
|
category = "xvideos"
|
||||||
root = "https://www.xvideos.com"
|
root = "https://www.xvideos.com"
|
||||||
|
|
||||||
|
|
||||||
class XvideosGalleryExtractor(XvideosExtractor):
|
class XvideosGalleryExtractor(XvideosBase, GalleryExtractor):
|
||||||
"""Extractor for user profile galleries from xvideos.com"""
|
"""Extractor for user profile galleries on xvideos.com"""
|
||||||
subcategory = "gallery"
|
subcategory = "gallery"
|
||||||
directory_fmt = ("{category}", "{user[name]}", "{title}")
|
directory_fmt = ("{category}", "{user[name]}",
|
||||||
filename_fmt = "{category}_{gallery_id}_{num:>03}.{extension}"
|
"{gallery[id]} {gallery[title]}")
|
||||||
archive_fmt = "{gallery_id}_{num}"
|
filename_fmt = "{category}_{gallery[id]}_{num:>03}.{extension}"
|
||||||
|
archive_fmt = "{gallery[id]}_{num}"
|
||||||
pattern = (r"(?:https?://)?(?:www\.)?xvideos\.com"
|
pattern = (r"(?:https?://)?(?:www\.)?xvideos\.com"
|
||||||
r"/profiles/([^/?&#]+)/photos/(\d+)")
|
r"/(?:profiles|amateur-channels|model-channels)"
|
||||||
|
r"/([^/?&#]+)/photos/(\d+)")
|
||||||
test = (
|
test = (
|
||||||
(("https://www.xvideos.com/profiles"
|
("https://www.xvideos.com/profiles/pervertedcouple/photos/751031", {
|
||||||
"/pervertedcouple/photos/751031/random_stuff"), {
|
|
||||||
"url": "4f0d992e5dc39def2c3ac8e099d17bf09e76e3c7",
|
"url": "4f0d992e5dc39def2c3ac8e099d17bf09e76e3c7",
|
||||||
"keyword": "65979d63a69576cf692b41d5fbbd995cc40a51b9",
|
"keyword": {
|
||||||
}),
|
"gallery": {
|
||||||
("https://www.xvideos.com/profiles/pervertedcouple/photos/751032/", {
|
"id" : 751031,
|
||||||
"exception": exception.NotFoundError,
|
"title": "Random Stuff",
|
||||||
|
"tags" : list,
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"id" : 20245371,
|
||||||
|
"name" : "pervertedcouple",
|
||||||
|
"display" : "Pervertedcouple",
|
||||||
|
"sex" : "Woman",
|
||||||
|
"description": str,
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
|
("https://www.xvideos.com/amateur-channels/pervertedcouple/photos/12"),
|
||||||
|
("https://www.xvideos.com/model-channels/pervertedcouple/photos/12"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
XvideosExtractor.__init__(self, match)
|
self.user, self.gallery_id = match.groups()
|
||||||
self.user, self.gid = match.groups()
|
url = "{}/profiles/{}/photos/{}".format(
|
||||||
|
self.root, self.user, self.gallery_id)
|
||||||
|
GalleryExtractor.__init__(self, match, url)
|
||||||
|
|
||||||
def items(self):
|
def metadata(self, page):
|
||||||
url = "{}/profiles/{}/photos/{}".format(self.root, self.user, self.gid)
|
extr = text.extract_from(page)
|
||||||
page = self.request(url, notfound=self.subcategory).text
|
user = {
|
||||||
data = self.get_metadata(page)
|
"id" : text.parse_int(extr('"id_user":', ',')),
|
||||||
imgs = self.get_images(page)
|
"display": extr('"display":"', '"'),
|
||||||
data["count"] = len(imgs)
|
"sex" : extr('"sex":"', '"'),
|
||||||
yield Message.Version, 1
|
"name" : self.user,
|
||||||
yield Message.Directory, data
|
}
|
||||||
for url in imgs:
|
title = extr('"title":"', '"')
|
||||||
data["num"] = text.parse_int(url.rsplit("_", 2)[1])
|
user["description"] = extr(
|
||||||
data["extension"] = url.rpartition(".")[2]
|
'<small class="mobile-hide">', '</small>').strip()
|
||||||
yield Message.Url, url, data
|
tags = extr('<em>Tagged:</em>', '<').strip()
|
||||||
|
|
||||||
def get_metadata(self, page):
|
|
||||||
"""Collect metadata for extractor-job"""
|
|
||||||
data = text.extract_all(page, (
|
|
||||||
("userid" , '"id_user":', ','),
|
|
||||||
("display", '"display":"', '"'),
|
|
||||||
("title" , '"title":"', '"'),
|
|
||||||
("descr" , '<small class="mobile-hide">', '</small>'),
|
|
||||||
("tags" , '<em>Tagged:</em>', '<'),
|
|
||||||
))[0]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"user": {
|
"user": user,
|
||||||
"id": text.parse_int(data["userid"]),
|
"gallery": {
|
||||||
"name": self.user,
|
"id" : text.parse_int(self.gallery_id),
|
||||||
"display": data["display"],
|
"title": text.unescape(title),
|
||||||
"description": data["descr"].strip(),
|
"tags" : text.unescape(tags).split(", ") if tags else [],
|
||||||
},
|
},
|
||||||
"tags": text.unescape(data["tags"] or "").strip().split(", "),
|
|
||||||
"title": text.unescape(data["title"]),
|
|
||||||
"gallery_id": text.parse_int(self.gid),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_images(page):
|
def images(page):
|
||||||
"""Return a list of all image urls for this gallery"""
|
"""Return a list of all image urls for this gallery"""
|
||||||
return list(text.extract_iter(
|
return [
|
||||||
page, '<a class="embed-responsive-item" href="', '"'))
|
(url, None)
|
||||||
|
for url in text.extract_iter(
|
||||||
|
page, '<a class="embed-responsive-item" href="', '"')
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class XvideosUserExtractor(XvideosExtractor):
|
class XvideosUserExtractor(XvideosBase, Extractor):
|
||||||
"""Extractor for user profiles from xvideos.com"""
|
"""Extractor for user profiles on xvideos.com"""
|
||||||
subcategory = "user"
|
subcategory = "user"
|
||||||
categorytransfer = True
|
categorytransfer = True
|
||||||
pattern = (r"(?:https?://)?(?:www\.)?xvideos\.com"
|
pattern = (r"(?:https?://)?(?:www\.)?xvideos\.com"
|
||||||
@@ -93,16 +98,13 @@ class XvideosUserExtractor(XvideosExtractor):
|
|||||||
test = (
|
test = (
|
||||||
("https://www.xvideos.com/profiles/pervertedcouple", {
|
("https://www.xvideos.com/profiles/pervertedcouple", {
|
||||||
"url": "a413f3e60d6d3a2de79bd44fa3b7a9c03db4336e",
|
"url": "a413f3e60d6d3a2de79bd44fa3b7a9c03db4336e",
|
||||||
"keyword": "a796760d34732adc7ec52a8feb057515209a2ca6",
|
"keyword": "335a3304941ff2e666c0201e9122819b61b34adb",
|
||||||
}),
|
|
||||||
("https://www.xvideos.com/profiles/niwehrwhernvh", {
|
|
||||||
"exception": exception.NotFoundError,
|
|
||||||
}),
|
}),
|
||||||
("https://www.xvideos.com/profiles/pervertedcouple#_tabPhotos"),
|
("https://www.xvideos.com/profiles/pervertedcouple#_tabPhotos"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
XvideosExtractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
self.user = match.group(1)
|
self.user = match.group(1)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
@@ -118,17 +120,17 @@ class XvideosUserExtractor(XvideosExtractor):
|
|||||||
|
|
||||||
galleries = [
|
galleries = [
|
||||||
{
|
{
|
||||||
"gallery_id": text.parse_int(gid),
|
"id" : text.parse_int(gid),
|
||||||
"title": text.unescape(gdata["title"]),
|
"title": text.unescape(gdata["title"]),
|
||||||
"count": gdata["nb_pics"],
|
"count": gdata["nb_pics"],
|
||||||
"_extractor": XvideosGalleryExtractor,
|
"_extractor": XvideosGalleryExtractor,
|
||||||
}
|
}
|
||||||
for gid, gdata in data["galleries"].items()
|
for gid, gdata in data["galleries"].items()
|
||||||
]
|
]
|
||||||
galleries.sort(key=lambda x: x["gallery_id"])
|
galleries.sort(key=lambda x: x["id"])
|
||||||
|
|
||||||
yield Message.Version, 1
|
yield Message.Version, 1
|
||||||
for gallery in galleries:
|
for gallery in galleries:
|
||||||
url = "https://www.xvideos.com/profiles/{}/photos/{}".format(
|
url = "https://www.xvideos.com/profiles/{}/photos/{}".format(
|
||||||
self.user, gallery["gallery_id"])
|
self.user, gallery["id"])
|
||||||
yield Message.Queue, url, gallery
|
yield Message.Queue, url, gallery
|
||||||
|
|||||||
Reference in New Issue
Block a user