mirror of
https://github.com/karl0ss/GoGoDownloader.git
synced 2025-04-27 03:59:22 +01:00
Dynamic episode_start and episode_end feature added
This commit is contained in:
parent
13c49e5fe4
commit
46038e93a3
@ -1,14 +1,16 @@
|
|||||||
import requests as req
|
import requests as req
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import backend as bd
|
|
||||||
import colorama
|
import colorama
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
from backend import Download, CustomError
|
||||||
from tqdm.contrib.concurrent import thread_map
|
from tqdm.contrib.concurrent import thread_map
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from colorama import Fore
|
from colorama import Fore
|
||||||
|
|
||||||
colorama.init(autoreset=True)
|
colorama.init(autoreset=True)
|
||||||
|
PLUS = f"[{Fore.GREEN}+{Fore.RESET}] "
|
||||||
|
MINUS = f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}"
|
||||||
try:
|
try:
|
||||||
ctypes.windll.kernel32.SetConsoleTitleW("BitAnime")
|
ctypes.windll.kernel32.SetConsoleTitleW("BitAnime")
|
||||||
except (AttributeError):
|
except (AttributeError):
|
||||||
@ -30,7 +32,7 @@ def bitanime():
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
while True:
|
while True:
|
||||||
name = input(f"[{Fore.GREEN}+{Fore.RESET}] Enter anime name > ").lower()
|
name = input(f"{PLUS}Enter anime name > ").lower()
|
||||||
if "-" in name:
|
if "-" in name:
|
||||||
title = name.replace("-", " ").title().strip()
|
title = name.replace("-", " ").title().strip()
|
||||||
else:
|
else:
|
||||||
@ -39,16 +41,14 @@ def bitanime():
|
|||||||
with req.get(source) as res:
|
with req.get(source) as res:
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
soup = BeautifulSoup(res.content, "html.parser")
|
soup = BeautifulSoup(res.content, "html.parser")
|
||||||
episode_number = soup.find("ul", {"id": "episode_page"})
|
all_episodes = soup.find("ul", {"id": "episode_page"})
|
||||||
episode_number = episode_number.get_text().split("-")[-1].strip()
|
all_episodes = int(all_episodes.get_text().split("-")[-1].strip())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(
|
print(f"{MINUS}Error 404: Anime not found. Please try again.")
|
||||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Error 404: Anime not found. Please try again."
|
|
||||||
)
|
|
||||||
while True:
|
while True:
|
||||||
quality = input(
|
quality = input(
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Enter episode quality (1.SD/360P|2.HD/720P|3.FULLHD/1080P) > "
|
f"{PLUS}Enter episode quality (1.SD/360P|2.HD/720P|3.FULLHD/1080P) > "
|
||||||
)
|
)
|
||||||
if quality == "1" or quality == "":
|
if quality == "1" or quality == "":
|
||||||
episode_quality = "SDP"
|
episode_quality = "SDP"
|
||||||
@ -60,54 +60,59 @@ def bitanime():
|
|||||||
episode_quality = "FullHDP"
|
episode_quality = "FullHDP"
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(
|
print(f"{MINUS}Invalid input. Please try again.")
|
||||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
print(f"{PLUS}Title: {Fore.LIGHTCYAN_EX}{title}")
|
||||||
)
|
print(f"{PLUS}Episode/s: {Fore.LIGHTCYAN_EX}{all_episodes}")
|
||||||
print(f"[{Fore.GREEN}+{Fore.RESET}] Title: {Fore.LIGHTCYAN_EX}{title}")
|
print(f"{PLUS}Quality: {Fore.LIGHTCYAN_EX}{episode_quality}")
|
||||||
print(
|
print(f"{PLUS}Link: {Fore.LIGHTCYAN_EX}{source}")
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Episode/s: {Fore.LIGHTCYAN_EX}{episode_number}"
|
|
||||||
)
|
|
||||||
print(
|
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Quality: {Fore.LIGHTCYAN_EX}{episode_quality}"
|
|
||||||
)
|
|
||||||
print(f"[{Fore.GREEN}+{Fore.RESET}] Link: {Fore.LIGHTCYAN_EX}{source}")
|
|
||||||
folder = os.path.join(os.getcwd(), title)
|
folder = os.path.join(os.getcwd(), title)
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
os.mkdir(folder)
|
os.mkdir(folder)
|
||||||
|
|
||||||
|
choice = "y"
|
||||||
|
|
||||||
|
if all_episodes != 1:
|
||||||
while True:
|
while True:
|
||||||
choice = input(
|
choice = input(
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Do you want to download all episode? (y/n) > "
|
f"{PLUS}Do you want to download all episode? (y/n) > "
|
||||||
)
|
).lower()
|
||||||
if choice in ["y", "n"]:
|
if choice in ["y", "n"]:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(
|
print(f"{MINUS}Invalid input. Please try again.")
|
||||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
|
||||||
)
|
episode_start = None
|
||||||
|
episode_end = None
|
||||||
|
|
||||||
if choice == "n":
|
if choice == "n":
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
custom_episode_number = int(
|
episode_start = int(input(f"{PLUS}Episode start > "))
|
||||||
input(
|
episode_end = int(input(f"{PLUS}Episode end > "))
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] How many episode do you want to download? > "
|
if episode_start <= 0 or episode_end <= 0:
|
||||||
)
|
CustomError(
|
||||||
)
|
f"{MINUS}episode_start or episode_end cannot be less than or equal to 0"
|
||||||
if custom_episode_number == 0 or custom_episode_number > int(
|
).print_error()
|
||||||
episode_number
|
elif episode_start >= all_episodes or episode_end > all_episodes:
|
||||||
):
|
CustomError(
|
||||||
raise bd.InvalidInputValue
|
f"{MINUS}episode_start or episode_end cannot be more than {all_episodes}"
|
||||||
|
).print_error()
|
||||||
|
elif episode_end <= episode_start:
|
||||||
|
CustomError(
|
||||||
|
f"{MINUS}episode_end cannot be less than or equal to episode_start"
|
||||||
|
).print_error()
|
||||||
else:
|
else:
|
||||||
episode_number = custom_episode_number
|
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(
|
print(f"{MINUS}Invalid input. Please try again.")
|
||||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
|
||||||
|
episode_start = episode_start if episode_start != None else 1
|
||||||
|
episode_end = episode_end if episode_end != None else all_episodes
|
||||||
|
|
||||||
|
download = Download(
|
||||||
|
name, episode_quality, folder, all_episodes, episode_start, episode_end
|
||||||
)
|
)
|
||||||
except bd.InvalidInputValue:
|
|
||||||
print(
|
|
||||||
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Custom episode cannot be equal to 0 or it cannot be greater than {episode_number}"
|
|
||||||
)
|
|
||||||
download = bd.Download(name, episode_quality, int(episode_number), folder)
|
|
||||||
source = f"https://gogoanime.pe/{name}"
|
source = f"https://gogoanime.pe/{name}"
|
||||||
with req.get(source) as res:
|
with req.get(source) as res:
|
||||||
soup = BeautifulSoup(res.content, "html.parser")
|
soup = BeautifulSoup(res.content, "html.parser")
|
||||||
@ -115,7 +120,9 @@ def bitanime():
|
|||||||
if episode_zero is None:
|
if episode_zero is None:
|
||||||
# Episode 0 == 200
|
# Episode 0 == 200
|
||||||
with concurrent.futures.ThreadPoolExecutor() as exec:
|
with concurrent.futures.ThreadPoolExecutor() as exec:
|
||||||
episode_links = download.get_links(source)
|
episode_links = download.get_links(
|
||||||
|
source=source if choice == "y" else None
|
||||||
|
)
|
||||||
download_links = list(
|
download_links = list(
|
||||||
exec.map(download.get_download_links, episode_links)
|
exec.map(download.get_download_links, episode_links)
|
||||||
)
|
)
|
||||||
@ -133,7 +140,7 @@ def bitanime():
|
|||||||
exec.map(download.get_download_urls, download_links)
|
exec.map(download.get_download_urls, download_links)
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Downloading {Fore.LIGHTCYAN_EX}{len(download_urls)}{Fore.RESET} episode/s"
|
f"{PLUS}Downloading {Fore.LIGHTCYAN_EX}{len(download_urls)}{Fore.RESET} episode/s"
|
||||||
)
|
)
|
||||||
thread_map(
|
thread_map(
|
||||||
download.download_episodes,
|
download.download_episodes,
|
||||||
@ -148,9 +155,7 @@ def bitanime():
|
|||||||
|
|
||||||
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
||||||
subprocess.call([opener, folder])
|
subprocess.call([opener, folder])
|
||||||
use_again = input(
|
use_again = input(f"{PLUS}Do you want to use the app again? (y|n) > ").lower()
|
||||||
f"[{Fore.GREEN}+{Fore.RESET}] Do you want to use the app again? (y|n) > "
|
|
||||||
).lower()
|
|
||||||
if use_again == "y":
|
if use_again == "y":
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user