Skip to content

Instantly share code, notes, and snippets.

@Safihre
Created October 28, 2017 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Safihre/8fda8c55c589fb8234072dfeadb881a4 to your computer and use it in GitHub Desktop.
Save Safihre/8fda8c55c589fb8234072dfeadb881a4 to your computer and use it in GitHub Desktop.
SABnzbdUnwantedExtensions.py
#!/usr/bin/python -OO
# Copyright 2008-2017 The SABnzbd-Team <team@sabnzbd.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
Unwanted extensions post-processing script for SABnzbd
Make sure to enable "Post-processing script can flag job as failed"
"""
import os
import sys
# Extensions that should trigger failure.
# Make sure to use lowercase!
BAD_EXT = ('.avi', '.m2ts', '.bin')
# Are we being called from SABnzbd?
if not os.environ.get('SAB_VERSION'):
print "This script needs to be called from SABnzbd as post-processing script."
sys.exit(1)
# Search for bad files
for root, dirnames, filenames in os.walk(os.environ['SAB_COMPLETE_DIR']):
# Filter for each folder
bad_files = [filename for filename in filenames if os.path.splitext(filename)[1].lower() in BAD_EXT]
if any(bad_files):
# Found, let's fail
print bad_files
print "Found files matching unwanted extensions!"
sys.exit(1)
# Nothing, all good
print "No unwanted extensions found!"
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment