From 82cba2a937808182f6a44d188f5ae3aaccc199e6 Mon Sep 17 00:00:00 2001 From: Alfian Ali Murtadlo <115053112+AlfianAliM@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:03:11 +0700 Subject: [PATCH 1/2] Update fetch_anime_and_play.py --- web_programming/fetch_anime_and_play.py | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index fd7c3a3a7381..ac553b95a1c4 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -1,5 +1,7 @@ +import os +import subprocess import requests -from bs4 import BeautifulSoup, NavigableString, Tag +from bs4 import BeautifulSoup from fake_useragent import UserAgent BASE_URL = "https://ww1.gogoanime2.org" @@ -154,6 +156,17 @@ 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) -> None: + """Download video using ffmpeg.""" + command = ['ffmpeg', '-i', download_url, output_filename] + try: + subprocess.run(command, check=True) + except FileNotFoundError: + # If ffmpeg is not found, instruct the user on how to install it + print("Error: ffmpeg is not installed.") + print("Please install ffmpeg using the following command:") + print("brew install ffmpeg") # This is the command for macOS + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) @@ -186,3 +199,15 @@ def get_anime_episode(episode_endpoint: str) -> list: 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 89b8fed50c76ee94226de6ac930d66e8d3a1cdb4 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:05:25 +0000 Subject: [PATCH 2/2] [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 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web_programming/fetch_anime_and_play.py b/web_programming/fetch_anime_and_play.py index ac553b95a1c4..fc021de5ddbb 100644 --- a/web_programming/fetch_anime_and_play.py +++ b/web_programming/fetch_anime_and_play.py @@ -158,7 +158,7 @@ def get_anime_episode(episode_endpoint: str) -> list: def download_video(download_url: str, output_filename: str) -> None: """Download video using ffmpeg.""" - command = ['ffmpeg', '-i', download_url, output_filename] + command = ["ffmpeg", "-i", download_url, output_filename] try: subprocess.run(command, check=True) except FileNotFoundError: @@ -167,6 +167,7 @@ def download_video(download_url: str, output_filename: str) -> None: print("Please install ffmpeg using the following command:") print("brew install ffmpeg") # This is the command for macOS + if __name__ == "__main__": anime_name = input("Enter anime name: ").strip() anime_list = search_scraper(anime_name) @@ -201,13 +202,19 @@ def download_video(download_url: str, output_filename: str) -> None: 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