Skip to content

Commit 4944dd0

Browse files
authored
Update fetch_anime_and_play.py
1 parent 00e9d86 commit 4944dd0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

web_programming/fetch_anime_and_play.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
from bs4 import BeautifulSoup, NavigableString, Tag
33
from fake_useragent import UserAgent
4+
import subprocess
45

56
BASE_URL = "https://ww1.gogoanime2.org"
67

@@ -153,6 +154,16 @@ def get_anime_episode(episode_endpoint: str) -> list:
153154

154155
return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
155156

157+
def download_video(download_url: str, output_filename: str) -> None:
158+
"""Download video using ffmpeg."""
159+
command = ['ffmpeg', '-i', download_url, output_filename]
160+
try:
161+
subprocess.run(command, check=True)
162+
except FileNotFoundError:
163+
# If ffmpeg is not found, instruct the user on how to install it
164+
print("Error: ffmpeg is not installed.")
165+
print("Please install ffmpeg using the following command:")
166+
print("brew install ffmpeg") # This is the command for macOS
156167

157168
if __name__ == "__main__":
158169
anime_name = input("Enter anime name: ").strip()
@@ -185,4 +196,15 @@ def get_anime_episode(episode_endpoint: str) -> list:
185196

186197
episode_url, download_url = get_anime_episode(chosen_episode["url"])
187198
print(f"\nTo watch, ctrl+click on {episode_url}.")
188-
print(f"To download, ctrl+click on {download_url}.")
199+
200+
# Add an option to download or not
201+
download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower()
202+
if download_choice in ["yes", "y"]:
203+
output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed
204+
download_video(download_url, output_filename)
205+
print(f"{chosen_episode['title']} has been downloaded as {output_filename}.")
206+
else:
207+
print("Download skipped.")
208+
209+
#if error download please install ffmeg
210+
#brew install ffmpeg for mac

0 commit comments

Comments
 (0)