From 37e75370b0815299334461260643dff75317e657 Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Tue, 4 Jun 2024 22:06:46 +0200 Subject: [PATCH] Only 4 workers. --- Src/Api/Animeunity/Core/Vix_player/player.py | 45 +------------------ .../Core/Vix_player/player.py | 45 +------------------ Src/Api/Streamingcommunity/costant.py | 5 --- Src/Api/Streamingcommunity/film.py | 4 +- Src/Api/Streamingcommunity/series.py | 4 +- Src/Lib/Hls/segments.py | 31 +++++++++++++ config.json | 2 +- 7 files changed, 38 insertions(+), 98 deletions(-) diff --git a/Src/Api/Animeunity/Core/Vix_player/player.py b/Src/Api/Animeunity/Core/Vix_player/player.py index 30b30d0..bcac59a 100644 --- a/Src/Api/Animeunity/Core/Vix_player/player.py +++ b/Src/Api/Animeunity/Core/Vix_player/player.py @@ -206,47 +206,4 @@ class VideoSource: new_url = m._replace(query=new_query) # Replace the old query string with the new one final_url = urlunparse(new_url) # Construct the final URL from the modified parts - if "canPlayFHD" in current_params and self.window_video.quality == "1080": - return final_url - else: - console.log("[red]Rebuild master playlist.") - return self.re_build_master() - - def re_build_master(self) -> str: - """ - Rebuild the master playlist. - - Returns: - str: The rebuilt master playlist text, or an empty string if there's an error. - """ - try: - index_resolution = None - master_url = f'https://vixcloud.co/playlist/{self.window_video.id}' - index_url = f'https://vixcloud.co/playlist/{self.window_video.id}?type=video&rendition={self.window_video.quality}p' - - try: - # Fetch the master playlist text - master_text = requests.get(master_url).text - except requests.RequestException as e: - logging.error(f"Error fetching master playlist from URL: {master_url}, error: {e}") - return "" - - # Find the resolution in the index URL - for resolution in [(7680, 4320), (3840, 2160), (2560, 1440), (1920, 1080), (1280, 720), (640, 480)]: - if str(resolution[1]) in index_url: - index_resolution = resolution - break - - # Add resolution and index URL to the master playlist text - if index_resolution: - master_text += f'\n#EXT-X-STREAM-INF:BANDWIDTH=2150000,CODECS="avc1.640028,mp4a.40.2",RESOLUTION={index_resolution[0]}x{index_resolution[1]},SUBTITLES="subs"\n' - master_text += index_url - - else: - logging.warning(f"No matching resolution found in index URL: {index_url}") - - return master_text - - except Exception as e: - logging.error(f"Unexpected error in re_build_master: {e}") - sys.exit(0) + return final_url diff --git a/Src/Api/Streamingcommunity/Core/Vix_player/player.py b/Src/Api/Streamingcommunity/Core/Vix_player/player.py index 545944c..e72e7e0 100644 --- a/Src/Api/Streamingcommunity/Core/Vix_player/player.py +++ b/Src/Api/Streamingcommunity/Core/Vix_player/player.py @@ -239,47 +239,4 @@ class VideoSource: new_url = m._replace(query=new_query) # Replace the old query string with the new one final_url = urlunparse(new_url) # Construct the final URL from the modified parts - if "canPlayFHD" in current_params and self.window_video.quality == "1080": - return final_url - else: - console.log("[red]Rebuild master playlist.") - return self.re_build_master() - - def re_build_master(self) -> str: - """ - Rebuild the master playlist. - - Returns: - str: The rebuilt master playlist text, or an empty string if there's an error. - """ - try: - index_resolution = None - master_url = f'https://vixcloud.co/playlist/{self.window_video.id}' - index_url = f'https://vixcloud.co/playlist/{self.window_video.id}?type=video&rendition={self.window_video.quality}p' - - try: - # Fetch the master playlist text - master_text = requests.get(master_url).text - except requests.RequestException as e: - logging.error(f"Error fetching master playlist from URL: {master_url}, error: {e}") - return "" - - # Find the resolution in the index URL - for resolution in [(7680, 4320), (3840, 2160), (2560, 1440), (1920, 1080), (1280, 720), (640, 480)]: - if str(resolution[1]) in index_url: - index_resolution = resolution - break - - # Add resolution and index URL to the master playlist text - if index_resolution: - master_text += f'\n#EXT-X-STREAM-INF:BANDWIDTH=2150000,CODECS="avc1.640028,mp4a.40.2",RESOLUTION={index_resolution[0]}x{index_resolution[1]},SUBTITLES="subs"\n' - master_text += index_url - - else: - logging.warning(f"No matching resolution found in index URL: {index_url}") - - return master_text - - except Exception as e: - logging.error(f"Unexpected error in re_build_master: {e}") - sys.exit(0) + return final_url diff --git a/Src/Api/Streamingcommunity/costant.py b/Src/Api/Streamingcommunity/costant.py index 2ebb247..6038c67 100644 --- a/Src/Api/Streamingcommunity/costant.py +++ b/Src/Api/Streamingcommunity/costant.py @@ -3,8 +3,3 @@ STREAMING_FOLDER = "streamingcommunity" MOVIE_FOLDER = "Movie" SERIES_FOLDER = "Serie" - -SERVER_IP = ['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'] \ No newline at end of file diff --git a/Src/Api/Streamingcommunity/film.py b/Src/Api/Streamingcommunity/film.py index 47b0e90..2b9d7bf 100644 --- a/Src/Api/Streamingcommunity/film.py +++ b/Src/Api/Streamingcommunity/film.py @@ -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, SERVER_IP +from .costant import STREAMING_FOLDER, MOVIE_FOLDER # 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(SERVER_IP) \ No newline at end of file + ).start() \ No newline at end of file diff --git a/Src/Api/Streamingcommunity/series.py b/Src/Api/Streamingcommunity/series.py index f10be43..9b2ecc0 100644 --- a/Src/Api/Streamingcommunity/series.py +++ b/Src/Api/Streamingcommunity/series.py @@ -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, SERVER_IP +from .costant import STREAMING_FOLDER, SERIES_FOLDER # 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(SERVER_IP) + ).start() def donwload_episode(tv_name: str, index_season_selected: int, donwload_all: bool = False) -> None: diff --git a/Src/Lib/Hls/segments.py b/Src/Lib/Hls/segments.py index 9a5e428..fe2a131 100644 --- a/Src/Lib/Hls/segments.py +++ b/Src/Lib/Hls/segments.py @@ -109,6 +109,34 @@ class M3U8_Segments: logging.info(f"Key: ('hex': {hex_content}, 'byte': {byte_content})") return byte_content + def __test_ip(self): + """ + Tests each proxy IP by sending a request to a corresponding segment URL. + """ + + failed_ips = [] + + for i in range(len(self.fake_proxy_ip)): + url_to_test = self.segments[i] + + try: + + # 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}") + failed_ips.append(i) + + # Remove the failed IPs from the fake_proxy_ip list + self.fake_proxy_ip = [ip for j, ip in enumerate(self.fake_proxy_ip) if j not in failed_ips] + + # 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) + def parse_data(self, m3u8_content: str) -> None: """ Parses the M3U8 content to extract segment information. @@ -156,6 +184,9 @@ class M3U8_Segments: self.segments[i] = self.__gen_proxy__(segment_url, self.segments.index(segment_url)) + # Test new url with ip + self.__test_ip() + # Save new playlist of segment path_m3u8_file = os.path.join(self.tmp_folder, "playlist_fix.m3u8") with open(path_m3u8_file, "w") as file: diff --git a/config.json b/config.json index b07741d..4cfd9e6 100644 --- a/config.json +++ b/config.json @@ -17,7 +17,7 @@ "segments": { "user-agent": ""} }, "M3U8_DOWNLOAD": { - "tdqm_workers": 30, + "tdqm_workers": 4, "tqdm_use_large_bar": true, "download_video": true, "download_audio": true,