mirror of
https://github.com/karl0ss/GoGoDownloader.git
synced 2025-04-27 03:59:22 +01:00
added a feature that will let you download custom number of episodes
This commit is contained in:
parent
c4a265d168
commit
70cc84eede
206
src/bitanime.py
206
src/bitanime.py
@ -1,8 +1,4 @@
|
|||||||
# Dependencies
|
import requests as req
|
||||||
|
|
||||||
# DYNAMIC EPISODE QUALITY - WIP
|
|
||||||
|
|
||||||
import requests
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import backend as bd
|
import backend as bd
|
||||||
@ -20,8 +16,7 @@ except (AttributeError):
|
|||||||
|
|
||||||
|
|
||||||
def bitanime():
|
def bitanime():
|
||||||
again = True
|
while True:
|
||||||
while again:
|
|
||||||
print(
|
print(
|
||||||
f""" {Fore.LIGHTBLUE_EX}
|
f""" {Fore.LIGHTBLUE_EX}
|
||||||
____ _ _ _ _
|
____ _ _ _ _
|
||||||
@ -34,120 +29,117 @@ def bitanime():
|
|||||||
Github: https://github.com/sh1nobuu/BitAnime
|
Github: https://github.com/sh1nobuu/BitAnime
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
"""
|
while True:
|
||||||
Ask user for input and then check if the anime provided exists or if not, loop
|
name = input(f"[{Fore.GREEN}+{Fore.RESET}] Enter anime name > ").lower()
|
||||||
"""
|
|
||||||
check = True
|
|
||||||
while check:
|
|
||||||
name = input("Enter anime name >> ").lower()
|
|
||||||
if "-" in name:
|
if "-" in name:
|
||||||
title = name.replace("-", " ").title().strip()
|
title = name.replace("-", " ").title().strip()
|
||||||
else:
|
else:
|
||||||
title = name.title().strip()
|
title = name.title().strip()
|
||||||
source = f"https://gogoanime.pe/category/{name}"
|
source = f"https://gogoanime.pe/category/{name}"
|
||||||
resp = requests.get(source)
|
with req.get(source) as res:
|
||||||
if resp.status_code == 200:
|
if res.status_code == 200:
|
||||||
print(
|
soup = BeautifulSoup(res.content, "html.parser")
|
||||||
f"{Fore.LIGHTGREEN_EX}==========================================="
|
|
||||||
)
|
|
||||||
check = False
|
|
||||||
else:
|
|
||||||
print(
|
|
||||||
f"{Fore.LIGHTRED_EX}Error 404: Anime not found. Please try again."
|
|
||||||
)
|
|
||||||
check = True
|
|
||||||
check = True
|
|
||||||
while check:
|
|
||||||
quality = input("Enter episode quality >> ")
|
|
||||||
episode_quality = ""
|
|
||||||
if quality == "1" or quality == "":
|
|
||||||
episode_quality = "360P"
|
|
||||||
quality = "1"
|
|
||||||
check = False
|
|
||||||
elif quality == "2":
|
|
||||||
episode_quality = "480P"
|
|
||||||
check = False
|
|
||||||
elif quality == "3":
|
|
||||||
episode_quality = "720P"
|
|
||||||
check = False
|
|
||||||
elif quality == "4":
|
|
||||||
episode_quality = "1080P"
|
|
||||||
check = False
|
|
||||||
else:
|
|
||||||
print(f"{Fore.LIGHTRED_EX}Invalid input. Please try again.")
|
|
||||||
check = True
|
|
||||||
"""
|
|
||||||
Get how many episode/s the anime has
|
|
||||||
"""
|
|
||||||
soup = BeautifulSoup(resp.content, "html.parser")
|
|
||||||
episode_number = soup.find("ul", {"id": "episode_page"})
|
episode_number = soup.find("ul", {"id": "episode_page"})
|
||||||
episode_number = episode_number.get_text().split("-")[-1].strip()
|
episode_number = episode_number.get_text().split("-")[-1].strip()
|
||||||
"""
|
break
|
||||||
Print the anime name, episode, and the link of the anime
|
else:
|
||||||
"""
|
print(
|
||||||
print(f"Title: {Fore.LIGHTCYAN_EX}{title}")
|
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Error 404: Anime not found. Please try again."
|
||||||
print(f"Episode/s: {Fore.LIGHTCYAN_EX}{episode_number}")
|
)
|
||||||
print(f"Quality: {Fore.LIGHTCYAN_EX}{episode_quality}")
|
while True:
|
||||||
print(f"Link: {Fore.LIGHTCYAN_EX}{source}")
|
quality = input(
|
||||||
print(f"{Fore.LIGHTGREEN_EX}===========================================")
|
f"[{Fore.GREEN}+{Fore.RESET}] Enter episode quality (1.SD/360P|2.HD/720P|3.FULLHD/1080P) > "
|
||||||
"""
|
)
|
||||||
Create a download folder for the anime
|
if quality == "1" or quality == "":
|
||||||
"""
|
episode_quality = "SDP"
|
||||||
|
break
|
||||||
|
elif quality == "2":
|
||||||
|
episode_quality = "HDP"
|
||||||
|
break
|
||||||
|
elif quality == "3":
|
||||||
|
episode_quality = "FullHDP"
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
||||||
|
)
|
||||||
|
print(f"[{Fore.GREEN}+{Fore.RESET}] Title: {Fore.LIGHTCYAN_EX}{title}")
|
||||||
|
print(
|
||||||
|
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)
|
||||||
"""
|
while True:
|
||||||
Check if the anime has episode 0 or not
|
choice = input(
|
||||||
"""
|
f"[{Fore.GREEN}+{Fore.RESET}] Do you want to download all episode? (y/n) > "
|
||||||
|
)
|
||||||
|
if choice in ["y", "n"]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
||||||
|
)
|
||||||
|
if choice == "n":
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
custom_episode_number = int(
|
||||||
|
input(
|
||||||
|
f"[{Fore.GREEN}+{Fore.RESET}] How many episode do you want to download? > "
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if custom_episode_number == 0 or custom_episode_number > int(
|
||||||
|
episode_number
|
||||||
|
):
|
||||||
|
raise bd.InvalidInputValue
|
||||||
|
else:
|
||||||
|
episode_number = custom_episode_number
|
||||||
|
break
|
||||||
|
except ValueError:
|
||||||
|
print(
|
||||||
|
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Invalid input. Please try again."
|
||||||
|
)
|
||||||
|
except bd.InvalidInputValue:
|
||||||
|
print(
|
||||||
|
f"[{Fore.RED}-{Fore.RESET}] {Fore.LIGHTRED_EX}Custom episode cannot be equal to 0 or custom episode 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}"
|
||||||
resp = requests.get(source)
|
with req.get(source) as res:
|
||||||
soup = BeautifulSoup(resp.content, "html.parser")
|
soup = BeautifulSoup(res.content, "html.parser")
|
||||||
episode_zero = soup.find("h1", {"class": "entry-title"})
|
episode_zero = soup.find("h1", {"class": "entry-title"})
|
||||||
if episode_zero is None:
|
if episode_zero is None:
|
||||||
# Episode 0 does exist
|
# Episode 0 == 200
|
||||||
exec = concurrent.futures.ThreadPoolExecutor()
|
with concurrent.futures.ThreadPoolExecutor() as exec:
|
||||||
episode_links = bd.get_links(name, episode_number)
|
episode_links = download.get_links(source)
|
||||||
download_links = list(exec.map(bd.get_download_links, episode_links))
|
download_links = list(
|
||||||
filtered_download_links = [
|
exec.map(download.get_download_links, episode_links)
|
||||||
[quality, download_link]
|
)
|
||||||
for download_link in download_links
|
|
||||||
if download_link
|
|
||||||
]
|
|
||||||
download_urls = list(
|
download_urls = list(
|
||||||
exec.map(bd.get_download_urls, filtered_download_links)
|
exec.map(download.get_download_urls, download_links)
|
||||||
)
|
)
|
||||||
print(f"Downloading {Fore.LIGHTCYAN_EX}{len(download_urls)} episode/s")
|
|
||||||
print(f"{Fore.LIGHTGREEN_EX}===========================================")
|
|
||||||
bd.get_path(folder)
|
|
||||||
thread_map(
|
|
||||||
bd.download_episodes, download_urls, ncols=75, total=len(download_urls)
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
os.startfile(folder)
|
|
||||||
except (AttributeError):
|
|
||||||
import sys, subprocess
|
|
||||||
|
|
||||||
opener = "open" if sys.platform == "darwin" else "xdg-open"
|
|
||||||
subprocess.call([opener, folder])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Episode 0 does not exist
|
# Episode 0 == 404
|
||||||
exec = concurrent.futures.ThreadPoolExecutor()
|
with concurrent.futures.ThreadPoolExecutor() as exec:
|
||||||
episode_links = bd.get_links(name, episode_number)
|
episode_links = download.get_links()
|
||||||
download_links = list(exec.map(bd.get_download_links, episode_links))
|
download_links = list(
|
||||||
filtered_download_links = [
|
exec.map(download.get_download_links, episode_links)
|
||||||
[quality, download_link]
|
)
|
||||||
for download_link in download_links
|
download_urls = list(
|
||||||
if download_link
|
exec.map(download.get_download_urls, download_links)
|
||||||
]
|
)
|
||||||
download_urls = list(
|
print(
|
||||||
exec.map(bd.get_download_urls, filtered_download_links)
|
f"[{Fore.GREEN}+{Fore.RESET}] Downloading {Fore.LIGHTCYAN_EX}{len(download_urls)}{Fore.RESET} episode/s"
|
||||||
)
|
)
|
||||||
print(f"Downloading {Fore.LIGHTCYAN_EX}{len(download_urls)} episode/s")
|
|
||||||
print(f"{Fore.LIGHTGREEN_EX}===========================================")
|
|
||||||
bd.get_path(folder)
|
|
||||||
thread_map(
|
thread_map(
|
||||||
bd.download_episodes, download_urls, ncols=75, total=len(download_urls)
|
download.download_episodes,
|
||||||
|
download_urls,
|
||||||
|
ncols=75,
|
||||||
|
total=len(download_urls),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
os.startfile(folder)
|
os.startfile(folder)
|
||||||
@ -156,13 +148,13 @@ 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("Do you want to download other anime? (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":
|
||||||
again = True
|
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
else:
|
else:
|
||||||
again = False
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user