|
2 | 2 | import requests
|
3 | 3 | from bs4 import BeautifulSoup, NavigableString, Tag
|
4 | 4 | from fake_useragent import UserAgent
|
5 |
| - |
6 | 5 | import re
|
7 | 6 |
|
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 |
| - |
23 | 7 | BASE_URL = "https://ww1.gogoanime2.org"
|
24 | 8 |
|
| 9 | +def is_safe_filename(filename: str) -> bool: |
| 10 | + return re.match(r'^[\w\-. ]+$', filename) is not None |
25 | 11 |
|
26 | 12 | def search_scraper(anime_name: str) -> list:
|
27 | 13 | """[summary]
|
@@ -172,6 +158,12 @@ def get_anime_episode(episode_endpoint: str) -> list:
|
172 | 158 | return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
|
173 | 159 |
|
174 | 160 |
|
| 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 | + |
175 | 167 | if __name__ == "__main__":
|
176 | 168 | anime_name = input("Enter anime name: ").strip()
|
177 | 169 | anime_list = search_scraper(anime_name)
|
|
0 commit comments