Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI update #31

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ monkey_dl/build/
monkey_dl/dist/
monkey_dl/settings.json
monkey_dl/results.csv
*.spec
*.spec

*.mp4
*.mkv
53 changes: 53 additions & 0 deletions monkey_dl/cli/CLI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import argparse
from util.downloader import Downloader

def cli_download_wrapper(anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, gui,
resolution="720", is_dub=False):

downloader = Downloader(anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, gui, resolution, is_dub)
downloader.download()

class AnimeCLI:
def __init__(self):
pass

def run(self):
parser = argparse.ArgumentParser(description="Anime Downloader Command Line Tool")
argparse.ArgumentParser(description="Help option parcer for Anime Downloader Command Line Tool", add_help=False,
formatter_class=argparse.HelpFormatter)

parser.add_argument("-u", "--url", required=False, help="9Anime.to URL for the anime to be downloaded", dest="url")
parser.add_argument("-n", "--names", required=False,
help="https://www.animefillerlist.com/ URL to retrieve episode titles", dest="title_url")
parser.add_argument("-d", "--directory", required=False,
help="Download destination. Will use the current directory if not provided", default="",
dest="dir")
parser.add_argument("-s", "--start", required=False, help="Starting episode", default=1, type=int, dest="start")
parser.add_argument("-e", "--end", required=False, help="End episode", default=9999, type=int, dest="end")
parser.add_argument("-c", "--code", required=False,
help="Recaptcha answer token code. Insert this if you don't have 2captcha captcha bypass api_key",
default=None, dest="token")
parser.add_argument("-t", "--threads", required=False,
help="Number of parrallel downloads. Will download sequencially if not provided", default=1,
type=int, dest="threads")
parser.add_argument("-f", "--filler", required=False, help="Whether fillers needed", default=True, type=bool,
dest="isFiller")
parser.add_argument("--nogui", action='store_true', required=False, help="Disable GUI for cli",
dest="nogui")

args = parser.parse_args()

titles = False
if args.title_url:
titles = True

directory = args.dir
if directory != "":
directory = directory.replace("\\", "/")
if not directory.endswith("/"):
directory += "/"

if args.nogui:
cli_download_wrapper(args.url, args.title_url, args.start, args.end, args.isFiller, titles, args.token, args.threads, directory, None)

return args.nogui
Empty file added monkey_dl/cli/__init__.py
Empty file.
120 changes: 6 additions & 114 deletions monkey_dl/gui/GUI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import queue
import json
import cloudscraper
import traceback
import monkey_dl
import PySimpleGUI as sg
Expand All @@ -10,126 +9,19 @@
from util.downloader import Downloader
from util.Color import printer
from util.name_collector import EpisodeNamesCollector
from scrapers.fouranime.fouranime_scraper import FourAnimeScraper
from scrapers.nineanime.nineanime_scraper import NineAnimeScraper
from scrapers.animeultima.animeultima_scraper import AnimeUltimaScraper
from scrapers.animeflix.animeflix_scraper import AnimeFlixScraper
from scrapers.animepahe.animepahe_scraper import AnimePaheScraper
from scrapers.gogoanime.gogoanime_scraper import GoGoAnimeScraper
from scrapers.animefreak.animefreak_scraper import AnimeFreakScraper
from scrapers.animetake.animetake_scraper import AnimeTakeScraper
from scrapers.twist.twist_scraper import TwistScraper

sg.theme('Dark Amber')
i = 0
max_val = 100


def download(anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, gui,
resolution="720", is_dub=False):
def gui_download_wrapper(anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, gui,
resolution="720", is_dub=False):
global max_val

session = cloudscraper.create_scraper()
api_key = ""
try:
with open("settings.json", "r") as json_file:
data = json.load(json_file)
api_key = data["api_key"]
except Exception:
api_key = ""

if api_key != "" and api_key != "insert_2captcha_api_key":
session = cloudscraper.create_scraper(
recaptcha={
'provider': '2captcha',
'api_key': api_key
}
)

scraper = None
episodes = []

anime_url = anime_url.lower()

