Skip to content

Commit 4bc6a88

Browse files
authored
Update fetch_anime_and_play.py
1 parent 00e9d86 commit 4bc6a88

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

web_programming/fetch_anime_and_play.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import subprocess
12
import requests
23
from bs4 import BeautifulSoup, NavigableString, Tag
34
from fake_useragent import UserAgent
@@ -153,6 +154,10 @@ 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):
158+
"""Download video using ffmpeg."""
159+
command = ['ffmpeg', '-i', download_url, output_filename]
160+
subprocess.run(command, check=True)
156161

157162
if __name__ == "__main__":
158163
anime_name = input("Enter anime name: ").strip()
@@ -173,16 +178,28 @@ def get_anime_episode(episode_endpoint: str) -> list:
173178

174179
episode_list = search_anime_episode_list(chosen_anime["url"])
175180
if len(episode_list) == 0:
176-
print("No episode found for this anime")
181+
print("No episodes found for this anime")
177182
else:
178183
print(f"Found {len(episode_list)} results: ")
179184
for i, episode in enumerate(episode_list):
180-
print(f"{i+1}. {episode['title']}")
185+
print(f"{i + 1}. {episode['title']}")
181186

182-
episode_choice = int(input("\nChoose an episode by serial no: ").strip())
187+
episode_choice = int(input("\nChoose an episode by serial number: ").strip())
183188
chosen_episode = episode_list[episode_choice - 1]
184189
print(f"You chose {chosen_episode['title']}. Searching...")
185190

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

0 commit comments

Comments
 (0)