|
3 | 3 | from bs4 import BeautifulSoup, NavigableString, Tag
|
4 | 4 | from fake_useragent import UserAgent
|
5 | 5 |
|
| 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 | + |
6 | 20 | BASE_URL = "https://ww1.gogoanime2.org"
|
7 | 21 |
|
8 | 22 |
|
@@ -154,13 +168,6 @@ def get_anime_episode(episode_endpoint: str) -> list:
|
154 | 168 |
|
155 | 169 | return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
|
156 | 170 |
|
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 |
| - |
164 | 171 | if __name__ == "__main__":
|
165 | 172 | anime_name = input("Enter anime name: ").strip()
|
166 | 173 | anime_list = search_scraper(anime_name)
|
|
0 commit comments