Guest User

Untitled

a guest
Jun 7th, 2019
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import os
  3. import time
  4. import traceback
  5. import logging
  6. import logging.config
  7. import yaml
  8. from subprocess import Popen, PIPE
  9.  
  10.  
  11. def setup_logging(
  12. default_path='logging.yaml',
  13. default_level=logging.INFO,
  14. env_key='LOG_CFG'
  15. ):
  16. """Setup logging configuration"""
  17. path = default_path
  18. value = os.getenv(env_key, None)
  19. if value:
  20. path = value
  21. if os.path.exists(path):
  22. with open(path, 'rt') as f:
  23. config = yaml.safe_load(f.read())
  24. logging.config.dictConfig(config)
  25. else:
  26. logging.basicConfig(level=default_level)
  27.  
  28. # logging setup
  29. setup_logging()
  30.  
  31. log = logging.getLogger('EmberMediaManager')
  32.  
  33. log.info("Ranarr Ember Media Manager post-processing script started.")
  34.  
  35. # Ember Media Manager installation path (MUST BET SET AS AN ENV VARIABLE)
  36. app_path = os.environ.get('EmberMediaManager')
  37.  
  38. if not app_path:
  39. log.info("You MUST set EmberMediaManager an env and point to executable")
  40. else:
  41. # build command to run Ember Media Manager and update / scrape new Movie
  42. command = []
  43. command.append(app_path)
  44. command.append(u'-profile')
  45. command.append(u'redglory')
  46. command.append(u'-scanfolder')
  47. command.append(u'"{}"'.format(os.environ.get('Radarr_Movie_Path')))
  48. command.append(u'-scrapemovies')
  49. command.append(u'newauto')
  50. command.append(u'all')
  51. command.append(u'-nowindow')
  52.  
  53. startTime = time.time()
  54.  
  55. log.info("Starting Ember Media Manager with application arguments: %s", str(command))
  56. log.info("Movie Title: %s", os.environ.get('Radarr_Movie_Title'))
  57. log.info("Movie Full Path: %s", os.environ.get('Radarr_Movie_Path'))
  58. log.info("Movie IMDB ID: %s", os.environ.get('Radarr_Movie_ImdbId'))
  59.  
  60. try:
  61. p = Popen(command, stdout=PIPE, stderr=PIPE)
  62. log.info("Ember Media Manager: running on PID: (" + str(p.pid) + ")")
  63. output, error = p.communicate()
  64. if p.returncode == 0:
  65. endTime = time.time()
  66. log.info("Ember Media Manager ran sucessfully for: %s seconds", str(int(endTime - startTime)))
  67. else:
  68. log.error("Ember Media Manager failed with: %d %s %s" % (p.returncode, output, error))
  69. except:
  70. log.error("Oh No! Something went wrong!: %s", traceback.format_exc())
RAW Paste Data