eaf-base-api 1.6__tar.gz → 1.6.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eaf_base_api
3
- Version: 1.6
3
+ Version: 1.6.2
4
4
  Summary: A base API for EchterAlsFake's Porn APIs
5
5
  Home-page: https://github.com/EchterAlsFake/eaf_base_api
6
6
  Author: Johannes Habel
@@ -0,0 +1,5 @@
1
+ __all__ = ["Core", "Quality", "setup_api", "default", "threaded", "FFMPEG", "Callback"]
2
+
3
+ from base_api.base import Core, Quality, setup_api
4
+ from base_api.modules.download import default, threaded, FFMPEG
5
+ from base_api.modules.progress_bars import Callback
@@ -7,7 +7,7 @@ import os
7
7
  from base_api.modules.quality import Quality
8
8
  from base_api.modules.progress_bars import Callback
9
9
  from base_api.modules.download import default, threaded, FFMPEG
10
- from base_api.modules.consts import MAX_RETRIES
10
+ from base_api.modules.consts import MAX_RETRIES, REQUEST_DELAY
11
11
  from pathlib import Path
12
12
 
13
13
 
@@ -20,14 +20,24 @@ def setup_api(do_logging=False):
20
20
  logging.disable(logging.CRITICAL)
21
21
 
22
22
 
23
- base_qualities = ["250p", "360p", "480p", "720p", "1080p", "1440p", "2160p"]
24
-
25
-
26
23
  class Core:
27
- @classmethod
28
- def get_content(cls, url, headers=None, cookies=None, stream=False):
24
+ def __init__(self, delay=REQUEST_DELAY):
25
+ self.delay = delay
26
+ self.start_delay = False
27
+ self.last_request_time = None
28
+
29
+ def get_content(self, url, headers=None, cookies=None, stream=False):
29
30
  for i in range(MAX_RETRIES):
30
31
  try:
32
+
33
+ # Delay mechanism
34
+ if self.last_request_time:
35
+ elapsed_time = time.time() - self.last_request_time
36
+ if elapsed_time < self.delay:
37
+ time.sleep(self.delay - elapsed_time)
38
+
39
+ self.last_request_time = time.time() # Update the time of the last request
40
+
31
41
  logging.debug(f"Trying to fetch {url} / Attempt: [{i+1}]")
32
42
  response = requests.get(url, headers=headers, cookies=cookies, stream=stream)
33
43
  if response.status_code == 200:
@@ -58,7 +68,7 @@ class Core:
58
68
  elif str(quality) == "worst":
59
69
  return Quality.WORST
60
70
 
61
- def get_available_qualities(self, m3u8_base_url):
71
+ def get_available_qualities(self, m3u8_base_url, base_qualities, seperator):
62
72
  """Returns the available qualities from the M3U8 base url"""
63
73
  content = self.get_content(m3u8_base_url).decode("utf-8")
64
74
  lines = content.splitlines()
@@ -67,18 +77,18 @@ class Core:
67
77
 
68
78
  for line in lines:
69
79
  for quality in base_qualities:
70
- if f"hls-{quality}" in line:
80
+ if f"{seperator}{quality}" in line and not str(line).startswith("#"):
71
81
  quality_url_map[quality] = line
72
82
 
73
83
  self.quality_url_map = quality_url_map
74
84
  self.available_qualities = list(quality_url_map.keys())
75
85
  return self.available_qualities
76
86
 
77
- def get_m3u8_by_quality(self, quality, m3u8_base_url):
87
+ def get_m3u8_by_quality(self, quality, m3u8_base_url, base_qualities, seperator):
78
88
  """Returns the m3u8 url for the given quality"""
79
89
  quality = self.fix_quality(quality)
80
90
 
81
- self.get_available_qualities(m3u8_base_url)
91
+ self.get_available_qualities(m3u8_base_url, base_qualities, seperator=seperator)
82
92
  if quality == Quality.BEST:
83
93
  selected_quality = max(self.available_qualities, key=lambda q: base_qualities.index(q))
84
94
  elif quality == Quality.WORST:
@@ -118,10 +128,11 @@ class Core:
118
128
  return Path(path)
119
129
 
120
130
  @classmethod
121
- def get_segments(cls, quality, m3u8_base_url):
131
+ def get_segments(cls, quality, m3u8_base_url, base_qualities, seperator, source=1):
122
132
  quality = Core().fix_quality(quality)
123
133
  base_url = m3u8_base_url
124
- new_segment = Core().get_m3u8_by_quality(quality, m3u8_base_url=base_url)
134
+ new_segment = Core().get_m3u8_by_quality(quality, m3u8_base_url=base_url, base_qualities=base_qualities,
135
+ seperator=seperator)
125
136
  # Split the base URL into components
126
137
  url_components = base_url.split('/')
127
138
 
@@ -130,6 +141,10 @@ class Core:
130
141
 
131
142
  # Rejoin the components into the new full URL
132
143
  new_url = '/'.join(url_components)
144
+
145
+ if source == "spankbang":
146
+ new_url = new_url.split(".mp4.urlset/")[1] # Please just don't ask, I'm a terrible programmer fr
147
+
133
148
  master_src = Core().get_content(url=new_url).decode("utf-8")
134
149
 
135
150
  urls = [l for l in master_src.splitlines()
@@ -0,0 +1,3 @@
1
+ MAX_RETRIES = 4
2
+ REQUEST_DELAY = 0
3
+ FFMPEG_PATH = "ffmpeg"
@@ -10,12 +10,16 @@ class Callback:
10
10
  print(f"Downloaded: {downloaded} bytes / {total} bytes ({percentage:.2f}%)")
11
11
 
12
12
  @classmethod
13
- def text_progress_bar(cls, downloaded, total):
13
+ def text_progress_bar(cls, downloaded, total, title=False):
14
14
  bar_length = 50
15
15
  filled_length = int(round(bar_length * downloaded / float(total)))
16
16
  percents = round(100.0 * downloaded / float(total), 1)
17
17
  bar = '#' * filled_length + '-' * (bar_length - filled_length)
18
- print(f"\r[{bar}] {percents}%", end='')
18
+ if title is False:
19
+ print(f"\r[{bar}] {percents}%", end='')
20
+
21
+ else:
22
+ print(f"\r | {title} | -->: [{bar}] {percents}%", end='')
19
23
 
20
24
  @staticmethod
21
25
  def update_progress(downloaded, total, animation_phase):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: eaf_base_api
3
- Version: 1.6
3
+ Version: 1.6.2
4
4
  Summary: A base API for EchterAlsFake's Porn APIs
5
5
  Home-page: https://github.com/EchterAlsFake/eaf_base_api
6
6
  Author: Johannes Habel
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="eaf_base_api",
5
- version="1.6",
5
+ version="1.6.2",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "requests", "ffmpeg-progress-yield"
File without changes
@@ -1,2 +0,0 @@
1
- MAX_RETRIES = 4
2
- FFMPEG_PATH = "ffmpeg"
File without changes
File without changes