redglory

nzbToCouchpotato.py

Jul 29th, 2013
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. ##############################################################################
  4. ### NZBGET POST-PROCESSING SCRIPT                                          ###
  5.  
  6. # Post-Process to CouchPotato.
  7. #
  8. # This script sends the download to your automated media management servers.
  9. #
  10. # NOTE: This script requires Python to be installed on your system.
  11.  
  12. ##############################################################################
  13. ### OPTIONS                                                                ###
  14.  
  15. ## CouchPotato
  16.  
  17. # CouchPotato script category.
  18. #
  19. # category that gets called for post-processing with CouchPotatoServer.
  20. #cpsCategory=movie
  21.  
  22. # CouchPotato api key.
  23. #cpsapikey=
  24.  
  25. # CouchPotato host.
  26. #cpshost=localhost
  27.  
  28. # CouchPotato port.
  29. #cpsport=5050
  30.  
  31. # CouchPotato username.
  32. #cpsusername=
  33.  
  34. # CouchPotato password.
  35. #cpspassword=
  36.  
  37. # CouchPotato uses ssl (0, 1).
  38. #
  39. # Set to 1 if using ssl, else set to 0.
  40. #cpsssl=0
  41.  
  42. # CouchPotato URL_Base
  43. #
  44. # set this if using a reverse proxy.
  45. #cpsweb_root=
  46.  
  47. # CouchPotato Postprocess Delay.
  48. #
  49. # must be at least 60 seconds.
  50. #cpsdelay=65
  51.  
  52. # CouchPotato Postprocess Method (renamer, manage).
  53. #
  54. # use "renamer" for CPS renamer (default) or "manage" to call a manage update.
  55. #cpsmethod=renamer
  56.  
  57. # CouchPotato Delete Failed Downloads (0, 1).
  58. #
  59. # set to 1 to delete failed, or 0 to leave files in place.
  60. #cpsdelete_failed=0
  61.  
  62. ## Extensions
  63.  
  64. # Media Extensions
  65. #
  66. # This is a list of media extensions that may be transcoded if transcoder is enabled below.
  67. #mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso
  68.  
  69. ## Transcoder
  70.  
  71. # Transcode (0, 1).
  72. #
  73. # set to 1 to transcode, otherwise set to 0.
  74. #transcode=0
  75.  
  76. # create a duplicate, or replace the original (0, 1).
  77. #
  78. # set to 1 to cretae a new file or 0 to replace the original
  79. #duplicate=1
  80.  
  81. # ignore extensions
  82. #
  83. # list of extensions that won't be transcoded.
  84. #ignoreExtensions=.avi,.mkv
  85.  
  86. # ffmpeg output settings.
  87. #outputVideoExtension=.mp4
  88. #outputVideoCodec=libx264
  89. #outputVideoPreset=medium
  90. #outputVideoFramerate=24
  91. #outputVideoBitrate=800k
  92. #outputAudioCodec=libmp3lame
  93. #outputAudioBitrate=128k
  94. #outputSubtitleCodec=
  95.  
  96. ## WakeOnLan
  97.  
  98. # use WOL (0, 1).
  99. #
  100. # set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified.
  101. #wolwake=0
  102.  
  103. # WOL MAC
  104. #
  105. # enter the mac address of the system to be woken.
  106. #wolmac=00:01:2e:2D:64:e1
  107.  
  108. # Set the Host and Port of a server to verify system has woken.
  109. #wolhost=192.168.1.37
  110. #wolport=80
  111.  
  112. ### NZBGET POST-PROCESSING SCRIPT                                          ###
  113. ##############################################################################
  114.  
  115. import os
  116. import sys
  117. import logging
  118. import shlex
  119.  
  120. import autoProcess.migratecfg as migratecfg
  121. import autoProcess.autoProcessMovie as autoProcessMovie
  122. from autoProcess.nzbToMediaEnv import *
  123. from autoProcess.nzbToMediaUtil import *
  124.  
  125. #check to migrate old cfg before trying to load.
  126. if os.path.isfile(os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMedia.cfg.sample")):
  127.     migratecfg.migrate()
  128.  
  129. nzbtomedia_configure_logging(os.path.dirname(sys.argv[0]))
  130. Logger = logging.getLogger(__name__)
  131.  
  132. Logger.info("====================") # Seperate old from new log
  133. Logger.info("nzbToCouchPotato %s", VERSION)
  134.  
  135. #WakeUp()
  136.  
  137. # SABnzbd
  138. if len(sys.argv) == SABNZB_NO_OF_ARGUMENTS:
  139.     # SABnzbd argv:
  140.     # 1 The final directory of the job (full path)
  141.     # 2 The original name of the NZB file
  142.     # 3 Clean version of the job name (no path info and ".nzb" removed)
  143.     # 4 Indexer's report number (if supported)
  144.     # 5 User-defined category
  145.     # 6 Group that the NZB was posted in e.g. alt.binaries.x
  146.     # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
  147.     Logger.info("Script triggered from SABnzbd, starting autoProcessMovie...")
  148.     clientAgent = "sabnzbd"
  149.     Logger.info('SABnzbd command-line arguments ( ' + str(len(sys.argv)) + ' ): ' + str(sys.argv))    
  150.     result = autoProcessMovie.process(sys.argv[1], sys.argv[2], sys.argv[7], clientAgent)
  151. else:
  152.     Logger.warn("Invalid number of arguments received from client.")
  153.     Logger.info("Running autoProcessMovie as a manual run...")
  154.     clientAgent = "manual"
  155.     result = autoProcessMovie.process('Manual Run', 'Manual Run', 0, clientAgent)
  156.  
  157. if result == 0:
  158.     # Logger.info("Checking SABnzbd status...")
  159.     # autoProcessMovie.check_sabnzbd()
  160.     # Run Ember Media Manager to scrapre additional data
  161.     Logger.info("Launching Ember Media Manager to scrape additional data...")
  162.     result = autoProcessMovie.run_ember()
  163.     if result == 0:
  164.         # SUCCESS: Ember Media Manager ran successfully!
  165.         Logger.info("Ember Media Manager ran successfully.")
  166.         # Update XBMC Video Library
  167.         Logger.info("Building XBMC JSON Object")
  168.         xbmc = autoProcessMovie.get_xbmc_json_obj()
  169.         Logger.info("Update XBMC Video Library...")
  170.         autoProcessMovie.update_videolibrary(xbmc)
  171.         # SUCCESS: autoProcessMovie script ran successfully!
  172.         Logger.info("The autoProcessMovie script completed successfully.")
  173.     else:
  174.         # FAILURE: Ember Media Manager didn't run as expected!
  175.         Logger.info("Ember Media Manager didn't run as expected!")
  176.         Logger.info("MUST Run Ember Media Manager manually before updating XBMC Video Library!")
  177. else:
  178.     Logger.info("A problem was reported in the autoProcessMovie script.")
Advertisement
Add Comment
Please, Sign In to add comment