Fix index and playlist

This commit is contained in:
Lovi 2024-11-07 11:42:42 +01:00
parent 1aeac8fc59
commit c1662317f2
4 changed files with 47 additions and 38 deletions

View File

@ -114,10 +114,10 @@ class HttpClient:
) )
response.raise_for_status() response.raise_for_status()
return response.text # Return the response text return response.text
except Exception as e: except Exception as e:
logging.error(f"Request to {url} failed: {response.status_code} when get text.") logging.info(f"Request to {url} failed with error: {e}")
return 404 return 404
def get_content(self, url): def get_content(self, url):
@ -740,50 +740,60 @@ class HLS_Downloader:
# Determine whether to process a playlist or index # Determine whether to process a playlist or index
if self.m3u8_playlist: if self.m3u8_playlist:
if self.m3u8_playlist is not None:
# Parse data from url and get if is a master playlist # Parse data from url and check if is a master playlist
self.instace_parserClass.parse_data(uri=self.m3u8_playlist, raw_content=HttpClient().get(self.m3u8_playlist)) test_raw_content = HttpClient().get(self.m3u8_playlist)
is_masterPlaylist = self.instace_parserClass.is_master_playlist if test_raw_content != 404:
self.instace_parserClass.parse_data(uri=self.m3u8_playlist, raw_content=test_raw_content)
is_masterPlaylist = self.instace_parserClass.is_master_playlist
# Check if it's a real master playlist # Check if it's a real master playlist
if is_masterPlaylist: if is_masterPlaylist:
if not GET_ONLY_LINK: if not GET_ONLY_LINK:
r_proc = self._process_playlist() r_proc = self._process_playlist()
if r_proc == 404: if r_proc == 404:
return 404 return 404
else: else:
return None return None
else:
return {
'path': self.output_filename,
'url': self.m3u8_playlist
}
else: else:
return { console.log("[red]Error: URL passed to M3U8_Parser is an index playlist; expected a master playlist. Crucimorfo strikes again!")
'path': self.output_filename,
'url': self.m3u8_playlist
}
else: else:
console.log("[red]Error: URL passed to M3U8_Parser is an index playlist; expected a master playlist. Crucimorfo strikes again!") console.log("[red]Error: m3u8_playlist is None")
elif self.m3u8_index: elif self.m3u8_index:
if self.m3u8_index is not None:
# Parse data from url and get if is a master playlist # Parse data from url and check if is a master playlist
self.instace_parserClass.parse_data(uri=self.m3u8_index, raw_content=HttpClient().get(self.m3u8_playlist)) test_raw_content = HttpClient().get(self.m3u8_index)
is_masterPlaylist = self.instace_parserClass.is_master_playlist if test_raw_content != 404:
self.instace_parserClass.parse_data(uri=self.m3u8_index, raw_content=test_raw_content)
is_masterPlaylist = self.instace_parserClass.is_master_playlist
# Check if it's a real index playlist # Check if it's a real index playlist
if not is_masterPlaylist: if not is_masterPlaylist:
if not GET_ONLY_LINK: if not GET_ONLY_LINK:
self._process_index() self._process_index()
return None return None
else:
return {
'path': self.output_filename,
'url': self.m3u8_index
}
else: else:
return { console.log("[red]Error: URL passed to M3U8_Parser is an master playlist; expected a index playlist. Crucimorfo strikes again!")
'path': self.output_filename,
'url': self.m3u8_index
}
else: else:
console.log("[red]Error: URL passed to M3U8_Parser is an master playlist; expected a index playlist. Crucimorfo strikes again!") console.log("[red]Error: m3u8_index is None")
def _clean(self, out_path: str) -> None: def _clean(self, out_path: str) -> None:

View File

@ -444,7 +444,6 @@ class M3U8_Parser:
- m3u8_content (str): The content of the M3U8 file. - m3u8_content (str): The content of the M3U8 file.
""" """
# Get obj of the m3u8 text content download, dictionary with video, audio, segments, subtitles # Get obj of the m3u8 text content download, dictionary with video, audio, segments, subtitles
m3u8_obj = loads(raw_content, uri) m3u8_obj = loads(raw_content, uri)

View File

@ -14,6 +14,6 @@ from Src.Lib.Downloader import HLS_Downloader
# Test # Test
HLS_Downloader( HLS_Downloader(
output_filename=r".\EP_1.mp4", output_filename=r".\Video\undefined.mp4",
m3u8_playlist="" m3u8_index=""
).start() ).start()

View File

@ -15,5 +15,5 @@ from Src.Lib.Downloader import MP4_downloader
# Test # Test
MP4_downloader( MP4_downloader(
"", "",
"EP_1.mp4" ".\Video\undefined.mp4"
) )