|
1 | 1 | import requests
|
2 | 2 | from bs4 import BeautifulSoup, NavigableString, Tag
|
3 | 3 | from fake_useragent import UserAgent
|
| 4 | +import subprocess |
4 | 5 |
|
5 | 6 | BASE_URL = "https://ww1.gogoanime2.org"
|
6 | 7 |
|
@@ -153,6 +154,16 @@ def get_anime_episode(episode_endpoint: str) -> list:
|
153 | 154 |
|
154 | 155 | return [f"{BASE_URL}{episode_url}", f"{BASE_URL}{download_url}"]
|
155 | 156 |
|
| 157 | +def download_video(download_url: str, output_filename: str) -> None: |
| 158 | + """Download video using ffmpeg.""" |
| 159 | + command = ['ffmpeg', '-i', download_url, output_filename] |
| 160 | + try: |
| 161 | + subprocess.run(command, check=True) |
| 162 | + except FileNotFoundError: |
| 163 | + # If ffmpeg is not found, instruct the user on how to install it |
| 164 | + print("Error: ffmpeg is not installed.") |
| 165 | + print("Please install ffmpeg using the following command:") |
| 166 | + print("brew install ffmpeg") # This is the command for macOS |
156 | 167 |
|
157 | 168 | if __name__ == "__main__":
|
158 | 169 | anime_name = input("Enter anime name: ").strip()
|
@@ -185,4 +196,15 @@ def get_anime_episode(episode_endpoint: str) -> list:
|
185 | 196 |
|
186 | 197 | episode_url, download_url = get_anime_episode(chosen_episode["url"])
|
187 | 198 | print(f"\nTo watch, ctrl+click on {episode_url}.")
|
188 |
| - print(f"To download, ctrl+click on {download_url}.") |
| 199 | + |
| 200 | + # Add an option to download or not |
| 201 | + download_choice = input("\nDo you want to download this episode? (yes/no): ").strip().lower() |
| 202 | + if download_choice in ["yes", "y"]: |
| 203 | + output_filename = f"{chosen_anime['title']} - {chosen_episode['title']}.mp4" # Change extension as needed |
| 204 | + download_video(download_url, output_filename) |
| 205 | + print(f"{chosen_episode['title']} has been downloaded as {output_filename}.") |
| 206 | + else: |
| 207 | + print("Download skipped.") |
| 208 | + |
| 209 | + #if error download please install ffmeg |
| 210 | + #brew install ffmpeg for mac |
0 commit comments