downloader.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. try:
  2. import logger
  3. import helpers
  4. import pil
  5. import dlfuncs
  6. except ImportError:
  7. from . import logger
  8. from . import helpers
  9. from . import pil
  10. from . import dlfuncs
  11. def start():
  12. if pil.args.downloadfollowing:
  13. if not pil.dl_lives:
  14. logger.binfo("Livestream downloading is disabled either with an argument or in the config file.")
  15. logger.separator()
  16. if not pil.dl_replays:
  17. logger.binfo("Replay downloading is disabled either with an argument or in the config file.")
  18. logger.separator()
  19. if not helpers.command_exists("pyinstalive") and not pil.winbuild_path:
  20. logger.error("PyInstaLive must be properly installed when using the -df argument.")
  21. logger.separator()
  22. else:
  23. dlfuncs.download_following()
  24. else:
  25. if not helpers.download_folder_has_lockfile():
  26. helpers.create_lock_user()
  27. checking_self = pil.dl_user == pil.ig_api.authenticated_user_name
  28. if dlfuncs.get_broadcasts_info():
  29. if pil.dl_lives:
  30. if checking_self:
  31. logger.warn("Login with a different account to download your own livestreams.")
  32. elif pil.livestream_obj:
  33. logger.info("Livestream available, starting download.")
  34. dlfuncs.download_livestream()
  35. else:
  36. logger.info('There are no available livestreams.')
  37. else:
  38. logger.binfo("Livestream downloading is disabled either with an argument or in the config file.")
  39. logger.separator()
  40. if pil.dl_replays:
  41. if pil.replays_obj:
  42. logger.info(
  43. '{:s} available, beginning download.'.format("Replays" if len(
  44. pil.replays_obj) > 1 else "Replay"))
  45. dlfuncs.download_replays()
  46. else:
  47. logger.info('There are no available replays{:s}.'.format(" saved on your account" if checking_self else ""))
  48. else:
  49. logger.binfo("Replay downloading is disabled either with an argument or in the config file.")
  50. helpers.remove_lock()
  51. logger.separator()
  52. else:
  53. logger.warn("Lock file is already present for this user, there is probably another download ongoing.")
  54. logger.warn("If this is not the case, manually delete the file '{:s}' and try again.".format(
  55. pil.dl_user + '.lock'))
  56. logger.separator()