From 2d7e152c9d2acf0ae823071dd1f6ea73affd8b5e Mon Sep 17 00:00:00 2001 From: Johannes Habel Date: Sat, 3 Feb 2024 21:15:11 +0100 Subject: [PATCH 1/5] - Changed the JSON methods - Fixed a lot of issues in how the data is got - URLs with /hdporn/... are now also working - Written Tests for video.py #1 --- eporner_api/eporner_api.py | 90 ++++++++++++++++++++++++++------ eporner_api/modules/consts.py | 6 ++- eporner_api/modules/errors.py | 5 ++ eporner_api/tests/__init__.py | 0 eporner_api/tests/test_search.py | 0 eporner_api/tests/test_video.py | 78 +++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 17 deletions(-) create mode 100644 eporner_api/tests/__init__.py create mode 100644 eporner_api/tests/test_search.py create mode 100644 eporner_api/tests/test_video.py diff --git a/eporner_api/eporner_api.py b/eporner_api/eporner_api.py index 5e860c2..f0b073e 100644 --- a/eporner_api/eporner_api.py +++ b/eporner_api/eporner_api.py @@ -56,7 +56,7 @@ def __init__(self, url, enable_html_scraping=False): self.enable_html = enable_html_scraping self.html_content = None self.json_data = self.raw_json_data() - + print(self.json_data) if self.enable_html: self.request_html_content() self.html_json_data = self.extract_json_from_html() @@ -73,7 +73,12 @@ def video_id(self) -> str: return video_id.group(1) else: - raise InvalidURL("The URL is not valid. Couldn't extract ID!") + try: + video_id = REGEX_ID_ALTERNATE.search(self.url) + return video_id.group(1) + + except Exception: + raise InvalidURL("The URL is not valid. Couldn't extract ID!") else: return self.url # Assuming this is a video ID (hopefully) @@ -155,13 +160,35 @@ def extract_json_from_html(self): raise HTML_IS_DISABLED("HTML content is disabled! See Documentation for more details") soup = BeautifulSoup(self.html_content, 'lxml') - # Find the ') -REGEX_VIDEO_UPLOADER = re.compile(r'title="Uploader">(.*?)') \ No newline at end of file +REGEX_VIDEO_UPLOADER = re.compile(r'title="Uploader">(.*?)') +REGEX_VIDEO_PORNSTAR = re.compile('') +REGEX_VIDEO_LIKES = re.compile(r'
\d+(.*?)
') +REGEX_VIDEO_DISLIKES = re.compile(r'
\d+(\d+)
') diff --git a/eporner_api/modules/errors.py b/eporner_api/modules/errors.py index 4935d6e..b019f88 100644 --- a/eporner_api/modules/errors.py +++ b/eporner_api/modules/errors.py @@ -6,3 +6,8 @@ def __init__(self, msg): class HTML_IS_DISABLED(Exception): def __init__(self, msg): self.msg = msg + + +class NotAvailable(Exception): + def __init__(self, msg): + self.msg = msg diff --git a/eporner_api/tests/__init__.py b/eporner_api/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/eporner_api/tests/test_search.py b/eporner_api/tests/test_search.py new file mode 100644 index 0000000..e69de29 diff --git a/eporner_api/tests/test_video.py b/eporner_api/tests/test_video.py new file mode 100644 index 0000000..cd8ef1b --- /dev/null +++ b/eporner_api/tests/test_video.py @@ -0,0 +1,78 @@ +from ..eporner_api import Client, Quality, Encoding, NotAvailable + +url = "https://www.eporner.com/hd-porn/f8MuayGnGiS/Exciting-Moments-With-Lacey-Duvalle/" +video = Client.get_video(url, enable_html_scraping=True) + + +def test_title(): + assert isinstance(video.title, str) and len(video.title) > 0 + + +def test_video_id(): + assert isinstance(video.video_id, str) and len(video.video_id) > 0 + + +def test_keywords(): + assert isinstance(video.keywords, list) and len(video.keywords) > 0 + + +def test_views(): + assert isinstance(video.views, int) and video.views > 0 + + +def test_rate(): + assert isinstance(video.rate, str) and len(video.rate) > 0 + + +def test_publish_date(): + assert isinstance(video.publish_date, str) and len(video.publish_date) > 0 + + +def test_length_seconds(): + assert isinstance(video.length_seconds, int) > 0 + + +def test_length_minutes(): + assert isinstance(video.length_minutes, str) and len(video.length_minutes) > 0 + + +def test_embed_url(): + assert isinstance(video.embed_url, str) and len(video.embed_url) > 0 + + +def test_thumbnails(): + assert isinstance(video.thumbnails, list) and len(video.thumbnails) > 0 + + +def test_bitrate(): + assert isinstance(video.bitrate, str) and len(video.bitrate) > 0 + + +def test_source_video_url(): + assert isinstance(video.source_video_url, str) and len(video.source_video_url) > 0 + + +def test_rating(): + assert isinstance(video.rating, str) and len(video.rating) > 0 + + + +def test_rating_count(): + assert isinstance(video.rating_count, str) and len(video.rating_count) > 0 + + +def test_author(): + assert isinstance(video.author, str) and len(video.author) > 0 + + +def test_direct_download_url(): + assert isinstance(video.direct_download_link(quality=Quality.BEST, mode=Encoding.mp4_h264), str) + assert isinstance(video.direct_download_link(quality=Quality.HALF, mode=Encoding.mp4_h264), str) + assert isinstance(video.direct_download_link(quality=Quality.WORST, mode=Encoding.mp4_h264), str) + try: + assert isinstance(video.direct_download_link(quality=Quality.BEST, mode=Encoding.av1), str) + assert isinstance(video.direct_download_link(quality=Quality.HALF, mode=Encoding.av1), str) + assert isinstance(video.direct_download_link(quality=Quality.WORST, mode=Encoding.av1), str) + + except NotAvailable: + pass From ef85ba0f2fa989ec2dc2428e3b0e7721c2bab401 Mon Sep 17 00:00:00 2001 From: Johannes Habel Date: Sat, 3 Feb 2024 21:17:39 +0100 Subject: [PATCH 2/5] - removed useless print statement --- eporner_api/eporner_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eporner_api/eporner_api.py b/eporner_api/eporner_api.py index f0b073e..9f4eedd 100644 --- a/eporner_api/eporner_api.py +++ b/eporner_api/eporner_api.py @@ -169,7 +169,6 @@ def extract_json_from_html(self): data = json.loads(json_text) combined_data.update(data) cleaned_dictionary = self.flatten_json(combined_data) - print(cleaned_dictionary) return cleaned_dictionary def flatten_json(self, nested_json, parent_key='', sep='_'): From ec293f137a35e0e46c3030cdbb5f108abf642965 Mon Sep 17 00:00:00 2001 From: Johannes Habel Date: Sat, 3 Feb 2024 21:37:39 +0100 Subject: [PATCH 3/5] - Written Tests - Removed another useless print statement --- .github/workflows/tests.yml | 22 +++++++++++++++ README.md | 1 + eporner_api/eporner_api.py | 1 - eporner_api/tests/test_search.py | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..973b351 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,22 @@ +name: EPorner API test + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.11 + uses: actions/setup-python@v2 + with: + python-version: 3.11 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest requests bs4 lxml + - name: Test with pytest + run: | + pytest \ No newline at end of file diff --git a/README.md b/README.md index 84adb40..9a0ac2f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@
Downloads CodeQL Analysis + API Tests
# Description diff --git a/eporner_api/eporner_api.py b/eporner_api/eporner_api.py index 9f4eedd..5fa93e9 100644 --- a/eporner_api/eporner_api.py +++ b/eporner_api/eporner_api.py @@ -56,7 +56,6 @@ def __init__(self, url, enable_html_scraping=False): self.enable_html = enable_html_scraping self.html_content = None self.json_data = self.raw_json_data() - print(self.json_data) if self.enable_html: self.request_html_content() self.html_json_data = self.extract_json_from_html() diff --git a/eporner_api/tests/test_search.py b/eporner_api/tests/test_search.py index e69de29..541f238 100644 --- a/eporner_api/tests/test_search.py +++ b/eporner_api/tests/test_search.py @@ -0,0 +1,48 @@ +from ..eporner_api import Client, Gay, Order, LowQuality + +client = Client() +query = "Mia Khalifa" +pages = 2 +per_page = 10 + + +def test_search_1(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_gay=Gay.exclude_gay_content, sorting_order=Order.top_rated, sorting_low_quality=LowQuality.exclude_low_quality_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_2(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_gay=Gay.only_gay_content, sorting_order=Order.latest, sorting_low_quality=LowQuality.only_low_quality_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_3(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_gay=Gay.include_gay_content, sorting_order=Order.longest, sorting_low_quality=LowQuality.include_low_quality_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_4(): + videos = client.search_videos(query, page=pages, per_page=pages, sorting_gay=Gay.exclude_gay_content, sorting_order=Order.shortest, sorting_low_quality=LowQuality.include_low_quality_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_5(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_order=Gay.include_gay_content, sorting_gay=Order.top_weekly, sorting_low_quality=LowQuality.include_low_quality_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_6(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_order=Order.most_popular, sorting_low_quality=LowQuality.include_low_quality_content, sorting_gay=Gay.only_gay_content) + for video in videos: + assert len(video.title) > 0 + + +def test_search_7(): + videos = client.search_videos(query, page=pages, per_page=per_page, sorting_gay=Gay.include_gay_content, sorting_order=Order.top_monthly, sorting_low_quality=LowQuality.include_low_quality_content) + for video in videos: + assert len(video.title) > 0 From 5752c1d7791ac8c71f0b035be5a5d63bc69495c8 Mon Sep 17 00:00:00 2001 From: Johannes Habel Date: Sat, 3 Feb 2024 21:40:57 +0100 Subject: [PATCH 4/5] Release 1.3 --- README/Changelog.md | 9 ++++++++- README/Documentation.md | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README/Changelog.md b/README/Changelog.md index 2f46783..0e8f889 100644 --- a/README/Changelog.md +++ b/README/Changelog.md @@ -12,4 +12,11 @@ e.g: Quality.BEST would translate to "best" -
etc... \ No newline at end of file +
etc... + +# 1.3 + +- Changed JSON methods +- Fixed stuff +- Written Unit Tests +- /hdporn/ URls now also work \ No newline at end of file diff --git a/README/Documentation.md b/README/Documentation.md index 61abada..836f805 100644 --- a/README/Documentation.md +++ b/README/Documentation.md @@ -1,6 +1,6 @@ # EPorner Documentation -> - Version 1.2 +> - Version 1.3 > - Author: Johannes Habel > - Copryight (C) 2024 > - License: GPL 3 From 0460ab19979bb0c6f21c33d53176f4d63045ea0f Mon Sep 17 00:00:00 2001 From: Johannes Habel Date: Sat, 3 Feb 2024 21:41:43 +0100 Subject: [PATCH 5/5] Release 1.3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f434a81..276d745 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="Eporner_API", - version="1.2", + version="1.3", packages=find_packages(), install_requires=[ "requests", "bs4", "lxml"