Skip to content

Commit 9d555f1

Browse files
authored
Update fetch_anime_and_play.py
1 parent f63d329 commit 9d555f1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

web_programming/fetch_anime_and_play.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
from bs4 import BeautifulSoup, NavigableString, Tag
44
from fake_useragent import UserAgent
55

6+
import re
7+
8+
def is_safe_filename(filename: str) -> bool:
9+
# A simple regex to check if the filename is safe (no special characters)
10+
return re.match(r'^[\w\-. ]+$', filename) is not None
11+
12+
def download_video(download_url: str, output_filename: str):
13+
"""Download video using ffmpeg."""
14+
if not is_safe_filename(output_filename):
15+
raise ValueError("Unsafe output filename provided.")
16+
17+
command = ["ffmpeg", "-i", download_url, output_filename]
18+
subprocess.run(command, check=True)
19+
620
BASE_URL = "https://ww1.gogoanime2.org"
721

822

@@ -154,13 +168,6 @@ def get_anime_episode(episode_endpoint: str) -> list:
154168

155169
return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
156170

157-
158-
def download_video(download_url: str, output_filename: str):
159-
"""Download video using ffmpeg."""
160-
command = ["ffmpeg", "-i", download_url, output_filename]
161-
subprocess.run(command, check=True)
162-
163-
164171
if __name__ == "__main__":
165172
anime_name = input("Enter anime name: ").strip()
166173
anime_list = search_scraper(anime_name)

0 commit comments

Comments
 (0)