From 1b5d59a70d43dcd7002fef6358742572b7bd5b44 Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:33:27 +0700 Subject: [PATCH 01/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 1 + 1 file changed, 1 insertion(+) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index fd7c3a3a7381..ece1bee973ce 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -1,3 +1,4 @@ +import subprocess import requests from bs4 import BeautifulSoup, NavigableString, Tag from fake_useragent import UserAgent From e59c6358559ad8e10bcfac4e45dd91c1ec35eb32 Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:36:39 +0700 Subject: [PATCH 02/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index ece1bee973ce..4d346f818be6 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -154,6 +154,10 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] +def download_video(download_url: str, output_filename: str): + """Download video using ffmpeg.""" + command = ['ffmpeg', '-i', download_url, output_filename] + subprocess.run(command, check=True) if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() From f63d3296a905cfefa65f9626ae7c5dde9742b55e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:37:23 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- web_programming/fetch_anime_and_play.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 4d346f818be6..1b1316f68874 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -154,11 +154,13 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] + def download_video(download_url: str, output_filename: str): """Download video using ffmpeg.""" - command = ['ffmpeg', '-i', download_url, output_filename] + command = ["ffmpeg", "-i", download_url, output_filename] subprocess.run(command, check=True) + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) From 9d555f11b68c537d8c0c6b2c43105ddf9abbe789 Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:39:27 +0700 Subject: [PATCH 04/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 1b1316f68874..1439cf1765d9 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -3,6 +3,20 @@ from bs4 import BeautifulSoup, NavigableString, Tag from fake_useragent import UserAgent +import re + +def is_safe_filename(filename: str) -> bool: + # A simple regex to check if the filename is safe (no special characters) + return re.match(r'^[\w\-. ]+$', filename) is not None + +def download_video(download_url: str, output_filename: str): + """Download video using ffmpeg.""" + if not is_safe_filename(output_filename): + raise ValueError("Unsafe output filename provided.") + + command = ["ffmpeg", "-i", download_url, output_filename] + subprocess.run(command, check=True) + BASE_URL = "https://ww1.gogoanime2.org" @@ -154,13 +168,6 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] - -def download_video(download_url: str, output_filename: str): - """Download video using ffmpeg.""" - command = ["ffmpeg", "-i", download_url, output_filename] - subprocess.run(command, check=True) - - if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) From 1f6c5cc5bdd765b98c96a9ec4f3792f2cebf40e7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:39:48 +0000 Subject: [PATCH 05/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- web_programming/fetch_anime_and_play.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 1439cf1765d9..0581028e6150 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -5,9 +5,11 @@ import re + def is_safe_filename(filename: str) -> bool: # A simple regex to check if the filename is safe (no special characters) - return re.match(r'^[\w\-. ]+$', filename) is not None + return re.match(r"^[\w\-. ]+$", filename) is not None + def download_video(download_url: str, output_filename: str): """Download video using ffmpeg.""" @@ -17,6 +19,7 @@ def download_video(download_url: str, output_filename: str): command = ["ffmpeg", "-i", download_url, output_filename] subprocess.run(command, check=True) + BASE_URL = "https://ww1.gogoanime2.org" @@ -168,6 +171,7 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) From a493e3e4e947ad6bb623cc3e211a927ae381a18a Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:41:04 +0700 Subject: [PATCH 06/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 0581028e6150..38049efbff8e 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -2,26 +2,12 @@ import requests from bs4 import BeautifulSoup, NavigableString, Tag from fake_useragent import UserAgent - import re - -def is_safe_filename(filename: str) -> bool: - # A simple regex to check if the filename is safe (no special characters) - return re.match(r"^[\w\-. ]+$", filename) is not None - - -def download_video(download_url: str, output_filename: str): - """Download video using ffmpeg.""" - if not is_safe_filename(output_filename): - raise ValueError("Unsafe output filename provided.") - - command = ["ffmpeg", "-i", download_url, output_filename] - subprocess.run(command, check=True) - - BASE_URL = "https://ww1.gogoanime2.org" +def is_safe_filename(filename: str) -> bool: + return re.match(r'^[\w\-. ]+$', filename) is not None def search_scraper(anime_name: str) -> list: """[summary] @@ -172,6 +158,12 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] +def download_video(download_url: str, output_filename: str): + if not is_safe_filename(output_filename): + raise ValueError("Unsafe output filename provided.") + command = ["ffmpeg", "-i", download_url, output_filename] + subprocess.run(command, check=True) + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) From 3b4532c4c65d4389a728472afc3a8edb9b8766f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:41:25 +0000 Subject: [PATCH 07/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- web_programming/fetch_anime_and_play.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 38049efbff8e..00d302cfda6e 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -6,8 +6,10 @@ BASE_URL = "https://ww1.gogoanime2.org" + def is_safe_filename(filename: str) -> bool: - return re.match(r'^[\w\-. ]+$', filename) is not None + return re.match(r"^[\w\-. ]+$", filename) is not None + def search_scraper(anime_name: str) -> list: """[summary] @@ -164,6 +166,7 @@ def download_video(download_url: str, output_filename: str): command = ["ffmpeg", "-i", download_url, output_filename] subprocess.run(command, check=True) + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) From 660930148daddaef37cf8f8ff6a149c12af0a9de Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:42:11 +0700 Subject: [PATCH 08/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 00d302cfda6e..777a1d6344bc 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -199,3 +199,15 @@ def download_video(download_url: str, output_filename: str): episode_url, download_url = get_anime_episode(chosen_episode["url"]) print(f"\nTo watch, ctrl+click on {episode_url}.") print(f"To download, ctrl+click on {download_url}.") + + # Add an option to download or not + download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower() + if download_choice in ["yes", "y"]: + output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed + download_video(download_url, output_filename) + print(f"{chosen_episode['title']} has been downloaded as {output_filename}.") + else: + print("Download skipped.") + + #if error download please install ffmeg + #brew install ffmpeg for mac From dabb27c8061fc3444643ecf267c0244f03a5bed7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:42:31 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- web_programming/fetch_anime_and_play.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 777a1d6344bc..c988de655328 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -199,15 +199,21 @@ def download_video(download_url: str, output_filename: str): episode_url, download_url = get_anime_episode(chosen_episode["url"]) print(f"\nTo watch, ctrl+click on {episode_url}.") print(f"To download, ctrl+click on {download_url}.") - + # Add an option to download or not - download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower() + download_choice = ( + input("\nDo you want to download this episode? (yes/no): ") + .strip() + .lower() + ) if download_choice in ["yes", "y"]: output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed download_video(download_url, output_filename) - print(f"{chosen_episode['title']} has been downloaded as {output_filename}.") + print( + f"{chosen_episode['title']} has been downloaded as {output_filename}." + ) else: print("Download skipped.") - #if error download please install ffmeg - #brew install ffmpeg for mac + # if error download please install ffmeg + # brew install ffmpeg for mac From a4ede93074c3aa02de30eba194dd7608c8372ebc Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:33:48 +0700 Subject: [PATCH 10/11] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 34 ++++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index c988de655328..296f51259fac 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -2,15 +2,10 @@ import requests from bs4 import BeautifulSoup, NavigableString, Tag from fake_useragent import UserAgent -import re BASE_URL = "https://ww1.gogoanime2.org" -def is_safe_filename(filename: str) -> bool: - return re.match(r"^[\w\-. ]+$", filename) is not None - - def search_scraper(anime_name: str) -> list: """[summary] @@ -159,14 +154,11 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] - def download_video(download_url: str, output_filename: str): - if not is_safe_filename(output_filename): - raise ValueError("Unsafe output filename provided.") - command = ["ffmpeg", "-i", download_url, output_filename] + """Download video using ffmpeg.""" + command = ['ffmpeg', '-i', download_url, output_filename] subprocess.run(command, check=True) - if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) @@ -186,34 +178,28 @@ def download_video(download_url: str, output_filename: str): episode_list = search_anime_episode_list(chosen_anime["url"]) if len(episode_list) == 0: - print("No episode found for this anime") + print("No episodes found for this anime") else: print(f"Found {len(episode_list)} results: ") for i, episode in enumerate(episode_list): - print(f"{i+1}. {episode['title']}") + print(f"{i + 1}. {episode['title']}") - episode_choice = int(input("\nChoose an episode by serial no: ").strip()) + episode_choice = int(input("\nChoose an episode by serial number: ").strip()) chosen_episode = episode_list[episode_choice - 1] print(f"You chose {chosen_episode['title']}. Searching...") episode_url, download_url = get_anime_episode(chosen_episode["url"]) print(f"\nTo watch, ctrl+click on {episode_url}.") - print(f"To download, ctrl+click on {download_url}.") + # Add an option to download or not - download_choice = ( - input("\nDo you want to download this episode? (yes/no): ") - .strip() - .lower() - ) + download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower() if download_choice in ["yes", "y"]: output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed download_video(download_url, output_filename) - print( - f"{chosen_episode['title']} has been downloaded as {output_filename}." - ) + print(f"{chosen_episode['title']} has been downloaded as {output_filename}.") else: print("Download skipped.") - # if error download please install ffmeg - # brew install ffmpeg for mac + #if error download please install ffmeg + #brew install ffmpeg for mac From 6f714d8e259fcbe66384148c56ce0ac20620c090 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 06:35:50 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- web_programming/fetch_anime_and_play.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index 296f51259fac..6c51cc977997 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -154,11 +154,13 @@ def get_anime_episode(episode_endpoint: str) -> list: return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"] + def download_video(download_url: str, output_filename: str): """Download video using ffmpeg.""" - command = ['ffmpeg', '-i', download_url, output_filename] + command = ["ffmpeg", "-i", download_url, output_filename] subprocess.run(command, check=True) + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) @@ -184,22 +186,29 @@ def download_video(download_url: str, output_filename: str): for i, episode in enumerate(episode_list): print(f"{i + 1}. {episode['title']}") - episode_choice = int(input("\nChoose an episode by serial number: ").strip()) + episode_choice = int( + input("\nChoose an episode by serial number: ").strip() + ) chosen_episode = episode_list[episode_choice - 1] print(f"You chose {chosen_episode['title']}. Searching...") episode_url, download_url = get_anime_episode(chosen_episode["url"]) print(f"\nTo watch, ctrl+click on {episode_url}.") - # Add an option to download or not - download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower() + download_choice = ( + input("\nDo you want to download this episode? (yes/no): ") + .strip() + .lower() + ) if download_choice in ["yes", "y"]: output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed download_video(download_url, output_filename) - print(f"{chosen_episode['title']} has been downloaded as {output_filename}.") + print( + f"{chosen_episode['title']} has been downloaded as {output_filename}." + ) else: print("Download skipped.") - #if error download please install ffmeg - #brew install ffmpeg for mac + # if error download please install ffmeg + # brew install ffmpeg for mac