mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 20:15:24 +00:00
Auto switch proxy.
This commit is contained in:
parent
37e75370b0
commit
4553cf9f45
@ -18,7 +18,7 @@ from .Core.Util import manage_selection
|
|||||||
|
|
||||||
# Config
|
# Config
|
||||||
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
|
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
|
# Variable
|
||||||
@ -61,7 +61,7 @@ def download_episode(index_select: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Start downloading
|
# Start downloading
|
||||||
obj_download.start()
|
obj_download.start(STATIC_IP_SERVER)
|
||||||
|
|
||||||
|
|
||||||
def donwload_series(tv_id: int, tv_name: str):
|
def donwload_series(tv_id: int, tv_name: str):
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
ANIME_FOLDER = "animeunity"
|
ANIME_FOLDER = "animeunity"
|
||||||
SERIES_FOLDER= "Serie"
|
SERIES_FOLDER= "Serie"
|
||||||
MOVIE_FOLDER = "Movie"
|
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']
|
@ -3,3 +3,5 @@
|
|||||||
STREAMING_FOLDER = "streamingcommunity"
|
STREAMING_FOLDER = "streamingcommunity"
|
||||||
MOVIE_FOLDER = "Movie"
|
MOVIE_FOLDER = "Movie"
|
||||||
SERIES_FOLDER = "Serie"
|
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']
|
@ -18,7 +18,7 @@ from .Core.Vix_player.player import VideoSource
|
|||||||
|
|
||||||
# Config
|
# Config
|
||||||
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
|
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
|
# Variable
|
||||||
@ -59,4 +59,4 @@ def download_film(id_film: str, title_name: str, domain: str):
|
|||||||
Downloader(
|
Downloader(
|
||||||
m3u8_playlist = master_playlist,
|
m3u8_playlist = master_playlist,
|
||||||
output_filename = os.path.join(mp4_path, mp4_format)
|
output_filename = os.path.join(mp4_path, mp4_format)
|
||||||
).start()
|
).start(STATIC_IP_SERVER)
|
@ -20,7 +20,7 @@ from .Core.Util import manage_selection, map_episode_title
|
|||||||
|
|
||||||
# Config
|
# Config
|
||||||
ROOT_PATH = config_manager.get('DEFAULT', 'root_path')
|
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
|
# Variable
|
||||||
@ -96,7 +96,7 @@ def donwload_video(tv_name: str, index_season_selected: int, index_episode_selec
|
|||||||
Downloader(
|
Downloader(
|
||||||
m3u8_playlist = master_playlist,
|
m3u8_playlist = master_playlist,
|
||||||
output_filename = os.path.join(mp4_path, mp4_name)
|
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:
|
def donwload_episode(tv_name: str, index_season_selected: int, donwload_all: bool = False) -> None:
|
||||||
|
@ -109,7 +109,7 @@ class M3U8_Segments:
|
|||||||
logging.info(f"Key: ('hex': {hex_content}, 'byte': {byte_content})")
|
logging.info(f"Key: ('hex': {hex_content}, 'byte': {byte_content})")
|
||||||
return 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.
|
Tests each proxy IP by sending a request to a corresponding segment URL.
|
||||||
"""
|
"""
|
||||||
@ -117,16 +117,18 @@ class M3U8_Segments:
|
|||||||
failed_ips = []
|
failed_ips = []
|
||||||
|
|
||||||
for i in range(len(self.fake_proxy_ip)):
|
for i in range(len(self.fake_proxy_ip)):
|
||||||
url_to_test = self.segments[i]
|
|
||||||
|
|
||||||
try:
|
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:
|
except:
|
||||||
|
|
||||||
# Log the error and add the IP to the list of failed IPs
|
# 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)
|
failed_ips.append(i)
|
||||||
|
|
||||||
# Remove the failed IPs from the fake_proxy_ip list
|
# Remove the failed IPs from the fake_proxy_ip list
|
||||||
@ -134,8 +136,13 @@ class M3U8_Segments:
|
|||||||
|
|
||||||
# Exit the program if 50% requests failed
|
# Exit the program if 50% requests failed
|
||||||
if len(failed_ips) / 2 > len(self.fake_proxy_ip):
|
if len(failed_ips) / 2 > len(self.fake_proxy_ip):
|
||||||
logging.error("All requests with ip failed. Exiting the program.")
|
logging.error("All requests with ip failed.")
|
||||||
sys.exit(0)
|
|
||||||
|
# Set to not use proxy
|
||||||
|
self.fake_proxy_ip = None
|
||||||
|
self.fake_proxy = False
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def parse_data(self, m3u8_content: str) -> None:
|
def parse_data(self, m3u8_content: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -182,10 +189,13 @@ class M3U8_Segments:
|
|||||||
for i in range(len(self.segments)):
|
for i in range(len(self.segments)):
|
||||||
segment_url = self.segments[i]
|
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.segments[i] = self.__gen_proxy__(segment_url, self.segments.index(segment_url))
|
||||||
self.__test_ip()
|
|
||||||
|
|
||||||
# Save new playlist of segment
|
# Save new playlist of segment
|
||||||
path_m3u8_file = os.path.join(self.tmp_folder, "playlist_fix.m3u8")
|
path_m3u8_file = os.path.join(self.tmp_folder, "playlist_fix.m3u8")
|
||||||
@ -226,6 +236,8 @@ class M3U8_Segments:
|
|||||||
Returns:
|
Returns:
|
||||||
str: The modified URL with the new IP address.
|
str: The modified URL with the new IP address.
|
||||||
"""
|
"""
|
||||||
|
if self.fake_proxy:
|
||||||
|
|
||||||
new_ip_address = self.fake_proxy_ip[url_index % len(self.fake_proxy_ip)]
|
new_ip_address = self.fake_proxy_ip[url_index % len(self.fake_proxy_ip)]
|
||||||
|
|
||||||
# Parse the original URL and replace the hostname with the new IP address
|
# Parse the original URL and replace the hostname with the new IP address
|
||||||
@ -233,6 +245,9 @@ class M3U8_Segments:
|
|||||||
|
|
||||||
return urlunparse(parsed_url)
|
return urlunparse(parsed_url)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return url
|
||||||
|
|
||||||
def make_requests_stream(self, ts_url: str, index: int, progress_bar: tqdm) -> None:
|
def make_requests_stream(self, ts_url: str, index: int, progress_bar: tqdm) -> None:
|
||||||
"""
|
"""
|
||||||
Downloads a TS segment and adds it to the segment queue.
|
Downloads a TS segment and adds it to the segment queue.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user