diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..0c7d5f5 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.11.4 diff --git a/Modules/config.py b/Modules/config.py index 98b864f..004d5e5 100644 --- a/Modules/config.py +++ b/Modules/config.py @@ -177,6 +177,9 @@ if username is not None: data = open(username[0]).read() username = filter(None, data.split("\n")) + if len(username) == 1 and args.folder is not None: + username = username[0] + # Custom input cookies = args.cookies output_folder = args.output_folder diff --git a/Modules/download.py b/Modules/download.py index 288ae08..c34336e 100644 --- a/Modules/download.py +++ b/Modules/download.py @@ -56,7 +56,7 @@ def download(path, max_retries=5): if config.category != "gallery": output = f"{config.output_folder}/{author}/{config.category}" if config.folder is not None: - output = f"{config.output_folder}/{author}/{config.folder}" + output = f"{config.output_folder}/{author}/folders/{config.folder.split('/')[1]}" os.makedirs(output, exist_ok=True) output_path = f"{output}/{title} ({view_id}) - {filename}" diff --git a/Modules/functions.py b/Modules/functions.py index cea829e..f1b2601 100644 --- a/Modules/functions.py +++ b/Modules/functions.py @@ -125,19 +125,14 @@ def next_button(page_url): if config.submissions is True: # unlike galleries that are sequentially numbered, submissions use a different scheme. # the "page_num" is instead: new~[set of numbers]@(12 or 48 or 72) if sorting by new - try: - parse_next_button = s.find("a", class_="button standard more").attrs.get( - "href" - ) - except AttributeError: - try: - parse_next_button = s.find( - "a", class_="button standard more-half" - ).attrs.get("href") - except AttributeError as e: - print(f"{config.WARN_COLOR}Unable to find next button{config.END}") - raise DownloadComplete from e - page_num = parse_next_button.split("/")[-2] + parse_next_button = s.find("a", class_="button standard more") + if parse_next_button is None: + parse_next_button = s.find("a", class_="button standard more-half") + if parse_next_button is not None: + page_num = parse_next_button.attrs['href'].split("/")[-2] + else: + print(f"{config.WARN_COLOR}Unable to find next button{config.END}") + raise DownloadComplete elif config.category != "favorites": parse_next_button = s.find("button", class_="button standard", text="Next") if parse_next_button is None or parse_next_button.parent is None: @@ -147,10 +142,9 @@ def next_button(page_url): else: parse_next_button = s.find("a", class_="button standard right", text="Next") page_num = fav_next_button(parse_next_button) - next_page_url = (parse_next_button.parent.attrs['action'] if 'action' - in parse_next_button.parent.attrs else parse_next_button.attrs['href']) + print( - f"Downloading page {page_num} - {config.BASE_URL}{next_page_url}" + f"Downloading page {page_num}" ) return page_num diff --git a/furaffinity-dl.py b/furaffinity-dl.py index 4f5cfba..9606a84 100644 --- a/furaffinity-dl.py +++ b/furaffinity-dl.py @@ -16,8 +16,23 @@ from Modules.functions import system_message_handler from Modules.index import check_file from Modules.index import start_indexing +# Terminate the process +import threading +import queue +q = queue.Queue() + +workers = [] +def worker(): + while True: + item = q.get() + if item == 'shutdown': + break + download(item) + q.task_done() + def main(): + urls = [] """loop over and download all images on the page(s)""" page_num = config.start with contextlib.suppress(DownloadComplete): @@ -67,10 +82,16 @@ it\'s already downloaded{config.END}' ) continue - download(img_url) + #download(img_url) + q.put(img_url) sleep(config.interval) - + q.join() page_num = next_button(page_url) + stop_threads = True + for _ in range(3): + q.put("shutdown") + for t in workers: + t.join() if __name__ == "__main__": @@ -104,6 +125,13 @@ is inaccessible{config.END}" if config.download is not None: download(f"/view/{config.download}/") exit() + + stop_threads = False + for id in range(3): + print(id, 'started thread') + tmp = threading.Thread(target=worker, daemon=False) + workers.append(tmp) + tmp.start() if config.submissions is True: download_url = f"{config.BASE_URL}/msg/submissions" @@ -117,7 +145,7 @@ downloading submissions{config.END}" if config.folder is not None: folder = config.folder.split("/") download_url = ( - f"{config.BASE_URL}/gallery/{config.username}/folder/{config.folder[1]}" + f"{config.BASE_URL}/gallery/{config.username}/folder/{config.folder}" ) main() print( @@ -137,6 +165,7 @@ downloading "{config.folder[1]}"{config.END}' str.maketrans(config.username_replace_chars) ) if username != "": + print(f'{config.SUCCESS_COLOR}Now downloading "{username}"{config.END}') download_url = f"{config.BASE_URL}/{config.category}/{username}" print(f"Downloading page {config.start} - {download_url}/{config.start}") @@ -145,3 +174,4 @@ downloading "{config.folder[1]}"{config.END}' f'{config.SUCCESS_COLOR}Finished \ downloading "{username}"{config.END}' ) +