try:
if "9anime" in anime_url:
printer("INFO", "9Anime URL detected...", gui)
scraper = NineAnimeScraper(anime_url, start_epi, end_epi, session, gui, token)

elif "4anime.to" in anime_url:
printer("INFO", "4Anime URL detected...", gui)
scraper = FourAnimeScraper(anime_url, start_epi, end_epi, session, gui)

elif "animeultima.to" in anime_url:
printer("INFO", "AnimeUltima URL detected...", gui)
scraper = AnimeUltimaScraper(anime_url, start_epi, end_epi, session, gui, resolution, is_dub)

elif "animeflix" in anime_url:
printer("INFO", "AnimeFlix URL detected...", gui)
scraper = AnimeFlixScraper(anime_url, start_epi, end_epi, session, gui, resolution, is_dub)

elif "gogoanime" in anime_url:
printer("INFO", "GoGoAnime URL detected...", gui)
if "gogoanime.pro" in anime_url:
printer("ERROR", "goganime.pro links are not supported yet try gogoanime.io or gogoanime.video", gui)
return

scraper = GoGoAnimeScraper(anime_url, start_epi, end_epi, session, gui, resolution)

elif "animefreak" in anime_url:
printer("INFO", "AnimeFreak URL detected...", gui)
scraper = AnimeFreakScraper(anime_url, start_epi, end_epi, session, gui, is_dub)

elif "twist" in anime_url:
printer("INFO", "Twist URL detected...", gui)
scraper = TwistScraper(anime_url, start_epi, end_epi, session, gui)

elif "animetake" in anime_url:
printer("INFO", "AnimeTake URL detected...", gui)
scraper = AnimeTakeScraper(anime_url, start_epi, end_epi, session, gui, resolution)

elif "animepahe.com" in anime_url:
printer("INFO", "AnimePahe URL detected...", gui)

if api_key == "" or api_key == "insert_2captcha_api_key":
printer("ERROR", "You need 2captcha API key to download from AnimePahe!", gui)
printer("ERROR", "Set 2captcha API key in 'settings.json' file to download from AnimePahe!", gui)
return

scraper = AnimePaheScraper(anime_url, start_epi, end_epi, session, gui, resolution, is_filler)

else:
printer("ERROR", "Incorrect URL provided!", gui)
return

printer("INFO", "Collecting download links...", gui)
episodes = scraper.get_direct_links()

if episodes is None:
printer("INFO", "Retrying to collect download links...", gui)
sleep(5)
episodes = scraper.get_direct_links()

if episodes:
if is_titles:
printer("INFO", "Setting episode titles...", gui)
episodes = EpisodeNamesCollector(names_url, start_epi, end_epi, is_filler,
episodes).collect_episode_names()

else:
printer("ERROR", "Failed to retrieve download links!", gui)
return

max_val = len(episodes)
# print("is titles", is_titles)
downloader = Downloader(directory, episodes, threads, gui, is_titles)
downloader.download()

except Exception as ex:
trace = traceback.format_exc()
print(trace)
printer("ERROR", ex, gui)
printer("ERROR", "Something went wrong! Please close and restart Anime Downloader to retry!", gui)
downloader = Downloader(anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, gui, resolution, is_dub)
max_val = downloader.get_episodes()
downloader.download()


class AnimeGUI:
Expand Down Expand Up @@ -242,7 +134,7 @@ def run(self):
self.window["txt_msg"].update("")
self.window.refresh()

thread = Thread(target=download, args=(
thread = Thread(target=gui_download_wrapper, args=(
anime_url, names_url, start_epi, end_epi, is_filler, is_titles, token, threads, directory, self,
resolution, is_dub), daemon=True)
thread.start()
Expand Down
10 changes: 9 additions & 1 deletion monkey_dl/monkey-dl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from queue import Queue
from gui.GUI import AnimeGUI
from cli.CLI import AnimeCLI

def main():

noGui = AnimeCLI().run()

if not noGui:
AnimeGUI(Queue()).run()

if __name__ == "__main__":
AnimeGUI(Queue()).run()
main()
Loading