Auto switch proxy.

This commit is contained in:
Ghost 2024-06-04 23:18:16 +02:00
parent 37e75370b0
commit 4553cf9f45
7 changed files with 41 additions and 22 deletions

View File

@ -18,7 +18,7 @@ from .Core.Util import manage_selection
# Config
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
from .costant import ANIME_FOLDER, SERIES_FOLDER, MOVIE_FOLDER
from .costant import ANIME_FOLDER, SERIES_FOLDER, MOVIE_FOLDER, STATIC_IP_SERVER
# Variable
@ -61,7 +61,7 @@ def download_episode(index_select: int):
)
# Start downloading
obj_download.start()
obj_download.start(STATIC_IP_SERVER)
def donwload_series(tv_id: int, tv_name: str):

View File

@ -3,3 +3,5 @@
ANIME_FOLDER = "animeunity"
SERIES_FOLDER= "Serie"
MOVIE_FOLDER = "Movie"
STATIC_IP_SERVER = ['57.129.7.85', '57.129.7.188', '57.129.7.174', '57.129.4.77', '57.129.16.196', '57.129.16.156', '57.129.16.139', '57.129.16.135', '57.129.13.175', '57.129.13.157', '51.38.112.237', '51.195.107.7', '51.195.107.230', '162.19.255.78', '162.19.255.36', '162.19.255.224', '162.19.255.223', '162.19.254.244', '162.19.254.232', '162.19.254.230', '162.19.253.242', '162.19.249.48', '162.19.245.142', '162.19.231.20', '162.19.229.177', '162.19.228.128', '162.19.228.127', '162.19.228.105', '141.95.1.32', '141.95.1.196', '141.95.1.102', '141.95.0.50', '141.95.0.248', '135.125.237.84', '135.125.233.236']

View File

@ -3,3 +3,5 @@
STREAMING_FOLDER = "streamingcommunity"
MOVIE_FOLDER = "Movie"
SERIES_FOLDER = "Serie"
STATIC_IP_SERVER = ['57.129.7.85', '57.129.7.188', '57.129.7.174', '57.129.4.77', '57.129.16.196', '57.129.16.156', '57.129.16.139', '57.129.16.135', '57.129.13.175', '57.129.13.157', '51.38.112.237', '51.195.107.7', '51.195.107.230', '162.19.255.78', '162.19.255.36', '162.19.255.224', '162.19.255.223', '162.19.254.244', '162.19.254.232', '162.19.254.230', '162.19.253.242', '162.19.249.48', '162.19.245.142', '162.19.231.20', '162.19.229.177', '162.19.228.128', '162.19.228.127', '162.19.228.105', '141.95.1.32', '141.95.1.196', '141.95.1.102', '141.95.0.50', '141.95.0.248', '135.125.237.84', '135.125.233.236']

View File

@ -18,7 +18,7 @@ from .Core.Vix_player.player import VideoSource
# Config
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
from .costant import STREAMING_FOLDER, MOVIE_FOLDER
from .costant import STREAMING_FOLDER, MOVIE_FOLDER, STATIC_IP_SERVER
# Variable
@ -59,4 +59,4 @@ def download_film(id_film: str, title_name: str, domain: str):
Downloader(
m3u8_playlist = master_playlist,
output_filename = os.path.join(mp4_path, mp4_format)
).start()
).start(STATIC_IP_SERVER)

View File

@ -20,7 +20,7 @@ from .Core.Util import manage_selection, map_episode_title
# Config
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
from .costant import STREAMING_FOLDER, SERIES_FOLDER
from .costant import STREAMING_FOLDER, SERIES_FOLDER, STATIC_IP_SERVER
# Variable
@ -96,7 +96,7 @@ def donwload_video(tv_name: str, index_season_selected: int, index_episode_selec
Downloader(
m3u8_playlist = master_playlist,
output_filename = os.path.join(mp4_path, mp4_name)
).start()
).start(STATIC_IP_SERVER)
def donwload_episode(tv_name: str, index_season_selected: int, donwload_all: bool = False) -> None:

View File

@ -109,7 +109,7 @@ class M3U8_Segments:
logging.info(f"Key: ('hex': {hex_content}, 'byte': {byte_content})")
return byte_content
def __test_ip(self):
def __test_ip(self, url_to_test: str):
"""
Tests each proxy IP by sending a request to a corresponding segment URL.
"""
@ -117,16 +117,18 @@ class M3U8_Segments:
failed_ips = []
for i in range(len(self.fake_proxy_ip)):
url_to_test = self.segments[i]
try:
response = requests.get(url_to_test, verify=False, retries=0)
if response == None:
logging.error(f"[Work] to make request using: {url_to_test}")
failed_ips.append(i)
# Attempt to send a GET request to the URL
requests.get(url_to_test, verify=self.verify_ssl)
except:
# Log the error and add the IP to the list of failed IPs
logging.error(f"Failed to make request using IP in this request: {url_to_test}")
logging.error(f"[Fail] to make request using IP in this request: {url_to_test}")
failed_ips.append(i)
# Remove the failed IPs from the fake_proxy_ip list
@ -134,8 +136,13 @@ class M3U8_Segments:
# Exit the program if 50% requests failed
if len(failed_ips) / 2 > len(self.fake_proxy_ip):
logging.error("All requests with ip failed. Exiting the program.")
sys.exit(0)
logging.error("All requests with ip failed.")
# Set to not use proxy
self.fake_proxy_ip = None
self.fake_proxy = False
return False
def parse_data(self, m3u8_content: str) -> None:
"""
@ -182,10 +189,13 @@ class M3U8_Segments:
for i in range(len(self.segments)):
segment_url = self.segments[i]
self.segments[i] = self.__gen_proxy__(segment_url, self.segments.index(segment_url))
# Set to not use proxy if 50% failed
if not self.__test_ip(segment_url):
console.log("[red]Cant use proxy switch to normal url.")
self.fake_proxy = False
break
# Test new url with ip
self.__test_ip()
self.segments[i] = self.__gen_proxy__(segment_url, self.segments.index(segment_url))
# Save new playlist of segment
path_m3u8_file = os.path.join(self.tmp_folder, "playlist_fix.m3u8")
@ -226,12 +236,17 @@ class M3U8_Segments:
Returns:
str: The modified URL with the new IP address.
"""
new_ip_address = self.fake_proxy_ip[url_index % len(self.fake_proxy_ip)]
if self.fake_proxy:
# Parse the original URL and replace the hostname with the new IP address
parsed_url = urlparse(url)._replace(netloc=new_ip_address)
new_ip_address = self.fake_proxy_ip[url_index % len(self.fake_proxy_ip)]
return urlunparse(parsed_url)
# Parse the original URL and replace the hostname with the new IP address
parsed_url = urlparse(url)._replace(netloc=new_ip_address)
return urlunparse(parsed_url)
else:
return url
def make_requests_stream(self, ts_url: str, index: int, progress_bar: tqdm) -> None:
"""