Skip to content

Commit a493e3e

Browse files
authored
Update fetch_anime_and_play.py
1 parent 1f6c5cc commit a493e3e

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

web_programming/fetch_anime_and_play.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,12 @@
22
import requests
33
from bs4 import BeautifulSoup, NavigableString, Tag
44
from fake_useragent import UserAgent
5-
65
import re
76

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

9+
def is_safe_filename(filename: str) -> bool:
10+
return re.match(r'^[\w\-. ]+$', filename) is not None
2511

2612
def search_scraper(anime_name: str) -> list:
2713
"""[summary]
@@ -172,6 +158,12 @@ def get_anime_episode(episode_endpoint: str) -> list:
172158
return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
173159

174160

161+
def download_video(download_url: str, output_filename: str):
162+
if not is_safe_filename(output_filename):
163+
raise ValueError("Unsafe output filename provided.")
164+
command = ["ffmpeg", "-i", download_url, output_filename]
165+
subprocess.run(command, check=True)
166+
175167
if __name__ == "__main__":
176168
anime_name = input("Enter anime name: ").strip()
177169
anime_list = search_scraper(anime_name)

0 commit comments

Comments
 (0)