__main___1.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. def main():
  2. # Parse arguments from file docstring
  3. args = docopt.docopt(__doc__, version=__version__)
  4. URLs = args['<url>']
  5. cookie_file = args['--cookies']
  6. proxy_url = args['--proxy']
  7. username = args['--username']
  8. password = args['--password']
  9. quiet_mode = args['--quiet']
  10. debug_mode = args['--debug']
  11. use_download_archive = args['--use-download-archive']
  12. get_comments = args['--get-comments']
  13. ignore_existing_item = args['--ignore-existing-item']
  14. if debug_mode:
  15. # Display log messages.
  16. root = logging.getLogger()
  17. root.setLevel(logging.DEBUG)
  18. ch = logging.StreamHandler(sys.stdout)
  19. ch.setLevel(logging.DEBUG)
  20. formatter = logging.Formatter(
  21. '\033[92m[DEBUG]\033[0m %(asctime)s - %(name)s - %(levelname)s - '
  22. '%(message)s')
  23. ch.setFormatter(formatter)
  24. root.addHandler(ch)
  25. metadata = internetarchive.cli.argparser.get_args_dict(args['--metadata'])
  26. tu = TubeUp(verbose=not quiet_mode,
  27. output_template=args['--output'],
  28. get_comments=get_comments)
  29. try:
  30. for identifier, meta in tu.archive_urls(URLs, metadata,
  31. cookie_file, proxy_url,
  32. username, password,
  33. use_download_archive,
  34. ignore_existing_item):
  35. print('\n:: Upload Finished. Item information:')
  36. print('Title: %s' % meta['title'])
  37. print('Upload URL: https://archive.org/details/%s\n' % identifier)
  38. except Exception:
  39. print('\n\033[91m' # Start red color text
  40. 'An exception just occured, if you found this '
  41. "exception isn't related with any of your connection problem, "
  42. 'please report this issue to '
  43. 'https://github.com/bibanon/tubeup/issues')
  44. traceback.print_exc()
  45. print('\033[0m') # End the red color text
  46. sys.exit(1)