From c86d2a8cac599cf9a47cc84ddbc3303a9e5baef9 Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Wed, 29 May 2024 19:14:00 +0200 Subject: [PATCH] Add other special char, update readme with temux --- README.md | 13 ++++++++++++- Src/Lib/Hls/downloader.py | 2 +- Src/Lib/Hls/segments.py | 7 ++++--- Src/Lib/M3U8/parser.py | 29 ++++++++++++++++------------- Src/Util/os.py | 2 +- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f301f46..a05a96e 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,13 @@ You can chat, help improve this repo, or just hang around for some fun in the ** * [INSTALLATION](#installation) * [Requirement](#requirement) * [Usage](#usage) + * [Win 7](https://github.com/Ghost6446/StreamingCommunity_api/wiki/Installation#win-7) + * [Termux](https://github.com/Ghost6446/StreamingCommunity_api/wiki/Termux) * [CONFIGURATION](#Configuration) * [DOCKER](#docker) * [TUTORIAL](#tutorial) +* [TO DO](#to-do) + ## Requirement @@ -49,6 +53,7 @@ python run.py python3 run.py ``` + ## Configuration You can change some behaviors by tweaking the configuration file. @@ -164,7 +169,7 @@ You can change some behaviors by tweaking the configuration file. > [!IMPORTANT] -> If you're on **Windows** you'll need to use double black slashes. On Linux/MacOS, one slash is fine. +> If you're on **Windows** you'll need to use double back slash. On Linux/MacOS, one slash is fine. #### Path examples: @@ -205,3 +210,9 @@ docker run -it -p 8000:8000 -v /path/to/download:/app/Video streaming-community- ## Tutorial For a detailed walkthrough, refer to the [video tutorial](https://www.youtube.com/watch?v=Ok7hQCgxqLg&ab_channel=Nothing) + + +## To do +- GUI +- Website api +- Add other site \ No newline at end of file diff --git a/Src/Lib/Hls/downloader.py b/Src/Lib/Hls/downloader.py index c551d72..e875bcf 100644 --- a/Src/Lib/Hls/downloader.py +++ b/Src/Lib/Hls/downloader.py @@ -206,7 +206,7 @@ class Downloader(): logging.info(f"M3U8 index select: {self.m3u8_index}, with resolution: {video_res}") # Get URI of the best quality and codecs parameters - console.log(f"[cyan]Find resolution [white]=> [red]{list_available_resolution}") + console.log(f"[cyan]Find resolution [white]=> [red]{sorted(list_available_resolution, reverse=True)}") # Fix URL if it is not complete with http:\\site_name.domain\... if "http" not in self.m3u8_index: diff --git a/Src/Lib/Hls/segments.py b/Src/Lib/Hls/segments.py index 28ef0c1..7c049b2 100644 --- a/Src/Lib/Hls/segments.py +++ b/Src/Lib/Hls/segments.py @@ -175,11 +175,12 @@ class M3U8_Segments: # Send a GET request to retrieve the index M3U8 file response = requests.get(self.url, headers=headers_index) - response.raise_for_status() # Raise an exception for HTTP errors + response.raise_for_status() # Save the M3U8 file to the temporary folder - path_m3u8_file = os.path.join(self.tmp_folder, "playlist.m3u8") - open(path_m3u8_file, "w+").write(response.text) + if response.ok: + path_m3u8_file = os.path.join(self.tmp_folder, "playlist.m3u8") + open(path_m3u8_file, "w+").write(response.text) # Parse the text from the M3U8 index file self.parse_data(response.text) diff --git a/Src/Lib/M3U8/parser.py b/Src/Lib/M3U8/parser.py index 7668229..4c4d476 100644 --- a/Src/Lib/M3U8/parser.py +++ b/Src/Lib/M3U8/parser.py @@ -434,8 +434,7 @@ class M3U8_Parser: return resolution # Default resolution return (not best) - logging.error("No resolution found with custom parsing.") - logging.warning("Try set remove duplicate line to TRUE.") + logging.warning("No resolution found with custom parsing.") return (0, 0) def __parse_video_info__(self, m3u8_obj) -> None: @@ -449,6 +448,15 @@ class M3U8_Parser: try: for playlist in m3u8_obj.playlists: + there_is_codec = not M3U8_Parser.extract_resolution(playlist.uri) == (0,0) + + if there_is_codec: + self.codec = M3U8_Codec( + playlist.stream_info.bandwidth, + None, + playlist.stream_info.codecs + ) + # Direct access resolutions in m3u8 obj if playlist.stream_info.resolution is not None: @@ -456,6 +464,9 @@ class M3U8_Parser: "uri": playlist.uri, "resolution": playlist.stream_info.resolution }) + + if there_is_codec: + self.codec.resolution = playlist.stream_info.resolution # Find resolutions in uri else: @@ -465,18 +476,10 @@ class M3U8_Parser: "resolution": M3U8_Parser.extract_resolution(playlist.uri) }) - # Dont stop - continue + if there_is_codec: + self.codec.resolution = M3U8_Parser.extract_resolution(playlist.uri) - # Check if all key is present to create codec - try: - self.codec = M3U8_Codec( - playlist.stream_info.bandwidth, - playlist.stream_info.resolution, - playlist.stream_info.codecs - ) - except: - logging.error(f"Error parsing codec: {e}") + continue except Exception as e: logging.error(f"Error parsing video info: {e}") diff --git a/Src/Util/os.py b/Src/Util/os.py index a0b2b89..6f7260f 100644 --- a/Src/Util/os.py +++ b/Src/Util/os.py @@ -29,7 +29,7 @@ from .console import console # --> OS FILE ASCII -special_chars_to_remove = ['!','@','#','$','%','^','&','*','(',')','[',']','{','}','<','|','`','~',"'",'"',';',':',',','?',"\\","/"] +special_chars_to_remove = ['!','@','#','$','%','^','&','*','(',')','[',']','{','}','<','|','`','~',"'",'"',';',':',',','?',"\\","/","\t"] def get_max_length_by_os(system: str) -> int: """