downloader.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 helpers.command_exists("pyinstalive"):
  14. logger.error("PyInstaLive must be properly installed when using the -df argument.")
  15. logger.separator()
  16. else:
  17. dlfuncs.download_following()
  18. else:
  19. if not helpers.check_lock_file():
  20. helpers.create_lock_user()
  21. checking_self = pil.dl_user == pil.ig_api.authenticated_user_name
  22. if dlfuncs.get_broadcasts_info():
  23. if pil.dl_lives:
  24. if checking_self:
  25. logger.warn("Login with a different account to download your own livestreams.")
  26. elif pil.livestream_obj:
  27. logger.info("Livestream available, starting download.")
  28. dlfuncs.download_livestream()
  29. else:
  30. logger.info('There are no available livestreams.')
  31. else:
  32. logger.binfo("Livestream downloading is disabled either with an argument or in the config file.")
  33. logger.separator()
  34. if pil.dl_replays:
  35. if pil.replays_obj:
  36. logger.info(
  37. '{:d} {:s} available, beginning download.'.format(len(pil.replays_obj), "replays" if len(
  38. pil.replays_obj) > 1 else "replay"))
  39. dlfuncs.download_replays()
  40. else:
  41. logger.info('There are no available replays{:s}.'.format(" saved on your account" if checking_self else ""))
  42. else:
  43. logger.binfo("Replay downloading is disabled either with an argument or in the config file.")
  44. helpers.remove_lock()
  45. logger.separator()
  46. else:
  47. logger.warn("Lock file is already present for this user, there is probably another download ongoing.")
  48. logger.warn("If this is not the case, manually delete the file '{:s}' and try again.".format(
  49. pil.dl_user + '.lock'))
  50. logger.separator()