Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Commit

Permalink
Move code of main script under __main__ condition
Browse files Browse the repository at this point in the history
Multiprocessing on Windows does full copy of module and this would lead
to the re-execution of this code.

Posibly fixes #33.
  • Loading branch information
setnicka committed Nov 15, 2020
1 parent aaea5f2 commit f563a20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='ulozto-downloader',
version='1.5.1',
version='1.5.2',
license='MIT',
description='Uloz.to quick multiple sessions downloader.',
long_description=long_description,
Expand Down
47 changes: 24 additions & 23 deletions ulozto-downloader
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ import signal

from ulozto_downloader import downloader, captcha

parser = argparse.ArgumentParser(
description='Download file from Uloz.to using multiple parallel downloads.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument('url', metavar='URL', type=str, help="URL from Uloz.to (tip: enter in 'quotes' because the URL contains ! sign)")
parser.add_argument('--parts', metavar='N', type=int, default=10, help='Number of parts that will be downloaded in parallel')
parser.add_argument('--output', metavar='DIRECTORY', type=str, default="./", help='Target directory')
parser.add_argument('--auto-captcha', default=False, action="store_true", help='Try to solve captchas automatically using TensorFlow')

args = parser.parse_args()

if args.auto_captcha:
model_path = "model.tflite"
model_download_url = "https://github.com/JanPalasek/ulozto-captcha-breaker/releases/download/v2.2/model.tflite"
captcha_solve_fnc = captcha.AutoReadCaptcha(model_path, model_download_url)
else:
captcha_solve_fnc = captcha.tkinter_user_prompt

d = downloader.Downloader(captcha_solve_fnc)


# Register sigint handler
def sigint_handler(sig, frame):
d.terminate()
print('Program terminated.')
sys.exit(1)


signal.signal(signal.SIGINT, sigint_handler)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Download file from Uloz.to using multiple parallel downloads.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument('url', metavar='URL', type=str, help="URL from Uloz.to (tip: enter in 'quotes' because the URL contains ! sign)")
parser.add_argument('--parts', metavar='N', type=int, default=10, help='Number of parts that will be downloaded in parallel')
parser.add_argument('--output', metavar='DIRECTORY', type=str, default="./", help='Target directory')
parser.add_argument('--auto-captcha', default=False, action="store_true", help='Try to solve captchas automatically using TensorFlow')

args = parser.parse_args()

if args.auto_captcha:
model_path = "model.tflite"
model_download_url = "https://github.com/JanPalasek/ulozto-captcha-breaker/releases/download/v2.2/model.tflite"
captcha_solve_fnc = captcha.AutoReadCaptcha(model_path, model_download_url)
else:
captcha_solve_fnc = captcha.tkinter_user_prompt

d = downloader.Downloader(captcha_solve_fnc)

# Register sigint handler
signal.signal(signal.SIGINT, sigint_handler)

d.download(args.url, args.parts, args.output)
d.download(args.url, args.parts, args.output)

0 comments on commit f563a20

Please sign in to comment.