porntrex_api 1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- porntrex_api-1.1/LICENSE +56 -0
- porntrex_api-1.1/PKG-INFO +101 -0
- porntrex_api-1.1/README.md +81 -0
- porntrex_api-1.1/porntrex_api/__init__.py +4 -0
- porntrex_api-1.1/porntrex_api/modules/consts.py +28 -0
- porntrex_api-1.1/porntrex_api/porntrex_api.py +299 -0
- porntrex_api-1.1/porntrex_api/tests/__init__.py +0 -0
- porntrex_api-1.1/porntrex_api/tests/test_channel.py +23 -0
- porntrex_api-1.1/porntrex_api/tests/test_model.py +22 -0
- porntrex_api-1.1/porntrex_api/tests/test_search.py +16 -0
- porntrex_api-1.1/porntrex_api/tests/test_video.py +24 -0
- porntrex_api-1.1/pyproject.toml +36 -0
porntrex_api-1.1/LICENSE
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
|
|
9
|
+
|
|
10
|
+
0. Additional Definitions.
|
|
11
|
+
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
|
|
12
|
+
|
|
13
|
+
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
|
|
14
|
+
|
|
15
|
+
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
|
|
16
|
+
|
|
17
|
+
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
|
|
18
|
+
|
|
19
|
+
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
|
|
20
|
+
|
|
21
|
+
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
|
|
22
|
+
|
|
23
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
24
|
+
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
|
|
25
|
+
|
|
26
|
+
2. Conveying Modified Versions.
|
|
27
|
+
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
|
|
28
|
+
|
|
29
|
+
a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
|
|
30
|
+
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
|
|
31
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
32
|
+
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
|
|
33
|
+
|
|
34
|
+
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
|
|
35
|
+
b) Accompany the object code with a copy of the GNU GPL and this license document.
|
|
36
|
+
4. Combined Works.
|
|
37
|
+
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
|
|
38
|
+
|
|
39
|
+
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
|
|
40
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
|
|
41
|
+
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
|
|
42
|
+
d) Do one of the following:
|
|
43
|
+
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
|
|
44
|
+
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
|
|
45
|
+
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
|
|
46
|
+
5. Combined Libraries.
|
|
47
|
+
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
|
|
48
|
+
|
|
49
|
+
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
|
|
50
|
+
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
|
|
51
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
52
|
+
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
|
53
|
+
|
|
54
|
+
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
|
|
55
|
+
|
|
56
|
+
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: porntrex_api
|
|
3
|
+
Version: 1.1
|
|
4
|
+
Summary: A Python API for the Porn Site xvideos.com
|
|
5
|
+
Author: Johannes Habel
|
|
6
|
+
Author-email: Johannes Habel <EchterAlsFake@proton.me>
|
|
7
|
+
License-Expression: LGPL-3.0-only
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Requires-Dist: bs4
|
|
11
|
+
Requires-Dist: eaf-base-api
|
|
12
|
+
Requires-Dist: json5
|
|
13
|
+
Requires-Dist: lxml ; extra == 'full'
|
|
14
|
+
Requires-Dist: httpx[http2] ; extra == 'full'
|
|
15
|
+
Requires-Dist: httpx[socks] ; extra == 'full'
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Project-URL: Homepage, https://github.com/EchterAlsFake/porntrex_api
|
|
18
|
+
Provides-Extra: full
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
<h1 align="center">Porntrex API</h1>
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
<a href="https://pepy.tech/project/porntrex_api"><img src="https://static.pepy.tech/badge/porntrex_api" alt="Downloads"></a>
|
|
25
|
+
<a href="https://github.com/EchterAlsFake/porntrex_api/workflows/"><img src="https://github.com/EchterAlsFake/porntrex_api/workflows/CodeQL/badge.svg" alt="CodeQL Analysis"/></a>
|
|
26
|
+
<a href="https://echteralsfake.me/ci/porntrex_api/badge.svg"><img src="https://echteralsfake.me/ci/porntrex_api/badge.svg" alt="Sync API Tests"/></a>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
# Disclaimer
|
|
30
|
+
> [!IMPORTANT]
|
|
31
|
+
> This is an unofficial and unaffiliated project. Please read the full disclaimer before use:
|
|
32
|
+
> **[DISCLAIMER.md](https://github.com/EchterAlsFake/API_Docs/blob/master/Disclaimer.md)**
|
|
33
|
+
>
|
|
34
|
+
> By using this project you agree to comply with the target site’s rules, copyright/licensing requirements,
|
|
35
|
+
> and applicable laws. Do not use it to bypass access controls or scrape at disruptive rates.
|
|
36
|
+
|
|
37
|
+
# Features
|
|
38
|
+
- Fetch videos + metadata
|
|
39
|
+
- Download videos
|
|
40
|
+
- Fetch Channels
|
|
41
|
+
- Fetch Pornstars
|
|
42
|
+
- Search for videos
|
|
43
|
+
- Built-in caching
|
|
44
|
+
- Easy interface
|
|
45
|
+
- Great type hinting
|
|
46
|
+
- Proxy support
|
|
47
|
+
- Very customizable
|
|
48
|
+
|
|
49
|
+
# Supported Platforms
|
|
50
|
+
This API has been tested and confirmed working on:
|
|
51
|
+
|
|
52
|
+
- Windows 11 (x64)
|
|
53
|
+
- macOS Sequoia (x86_64)
|
|
54
|
+
- Linux (Arch) (x86_64)
|
|
55
|
+
- Android 16 (aarch64)
|
|
56
|
+
|
|
57
|
+
# Quickstart
|
|
58
|
+
|
|
59
|
+
### Have a look at the [Documentation](https://github.com/EchterAlsFake/API_Docs/blob/master/Porn_APIs/Porntrex.md) for more details
|
|
60
|
+
- Install the library with `pip install porntrex_api`
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from porntrex_api import Client
|
|
65
|
+
# Initialize a Client object
|
|
66
|
+
client = Client()
|
|
67
|
+
|
|
68
|
+
# Fetch a video
|
|
69
|
+
video_object = client.get_video("<insert_url_here>")
|
|
70
|
+
|
|
71
|
+
# Information from Video objects
|
|
72
|
+
print(video_object.title)
|
|
73
|
+
print(video_object.duration)
|
|
74
|
+
# Download the video
|
|
75
|
+
|
|
76
|
+
video_object.download(quality="best", path="your_output_path + filename")
|
|
77
|
+
|
|
78
|
+
# SEE DOCUMENTATION FOR MORE
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
# Support (Donations)
|
|
82
|
+
I am developing all my projects entirely for free. I do that because I have fun and I don't want
|
|
83
|
+
to charge 30€ like other people do.
|
|
84
|
+
|
|
85
|
+
However, if you find my work useful, please consider donating something. A tiny amount such as 1€
|
|
86
|
+
means a lot to me.
|
|
87
|
+
|
|
88
|
+
- Paypal: https://paypal.me/EchterAlsFake
|
|
89
|
+
- Ko-Fi: https://ko-fi.com/EchterAlsFake
|
|
90
|
+
- XMR (Monero): `42XwGZYbSxpMvhn9eeP4DwMwZV91tQgAm3UQr6Zwb2wzBf5HcuZCHrsVxa4aV2jhP4gLHsWWELxSoNjfnkt4rMfDDwXy9jR`
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Contribution
|
|
94
|
+
Do you see any issues or having some feature requests? Simply open an Issue or talk
|
|
95
|
+
in the discussions.
|
|
96
|
+
|
|
97
|
+
Pull requests are also welcome.
|
|
98
|
+
|
|
99
|
+
# License
|
|
100
|
+
Licensed under the LGPLv3 License
|
|
101
|
+
<br>Copyright (C) 2025-2026 Johannes Habel
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<h1 align="center">Porntrex API</h1>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://pepy.tech/project/porntrex_api"><img src="https://static.pepy.tech/badge/porntrex_api" alt="Downloads"></a>
|
|
5
|
+
<a href="https://github.com/EchterAlsFake/porntrex_api/workflows/"><img src="https://github.com/EchterAlsFake/porntrex_api/workflows/CodeQL/badge.svg" alt="CodeQL Analysis"/></a>
|
|
6
|
+
<a href="https://echteralsfake.me/ci/porntrex_api/badge.svg"><img src="https://echteralsfake.me/ci/porntrex_api/badge.svg" alt="Sync API Tests"/></a>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
# Disclaimer
|
|
10
|
+
> [!IMPORTANT]
|
|
11
|
+
> This is an unofficial and unaffiliated project. Please read the full disclaimer before use:
|
|
12
|
+
> **[DISCLAIMER.md](https://github.com/EchterAlsFake/API_Docs/blob/master/Disclaimer.md)**
|
|
13
|
+
>
|
|
14
|
+
> By using this project you agree to comply with the target site’s rules, copyright/licensing requirements,
|
|
15
|
+
> and applicable laws. Do not use it to bypass access controls or scrape at disruptive rates.
|
|
16
|
+
|
|
17
|
+
# Features
|
|
18
|
+
- Fetch videos + metadata
|
|
19
|
+
- Download videos
|
|
20
|
+
- Fetch Channels
|
|
21
|
+
- Fetch Pornstars
|
|
22
|
+
- Search for videos
|
|
23
|
+
- Built-in caching
|
|
24
|
+
- Easy interface
|
|
25
|
+
- Great type hinting
|
|
26
|
+
- Proxy support
|
|
27
|
+
- Very customizable
|
|
28
|
+
|
|
29
|
+
# Supported Platforms
|
|
30
|
+
This API has been tested and confirmed working on:
|
|
31
|
+
|
|
32
|
+
- Windows 11 (x64)
|
|
33
|
+
- macOS Sequoia (x86_64)
|
|
34
|
+
- Linux (Arch) (x86_64)
|
|
35
|
+
- Android 16 (aarch64)
|
|
36
|
+
|
|
37
|
+
# Quickstart
|
|
38
|
+
|
|
39
|
+
### Have a look at the [Documentation](https://github.com/EchterAlsFake/API_Docs/blob/master/Porn_APIs/Porntrex.md) for more details
|
|
40
|
+
- Install the library with `pip install porntrex_api`
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from porntrex_api import Client
|
|
45
|
+
# Initialize a Client object
|
|
46
|
+
client = Client()
|
|
47
|
+
|
|
48
|
+
# Fetch a video
|
|
49
|
+
video_object = client.get_video("<insert_url_here>")
|
|
50
|
+
|
|
51
|
+
# Information from Video objects
|
|
52
|
+
print(video_object.title)
|
|
53
|
+
print(video_object.duration)
|
|
54
|
+
# Download the video
|
|
55
|
+
|
|
56
|
+
video_object.download(quality="best", path="your_output_path + filename")
|
|
57
|
+
|
|
58
|
+
# SEE DOCUMENTATION FOR MORE
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
# Support (Donations)
|
|
62
|
+
I am developing all my projects entirely for free. I do that because I have fun and I don't want
|
|
63
|
+
to charge 30€ like other people do.
|
|
64
|
+
|
|
65
|
+
However, if you find my work useful, please consider donating something. A tiny amount such as 1€
|
|
66
|
+
means a lot to me.
|
|
67
|
+
|
|
68
|
+
- Paypal: https://paypal.me/EchterAlsFake
|
|
69
|
+
- Ko-Fi: https://ko-fi.com/EchterAlsFake
|
|
70
|
+
- XMR (Monero): `42XwGZYbSxpMvhn9eeP4DwMwZV91tQgAm3UQr6Zwb2wzBf5HcuZCHrsVxa4aV2jhP4gLHsWWELxSoNjfnkt4rMfDDwXy9jR`
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Contribution
|
|
74
|
+
Do you see any issues or having some feature requests? Simply open an Issue or talk
|
|
75
|
+
in the discussions.
|
|
76
|
+
|
|
77
|
+
Pull requests are also welcome.
|
|
78
|
+
|
|
79
|
+
# License
|
|
80
|
+
Licensed under the LGPLv3 License
|
|
81
|
+
<br>Copyright (C) 2025-2026 Johannes Habel
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
from bs4 import BeautifulSoup
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
import lxml
|
|
8
|
+
parser = "lxml"
|
|
9
|
+
|
|
10
|
+
except (ModuleNotFoundError, ImportError):
|
|
11
|
+
parser = "html.parser"
|
|
12
|
+
|
|
13
|
+
PATTERN_URL_KEY = re.compile(r"^video_(?:alt_)?url(?:\d+)?$", re.I) # video_url, video_alt_url, video_alt_url2, ...
|
|
14
|
+
PATTERN_RESOLUTION_TEXT = re.compile(r"(\d{3,4})p", re.I) # "480p", "1080p FHD", "2160p 4K"
|
|
15
|
+
PATTERN_RESOLUTION_IN_URL = re.compile(r"_(\d{3,4})p\.mp4/?$", re.I) # "..._720p.mp4" or "..._2160p.mp4"
|
|
16
|
+
PATTERN_MP4 = re.compile(r"\.mp4/?$", re.I)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def extractor_html(content: str) -> List[str]:
|
|
20
|
+
soup = BeautifulSoup(content, parser)
|
|
21
|
+
|
|
22
|
+
video_urls = []
|
|
23
|
+
containers = soup.find_all("div", class_="video-preview-screen video-item thumb-item")
|
|
24
|
+
for container in containers:
|
|
25
|
+
video_urls.append(container.find("a")["href"])
|
|
26
|
+
|
|
27
|
+
print(video_urls)
|
|
28
|
+
return video_urls
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2024-2025 Johannes Habel
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU General Public License as published by
|
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
(at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program 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
|
|
12
|
+
GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
import json5
|
|
19
|
+
import logging
|
|
20
|
+
import traceback
|
|
21
|
+
import threading
|
|
22
|
+
|
|
23
|
+
from functools import cached_property
|
|
24
|
+
from typing import Union, Generator, Tuple, Dict
|
|
25
|
+
from base_api.base import BaseCore, setup_logger, Helper, _choose_quality_from_list, _normalize_quality_value
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
import lxml
|
|
29
|
+
parser = "lxml"
|
|
30
|
+
|
|
31
|
+
except (ModuleNotFoundError, ImportError):
|
|
32
|
+
parser = "html.parser"
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
from modules.consts import *
|
|
36
|
+
|
|
37
|
+
except (ModuleNotFoundError, ImportError):
|
|
38
|
+
from .modules.consts import *
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Video:
|
|
42
|
+
def __init__(self, url: str, core: BaseCore):
|
|
43
|
+
self.url = url
|
|
44
|
+
self.core = core
|
|
45
|
+
self.logger = setup_logger(name="PORNTREX API - [Video]", log_file=None, level=logging.ERROR)
|
|
46
|
+
self.logger.debug("Trying to fetch HTML Content... [1/3]")
|
|
47
|
+
self.html_content = self.core.fetch(self.url)
|
|
48
|
+
self.logger.debug("Got HTML Content... [2/3]")
|
|
49
|
+
self.soup = BeautifulSoup(self.html_content, parser)
|
|
50
|
+
self.logger.debug("Initialized Beautifulsoup... [2/3]")
|
|
51
|
+
self.video_metadata = self.soup.find("div", class_="video-info").find("div", class_="item")
|
|
52
|
+
self.json_data = self.get_json_data()
|
|
53
|
+
self.logger.debug("Extracted JSON Data... [3/3]")
|
|
54
|
+
|
|
55
|
+
def enable_logging(self, log_file: str = None, level = None, log_ip: str = None, log_port: int = None):
|
|
56
|
+
self.logger = setup_logger(name="PORNTREX API - [Video]", log_file=log_file, level=level, http_ip=log_ip, http_port=log_port)
|
|
57
|
+
|
|
58
|
+
def get_json_data(self) -> dict:
|
|
59
|
+
# Grab the object literal after `var flashvars =`
|
|
60
|
+
m = re.search(r"var\s+flashvars\s*=\s*({.*?})\s*;", self.html_content, re.S)
|
|
61
|
+
obj_literal = m.group(1)
|
|
62
|
+
return json5.loads(obj_literal)
|
|
63
|
+
|
|
64
|
+
def _extract_height_for_key(self, key: str, url: str) -> Union[int, None]:
|
|
65
|
+
"""
|
|
66
|
+
Try to get the numeric height from "<key>_text" first, then from the URL pattern.
|
|
67
|
+
"""
|
|
68
|
+
# 1) From "<key>_text" if present (e.g., "720p HD")
|
|
69
|
+
label = self.json_data.get(f"{key}_text")
|
|
70
|
+
if label:
|
|
71
|
+
m = PATTERN_RESOLUTION_TEXT.search(label)
|
|
72
|
+
if m:
|
|
73
|
+
return int(m.group(1))
|
|
74
|
+
|
|
75
|
+
# 2) From the URL itself if it ends with "..._720p.mp4"
|
|
76
|
+
m = PATTERN_RESOLUTION_IN_URL.search(url)
|
|
77
|
+
if m:
|
|
78
|
+
return int(m.group(1))
|
|
79
|
+
|
|
80
|
+
# 3) Special-case fallback: the base "video_url" sometimes lacks "_480p" in the URL;
|
|
81
|
+
# use "video_url_text" if available.
|
|
82
|
+
if key == "video_url":
|
|
83
|
+
txt = self.json_data.get("video_url_text")
|
|
84
|
+
if txt:
|
|
85
|
+
m = PATTERN_RESOLUTION_TEXT.search(txt)
|
|
86
|
+
if m:
|
|
87
|
+
return int(m.group(1))
|
|
88
|
+
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
def _collect_height_url_pairs(self) -> List[Tuple[int, str]]:
|
|
92
|
+
"""
|
|
93
|
+
Build (height, url) pairs from the JSON payload.
|
|
94
|
+
Only keeps valid .mp4 URLs that have a resolvable height.
|
|
95
|
+
Deduplicates by height (last one wins if duplicates found).
|
|
96
|
+
"""
|
|
97
|
+
by_height: Dict[int, str] = {}
|
|
98
|
+
for k, v in self.json_data.items():
|
|
99
|
+
if not isinstance(v, str):
|
|
100
|
+
continue
|
|
101
|
+
if not PATTERN_URL_KEY.match(k):
|
|
102
|
+
continue
|
|
103
|
+
if not PATTERN_MP4.search(v):
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
h = self._extract_height_for_key(k, v)
|
|
107
|
+
if h is not None:
|
|
108
|
+
by_height[h] = v
|
|
109
|
+
|
|
110
|
+
# Sort by ascending height
|
|
111
|
+
return sorted(by_height.items(), key=lambda kv: kv[0])
|
|
112
|
+
|
|
113
|
+
def video_qualities(self) -> list:
|
|
114
|
+
"""
|
|
115
|
+
:return: (list[str]) available qualities as e.g. ["480", "720", "1080", "2160"]
|
|
116
|
+
"""
|
|
117
|
+
pairs = self._collect_height_url_pairs()
|
|
118
|
+
heights = [str(h) for h, _ in pairs]
|
|
119
|
+
return heights
|
|
120
|
+
|
|
121
|
+
def direct_download_urls(self) -> list:
|
|
122
|
+
"""
|
|
123
|
+
:return: (list[str]) direct MP4 URLs aligned in ascending order of quality.
|
|
124
|
+
Ordering matches the sorted `video_qualities`.
|
|
125
|
+
"""
|
|
126
|
+
pairs = self._collect_height_url_pairs()
|
|
127
|
+
urls = [url for _, url in pairs]
|
|
128
|
+
return urls
|
|
129
|
+
|
|
130
|
+
@cached_property
|
|
131
|
+
def title(self) -> str:
|
|
132
|
+
return self.json_data["video_title"]
|
|
133
|
+
|
|
134
|
+
@cached_property
|
|
135
|
+
def video_id(self) -> str:
|
|
136
|
+
return self.json_data["video_id"]
|
|
137
|
+
|
|
138
|
+
@cached_property
|
|
139
|
+
def categories(self) -> List[str]:
|
|
140
|
+
return self.json_data["video_categories"].split(",")
|
|
141
|
+
|
|
142
|
+
@cached_property
|
|
143
|
+
def tags(self) -> List[str]:
|
|
144
|
+
return self.json_data["video_tags"].split(",")
|
|
145
|
+
|
|
146
|
+
@cached_property
|
|
147
|
+
def license_code(self) -> str:
|
|
148
|
+
return self.json_data["license_code"]
|
|
149
|
+
|
|
150
|
+
@cached_property
|
|
151
|
+
def lrc(self) -> str:
|
|
152
|
+
return self.json_data["lrc"]
|
|
153
|
+
|
|
154
|
+
@cached_property
|
|
155
|
+
def rnd(self) -> str:
|
|
156
|
+
return self.json_data["rnd"]
|
|
157
|
+
|
|
158
|
+
@cached_property
|
|
159
|
+
def author(self) -> str:
|
|
160
|
+
return self.soup.find("div", class_="username").find("a").text.strip()
|
|
161
|
+
|
|
162
|
+
@cached_property
|
|
163
|
+
def publish_date(self) -> str:
|
|
164
|
+
return self.video_metadata.find("em").text.strip()
|
|
165
|
+
|
|
166
|
+
@cached_property
|
|
167
|
+
def views(self) -> str:
|
|
168
|
+
return self.video_metadata.find_all("em")[1].text.strip()
|
|
169
|
+
|
|
170
|
+
@cached_property
|
|
171
|
+
def duration(self) -> str:
|
|
172
|
+
return self.video_metadata.find_all("em")[2].text.strip()
|
|
173
|
+
|
|
174
|
+
@cached_property
|
|
175
|
+
def description(self) -> str:
|
|
176
|
+
return self.soup.find("em", class_="des-link").text.strip()
|
|
177
|
+
|
|
178
|
+
@cached_property
|
|
179
|
+
def subscribers_count(self) -> str:
|
|
180
|
+
return self.soup.find("div", class_="button-infow").text.strip()
|
|
181
|
+
|
|
182
|
+
@cached_property
|
|
183
|
+
def thumbnail(self) -> str:
|
|
184
|
+
image = self.json_data["preview_url"]
|
|
185
|
+
return f"https:{image}"
|
|
186
|
+
|
|
187
|
+
def download(self, quality, path: str = "./", callback=None, no_title: bool = False,
|
|
188
|
+
stop_event: threading.Event = None) -> bool:
|
|
189
|
+
"""
|
|
190
|
+
`quality` can be an int (e.g., 720) or "best" / "half" / "worst".
|
|
191
|
+
"""
|
|
192
|
+
cdn_urls = self.direct_download_urls()
|
|
193
|
+
quals = self.video_qualities() # e.g., ["480", "720", "1080", "2160"]
|
|
194
|
+
|
|
195
|
+
qn = _normalize_quality_value(quality)
|
|
196
|
+
chosen_height = _choose_quality_from_list(quals, qn)
|
|
197
|
+
|
|
198
|
+
quality_url_map = {int(q): url for q, url in zip(quals, cdn_urls)}
|
|
199
|
+
download_url = quality_url_map[chosen_height]
|
|
200
|
+
|
|
201
|
+
if no_title is False:
|
|
202
|
+
safe_title = f"{self.title}.mp4"
|
|
203
|
+
path = os.path.join(path, safe_title)
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
self.logger.debug(f"Trying legacy video download for: {download_url} -->: {path}")
|
|
207
|
+
self.core.legacy_download(url=download_url, path=path, callback=callback, stop_event=stop_event)
|
|
208
|
+
return True
|
|
209
|
+
|
|
210
|
+
except Exception:
|
|
211
|
+
error = traceback.format_exc()
|
|
212
|
+
self.logger.error(error)
|
|
213
|
+
return False
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class ChannelModelHelper(Helper):
|
|
217
|
+
def __init__(self, url: str, core: BaseCore):
|
|
218
|
+
super().__init__(core=core, video=Video)
|
|
219
|
+
self.url = url
|
|
220
|
+
self.core = core
|
|
221
|
+
self.logger.debug("Trying to fetch HTML content... [1/3]")
|
|
222
|
+
self.html_content = self.core.fetch(self.url)
|
|
223
|
+
self.logger.debug("Received HTML content: [2/3]")
|
|
224
|
+
self.soup = BeautifulSoup(self.html_content, parser)
|
|
225
|
+
self.info_container = self.soup.find("div", class_="sidebar").find("div", class_="info")
|
|
226
|
+
self.logger.debug("Finished processing Channel / Model [3/3]")
|
|
227
|
+
|
|
228
|
+
@cached_property
|
|
229
|
+
def name(self) -> str:
|
|
230
|
+
return self.soup.find("div", class_="name").find("a").text.strip()
|
|
231
|
+
|
|
232
|
+
@cached_property
|
|
233
|
+
def information(self) -> dict:
|
|
234
|
+
dictionary = {}
|
|
235
|
+
|
|
236
|
+
info_stuff = self.info_container.find_all("p")
|
|
237
|
+
for p in info_stuff:
|
|
238
|
+
_list = p.text.split(":")
|
|
239
|
+
try:
|
|
240
|
+
dictionary[_list[0]] = _list[1]
|
|
241
|
+
|
|
242
|
+
except IndexError:
|
|
243
|
+
break # No more useful data
|
|
244
|
+
|
|
245
|
+
return dictionary
|
|
246
|
+
|
|
247
|
+
@cached_property
|
|
248
|
+
def image(self) -> str:
|
|
249
|
+
image = self.soup.find("div", class_="profile-model-info").find("img")["data-src"]
|
|
250
|
+
return f"https:{image}"
|
|
251
|
+
|
|
252
|
+
def videos(self, pages: int = 2, videos_concurrency: int = None, pages_concurrency: int = None) -> Generator[Video, None, None]:
|
|
253
|
+
page_urls = [f"{self.url}?mode=async&function=get_block&block_id=list_videos_common_videos_list_norm&sort_by=post_date&from={page:02d}&_=1761740123131" for page in range(pages)]
|
|
254
|
+
self.logger.debug(f"Built page URLs: {page_urls}")
|
|
255
|
+
videos_concurrency = videos_concurrency or self.core.config.videos_concurrency
|
|
256
|
+
pages_concurrency = pages_concurrency or self.core.config.pages_concurrency
|
|
257
|
+
|
|
258
|
+
self.logger.debug(f"Iterating with video concurrency: {videos_concurrency} and pages concurrency: {pages_concurrency}")
|
|
259
|
+
|
|
260
|
+
yield from self.iterator(page_urls=page_urls, videos_concurrency=videos_concurrency,
|
|
261
|
+
pages_concurrency=pages_concurrency, extractor=extractor_html)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
class Model(ChannelModelHelper):
|
|
265
|
+
pass
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class Channel(ChannelModelHelper):
|
|
269
|
+
|
|
270
|
+
@cached_property
|
|
271
|
+
def image(self) -> str:
|
|
272
|
+
image = self.soup.find("div", class_="profile-model-info").find("img")["src"]
|
|
273
|
+
return f"https:{image}"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
class Client(Helper):
|
|
277
|
+
def __init__(self, core: BaseCore = None):
|
|
278
|
+
super().__init__(video=Video, core=core)
|
|
279
|
+
self.core = core or BaseCore()
|
|
280
|
+
|
|
281
|
+
def get_video(self, url: str) -> Video:
|
|
282
|
+
return Video(url, self.core)
|
|
283
|
+
|
|
284
|
+
def get_model(self, url: str) -> Model:
|
|
285
|
+
return Model(url, self.core)
|
|
286
|
+
|
|
287
|
+
def get_channel(self, url: str) -> Channel:
|
|
288
|
+
return Channel(url, self.core)
|
|
289
|
+
|
|
290
|
+
def search(self, query: str, pages: int = 2,
|
|
291
|
+
videos_concurrency: int = None, pages_concurrency: int = None) -> Generator[Video, None, None]:
|
|
292
|
+
|
|
293
|
+
page_urls = [f"https://www.porntrex.com/search/{query}/?mode=async&function=get_block&block_id=list_videos_videos&q={query}&category_ids=&sort_by=relevance&from={page:02d}&_=1761771312451" for page in range(pages)]
|
|
294
|
+
videos_concurrency = videos_concurrency or self.core.config.videos_concurrency
|
|
295
|
+
pages_concurrency = pages_concurrency or self.core.config.pages_concurrency
|
|
296
|
+
|
|
297
|
+
yield from self.iterator(page_urls=page_urls, videos_concurrency=videos_concurrency,
|
|
298
|
+
pages_concurrency=pages_concurrency, extractor=extractor_html)
|
|
299
|
+
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .. import Client, Video
|
|
2
|
+
from base_api.base import BaseCore
|
|
3
|
+
|
|
4
|
+
core = BaseCore()
|
|
5
|
+
core.config.videos_concurrency = 1
|
|
6
|
+
core.config.pages_concurrency = 1
|
|
7
|
+
|
|
8
|
+
client = Client()
|
|
9
|
+
model = client.get_model("https://www.porntrex.com/channels/nubile-films/")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_model_information():
|
|
13
|
+
assert isinstance(model.name, str) and len(model.name) > 0
|
|
14
|
+
assert isinstance(model.information, dict) and len(model.information) > 0
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_model_videos():
|
|
18
|
+
for idx, video in enumerate(model.videos()):
|
|
19
|
+
if idx == 5:
|
|
20
|
+
break
|
|
21
|
+
|
|
22
|
+
assert isinstance(video, Video) and video.title is not None
|
|
23
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .. import Client, Video
|
|
2
|
+
from base_api.base import BaseCore
|
|
3
|
+
|
|
4
|
+
core = BaseCore()
|
|
5
|
+
core.config.videos_concurrency = 1
|
|
6
|
+
core.config.pages_concurrency = 1
|
|
7
|
+
|
|
8
|
+
client = Client()
|
|
9
|
+
model = client.get_model("https://www.porntrex.com/models/rose/")
|
|
10
|
+
|
|
11
|
+
def test_model_information():
|
|
12
|
+
assert isinstance(model.name, str) and len(model.name) > 0
|
|
13
|
+
assert isinstance(model.information, dict) and len(model.information) > 0
|
|
14
|
+
|
|
15
|
+
def test_model_videos():
|
|
16
|
+
for idx, video in enumerate(model.videos()):
|
|
17
|
+
if idx == 5:
|
|
18
|
+
break
|
|
19
|
+
|
|
20
|
+
assert isinstance(video, Video) and video.title is not None
|
|
21
|
+
|
|
22
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .. import Client
|
|
2
|
+
from base_api import BaseCore
|
|
3
|
+
|
|
4
|
+
core = BaseCore()
|
|
5
|
+
core.config.pages_concurrency = 1
|
|
6
|
+
core.config.videos_concurrency = 1
|
|
7
|
+
|
|
8
|
+
client = Client(core=core)
|
|
9
|
+
search = client.search(query="stepmom")
|
|
10
|
+
|
|
11
|
+
def test_search():
|
|
12
|
+
for idx, video in enumerate(search):
|
|
13
|
+
if idx == 5:
|
|
14
|
+
break
|
|
15
|
+
|
|
16
|
+
assert isinstance(video.title, str) and len(video.title) > 0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from ..porntrex_api import Client
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
client = Client()
|
|
5
|
+
video = client.get_video("https://www.porntrex.com/video/2989480/i-have-two-big-titties-and-im-your-date")
|
|
6
|
+
|
|
7
|
+
def test_attributes():
|
|
8
|
+
assert isinstance(video.title, str) and len(video.title) > 0
|
|
9
|
+
assert isinstance(video.json_data, dict) and len(video.video_metadata) > 0
|
|
10
|
+
assert isinstance(video.description, str) and len(video.description) > 0
|
|
11
|
+
assert isinstance(video.duration, str) and len(video.duration) > 0
|
|
12
|
+
assert isinstance(video.video_id, str) and len(video.video_id) > 0
|
|
13
|
+
assert isinstance(video.author, str) and len(video.author) > 0
|
|
14
|
+
assert isinstance(video.categories, list) and len(video.categories) > 0
|
|
15
|
+
assert isinstance(video.tags, list) and len(video.tags) > 0
|
|
16
|
+
assert isinstance(video.subscribers_count, str) and len(video.subscribers_count) > 0
|
|
17
|
+
assert isinstance(video.lrc, str) and len(video.lrc) > 0
|
|
18
|
+
assert isinstance(video.license_code, str) and len(video.license_code) > 0
|
|
19
|
+
assert isinstance(video.views, str) and len(video.views) > 0
|
|
20
|
+
assert isinstance(video.rnd, str) and len(video.rnd) > 0
|
|
21
|
+
assert isinstance(video.thumbnail, str) and len(video.thumbnail) > 0
|
|
22
|
+
|
|
23
|
+
def test_download():
|
|
24
|
+
assert video.download(quality="worst") is True
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.9.18,<0.10.0"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "porntrex_api"
|
|
7
|
+
version = "1.1"
|
|
8
|
+
description = "A Python API for the Porn Site xvideos.com"
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "LGPL-3.0-only"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Johannes Habel", email = "EchterAlsFake@proton.me" }
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"bs4",
|
|
18
|
+
"eaf_base_api",
|
|
19
|
+
"json5"
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Programming Language :: Python",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
full = ["lxml", "httpx[http2]", "httpx[socks]"] # H2 for HTTP 2.0 support, LXML for faster parsing speed, though optional :)
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/EchterAlsFake/porntrex_api"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
packages = { find = {} }
|
|
33
|
+
|
|
34
|
+
[tool.uv.build-backend]
|
|
35
|
+
module-name = "porntrex_api"
|
|
36
|
+
module-root = ""
|