Created
March 20, 2022 12:22
-
-
Save Kakise/d1f6f0ad9e4649ddb476684142285c14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
########################################## | |
### NZBGET POST-PROCESSING SCRIPT ### | |
# Run untar on tar archives. | |
# | |
# Extract tar archives automatically after download | |
# Mainly used with Lidarr and Headphones as an indexer as some repacks and other files are | |
# in a tar archive and won't be detected by Lidarr unless it's extracted by nzbget after download. | |
# With this script I had success with the import, rename and managements of album in a tar archive. | |
# Made by Kakise, originally used with nzbget, nzbfinder, headphones & Lidarr | |
# | |
# | |
### NZBGET POST-PROCESSING SCRIPT ### | |
########################################### | |
import sys | |
import os | |
import re | |
# Exit codes used by NZBGet | |
POSTPROCESS_SUCCESS = 93 | |
POSTPROCESS_NONE = 95 | |
POSTPROCESS_ERROR = 94 | |
tarExt = re.compile(r'^.*\.(?!tar).*$') | |
print('Current directory:' + str(os.environ['NZBPP_DIRECTORY'])) | |
files = False | |
for (dirname, dirnames, filenames) in \ | |
os.walk(os.environ['NZBPP_DIRECTORY']): | |
for filename in filenames: | |
print('Processing file: ' + str(os.path.join(dirname, | |
filename))) | |
if tarExt.match(str(os.path.join(dirname, filename))): | |
print("File "+str(os.path.join(dirname, | |
filename))+" is a tar archive") | |
os.system('cd "' + str(os.environ['NZBPP_DIRECTORY']) + '"; tar -xvf "' + str(os.path.join(dirname, filename)) | |
+ '"') | |
files = True | |
if not files: | |
print('<no tar archive found in the destination directory (moved by a script?)>') | |
sys.exit(POSTPROCESS_NONE) | |
sys.exit(POSTPROCESS_SUCCESS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment