From 32b876a08cb9f4642932cdd2a68272c53b1c20a4 Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Sun, 2 Jun 2024 08:21:34 +0200 Subject: [PATCH] Add force 1080p. --- Src/Api/Animeunity/Core/Vix_player/player.py | 45 ++++++++++++++++++- .../Core/Vix_player/player.py | 45 ++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/Src/Api/Animeunity/Core/Vix_player/player.py b/Src/Api/Animeunity/Core/Vix_player/player.py index bcac59a..30b30d0 100644 --- a/Src/Api/Animeunity/Core/Vix_player/player.py +++ b/Src/Api/Animeunity/Core/Vix_player/player.py @@ -206,4 +206,47 @@ 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 - return final_url + 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) diff --git a/Src/Api/Streamingcommunity/Core/Vix_player/player.py b/Src/Api/Streamingcommunity/Core/Vix_player/player.py index e72e7e0..545944c 100644 --- a/Src/Api/Streamingcommunity/Core/Vix_player/player.py +++ b/Src/Api/Streamingcommunity/Core/Vix_player/player.py @@ -239,4 +239,47 @@ 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 - return final_url + 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)