diff --git a/Src/Lib/Downloader/HLS/downloader.py b/Src/Lib/Downloader/HLS/downloader.py index 176a4a4..50f9e2f 100644 --- a/Src/Lib/Downloader/HLS/downloader.py +++ b/Src/Lib/Downloader/HLS/downloader.py @@ -138,14 +138,14 @@ class HLS_Downloader(): Returns: str: The text content of the response. """ - - if "http" not in url or "https" not in url: + + if "http" not in str(url).lower().strip() or "https" not in str(url).lower().strip(): logging.error(f"Invalid url: {url}") sys.exit(0) # Send a GET request to the provided URL logging.info(f"Test url: {url}") - response = httpx.get(url, headers=headers_index) + response = httpx.get(url, headers=headers_index, timeout=20) try: response.raise_for_status() @@ -268,7 +268,7 @@ class HLS_Downloader(): # Download the video segments self.expected_real_time = video_m3u8.expected_real_time - list_available_resolution_size = self.main_obj_parser._video.get_list_resolution_and_size(video_m3u8.expected_real_time_s) + #list_available_resolution_size = self.main_obj_parser._video.get_list_resolution_and_size(video_m3u8.expected_real_time_s) #console.print(f"[cyan]Estimate size [white]=> [red]{sorted(list_available_resolution_size, reverse=True)}") video_m3u8.download_streams(f"{Colors.MAGENTA}video") @@ -406,6 +406,10 @@ class HLS_Downloader(): if not os.path.exists(path_join_video): + # If codec not exist set to None + if not hasattr(self, 'codec'): + self.codec = None + # Join the video segments into a single video file join_video( video_path = self.downloaded_video[0].get('path'), @@ -428,6 +432,10 @@ class HLS_Downloader(): if not os.path.exists(path_join_video_audio): + # If codec not exist set to None + if not hasattr(self, 'codec'): + self.codec = None + # Join the video with audio segments into a single video with audio file join_audios( video_path = self.downloaded_video[0].get('path'), diff --git a/Src/Lib/Downloader/HLS/segments.py b/Src/Lib/Downloader/HLS/segments.py index 31dede6..addc41c 100644 --- a/Src/Lib/Downloader/HLS/segments.py +++ b/Src/Lib/Downloader/HLS/segments.py @@ -217,16 +217,16 @@ class M3U8_Segments: with httpx.Client(proxies=proxy, verify=True) as client: if 'key_base_url' in self.__dict__: - response = client.get(ts_url, headers=random_headers(self.key_base_url), timeout=REQUEST_TIMEOUT) + response = client.get(ts_url, headers=random_headers(self.key_base_url), timeout=REQUEST_TIMEOUT, follow_redirects=True) else: - response = client.get(ts_url, headers={'user-agent': get_headers()}, timeout=REQUEST_TIMEOUT) + response = client.get(ts_url, headers={'user-agent': get_headers()}, timeout=REQUEST_TIMEOUT, follow_redirects=True) else: with httpx.Client(verify=True) as client_2: if 'key_base_url' in self.__dict__: - response = client_2.get(ts_url, headers=random_headers(self.key_base_url), timeout=REQUEST_TIMEOUT) + response = client_2.get(ts_url, headers=random_headers(self.key_base_url), timeout=REQUEST_TIMEOUT, follow_redirects=True) else: - response = client_2.get(ts_url, headers={'user-agent': get_headers()}, timeout=REQUEST_TIMEOUT) + response = client_2.get(ts_url, headers={'user-agent': get_headers()}, timeout=REQUEST_TIMEOUT, follow_redirects=True) # Get response content response.raise_for_status() diff --git a/Src/Lib/FFmpeg/util.py b/Src/Lib/FFmpeg/util.py index b043b3b..fc6ebab 100644 --- a/Src/Lib/FFmpeg/util.py +++ b/Src/Lib/FFmpeg/util.py @@ -68,8 +68,12 @@ def get_video_duration(file_path: str) -> float: probe_result = json.loads(stdout) # Extract duration from the video information - return float(probe_result['format']['duration']) - + try: + return float(probe_result['format']['duration']) + except: + logging.error("Cant get duration.") + return 1 + except Exception as e: logging.error(f"Error get video duration: {e}") sys.exit(0)