Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4ede93

Browse files
authoredOct 2, 2024··
Update fetch_anime_and_play.py
1 parent dabb27c commit a4ede93

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed
 

‎web_programming/fetch_anime_and_play.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
import requests
33
from bs4 import BeautifulSoup, NavigableString, Tag
44
from fake_useragent import UserAgent
5-
import re
65

76
BASE_URL = "https://ww1.gogoanime2.org"
87

98

10-
def is_safe_filename(filename: str) -> bool:
11-
return re.match(r"^[\w\-. ]+$", filename) is not None
12-
13-
149
def search_scraper(anime_name: str) -> list:
1510
"""[summary]
1611
@@ -159,14 +154,11 @@ def get_anime_episode(episode_endpoint: str) -> list:
159154

160155
return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
161156

162-
163157
def download_video(download_url: str, output_filename: str):
164-
if not is_safe_filename(output_filename):
165-
raise ValueError("Unsafe output filename provided.")
166-
command = ["ffmpeg", "-i", download_url, output_filename]
158+
"""Download video using ffmpeg."""
159+
command = ['ffmpeg', '-i', download_url, output_filename]
167160
subprocess.run(command, check=True)
168161

169-
170162
if __name__ == "__main__":
171163
anime_name = input("Enter anime name: ").strip()
172164
anime_list = search_scraper(anime_name)
@@ -186,34 +178,28 @@ def download_video(download_url: str, output_filename: str):
186178

187179
episode_list = search_anime_episode_list(chosen_anime["url"])
188180
if len(episode_list) == 0:
189-
print("No episode found for this anime")
181+
print("No episodes found for this anime")
190182
else:
191183
print(f"Found {len(episode_list)} results: ")
192184
for i, episode in enumerate(episode_list):
193-
print(f"{i+1}. {episode['title']}")
185+
print(f"{i + 1}. {episode['title']}")
194186

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

199191
episode_url, download_url = get_anime_episode(chosen_episode["url"])
200192
print(f"\nTo watch, ctrl+click on {episode_url}.")
201-
print(f"To download, ctrl+click on {download_url}.")
193+
202194

203195
# Add an option to download or not
204-
download_choice = (
205-
input("\nDo you want to download this episode? (yes/no): ")
206-
.strip()
207-
.lower()
208-
)
196+
download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower()
209197
if download_choice in ["yes", "y"]:
210198
output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed
211199
download_video(download_url, output_filename)
212-
print(
213-
f"{chosen_episode['title']} has been downloaded as {output_filename}."
214-
)
200+
print(f"{chosen_episode['title']} has been downloaded as {output_filename}.")
215201
else:
216202
print("Download skipped.")
217203

218-
# if error download please install ffmeg
219-
# brew install ffmpeg for mac
204+
#if error download please install ffmeg
205+
#brew install ffmpeg for mac

0 commit comments

Comments
 (0)
Please sign in to comment.